11using System ;
22using System . Collections . Generic ;
33using System . Runtime . CompilerServices ;
4+ using System . Windows . Forms ;
45using Luau ;
56using UnityEngine ;
67
@@ -25,12 +26,12 @@ private static int PushEmptyTable(IntPtr thread) {
2526 }
2627
2728 private static int GetAirshipBehaviourRootId ( GameObject gameObject ) {
28- // if (!AirshipBehaviourRootV2.HasId(gameObject)) {
29- // // See if it just needs to be started first:
30- // foreach (var binding in gameObject.GetComponents<AirshipComponent>()) {
31- // binding.InitEarly ();
32- // }
33- // }
29+ if ( ! AirshipBehaviourRootV2 . HasId ( gameObject ) ) {
30+ // See if it just needs to be started first:
31+ foreach ( var component in gameObject . GetComponents < AirshipComponent > ( ) ) {
32+ component . Init ( ) ;
33+ }
34+ }
3435
3536 if ( ! AirshipBehaviourRootV2 . HasId ( gameObject ) ) {
3637 return - 1 ;
@@ -39,8 +40,8 @@ private static int GetAirshipBehaviourRootId(GameObject gameObject) {
3940 return AirshipBehaviourRootV2 . GetId ( gameObject ) ;
4041 }
4142
42- private static bool IsTypeOrInheritingType ( AirshipComponent binding , string typeName , string targetTypeScriptPath ) {
43- var componentName = binding . GetAirshipComponentName ( ) ;
43+ private static bool IsTypeOrInheritingType ( AirshipComponent airshipComponent , string typeName , string targetTypeScriptPath ) {
44+ var componentName = airshipComponent . GetAirshipComponentName ( ) ;
4445
4546 if ( componentName == typeName ) {
4647 return true ;
@@ -50,7 +51,7 @@ private static bool IsTypeOrInheritingType(AirshipComponent binding, string type
5051 if ( ! buildInfo ) return false ;
5152
5253 // Check inheritance if possible
53- return targetTypeScriptPath != null && buildInfo . Inherits ( binding . script , targetTypeScriptPath ) ;
54+ return targetTypeScriptPath != null && buildInfo . Inherits ( airshipComponent . script , targetTypeScriptPath ) ;
5455 }
5556
5657 public static int GetAirshipComponent ( LuauContext context , IntPtr thread , GameObject gameObject , string typeName ) {
@@ -62,10 +63,11 @@ public static int GetAirshipComponent(LuauContext context, IntPtr thread, GameOb
6263 var buildInfo = AirshipBuildInfo . Instance ;
6364 var targetTypeScriptPath = buildInfo ? buildInfo . GetScriptPathByTypeName ( typeName ) : null ;
6465
65- foreach ( var binding in gameObject . GetComponents < AirshipComponent > ( ) ) {
66- if ( ! IsTypeOrInheritingType ( binding , typeName , targetTypeScriptPath ) ) continue ;
66+ foreach ( var airshipComponent in gameObject . GetComponents < AirshipComponent > ( ) ) {
67+ airshipComponent . Init ( ) ;
68+ if ( ! IsTypeOrInheritingType ( airshipComponent , typeName , targetTypeScriptPath ) ) continue ;
6769
68- var componentId = binding . GetAirshipComponentId ( ) ;
70+ var componentId = airshipComponent . GetAirshipComponentId ( ) ;
6971
7072 LuauPlugin . LuauPushAirshipComponent ( context , thread , unityInstanceId , componentId ) ;
7173 return 1 ;
@@ -82,10 +84,11 @@ public static int GetAirshipComponents(LuauContext context, IntPtr thread, GameO
8284 var targetTypeScriptPath = buildInfo ? buildInfo . GetScriptPathByTypeName ( typeName ) : null ;
8385
8486 var hasAny = false ;
85- foreach ( var binding in gameObject . GetComponents < AirshipComponent > ( ) ) {
86- if ( ! IsTypeOrInheritingType ( binding , typeName , targetTypeScriptPath ) ) continue ;
87+ foreach ( var airshipComponent in gameObject . GetComponents < AirshipComponent > ( ) ) {
88+ airshipComponent . Init ( ) ;
89+ if ( ! IsTypeOrInheritingType ( airshipComponent , typeName , targetTypeScriptPath ) ) continue ;
8790
88- var componentId = binding . GetAirshipComponentId ( ) ;
91+ var componentId = airshipComponent . GetAirshipComponentId ( ) ;
8992
9093 if ( ! hasAny ) {
9194 hasAny = true ;
@@ -105,18 +108,17 @@ public static int GetAirshipComponents(LuauContext context, IntPtr thread, GameO
105108
106109 public static int GetAirshipComponentInChildren ( LuauContext context , IntPtr thread , GameObject gameObject , string typeName , bool includeInactive ) {
107110 // Attempt to initialize any uninitialized bindings first:
108- var scriptBindings = gameObject . GetComponentsInChildren < AirshipComponent > ( ) ;
109- foreach ( var binding in scriptBindings ) {
111+ foreach ( var airshipComponent in gameObject . GetComponentsInChildren < AirshipComponent > ( ) ) {
110112 // Side effect loads the components if found. No need for its return result here.
111- GetAirshipBehaviourRootId ( binding . gameObject ) ;
113+ GetAirshipBehaviourRootId ( airshipComponent . gameObject ) ;
112114 }
113115
114116 var airshipComponents = gameObject . GetComponentsInChildren < AirshipComponent > ( includeInactive ) ;
115117 var buildInfo = AirshipBuildInfo . Instance ;
116118 var targetTypeScriptPath = buildInfo ? buildInfo . GetScriptPathByTypeName ( typeName ) : null ;
117119
118120 foreach ( var airshipComponent in airshipComponents ) {
119- var componentName = airshipComponent . GetAirshipComponentName ( ) ;
121+ airshipComponent . Init ( ) ;
120122 if ( ! IsTypeOrInheritingType ( airshipComponent , typeName , targetTypeScriptPath ) ) continue ;
121123
122124 var componentId = airshipComponent . GetAirshipComponentId ( ) ;
@@ -130,18 +132,18 @@ public static int GetAirshipComponentInChildren(LuauContext context, IntPtr thre
130132
131133 public static int GetAirshipComponentInParent ( LuauContext context , IntPtr thread , GameObject gameObject ,
132134 string typeName , bool includeInactive ) {
133- var scriptBindings = gameObject . GetComponentsInParent < AirshipComponent > ( ) ;
134135
135- foreach ( var binding in scriptBindings ) {
136+ foreach ( var airshipComponent in gameObject . GetComponentsInParent < AirshipComponent > ( ) ) {
136137 // Side effect loads the components if found. No need for its return result here.
137- GetAirshipBehaviourRootId ( binding . gameObject ) ;
138+ GetAirshipBehaviourRootId ( airshipComponent . gameObject ) ;
138139 }
139140
140141 var airshipComponents = gameObject . GetComponentsInParent < AirshipComponent > ( includeInactive ) ;
141142 var buildInfo = AirshipBuildInfo . Instance ;
142143 var targetTypeScriptPath = buildInfo ? buildInfo . GetScriptPathByTypeName ( typeName ) : null ;
143144
144145 foreach ( var airshipComponent in airshipComponents ) {
146+ airshipComponent . Init ( ) ;
145147 if ( ! IsTypeOrInheritingType ( airshipComponent , typeName , targetTypeScriptPath ) ) continue ;
146148
147149 var componentId = airshipComponent . GetAirshipComponentId ( ) ;
@@ -155,10 +157,9 @@ public static int GetAirshipComponentInParent(LuauContext context, IntPtr thread
155157
156158 public static int GetAirshipComponentsInChildren ( LuauContext context , IntPtr thread , GameObject gameObject , string typeName , bool includeInactive ) {
157159 // Attempt to initialize any uninitialized bindings first:
158- var scriptBindings = gameObject . GetComponentsInChildren < AirshipComponent > ( ) ;
159- foreach ( var binding in scriptBindings ) {
160+ foreach ( var airshipComponent in gameObject . GetComponentsInChildren < AirshipComponent > ( ) ) {
160161 // Side effect loads the components if found. No need for its return result here.
161- GetAirshipBehaviourRootId ( binding . gameObject ) ;
162+ GetAirshipBehaviourRootId ( airshipComponent . gameObject ) ;
162163 }
163164
164165 var airshipComponents = gameObject . GetComponentsInChildren < AirshipComponent > ( includeInactive ) ;
@@ -168,6 +169,7 @@ public static int GetAirshipComponentsInChildren(LuauContext context, IntPtr thr
168169 var componentIdsByUnityInstanceIds = new Dictionary < int , List < int > > ( ) ;
169170
170171 foreach ( var airshipComponent in airshipComponents ) {
172+ airshipComponent . Init ( ) ;
171173 if ( ! IsTypeOrInheritingType ( airshipComponent , typeName , targetTypeScriptPath ) ) continue ;
172174
173175 var componentId = airshipComponent . GetAirshipComponentId ( ) ;
@@ -195,10 +197,9 @@ public static int GetAirshipComponentsInParent(LuauContext context, IntPtr threa
195197 var foundComponents = false ;
196198
197199 // Attempt to initialize any uninitialized bindings first:
198- var scriptBindings = gameObject . GetComponentsInParent < AirshipComponent > ( ) ;
199- foreach ( var binding in scriptBindings ) {
200+ foreach ( var airshipComponent in gameObject . GetComponentsInParent < AirshipComponent > ( ) ) {
200201 // Side effect loads the components if found. No need for its return result here.
201- GetAirshipBehaviourRootId ( binding . gameObject ) ;
202+ GetAirshipBehaviourRootId ( airshipComponent . gameObject ) ;
202203 }
203204
204205 var airshipComponents = gameObject . GetComponentsInParent < AirshipComponent > ( includeInactive ) ;
@@ -208,6 +209,7 @@ public static int GetAirshipComponentsInParent(LuauContext context, IntPtr threa
208209 var componentIdsByUnityInstanceIds = new Dictionary < int , List < int > > ( ) ;
209210
210211 foreach ( var airshipComponent in airshipComponents ) {
212+ airshipComponent . Init ( ) ;
211213 if ( ! IsTypeOrInheritingType ( airshipComponent , typeName , targetTypeScriptPath ) ) continue ;
212214
213215 var componentId = airshipComponent . GetAirshipComponentId ( ) ;
0 commit comments