Skip to content

Commit 5b1aa27

Browse files
committed
Symbols Approach for Addressables
Modifed UnComment for Addressables code into a Settings in Build Settings Editor Window
1 parent 788b1cf commit 5b1aa27

File tree

12 files changed

+239
-30
lines changed

12 files changed

+239
-30
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"visualstudiotoolsforunity.vstuc"
4+
]
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Attach to Unity",
6+
"type": "vstuc",
7+
"request": "attach"
8+
}
9+
]
10+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"files.exclude": {
3+
"**/.DS_Store": true,
4+
"**/.git": true,
5+
"**/.gitmodules": true,
6+
"**/*.booproj": true,
7+
"**/*.pidb": true,
8+
"**/*.suo": true,
9+
"**/*.user": true,
10+
"**/*.userprefs": true,
11+
"**/*.unityproj": true,
12+
"**/*.dll": true,
13+
"**/*.exe": true,
14+
"**/*.pdf": true,
15+
"**/*.mid": true,
16+
"**/*.midi": true,
17+
"**/*.wav": true,
18+
"**/*.gif": true,
19+
"**/*.ico": true,
20+
"**/*.jpg": true,
21+
"**/*.jpeg": true,
22+
"**/*.png": true,
23+
"**/*.psd": true,
24+
"**/*.tga": true,
25+
"**/*.tif": true,
26+
"**/*.tiff": true,
27+
"**/*.3ds": true,
28+
"**/*.3DS": true,
29+
"**/*.fbx": true,
30+
"**/*.FBX": true,
31+
"**/*.lxo": true,
32+
"**/*.LXO": true,
33+
"**/*.ma": true,
34+
"**/*.MA": true,
35+
"**/*.obj": true,
36+
"**/*.OBJ": true,
37+
"**/*.asset": true,
38+
"**/*.cubemap": true,
39+
"**/*.flare": true,
40+
"**/*.mat": true,
41+
"**/*.meta": true,
42+
"**/*.prefab": true,
43+
"**/*.unity": true,
44+
"build/": true,
45+
"Build/": true,
46+
"Library/": true,
47+
"library/": true,
48+
"obj/": true,
49+
"Obj/": true,
50+
"ProjectSettings/": true,
51+
"temp/": true,
52+
"Temp/": true
53+
},
54+
"dotnet.defaultSolution": "DemoApp.sln"
55+
}

example/unity/DemoApp/Assets/FlutterUnityIntegration/Editor/Build.cs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
using Application = UnityEngine.Application;
99
using BuildResult = UnityEditor.Build.Reporting.BuildResult;
1010

11+
#if USING_ADDRESSABLES
1112
// uncomment for addressables
1213
//using UnityEditor.AddressableAssets;
1314
//using UnityEditor.AddressableAssets.Settings;
15+
#endif
1416

1517
namespace FlutterUnityIntegration.Editor
1618
{
@@ -28,6 +30,13 @@ public class Build : EditorWindow
2830
private bool _pluginMode = false;
2931
private static string _persistentKey = "flutter-unity-widget-pluginMode";
3032

33+
private const string USING_ADDRESSABLES = "USING_ADDRESSABLES";
34+
private static string _persistentKeyHasAddressable = "flutter-unity-widget-hasAddressable";
35+
private static bool _usingAddressables = false;
36+
37+
bool hasChanges = false;
38+
39+
3140
//#region GUI Member Methods
3241
[MenuItem("Flutter/Export Android (Debug) %&n", false, 101)]
3342
public static void DoBuildAndroidLibraryDebug()
@@ -101,6 +110,41 @@ private void OnGUI()
101110
{
102111
EditorPrefs.SetBool(_persistentKey, _pluginMode);
103112
}
113+
114+
using (new EditorGUILayout.HorizontalScope())
115+
{
116+
117+
EditorGUI.BeginChangeCheck();
118+
_usingAddressables = EditorGUILayout.Toggle("Using Addressables", _usingAddressables);
119+
if (EditorGUI.EndChangeCheck())
120+
{
121+
EditorPrefs.SetBool(_persistentKeyHasAddressable, _usingAddressables);
122+
hasChanges = true;
123+
Repaint();
124+
}
125+
126+
if (GUILayout.Button("Apply Symbols"))
127+
{
128+
if (hasChanges)
129+
{
130+
Apply();
131+
Repaint();
132+
}
133+
else
134+
{
135+
Debug.Log("No Changes required!");
136+
}
137+
}
138+
}
139+
140+
}
141+
142+
private void Apply()
143+
{
144+
EditorApplication.delayCall += () => {
145+
SymbolDefineHelper.SetScriptingDefine(USING_ADDRESSABLES, _usingAddressables);
146+
};
147+
Close();
104148
}
105149

