Skip to content

Commit cfc112d

Browse files
sample app restructuring WIP
1 parent 16c07fc commit cfc112d

File tree

90 files changed

+2183
-1645
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+2183
-1645
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
using System;
4+
using Object = UnityEngine.Object;
5+
6+
public class AttachAllFeatureScripts
7+
{
8+
[MenuItem("Tools/Attach All Passport Feature Scripts To All GameObjects")]
9+
static void AttachScripts()
10+
{
11+
string[] scriptNames = new string[]
12+
{
13+
"LoginScript",
14+
"LogoutScript",
15+
"ReloginScript",
16+
"ReconnectScript",
17+
"GetAccessTokenScript",
18+
"GetIdTokenScript",
19+
"GetUserInfoScript",
20+
"GetLinkedAddressesScript",
21+
"LinkWalletScript",
22+
"ImxConnectScript",
23+
"ImxRegisterScript",
24+
"ImxGetAddressScript",
25+
"ImxNftTransferScript",
26+
"ZkEvmSendTransactionScript",
27+
"ZkEvmGetBalanceScript",
28+
"ZkEvmGetTransactionReceiptScript",
29+
"ZkEvmSignTypedDataScript",
30+
"SetCallTimeoutScript"
31+
};
32+
33+
foreach (GameObject go in Object.FindObjectsOfType<GameObject>())
34+
{
35+
if (!go.scene.isLoaded) continue;
36+
foreach (string scriptName in scriptNames)
37+
{
38+
Type scriptType = GetTypeByName(scriptName);
39+
if (scriptType != null && go.GetComponent(scriptType) == null)
40+
{
41+
go.AddComponent(scriptType);
42+
Debug.Log($"Added {scriptName} to {go.name}");
43+
}
44+
}
45+
}
46+
Debug.Log("All feature scripts attached to all GameObjects in the scene.");
47+
}
48+
49+
static Type GetTypeByName(string typeName)
50+
{
51+
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
52+
{
53+
var type = assembly.GetType(typeName);
54+
if (type != null)
55+
return type;
56+
}
57+
return null;
58+
}
59+
}

sample/Assets/Scripts/Passport/SelectAuthMethodScript.cs.meta renamed to sample/Assets/Editor/AttachAllFeaturesScripts.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
using UnityEngine.UI;
4+
using System;
5+
using System.Reflection;
6+
7+
public class AutoSetupPassportFeatures : EditorWindow
8+
{
9+
[MenuItem("Tools/Auto-Setup Passport Feature Scripts")]
10+
public static void ShowWindow()
11+
{
12+
GetWindow<AutoSetupPassportFeatures>("Auto-Setup Passport Features");
13+
}
14+
15+
void OnGUI()
16+
{
17+
if (GUILayout.Button("Auto-Setup All Passport Feature Scripts in Active Scene"))
18+
{
19+
SetupAllFeatures();
20+
}
21+
}
22+
23+
static void SetupAllFeatures()
24+
{
25+
// List of features and their expected GameObject names
26+
(string scriptName, string goName)[] features = new (string, string)[]
27+
{
28+
("LoginScript", "LoginPanel"),
29+
("LogoutScript", "LogoutPanel"),
30+
("ReloginScript", "ReloginPanel"),
31+
("ReconnectScript", "ReconnectPanel"),
32+
("GetAccessTokenScript", "GetAccessTokenPanel"),
33+
("GetIdTokenScript", "GetIdTokenPanel"),
34+
("GetUserInfoScript", "GetUserInfoPanel"),
35+
("GetLinkedAddressesScript", "GetLinkedAddressesPanel"),
36+
("LinkWalletScript", "LinkWalletPanel"),
37+
("ImxConnectScript", "ImxConnectPanel"),
38+
("ImxRegisterScript", "ImxRegisterPanel"),
39+
("ImxGetAddressScript", "ImxGetAddressPanel"),
40+
("ImxNftTransferScript", "ImxNftTransferPanel"),
41+
("ZkEvmSendTransactionScript", "ZkEvmSendTransactionPanel"),
42+
("ZkEvmGetBalanceScript", "ZkEvmGetBalancePanel"),
43+
("ZkEvmGetTransactionReceiptScript", "ZkEvmGetTransactionReceiptPanel"),
44+
("ZkEvmSignTypedDataScript", "ZkEvmSignTypedDataPanel"),
45+
("SetCallTimeoutScript", "SetCallTimeoutPanel"),
46+
};
47+
48+
foreach (var (scriptName, goName) in features)
49+
{
50+
GameObject go = GameObject.Find(goName);
51+
if (go == null)
52+
{
53+
Debug.LogWarning($"GameObject '{goName}' not found in scene. Skipping {scriptName}.");
54+
continue;
55+
}
56+
57+
// Add the script if not already present
58+
Type scriptType = GetTypeByName(scriptName);
59+
if (scriptType == null)
60+
{
61+
Debug.LogWarning($"Script type '{scriptName}' not found. Make sure the script is compiled.");
62+
continue;
63+
}
64+
if (go.GetComponent(scriptType) == null)
65+
{
66+
go.AddComponent(scriptType);
67+
Debug.Log($"Added {scriptName} to {goName}");
68+
}
69+
70+
// Try to auto-assign UI fields by name
71+
var script = go.GetComponent(scriptType);
72+
if (script != null)
73+
{
74+
var fields = scriptType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
75+
foreach (var field in fields)
76+
{
77+
if (typeof(Component).IsAssignableFrom(field.FieldType))
78+
{
79+
var uiGo = GameObject.Find(field.Name);
80+
if (uiGo != null)
81+
{
82+
var comp = uiGo.GetComponent(field.FieldType);
83+
if (comp != null)
84+
{
85+
field.SetValue(script, comp);
86+
Debug.Log($"Assigned {field.Name} to {scriptName} on {goName}");
87+
}
88+
}
89+
}
90+
}
91+
}
92+
93+
// Try to auto-wire Button OnClick events
94+
var buttons = go.GetComponentsInChildren<Button>(true);
95+
foreach (var button in buttons)
96+
{
97+
string methodName = button.name.Replace("Button", "");
98+
var method = scriptType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
99+
if (method != null)
100+
{
101+
// Remove all existing persistent listeners
102+
int listenerCount = button.onClick.GetPersistentEventCount();
103+
for (int i = listenerCount - 1; i >= 0; i--)
104+
{
105+
UnityEditor.Events.UnityEventTools.RemovePersistentListener(button.onClick, i);
106+
}
107+
// Add the new persistent listener
108+
UnityEditor.Events.UnityEventTools.AddPersistentListener(button.onClick, Delegate.CreateDelegate(typeof(UnityEngine.Events.UnityAction), script, method) as UnityEngine.Events.UnityAction);
109+
Debug.Log($"Wired {button.name} to {methodName} on {scriptName}");
110+
}
111+
}
112+
}
113+
114+
Debug.Log("Auto-setup complete! Please check the Inspector for any fields that could not be auto-assigned.");
115+
}
116+
117+
static Type GetTypeByName(string typeName)
118+
{
119+
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
120+
{
121+
var type = assembly.GetType(typeName);
122+
if (type != null)
123+
return type;
124+
}
125+
return null;
126+
}
127+
}

