Skip to content

Commit 5ea1a6e

Browse files
committed
Adjust to new airship component
1 parent 956313e commit 5ea1a6e

File tree

11 files changed

+113
-223
lines changed

11 files changed

+113
-223
lines changed

Runtime/Code/Luau/AirshipBehaviourRoot.cs

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -6,87 +6,6 @@
66
#endif
77

88
namespace Luau {
9-
public static class AirshipBehaviourRootV3 {
10-
private static int _idGen = 10000000;
11-
12-
private static readonly Dictionary<GameObject, int> Ids = new();
13-
private static readonly Dictionary<int, GameObject> IdToGameObject = new();
14-
private static readonly Dictionary<int, HashSet<int>> GameObjectComponentIds = new();
15-
16-
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
17-
private static void ResetOnLoad() {
18-
_idGen = 10000000;
19-
Ids.Clear();
20-
IdToGameObject.Clear();
21-
}
22-
23-
public static int GetId(GameObject gameObject) {
24-
if (Ids.TryGetValue(gameObject, out var id)) return id;
25-
26-
id = ++_idGen;
27-
Ids.Add(gameObject, id);
28-
IdToGameObject.Add(id, gameObject);
29-
30-
return id;
31-
}
32-
33-
public static int GetId(Component component) {
34-
return GetId(component.gameObject);
35-
}
36-
37-
/// <summary>
38-
/// This will ensure that the parent GameObject has a reference to the AirshipComponent
39-
/// </summary>
40-
internal static void LinkComponentToGameObject(AirshipComponentV2 component, out int gameObjectId) {
41-
gameObjectId = GetId(component.gameObject);
42-
var componentId = component.GetAirshipComponentId();
43-
44-
if (!GameObjectComponentIds.TryGetValue(gameObjectId, out var componentIds)) {
45-
componentIds = new HashSet<int>();
46-
GameObjectComponentIds.Add(gameObjectId, componentIds);
47-
}
48-
49-
componentIds.Add(componentId);
50-
}
51-
52-
internal static void CleanIdOnDestroy(GameObject gameObject, AirshipComponentV2 component) {
53-
if (!Ids.TryGetValue(gameObject, out var id)) return;
54-
55-
var components = gameObject.GetComponents<AirshipComponentV2>().Where(c => c != component);
56-
if (components.Any() && gameObject.activeInHierarchy) return;
57-
58-
var componentIds = GameObjectComponentIds[id];
59-
60-
componentIds.Remove(component.GetAirshipComponentId());
61-
62-
if (componentIds.Count != 0) return;
63-
64-
// If no more components, we'll remove Id <-> GameObject mappings, tyvm
65-
Ids.Remove(gameObject);
66-
IdToGameObject.Remove(id);
67-
GameObjectComponentIds.Remove(id);
68-
}
69-
70-
public static bool HasId(GameObject gameObject) {
71-
return Ids.ContainsKey(gameObject);
72-
}
73-
74-
public static GameObject GetGameObject(int objectId) {
75-
return IdToGameObject.GetValueOrDefault(objectId);
76-
}
77-
78-
public static AirshipComponentV2 GetComponent(GameObject gameObject, int componentId) {
79-
return gameObject != null
80-
? gameObject.GetComponents<AirshipComponentV2>()
81-
.FirstOrDefault(f => f.GetAirshipComponentId() == componentId)
82-
: null;
83-
}
84-
85-
public static AirshipComponentV2 GetComponent(int unityInstanceId, int componentId) {
86-
return GetComponent(GetGameObject(unityInstanceId), componentId);
87-
}
88-
}
89-
909
public static class AirshipBehaviourRootV2 {
9110
private static int _idGen;
9211

Runtime/Code/Luau/AirshipComponent.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class AirshipComponent : MonoBehaviour {
2222
private const bool ElevateToProtectedWithinCoreScene = true;
2323

2424
public static LuauScript.AwakeData QueuedAwakeData = null;
25+
public static Dictionary<int, string> ComponentIdToScriptName = new();
2526
private static int _airshipComponentIdGen = 10000000;
2627
private static bool _validatedSceneInGameConfig = false;
2728

@@ -40,8 +41,9 @@ public class AirshipComponent : MonoBehaviour {
4041
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
4142
private static void OnReload() {
4243
_airshipComponentIdGen = 10000000;
43-
QueuedAwakeData = null;
4444
_validatedSceneInGameConfig = false;
45+
QueuedAwakeData = null;
46+
ComponentIdToScriptName.Clear();
4547
}
4648

4749
private void Awake() {
@@ -50,6 +52,8 @@ private void Awake() {
5052
context = QueuedAwakeData.Context;
5153
QueuedAwakeData = null;
5254
}
55+
56+
ComponentIdToScriptName[_airshipComponentId] = string.Intern(script.name);
5357

5458
ScriptingEntryPoint.InvokeOnLuauStartup();
5559

@@ -144,6 +148,8 @@ private void OnDisable() {
144148
}
145149

146150
private void OnDestroy() {
151+
ComponentIdToScriptName.Remove(_airshipComponentId);
152+
147153
if (thread == IntPtr.Zero || !LuauCore.IsReady) return;
148154

149155
print("C# OnDestroy");

Runtime/Code/Luau/AirshipComponentUpdater.cs

Lines changed: 0 additions & 59 deletions
This file was deleted.

Runtime/Code/Luau/AirshipComponentUpdater.cs.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

Runtime/Code/Luau/LuauCore.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#endif
1515

1616
//Singleton
17-
[RequireComponent(typeof(AirshipComponentUpdater))]
1817
public partial class LuauCore : MonoBehaviour {
1918
#if UNITY_EDITOR
2019
[InitializeOnLoad]
@@ -98,8 +97,6 @@ public enum PODTYPE : int {
9897

9998
private Dictionary<Type, Dictionary<ulong, PropertyInfo>> unityPropertyAlias = new();
10099
private Dictionary<Type, Dictionary<ulong, FieldInfo>> unityFieldAlias = new();
101-
102-
private AirshipComponentUpdater _airshipComponentUpdater;
103100

104101
private class CallbackRecord {
105102
public IntPtr callback;
@@ -128,22 +125,6 @@ public static LuauState GetInstance(LuauContext context) {
128125
return LuauState.FromContext(context);
129126
}
130127

131-
public static void RegisterAirshipComponent(AirshipComponent component) {
132-
var instance = CoreInstance;
133-
if (ReferenceEquals(instance, null)) return;
134-
135-
instance._airshipComponentUpdater ??= instance.GetComponent<AirshipComponentUpdater>();
136-
instance._airshipComponentUpdater.Register(component);
137-
}
138-
139-
public static void UnregisterAirshipComponent(AirshipComponent component) {
140-
var instance = CoreInstance;
141-
if (ReferenceEquals(instance, null)) return;
142-
143-
instance._airshipComponentUpdater ??= instance.GetComponent<AirshipComponentUpdater>();
144-
instance._airshipComponentUpdater.Unregister(component);
145-
}
146-
147128
public bool CheckSetup() {
148129
if (initialized) return false;
149130

@@ -336,8 +317,6 @@ private void Start() {
336317
LuauPlugin.unityMainThreadId = Thread.CurrentThread.ManagedThreadId;
337318
StartCoroutine(PrintReferenceAssemblies());
338319
endOfFrameCoroutine = StartCoroutine(RunAtVeryEndOfFrame());
339-
340-
_airshipComponentUpdater = GetComponent<AirshipComponentUpdater>();
341320

342321
#if UNITY_EDITOR
343322
EditorApplication.pauseStateChanged += OnPauseStateChanged;

0 commit comments

Comments
 (0)