106150
private void OnEnable()
@@ -537,7 +581,7 @@ private static string[] GetEnabledScenes()
537581

538582
// uncomment for addressables
539583
private static void ExportAddressables() {
540-
/*
584+
#if USING_ADDRESSABLES
541585
Debug.Log("Start building player content (Addressables)");
542586
Debug.Log("BuildAddressablesProcessor.PreExport start");
543587

@@ -550,7 +594,7 @@ private static void ExportAddressables() {
550594

551595
AddressableAssetSettings.BuildPlayerContent();
552596
Debug.Log("BuildAddressablesProcessor.PreExport done");
553-
*/
597+
#endif
554598
}
555599

556600

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "FlutterUnityIntegration.Editor",
3+
"rootNamespace": "FlutterUnityIntegration.Editor",
4+
"references": [],
5+
"includePlatforms": [
6+
"Editor"
7+
],
8+
"excludePlatforms": [],
9+
"allowUnsafeCode": false,
10+
"overrideReferences": false,
11+
"precompiledReferences": [],
12+
"autoReferenced": true,
13+
"defineConstraints": [],
14+
"versionDefines": [],
15+
"noEngineReferences": false
16+
}

example/unity/DemoApp/Assets/FlutterUnityIntegration/Editor/FlutterUnityIntegration.Editor.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.Collections.Generic;
2+
using UnityEditor;
3+
using UnityEditor.Build;
4+
using UnityEngine;
5+
6+
namespace FlutterUnityIntegration.Editor
7+
{
8+
public static class SymbolDefineHelper
9+
{
10+
public static void SetScriptingDefine(string symbol, bool enable)
11+
{
12+
bool changesMade = false;
13+
14+
// Iterate over all named build targets available
15+
foreach (NamedBuildTarget namedTarget in GetAllNamedBuildTargets())
16+
{
17+
string defines = PlayerSettings.GetScriptingDefineSymbols(namedTarget);
18+
var defineList = new List<string>(defines.Split(';'));
19+
20+
bool contains = defineList.Contains(symbol);
21+
22+
if (enable && !contains)
23+
{
24+
defineList.Add(symbol);
25+
changesMade = true;
26+
Debug.Log($"Added '{symbol}' to {namedTarget.TargetName}");
27+
}
28+
else if (!enable && contains)
29+
{
30+
defineList.Remove(symbol);
31+
changesMade = true;
32+
Debug.Log($"Removed '{symbol}' from {namedTarget.TargetName}");
33+
}
34+
35+
string updatedDefines = string.Join(";", defineList);
36+
PlayerSettings.SetScriptingDefineSymbols(namedTarget, updatedDefines);
37+
}
38+
39+
if (changesMade)
40+
{
41+
EditorUtility.RequestScriptReload();
42+
Debug.Log("Script reload requested.");
43+
}
44+
else
45+
{
46+
Debug.Log("No changes made to scripting define symbols.");
47+
}
48+
}
49+
50+
private static IEnumerable<NamedBuildTarget> GetAllNamedBuildTargets()
51+
{
52+
yield return NamedBuildTarget.FromBuildTargetGroup(BuildTargetGroup.Standalone);
53+
yield return NamedBuildTarget.FromBuildTargetGroup(BuildTargetGroup.Android);
54+
yield return NamedBuildTarget.FromBuildTargetGroup(BuildTargetGroup.iOS);
55+
yield return NamedBuildTarget.FromBuildTargetGroup(BuildTargetGroup.WebGL);
56+
}
57+
}
58+
}