sample/Assets/Scripts/Passport/AuthenticatedScript.cs.meta renamed to sample/Assets/Editor/AutoSetupPassportFeatures.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
public class ListAllGameObjects
5+
{
6+
[MenuItem("Tools/List All GameObjects In Scene")]
7+
static void ListGameObjects()
8+
{
9+
foreach (GameObject go in Object.FindObjectsOfType<GameObject>())
10+
{
11+
if (go.scene.isLoaded)
12+
Debug.Log(go.name);
13+
}
14+
}
15+
}

sample/Assets/Scripts/Passport/UnauthenticatedScript.cs.meta renamed to sample/Assets/Editor/ListAllGameObjects.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
using UnityEditor.SceneManagement;
4+
using System.IO;
5+
6+
public class FullRemoveMissingScripts
7+
{
8+
[MenuItem("Tools/Full Remove All Missing Scripts (Scenes & Prefabs)")]
9+
static void RemoveAllMissingScriptsEverywhere()
10+
{
11+
int totalRemoved = 0;
12+
13+
// 1. Clean all scenes
14+
string[] scenePaths = Directory.GetFiles("Assets", "*.unity", SearchOption.AllDirectories);
15+
foreach (string scenePath in scenePaths)
16+
{
17+
var scene = EditorSceneManager.OpenScene(scenePath);
18+
int removed = 0;
19+
foreach (GameObject go in Resources.FindObjectsOfTypeAll<GameObject>())
20+
{
21+
if (go.scene == scene && go.hideFlags == HideFlags.None)
22+
{
23+
removed += GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go);
24+
}
25+
}
26+
if (removed > 0)
27+
{
28+
EditorSceneManager.MarkSceneDirty(scene);
29+
EditorSceneManager.SaveScene(scene);
30+
Debug.Log($"Removed {removed} missing scripts from scene: {scenePath}");
31+
totalRemoved += removed;
32+
}
33+
}
34+
35+
// 2. Clean all prefabs
36+
string[] prefabPaths = Directory.GetFiles("Assets", "*.prefab", SearchOption.AllDirectories);
37+
foreach (string prefabPath in prefabPaths)
38+
{
39+
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
40+
if (prefab != null)
41+
{
42+
int removed = GameObjectUtility.RemoveMonoBehavioursWithMissingScript(prefab);
43+
if (removed > 0)
44+
{
45+
PrefabUtility.SavePrefabAsset(prefab);
46+
Debug.Log($"Removed {removed} missing scripts from prefab: {prefabPath}");
47+
totalRemoved += removed;
48+
}
49+
}
50+
}
51+
52+
Debug.Log($"Full cleanup complete. Total missing scripts removed: {totalRemoved}");
53+
AssetDatabase.Refresh();
54+
}
55+
}

