Skip to content

Commit 97b09d5

Browse files
fix: [SDK-4858] align Unity distribution layout (#887)
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 07a3b62 commit 97b09d5

77 files changed

Lines changed: 1456 additions & 556 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
import re
5+
import sys
6+
from pathlib import Path
7+
8+
9+
ROOT = Path(__file__).resolve().parents[2]
10+
DEMO = ROOT / "examples/demo"
11+
BOOTSTRAP = ROOT / "examples/demo/Assets/OneSignal"
12+
SAMPLE = ROOT / "com.onesignal.unity.core/Samples~"
13+
INVENTORY = BOOTSTRAP / "Editor/Resources/OneSignalFileInventory.asset"
14+
15+
EXCLUDED_PREFIXES = (
16+
"Assets/OneSignal/Attribution",
17+
"Assets/OneSignal/Example",
18+
)
19+
EXCLUDED_FILES = {
20+
"Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml",
21+
"Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml.meta",
22+
"Assets/OneSignal/Editor/OneSignaliOSDependencies.xml",
23+
"Assets/OneSignal/Editor/OneSignaliOSDependencies.xml.meta",
24+
}
25+
REQUIRED_SAMPLE_GUIDS = {
26+
"OneSignal.UnityPackage.Example.asmdef.meta": "a28dab59edddfb3448f1fd9318f85c32",
27+
"OneSignalExampleBehaviour.cs.meta": "1a40a711031e4cb8b9b3f674dda19d55",
28+
"OneSignalExampleScene.unity.meta": "54284d014d2241544a24b57b13c09ac8",
29+
"INCONSOLATA-VARIABLEFONT_WDTH,WGHT.TTF.meta": "792110c4f5f19e64196eb25f41c0b783",
30+
}
31+
32+
33+
def fail(message: str) -> None:
34+
print(f"Unity distribution validation failed: {message}", file=sys.stderr)
35+
raise SystemExit(1)
36+
37+
38+
def is_distributed(path: str) -> bool:
39+
if path in EXCLUDED_FILES or path.endswith("/.DS_Store"):
40+
return False
41+
return not any(
42+
path == prefix
43+
or path == f"{prefix}.meta"
44+
or path.startswith(f"{prefix}/")
45+
for prefix in EXCLUDED_PREFIXES
46+
)
47+
48+
49+
def validate_inventory() -> None:
50+
actual = sorted(
51+
path.relative_to(DEMO).as_posix()
52+
for path in BOOTSTRAP.rglob("*")
53+
if path.is_file() and is_distributed(path.relative_to(DEMO).as_posix())
54+
)
55+
recorded = re.findall(r"^\s*-\s+(Assets/OneSignal/.+)$", INVENTORY.read_text(), re.MULTILINE)
56+
57+
if actual != recorded:
58+
missing = sorted(set(actual) - set(recorded))
59+
stale = sorted(set(recorded) - set(actual))
60+
fail(
61+
"file inventory is out of date"
62+
+ (f"; missing: {', '.join(missing)}" if missing else "")
63+
+ (f"; stale: {', '.join(stale)}" if stale else "")
64+
)
65+
66+
67+
def validate_sample() -> None:
68+
for filename, expected_guid in REQUIRED_SAMPLE_GUIDS.items():
69+
path = SAMPLE / filename
70+
if not path.is_file():
71+
fail(f"sample is missing {path.relative_to(ROOT)}")
72+
match = re.search(r"^guid:\s*(\w+)$", path.read_text(), re.MULTILINE)
73+
if match is None or match.group(1) != expected_guid:
74+
fail(f"{path.relative_to(ROOT)} does not preserve GUID {expected_guid}")
75+
76+
scene = (SAMPLE / "OneSignalExampleScene.unity").read_text()
77+
if "OneSignalSDK.OneSignalExampleBehaviour" in scene:
78+
fail("sample scene contains stale OneSignalExampleBehaviour type references")
79+
if "OneSignalExampleBehaviour, OneSignal.UnityPackage.Example" not in scene:
80+
fail("sample scene does not contain OneSignalExampleBehaviour button bindings")
81+
behaviour = (SAMPLE / "OneSignalExampleBehaviour.cs").read_text()
82+
if "ExitLiveActivityAsync" in scene or "LiveActivities.ExitAsync" in behaviour:
83+
fail("sample exposes the deprecated Live Activities exit API")
84+
85+
asmdef = json.loads((SAMPLE / "OneSignal.UnityPackage.Example.asmdef").read_text())
86+
required_references = {
87+
"OneSignal.Core",
88+
"UnityEngine.UI",
89+
"UnityEngine.JSONSerializeModule",
90+
}
91+
if not required_references.issubset(asmdef["references"]):
92+
fail("sample assembly is missing required references")
93+
94+
package = json.loads((ROOT / "com.onesignal.unity.core/package.json").read_text())
95+
if not any(sample.get("path") == "Samples~" for sample in package.get("samples", [])):
96+
fail("core package does not register Samples~")
97+
if not any(
98+
version.get("name") == "com.onesignal.unity.core"
99+
and version.get("expression") == package["version"]
100+
and version.get("define") == "ONE_SIGNAL_INSTALLED"
101+
for version in asmdef.get("versionDefines", [])
102+
):
103+
fail("sample version define does not match the core package version")
104+
105+
106+
def main() -> None:
107+
if (BOOTSTRAP / "Example").exists() or (BOOTSTRAP / "Example.meta").exists():
108+
fail("empty legacy Asset Store Example path still exists")
109+
if (BOOTSTRAP / "Documentation~").exists():
110+
fail("Documentation~ is hidden from Unity and cannot be exported")
111+
if not (BOOTSTRAP / "Documentation").is_dir():
112+
fail("exportable bootstrap documentation is missing")
113+
validate_inventory()
114+
validate_sample()
115+
print("Unity distribution layout is valid.")
116+
117+
118+
if __name__ == "__main__":
119+
main()

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ jobs:
2222

2323
- name: Check formatting
2424
run: csharpier check .
25+
26+
- name: Validate Unity distribution layout
27+
run: python3 .github/scripts/validate-unity-distribution.py

‎CONTRIBUTING.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Before creating bug reports, please check this list of steps to follow.
2020

2121
#### How Do I Submit a Good Bug Report
2222
* **Use a clear and descriptive title** for the issue to identify the problem.
23-
* **Include Reproducibility** It is nearly always a good idea to include steps to reproduct the issue. If you cannot reliably reproduce the issue yourself, that's ok, but reproducible steps help best.
23+
* **Include Reproducibility** It is nearly always a good idea to include steps to reproduce the issue. If you cannot reliably reproduce the issue yourself, that's ok, but reproducible steps help best.
2424
* **Describe your environment**, tell us what version of the Unity OneSignal SDK you are using, what platforms the issue occurs on (android/iOS), related code samples, and so on.
2525
* **Include a Stack Trace** If your issue involves a crash/exception, ***PLEASE*** post the stack trace to help us identify the root issue.
26-
* **Include an Example Project** This isn't required, but if you want your issue fixed quickly, it's often a good idea to include an example project as a zip and include it with the issue. You can also download the Demo project (included in the `/OneSignalExample` folder of this repo) and set up an example project with this code as a starting point.
26+
* **Include an Example Project** This isn't required, but if you want your issue fixed quickly, it's often a good idea to include an example project as a zip and include it with the issue. You can also use the Demo project in [`examples/demo`](examples/demo) as a starting point.
-15.8 KB
Binary file not shown.

‎Documentation/menu_my_assets.png‎

-8.8 KB
Binary file not shown.
-6.92 KB
Binary file not shown.

‎Documentation/outdated_callout.png‎

-8.78 KB
Binary file not shown.

‎Documentation/package_import.png‎

-32.1 KB
Binary file not shown.

‎MIGRATION_GUIDE_v3_to_v5.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ The debug namespace is accessible via `OneSignal.Debug` and provides access to d
289289
# Troubleshooting
290290
## Android
291291
```
292-
Assets/OneSignal/Example/OneSignalExampleBehaviou.cs: error CS0246: The type or namespace name '...' could not be found (are you missing a using directive or an assembly reference?)
292+
Assets/Samples/OneSignal Unity SDK - Core/<version>/Full Usage/OneSignalExampleBehaviour.cs: error CS0246: The type or namespace name '...' could not be found (are you missing a using directive or an assembly reference?)
293293
```
294294

295295
```

‎README.md‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ If you run into any challenges or have concerns, please contact our support team
2020

2121
A free email, sms, push notification and in app messaging solution for mobile applications built through Unity.
2222

23-
[OneSignal](https://onesignal.com) provides a fully array of omni-channel messaging solutions across:
23+
[OneSignal](https://onesignal.com) provides a full array of omni-channel messaging solutions across:
2424

2525
- Push Notifications (mobile & web)
2626
- In App Messages
@@ -76,15 +76,15 @@ There are two methods of installation available for the OneSignal Unity SDK:
7676
2. Find the package waiting for you to download by clicking **Open in Unity** from that same page. This will open the Unity Editor and its Package Manager window.
7777
3. On the SDK's listing in the Editor click the **Download** button. When it finishes click **Import**.
7878

79-
![onesignal unity sdk in my assets](Documentation/asset_listing.png)
79+
![onesignal unity sdk in my assets](examples/demo/Assets/OneSignal/Documentation/asset_listing.png)
8080

8181
4. A prompt to import all of the files of the OneSignal Unity SDK will appear. Click **Import** to continue and compile the scripts into your project.
8282
5. Navigate to **Window > OneSignal SDK Setup** (or follow the popup if upgrading) in the Unity Editor which will bring up a window with some final steps which need
8383
to be completed in order to finalize the installation. The most important of these steps is **Import OneSignal packages**.
8484

8585
> *Depending on your project configuration and if you are upgrading from a previous version, some of these steps may already be marked as "completed"*
8686
87-
![sdk setup steps window](Documentation/setup_window.png)
87+
![sdk setup steps window](examples/demo/Assets/OneSignal/Documentation/setup_window.png)
8888

8989
6. After importing the packages Unity will notify you that a new registry has been added and the **OneSignal SDK Setup** window will have refreshed with a few additional
9090
steps. Following these will finalize your installation of the OneSignal Unity SDK.
@@ -95,7 +95,7 @@ There are two methods of installation available for the OneSignal Unity SDK:
9595

9696
1. From within the Unity Editor navigate to **Edit > Project Settings** and then to the **Package Manager** settings tab.
9797

98-
![unity registry manager](Documentation/package_manager_tab.png)
98+
![unity registry manager](examples/demo/Assets/OneSignal/Documentation/package_manager_tab.png)
9999

100100
2. Create a *New Scoped Registry* by entering
101101
```
@@ -111,7 +111,7 @@ There are two methods of installation available for the OneSignal Unity SDK:
111111
112112
> *Depending on your project configuration and if you are upgrading from a previous version, some of these steps may already be marked as "completed"*
113113
114-
![my registries menu selection](Documentation/registry_menu.png)
114+
![my registries menu selection](examples/demo/Assets/OneSignal/Documentation/registry_menu.png)
115115
116116
</details>
117117
@@ -122,16 +122,16 @@ After building in Unity and exporting the XCode project follow these steps:
122122
2. Click on the **Unity-iPhone** project and its similarly named target and select the **Signing & Capabilities** tab.
123123
3. From here check **Automatically manage signing**, on the prompt click **Enable Automatic**, and select your **Team**.
124124
125-
![automatically manage signing](Documentation/ios_auto_sign.png)
125+
![automatically manage signing](examples/demo/Assets/OneSignal/Documentation/ios_auto_sign.png)
126126
127127
4. Scroll down to **App Groups** and click on the refresh button.
128128
> NOTE: You may have to press this a few times as it will ask you for each signing type.
129129
130-
![refresh app groups](Documentation/ios_refresh_app_groups.png)
130+
![refresh app groups](examples/demo/Assets/OneSignal/Documentation/ios_refresh_app_groups.png)
131131
132132
5. Repeat the same steps above but for the **OneSignalNotificationServiceExtension** target this time.
133133
134-
![extension signing and groups](Documentation/ios_extension_sign_and_groups.png)
134+
![extension signing and groups](examples/demo/Assets/OneSignal/Documentation/ios_extension_sign_and_groups.png)
135135
136136
6. **App Groups** should now be provisioned for you going forward for your iOS bundle id, even on clean builds.
137137
@@ -168,8 +168,7 @@ With the location module disabled, Android resolves OneSignal's native modules w
168168
When toggling the flag, clear stale native outputs (the generated Xcode project, CocoaPods/Gradle caches, and prior `Build/` artifacts) so a previously linked location module isn't reused.
169169

170170
## Usage
171-
You can find a complete implementation in our included [example MonoBehaviour](OneSignalExample/Assets/OneSignal/Example/OneSignalExampleBehaviour.cs). Additionally we have included a
172-
[sample scene](OneSignalExample/Assets/OneSignal/Example/OneSignalExampleScene.unity) which you can run to test out the SDK.
171+
For a compact implementation of the major SDK features, open **Window > Package Manager**, select **OneSignal Unity SDK - Core**, and import the **Full Usage** sample. The sample requires Unity UI (`com.unity.ugui`). The repository's complete development demo is available in [`examples/demo`](examples/demo).
173172

174173
### Initialization
175174
#### Prefab

0 commit comments

Comments
 (0)