example/unity/DemoApp/Assets/FlutterUnityIntegration/Editor/SymbolDefineHelper.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/unity/DemoApp/Packages/manifest.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"dependencies": {
33
"com.unity.collab-proxy": "2.7.1",
4-
"com.unity.ext.nunit": "1.0.6",
4+
"com.unity.ext.nunit": "2.0.5",
55
"com.unity.ide.rider": "3.0.36",
66
"com.unity.ide.visualstudio": "2.0.23",
7-
"com.unity.ide.vscode": "1.2.5",
8-
"com.unity.test-framework": "1.1.33",
9-
"com.unity.textmeshpro": "3.0.9",
10-
"com.unity.timeline": "1.7.7",
11-
"com.unity.ugui": "1.0.0",
7+
"com.unity.multiplayer.center": "1.0.0",
8+
"com.unity.test-framework": "1.4.5",
9+
"com.unity.timeline": "1.8.7",
10+
"com.unity.ugui": "2.0.0",
11+
"com.unity.modules.accessibility": "1.0.0",
1212
"com.unity.modules.ai": "1.0.0",
1313
"com.unity.modules.androidjni": "1.0.0",
1414
"com.unity.modules.animation": "1.0.0",

example/unity/DemoApp/Packages/packages-lock.json

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"url": "https://packages.unity.com"
99
},
1010
"com.unity.ext.nunit": {
11-
"version": "1.0.6",
11+
"version": "2.0.5",
1212
"depth": 0,
1313
"source": "registry",
1414
"dependencies": {},
@@ -32,35 +32,27 @@
3232
},
3333
"url": "https://packages.unity.com"
3434
},
35-
"com.unity.ide.vscode": {
36-
"version": "1.2.5",
35+
"com.unity.multiplayer.center": {
36+
"version": "1.0.0",
3737
"depth": 0,
38-
"source": "registry",
39-
"dependencies": {},
40-
"url": "https://packages.unity.com"
38+
"source": "builtin",
39+
"dependencies": {
40+
"com.unity.modules.uielements": "1.0.0"
41+
}
4142
},
4243
"com.unity.test-framework": {
43-
"version": "1.1.33",
44+
"version": "1.4.5",
4445
"depth": 0,
4546
"source": "registry",
4647
"dependencies": {
47-
"com.unity.ext.nunit": "1.0.6",
48+
"com.unity.ext.nunit": "2.0.3",
4849
"com.unity.modules.imgui": "1.0.0",
4950
"com.unity.modules.jsonserialize": "1.0.0"
5051
},
5152
"url": "https://packages.unity.com"
5253
},
53-
"com.unity.textmeshpro": {
54-
"version": "3.0.9",
55-
"depth": 0,
56-
"source": "registry",
57-
"dependencies": {
58-
"com.unity.ugui": "1.0.0"
59-
},
60-
"url": "https://packages.unity.com"
61-
},
6254
"com.unity.timeline": {
63-
"version": "1.7.7",
55+
"version": "1.8.7",
6456
"depth": 0,
6557
"source": "registry",
6658
"dependencies": {
@@ -72,14 +64,20 @@
7264
"url": "https://packages.unity.com"
7365
},
7466
"com.unity.ugui": {
75-
"version": "1.0.0",
67+
"version": "2.0.0",
7668
"depth": 0,
7769
"source": "builtin",
7870
"dependencies": {
7971
"com.unity.modules.ui": "1.0.0",
8072
"com.unity.modules.imgui": "1.0.0"
8173
}
8274
},
75+
"com.unity.modules.accessibility": {
76+
"version": "1.0.0",
77+
"depth": 0,
78+
"source": "builtin",
79+
"dependencies": {}
80+
},
8381
"com.unity.modules.ai": {
8482
"version": "1.0.0",
8583
"depth": 0,
@@ -127,6 +125,12 @@
127125
"com.unity.modules.animation": "1.0.0"
128126
}
129127
},
128+
"com.unity.modules.hierarchycore": {
129+
"version": "1.0.0",
130+
"depth": 1,
131+
"source": "builtin",
132+
"dependencies": {}
133+
},
130134
"com.unity.modules.imageconversion": {
131135
"version": "1.0.0",
132136
"depth": 0,
@@ -215,7 +219,8 @@
215219
"dependencies": {
216220
"com.unity.modules.ui": "1.0.0",
217221
"com.unity.modules.imgui": "1.0.0",
218-
"com.unity.modules.jsonserialize": "1.0.0"
222+
"com.unity.modules.jsonserialize": "1.0.0",
223+
"com.unity.modules.hierarchycore": "1.0.0"
219224
}
220225
},
221226
"com.unity.modules.umbra": {

0 commit comments

Comments
 (0)