sample/Assets/Editor/RemoveMissingScripts.cs.meta

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

sample/Assets/Scenes/Passport/Imx/ImxNftTransfer.unity

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ MonoBehaviour:
658658
m_TargetGraphic: {fileID: 66309839}
659659
m_HandleRect: {fileID: 66309838}
660660
m_Direction: 0
661-
m_Value: 1
661+
m_Value: 0
662662
m_Size: 1
663663
m_NumberOfSteps: 0
664664
m_OnValueChanged:
@@ -866,7 +866,7 @@ MonoBehaviour:
866866
m_OnClick:
867867
m_PersistentCalls:
868868
m_Calls:
869-
- m_Target: {fileID: 1192763474}
869+
- m_Target: {fileID: 0}
870870
m_TargetAssemblyTypeName: ImxNftTransferScript, Assembly-CSharp
871871
m_MethodName: Cancel
872872
m_Mode: 1
@@ -1433,7 +1433,7 @@ MonoBehaviour:
14331433
m_OnClick:
14341434
m_PersistentCalls:
14351435
m_Calls:
1436-
- m_Target: {fileID: 1192763474}
1436+
- m_Target: {fileID: 0}
14371437
m_TargetAssemblyTypeName: ImxNftTransferScript, Assembly-CSharp
14381438
m_MethodName: Transfer
14391439
m_Mode: 1
@@ -1937,7 +1937,7 @@ MonoBehaviour:
19371937
m_TargetGraphic: {fileID: 1741513414}
19381938
m_HandleRect: {fileID: 1741513413}
19391939
m_Direction: 2
1940-
m_Value: 1
1940+
m_Value: 0
19411941
m_Size: 1
19421942
m_NumberOfSteps: 0
19431943
m_OnValueChanged:
@@ -2423,8 +2423,8 @@ RectTransform:
24232423
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
24242424
m_AnchorMin: {x: 0, y: 0}
24252425
m_AnchorMax: {x: 0, y: 0}
2426-
m_AnchoredPosition: {x: 885.5994, y: 0}
2427-
m_SizeDelta: {x: 1771.1991, y: 0}
2426+
m_AnchoredPosition: {x: 1172.8888, y: 0}
2427+
m_SizeDelta: {x: 2345.7776, y: 0}
24282428
m_Pivot: {x: 0.5, y: 0.5}
24292429
--- !u!114 &1128672539
24302430
MonoBehaviour:
@@ -2491,7 +2491,6 @@ GameObject:
24912491
serializedVersion: 6
24922492
m_Component:
24932493
- component: {fileID: 1192763473}
2494-
- component: {fileID: 1192763474}
24952494
m_Layer: 0
24962495
m_Name: Script
24972496
m_TagString: Untagged
@@ -2514,25 +2513,6 @@ Transform:
25142513
m_Father: {fileID: 0}
25152514
m_RootOrder: 2
25162515
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
2517-
--- !u!114 &1192763474
2518-
MonoBehaviour:
2519-
m_ObjectHideFlags: 0
2520-
m_CorrespondingSourceObject: {fileID: 0}
2521-
m_PrefabInstance: {fileID: 0}
2522-
m_PrefabAsset: {fileID: 0}
2523-
m_GameObject: {fileID: 1192763471}
2524-
m_Enabled: 1
2525-
m_EditorHideFlags: 0
2526-
m_Script: {fileID: 11500000, guid: 88155cf2270a947c68f0e5a82c3fc4fc, type: 3}
2527-
m_Name:
2528-
m_EditorClassIdentifier:
2529-
Output: {fileID: 1253661940}
2530-
TokenIdInput1: {fileID: 1142338628823642223}
2531-
TokenAddressInput1: {fileID: 1142338628822901615}
2532-
ReceiverInput1: {fileID: 1142338629240194742}
2533-
TokenIdInput2: {fileID: 1466996334}
2534-
TokenAddressInput2: {fileID: 391016289}
2535-
ReceiverInput2: {fileID: 1072814481}
25362516
--- !u!1 &1193726683
25372517
GameObject:
25382518
m_ObjectHideFlags: 0
@@ -3938,8 +3918,8 @@ RectTransform:
39383918
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
39393919
m_AnchorMin: {x: 0, y: 0}
39403920
m_AnchorMax: {x: 0, y: 0}
3941-
m_AnchoredPosition: {x: 885.59955, y: 0}
3942-
m_SizeDelta: {x: 1771.1991, y: 0}
3921+
m_AnchoredPosition: {x: 1172.8888, y: 0}
3922+
m_SizeDelta: {x: 2345.7776, y: 0}
39433923
m_Pivot: {x: 0.5, y: 0.5}
39443924
--- !u!114 &2125223059
39453925
MonoBehaviour:

0 commit comments

Comments
 (0)