gg.easy.airship 0.1.2189 → 0.1.2190

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/Editor/AirshipComponentBuildImporter.cs +13 -1
  2. package/Editor/AirshipComponentEditor.cs +106 -14
  3. package/Editor/AirshipEditors/AirshipCustomEditors.cs +319 -0
  4. package/Editor/AirshipEditors/AirshipCustomEditors.cs.meta +3 -0
  5. package/Editor/AirshipEditors/AirshipEditor.cs +257 -0
  6. package/Editor/AirshipEditors/AirshipEditor.cs.meta +3 -0
  7. package/Editor/AirshipEditors/AirshipPropertyDecorator.cs +75 -0
  8. package/Editor/AirshipEditors/AirshipPropertyDecorator.cs.meta +3 -0
  9. package/Editor/AirshipEditors/AirshipSerializedObject.cs +107 -0
  10. package/Editor/AirshipEditors/AirshipSerializedObject.cs.meta +3 -0
  11. package/Editor/AirshipEditors/CustomAirshipDecoratorAttribute.cs +20 -0
  12. package/Editor/AirshipEditors/CustomAirshipDecoratorAttribute.cs.meta +3 -0
  13. package/Editor/AirshipEditors/CustomAirshipEditorAttribute.cs +23 -0
  14. package/Editor/AirshipEditors/CustomAirshipEditorAttribute.cs.meta +3 -0
  15. package/Editor/AirshipEditors/DefaultAirshipComponentEditor.cs +15 -0
  16. package/Editor/AirshipEditors/DefaultAirshipComponentEditor.cs.meta +3 -0
  17. package/Editor/AirshipEditors/Properties/AirshipPropertyExtensions.cs +97 -0
  18. package/Editor/AirshipEditors/Properties/AirshipPropertyExtensions.cs.meta +3 -0
  19. package/Editor/AirshipEditors/Properties/AirshipSerializedArray.cs +143 -0
  20. package/Editor/AirshipEditors/Properties/AirshipSerializedArray.cs.meta +3 -0
  21. package/Editor/AirshipEditors/Properties/AirshipSerializedArrayValue.cs +21 -0
  22. package/Editor/AirshipEditors/Properties/AirshipSerializedArrayValue.cs.meta +3 -0
  23. package/Editor/AirshipEditors/Properties/AirshipSerializedProperty.cs +108 -0
  24. package/Editor/AirshipEditors/Properties/AirshipSerializedProperty.cs.meta +3 -0
  25. package/Editor/AirshipEditors/Properties/AirshipSerializedValue.cs +296 -0
  26. package/Editor/AirshipEditors/Properties/AirshipSerializedValue.cs.meta +3 -0
  27. package/Editor/AirshipEditors/Properties.meta +3 -0
  28. package/Editor/AirshipEditors.meta +3 -0
  29. package/Editor/AirshipScriptGUI.cs +4 -0
  30. package/Editor/Artifacts/AirshipReconciliationService.cs +5 -5
  31. package/Editor/AssemblyInfo.cs +4 -0
  32. package/Editor/AssemblyInfo.cs.meta +3 -0
  33. package/Editor/BuildMenu.cs +2 -2
  34. package/Editor/EditorIntegrationsConfig.cs +12 -3
  35. package/Editor/EditorInternal/AirshipObjectGUIInternal.cs +5 -3
  36. package/Editor/Settings/AirshipBetaSettingsProvider.cs +151 -0
  37. package/Editor/Settings/AirshipBetaSettingsProvider.cs.meta +3 -0
  38. package/Editor/Settings/AirshipLocalProjectEditorSettings.cs +59 -0
  39. package/Editor/Settings/AirshipLocalProjectEditorSettings.cs.meta +3 -0
  40. package/Editor/Settings/AirshipSettingsProvider.cs +7 -25
  41. package/Editor/TypescriptAst/TsArrayTypeNode.cs +87 -0
  42. package/Editor/TypescriptAst/TsArrayTypeNode.cs.meta +3 -0
  43. package/Editor/TypescriptAst/TsBlock.cs +20 -0
  44. package/Editor/TypescriptAst/TsBlock.cs.meta +3 -0
  45. package/Editor/TypescriptAst/TsComment.cs +43 -0
  46. package/Editor/TypescriptAst/TsComment.cs.meta +2 -0
  47. package/Editor/TypescriptAst/TsEnumDeclaration.cs +51 -0
  48. package/Editor/TypescriptAst/TsEnumDeclaration.cs.meta +2 -0
  49. package/Editor/TypescriptAst/TsEnumMember.cs +46 -0
  50. package/Editor/TypescriptAst/TsEnumMember.cs.meta +2 -0
  51. package/Editor/TypescriptAst/TsExpressionStatement.cs +12 -0
  52. package/Editor/TypescriptAst/TsExpressionStatement.cs.meta +3 -0
  53. package/Editor/TypescriptAst/TsExtensions.cs +15 -0
  54. package/Editor/TypescriptAst/TsExtensions.cs.meta +3 -0
  55. package/Editor/TypescriptAst/TsFunctionDeclaration.cs +80 -0
  56. package/Editor/TypescriptAst/TsFunctionDeclaration.cs.meta +3 -0
  57. package/Editor/TypescriptAst/TsIdentifier.cs +20 -0
  58. package/Editor/TypescriptAst/TsIdentifier.cs.meta +2 -0
  59. package/Editor/TypescriptAst/TsKeyOfOperator.cs +20 -0
  60. package/Editor/TypescriptAst/TsKeyOfOperator.cs.meta +2 -0
  61. package/Editor/TypescriptAst/TsKeywordModifier.cs +27 -0
  62. package/Editor/TypescriptAst/TsKeywordModifier.cs.meta +3 -0
  63. package/Editor/TypescriptAst/TsKeywordTypeNode.cs +48 -0
  64. package/Editor/TypescriptAst/TsKeywordTypeNode.cs.meta +3 -0
  65. package/Editor/TypescriptAst/TsNumericLiteral.cs +41 -0
  66. package/Editor/TypescriptAst/TsNumericLiteral.cs.meta +2 -0
  67. package/Editor/TypescriptAst/TsParameter.cs +48 -0
  68. package/Editor/TypescriptAst/TsParameter.cs.meta +3 -0
  69. package/Editor/TypescriptAst/TsPropertyName.cs +42 -0
  70. package/Editor/TypescriptAst/TsPropertyName.cs.meta +2 -0
  71. package/Editor/TypescriptAst/TsStatementBlock.cs +14 -0
  72. package/Editor/TypescriptAst/TsStatementBlock.cs.meta +3 -0
  73. package/Editor/TypescriptAst/TsStringLiteral.cs +22 -0
  74. package/Editor/TypescriptAst/TsStringLiteral.cs.meta +2 -0
  75. package/Editor/TypescriptAst/TsTypeDeclaration.cs +29 -0
  76. package/Editor/TypescriptAst/TsTypeDeclaration.cs.meta +2 -0
  77. package/Editor/TypescriptAst/TsTypeQuery.cs +20 -0
  78. package/Editor/TypescriptAst/TsTypeQuery.cs.meta +2 -0
  79. package/Editor/TypescriptAst/TypescriptCodeGen.cs +81 -0
  80. package/Editor/TypescriptAst/TypescriptCodeGen.cs.meta +2 -0
  81. package/Editor/TypescriptAst.meta +3 -0
  82. package/Editor/TypescriptImporter.cs +12 -4
  83. package/Editor/TypescriptServices/Compiler/TypescriptCompilationService.cs +27 -24
  84. package/Editor/TypescriptServices/Editor/TypescriptImporterEditor.cs +15 -3
  85. package/Editor/TypescriptServices/Projects/TypescriptProject.cs +8 -0
  86. package/Editor/TypescriptServices/TypescriptServices.cs +10 -9
  87. package/Editor/Util/AirshipBehaviourSelector.cs +38 -0
  88. package/Editor/Util/AirshipBehaviourSelector.cs.meta +3 -0
  89. package/Editor/Util/AirshipClipboardUtility.cs +46 -0
  90. package/Editor/Util/AirshipClipboardUtility.cs.meta +3 -0
  91. package/Editor/Util/AirshipEditorGUI.cs +678 -146
  92. package/Editor/Util/AirshipEditorGUI.cs.meta +2 -2
  93. package/Editor/Util/AirshipEditorGUI.internal.cs +693 -0
  94. package/Editor/Util/AirshipEditorGUI.internal.cs.meta +3 -0
  95. package/Editor/Util/AirshipGUI.cs +21 -0
  96. package/Editor/Util/AirshipGUI.cs.meta +3 -0
  97. package/Resources/AirshipEmptyMaterial.mat +1 -1
  98. package/Runtime/Code/Luau/AirshipEditorInfo.cs +121 -26
  99. package/Runtime/Code/Luau/LuauMetadata.cs +25 -5
  100. package/Runtime/Code/Misc/AirshipBuildInfo.cs +71 -2
  101. package/Runtime/Code/Misc/AirshipType.cs +67 -0
  102. package/Runtime/Code/Misc/AirshipType.cs.meta +3 -0
  103. package/Runtime/Code/VoxelWorld/Airship.VoxelWorld.asmdef +1 -1
  104. package/Runtime/Code/VoxelWorld/VoxelMeshProcessor.cs +36 -29
  105. package/Runtime/Code/VoxelWorld/VoxelQuarterBlock.cs +2 -2
  106. package/Runtime/Code/VoxelWorld/VoxelWorld.cs +433 -295
  107. package/Runtime/Code/VoxelWorld/VoxelWorldChunk.cs +15 -17
  108. package/Runtime/Code/VoxelWorld/VoxelWorldCollision.cs +8 -6
  109. package/Runtime/Code/VoxelWorld/VoxelWorldNetworker.cs +38 -31
  110. package/Runtime/Plugins/Mac/LuauPlugin.bundle/Contents/MacOS/LuauPlugin.meta +7 -0
  111. package/Runtime/Plugins/Mac/Titlebar.bundle/Contents/Info.plist.meta +7 -0
  112. package/Runtime/Plugins/Mac/Titlebar.bundle/Contents/MacOS/Titlebar.meta +7 -0
  113. package/Runtime/Plugins/Mac/Titlebar.bundle/Contents/MacOS.meta +8 -0
  114. package/Runtime/Plugins/Mac/Titlebar.bundle/Contents/_CodeSignature/CodeResources.meta +7 -0
  115. package/Runtime/Plugins/Mac/Titlebar.bundle/Contents/_CodeSignature.meta +8 -0
  116. package/Runtime/Plugins/Mac/Titlebar.bundle/Contents.meta +8 -0
  117. package/Runtime/Plugins/Mac/UnityInterfacePlugin.bundle/Contents/Info.plist.meta +7 -0
  118. package/Runtime/Plugins/Mac/UnityInterfacePlugin.bundle/Contents/MacOS/UnityInterfacePlugin.meta +7 -0
  119. package/Runtime/Plugins/Mac/UnityInterfacePlugin.bundle/Contents/MacOS.meta +8 -0
  120. package/Runtime/Plugins/Mac/UnityInterfacePlugin.bundle/Contents.meta +8 -0
  121. package/package.json +1 -1
@@ -1,5 +1,8 @@
1
- using System.IO;
1
+ using System;
2
+ using System.IO;
3
+ using System.Linq;
2
4
  using Luau;
5
+ using UnityEditor;
3
6
  using UnityEditor.AssetImporters;
4
7
  using UnityEngine;
5
8
 
@@ -18,4 +21,13 @@ namespace Editor {
18
21
  ctx.SetMainObject(airshipBuild);
19
22
  }
20
23
  }
24
+
25
+ public class AirshipTypePostProcessor : AssetPostprocessor {
26
+ private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets,
27
+ string[] movedFromAssetPaths) {
28
+ if (importedAssets.Contains(AirshipBuildInfo.PrimaryAssetPath)) {
29
+ AirshipCustomEditors.RegisterEditorsForRegisteredTypes();
30
+ }
31
+ }
32
+ }
21
33
  }
@@ -39,6 +39,8 @@ public class ScriptBindingEditor : UnityEditor.Editor {
39
39
  /** Maps (game object id, prop name) to ArrayDisplayInfo object (for Array properties) */
40
40
  private Dictionary<(int componentInstanceId, string propertyName), ArrayDisplayInfo> _reorderableLists = new();
41
41
 
42
+ private AirshipEditor editor;
43
+
42
44
  public void OnEnable() {
43
45
  var comp = (Component)serializedObject.targetObject;
44
46
  var metadata = serializedObject.FindProperty("metadata");
@@ -50,6 +52,16 @@ public class ScriptBindingEditor : UnityEditor.Editor {
50
52
  var listPropType = LuauMetadataPropertySerializer.GetAirshipComponentPropertyTypeFromString(arrayType, false);
51
53
  GetOrCreateArrayDisplayInfo(comp.GetInstanceID(), serializedProperty, serializedProperty.FindPropertyRelative("name").stringValue, listPropType, itemInfo);
52
54
  }
55
+
56
+ AirshipComponent binding = (AirshipComponent)target;
57
+ if (binding.script != null && binding.metadata != null) {
58
+ var customEditorType = AirshipCustomEditors.GetEditorTypeForTypeName(binding.metadata.name);
59
+
60
+ if (customEditorType != null && AirshipCustomEditors.TryGetEditorForComponent(binding, customEditorType, out var editor)) {
61
+ editor.OnEnable();
62
+ this.editor = editor;
63
+ }
64
+ }
53
65
  }
54
66
 
55
67
  private void OnDisable() {
@@ -58,24 +70,89 @@ public class ScriptBindingEditor : UnityEditor.Editor {
58
70
 
59
71
  var componentInstanceId = comp.GetInstanceID();
60
72
  _componentSeenArrayProps.Remove(componentInstanceId);
73
+
74
+ AirshipComponent binding = (AirshipComponent)target;
75
+ if (binding.script != null && binding.metadata != null) {
76
+ var customEditorType = AirshipCustomEditors.GetEditorTypeForTypeName(binding.metadata.name);
77
+ if (customEditorType != null) {
78
+ var editor = AirshipCustomEditors.GetEditorForComponent(binding, customEditorType, serializedObject);
79
+ editor.OnDisable();
80
+ }
81
+
82
+ this.editor = null;
83
+ }
84
+ }
85
+
86
+ private void OnDestroy() {
87
+ AirshipComponent binding = (AirshipComponent)target;
88
+ AirshipCustomEditors.DestroyEditor(binding);
61
89
  }
62
90
 
63
91
  private bool debugging = false;
64
-
65
- public override void OnInspectorGUI() {
66
- serializedObject.Update();
67
92
 
68
- AirshipComponent binding = (AirshipComponent)target;
93
+ private void OnSceneGUI() {
94
+ if (!AirshipCustomEditors.UseNewInspector) return;
95
+ if (!this.editor) return;
96
+ this.editor.OnSceneGUI();
97
+ }
69
98
 
70
- if (binding.script == null && !string.IsNullOrEmpty(binding.scriptPath)) {
71
- // Debug.Log("Setting Script File from Path: " + binding.scriptPath);
72
- // binding.SetScriptFromPath(binding.scriptPath, LuauContext.Game);
73
- if (binding.script == null) {
74
- Debug.LogWarning($"Failed to load script asset: {binding.scriptPath}");
75
- EditorGUILayout.HelpBox("Missing reference. This is likely from renaming a script.\n\nOld path: " + binding.scriptPath.Replace("Assets/Bundles/", ""), MessageType.Warning);
99
+ public override void OnPreviewGUI(Rect r, GUIStyle background) {
100
+ if (!AirshipCustomEditors.UseNewInspector) return;
101
+ if (!this.editor) return;
102
+ this.editor.OnPreviewGUI(r, background);
103
+ }
104
+
105
+ public override bool HasPreviewGUI() {
106
+ if (!AirshipCustomEditors.UseNewInspector) return false;
107
+ return this.editor != null ? this.editor.HasPreviewGUI() : false;
108
+ }
109
+
110
+ private bool OnAirshipInspectorGUI() {
111
+ if (!AirshipCustomEditors.UseNewInspector) return false;
112
+
113
+ AirshipComponent binding = (AirshipComponent)target;
114
+
115
+ Type customEditorType = null;
116
+ if (binding.script != null && binding.metadata != null) {
117
+ customEditorType = AirshipCustomEditors.GetEditorTypeForTypeName(binding.metadata.name);
118
+ }
119
+
120
+ if (customEditorType != null && binding.script != null) {
121
+ var metadata = serializedObject.FindProperty("metadata");
122
+ var metadataName = metadata.FindPropertyRelative("name");
123
+
124
+ if (binding.script != null && binding.script.m_metadata != null) {
125
+ if (ShouldReconcile(binding)) {
126
+ binding.ReconcileMetadata(ReconcileSource.Inspector);
127
+ serializedObject.ApplyModifiedProperties();
128
+ serializedObject.Update();
129
+ }
130
+
131
+ CheckDefaults(binding);
76
132
  }
133
+
134
+ if (!string.IsNullOrEmpty(metadataName.stringValue)) {
135
+ var componentEditor = AirshipCustomEditors.GetEditorForComponent(binding, customEditorType, serializedObject);
136
+ if (this.editor == null) this.editor = componentEditor;
137
+ componentEditor.script = binding.script;
138
+ componentEditor.target = binding;
139
+ componentEditor.OnInspectorGUI();
140
+ }
141
+
142
+ serializedObject.ApplyModifiedProperties();
143
+
144
+ if (Application.isPlaying) {
145
+ var component = (AirshipComponent)target;
146
+ component.WriteChangedComponentProperties();
147
+ }
148
+ return true;
77
149
  }
78
150
 
151
+ return false;
152
+ }
153
+
154
+ private void OnAirshipLegacyInspectorGUI() {
155
+ AirshipComponent binding = (AirshipComponent)target;
79
156
  DrawScriptBindingProperties(binding);
80
157
 
81
158
  if (binding.script != null && binding.script.m_metadata != null) {
@@ -115,6 +192,23 @@ public class ScriptBindingEditor : UnityEditor.Editor {
115
192
  serializedObject.ApplyModifiedProperties();
116
193
  }
117
194
 
195
+ public override void OnInspectorGUI() {
196
+ serializedObject.Update();
197
+
198
+ AirshipComponent binding = (AirshipComponent)target;
199
+
200
+ if (binding.script == null && !string.IsNullOrEmpty(binding.scriptPath)) {
201
+ if (binding.script == null) {
202
+ Debug.LogWarning($"Failed to load script asset: {binding.scriptPath}");
203
+ EditorGUILayout.HelpBox("Missing reference. This is likely from renaming a script.\n\nOld path: " + binding.scriptPath.Replace("Assets/Bundles/", ""), MessageType.Warning);
204
+ }
205
+ }
206
+
207
+ if (!OnAirshipInspectorGUI()) {
208
+ OnAirshipLegacyInspectorGUI();
209
+ }
210
+ }
211
+
118
212
 
119
213
  private Dictionary<int, HashSet<string>> _componentSeenArrayProps = new();
120
214
  private void CleanupOrphanedArrayDisplayInfos(int componentInstanceId) {
@@ -145,8 +239,6 @@ public class ScriptBindingEditor : UnityEditor.Editor {
145
239
  }
146
240
 
147
241
  private ArrayDisplayInfo GetOrCreateArrayDisplayInfo(int componentInstanceId, SerializedProperty arraySerializedProperty, string propName, AirshipComponentPropertyType listType, SerializedProperty itemInfo) {
148
-
149
-
150
242
  Type objType = null;
151
243
  if (listType == AirshipComponentPropertyType.AirshipObject || listType == AirshipComponentPropertyType.AirshipComponent) {
152
244
  objType = TypeReflection.GetTypeFromString(itemInfo.FindPropertyRelative("objectType").stringValue);
@@ -861,7 +953,7 @@ public class ScriptBindingEditor : UnityEditor.Editor {
861
953
  var objOld = objectRefs.arraySize > index ? objectRefs.GetArrayElementAtIndex(index).objectReferenceValue : null;
862
954
 
863
955
  if (objectType == typeof(Sprite) || objectType == typeof(Texture2D)) {
864
- var objNew = AirshipEditorGUI.ObjectField(rect, new GUIContent(label), objOld, objectType, true);
956
+ var objNew = AirshipEditorGUI.ObjectField(rect, new GUIContent(label), objOld, objectType, true, false);
865
957
  if (objOld != objNew) {
866
958
  objectRefs.GetArrayElementAtIndex(index).objectReferenceValue = objNew;
867
959
  arrayModified.boolValue = true;
@@ -1286,7 +1378,7 @@ public class ScriptBindingEditor : UnityEditor.Editor {
1286
1378
 
1287
1379
  UnityEngine.Object newObject;
1288
1380
  if (t == typeof(Sprite) || t == typeof(Texture2D)) {
1289
- newObject = AirshipEditorGUI.ObjectFieldLayout(guiContent, currentObject, t, true);
1381
+ newObject = AirshipEditorGUI.ObjectFieldLayout(guiContent, currentObject, t, true, false);
1290
1382
  } else {
1291
1383
  newObject = EditorGUILayout.ObjectField(guiContent, currentObject, t, true);
1292
1384
  }
@@ -0,0 +1,319 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using System.IO;
4
+ using System.Reflection;
5
+ using TypescriptAst;
6
+ using Luau;
7
+ using UnityEditor;
8
+ using UnityEngine;
9
+ using Object = UnityEngine.Object;
10
+
11
+ /// <summary>
12
+ /// The custom editor namespace for the Airship Editor
13
+ /// </summary>
14
+ public static class AirshipCustomEditors {
15
+ /// <summary>
16
+ /// Contains information about the custom Airship editor
17
+ /// </summary>
18
+ internal class CustomEditorInfo {
19
+ public Type EditorType { get; }
20
+ public AirshipType AirshipType { get; }
21
+ public CustomAirshipEditorAttribute EditorAttribute { get; }
22
+ public CustomEditorInfo(Type editorType, AirshipType airshipType, CustomAirshipEditorAttribute editorAttribute) {
23
+ EditorType = editorType;
24
+ EditorAttribute = editorAttribute;
25
+ AirshipType = airshipType;
26
+ }
27
+ }
28
+
29
+ #region Fields
30
+ private static Dictionary<AirshipType, CustomEditorInfo> airshipTypeToCustomEditor = new();
31
+ private static Dictionary<int, AirshipEditor> instanceToAirshipEditor = new();
32
+
33
+ private static Dictionary<Type, AirshipPropertyDecorator> typeToEditorPropertyDecorator = new();
34
+ private static Dictionary<string, Type> decoratorNameToEditorType = new();
35
+
36
+ internal const string inspectorModeKey = "AirshipBetaInspectorMode";
37
+ internal const EditorInspectorMode DefaultInspectorMode = EditorInspectorMode.UseLegacyInspector;
38
+ #endregion
39
+
40
+ #region Properties
41
+ /// <summary>
42
+ /// A list of the active custom editors
43
+ /// </summary>
44
+ internal static IEnumerable<CustomEditorInfo> CustomEditors {
45
+ get => airshipTypeToCustomEditor.Values;
46
+ }
47
+
48
+ /// <summary>
49
+ /// A list of all the active airship editors (includes the default inspectors)
50
+ /// </summary>
51
+ internal static IEnumerable<AirshipEditor> AllEditors {
52
+ get => instanceToAirshipEditor.Values;
53
+ }
54
+
55
+ internal static EditorInspectorMode UserInspectorMode {
56
+ get {
57
+ var value = (EditorInspectorMode) EditorPrefs.GetInt(inspectorModeKey, (int) EditorInspectorMode.Default);
58
+ return value;
59
+ }
60
+ set {
61
+ var current = (EditorInspectorMode) EditorPrefs.GetInt(inspectorModeKey, (int) EditorInspectorMode.Default);
62
+ if (value == current) return;
63
+
64
+ if (value == EditorInspectorMode.UseLegacyInspector) {
65
+ instanceToAirshipEditor.Clear();
66
+ airshipTypeToCustomEditor.Clear();
67
+ } else if (value == EditorInspectorMode.UseNewInspector || (value == EditorInspectorMode.Default &&
68
+ DefaultInspectorMode ==
69
+ EditorInspectorMode.UseNewInspector)) {
70
+ RegisterEditorsForRegisteredTypes();
71
+ }
72
+
73
+ EditorPrefs.SetInt(inspectorModeKey, (int) value);
74
+ }
75
+ }
76
+
77
+ internal static bool UseNewInspector {
78
+ get {
79
+ var inspector = UserInspectorMode;
80
+ if (inspector == EditorInspectorMode.Default) inspector = DefaultInspectorMode;
81
+ return inspector == EditorInspectorMode.UseNewInspector;
82
+ }
83
+ }
84
+
85
+ #endregion
86
+
87
+ #region Editor Registration Methods
88
+
89
+ private static bool RegisterEditor(Type editorType, CustomAirshipEditorAttribute editorAttribute) {
90
+ var typeName = editorAttribute.TypeName;
91
+ var filePath = editorAttribute.FilePath;
92
+
93
+ var pathType = string.IsNullOrEmpty(filePath) ?
94
+ AirshipBuildInfo.Instance.GetTypeByName(typeName) :
95
+ AirshipBuildInfo.Instance.GetTypeByPathAndName(filePath, typeName);
96
+
97
+ if (pathType == null) {
98
+ return false;
99
+ }
100
+
101
+ if (!AirshipCustomEditors.airshipTypeToCustomEditor.TryGetValue(pathType, out var _)) {
102
+ AirshipCustomEditors.airshipTypeToCustomEditor.Add(pathType, new CustomEditorInfo(editorType, pathType, editorAttribute));
103
+ }
104
+
105
+ return true;
106
+ }
107
+
108
+ internal static void RegisterEditorsForRegisteredTypes() {
109
+ airshipTypeToCustomEditor.Clear();
110
+ decoratorNameToEditorType.Clear();
111
+ typeToEditorPropertyDecorator.Clear();
112
+ instanceToAirshipEditor.Clear();
113
+
114
+ var typeEditorAttributes = TypeCache.GetTypesWithAttribute<CustomAirshipEditorAttribute>();
115
+
116
+ foreach (var editorType in typeEditorAttributes) {
117
+ var internalAttr = editorType.GetCustomAttribute<CustomAirshipCoreEditorAttribute>();
118
+ if (internalAttr != null) {
119
+ RegisterEditor(editorType, internalAttr);
120
+ continue;
121
+ }
122
+
123
+ var attr = editorType.GetCustomAttribute<CustomAirshipEditorAttribute>();
124
+ RegisterEditor(editorType, attr);
125
+ }
126
+
127
+ var decoratorStatements = new List<IStatement>();
128
+
129
+ var decoratorAttributes = TypeCache.GetTypesWithAttribute<CustomAirshipDecoratorAttribute>();
130
+ foreach (var decoratorAttributeType in decoratorAttributes) {
131
+ var attr = decoratorAttributeType.GetCustomAttribute<CustomAirshipDecoratorAttribute>();
132
+ decoratorNameToEditorType.Add(attr.Name, decoratorAttributeType);
133
+
134
+ var propertyDecorator = (AirshipPropertyDecorator)ScriptableObject.CreateInstance(decoratorAttributeType);
135
+ propertyDecorator.attribute = attr;
136
+ typeToEditorPropertyDecorator.Add(decoratorAttributeType, propertyDecorator);
137
+
138
+ var decoratorParams = propertyDecorator.GetFunctionDeclaration();
139
+ if (decoratorParams != null) {
140
+ decoratorStatements.Add(new TsComment() { IsJsDoc = true, Text = $"Generated editor decorator '{attr.Name}' from {decoratorAttributeType.FullName}" });
141
+ decoratorStatements.Add(decoratorParams);
142
+ }
143
+ }
144
+
145
+ if (decoratorStatements.Count > 0) {
146
+ var sourceFile = new TsSourceFile() {
147
+ Statements = decoratorStatements.ToArray(),
148
+ };
149
+
150
+ File.WriteAllText("Assets/decorators.d.ts", sourceFile.ToString());
151
+ } else if (File.Exists("Assets/decorators.d.ts")) {
152
+ File.Delete("Assets/decorators.d.ts");
153
+ }
154
+
155
+ #if AIRSHIP_INTERNAL
156
+ Debug.Log($"Registered {airshipTypeToCustomEditor.Count} custom editors, {decoratorNameToEditorType.Count} decorators.");
157
+ #endif
158
+ }
159
+
160
+ [InitializeOnLoadMethod]
161
+ internal static void InitializeEditorSymbols() {
162
+ string currentDefines = PlayerSettings.GetScriptingDefineSymbols(
163
+ UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup));
164
+
165
+ HashSet<string> defines = new HashSet<string>(currentDefines.Split(';')) {
166
+ "AIRSHIP_EDITOR_API"
167
+ };
168
+ string newDefines = string.Join(";", defines);
169
+
170
+ if (newDefines != currentDefines) {
171
+ PlayerSettings.SetScriptingDefineSymbols(
172
+ UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup), newDefines);
173
+ }
174
+ }
175
+
176
+ [InitializeOnLoadMethod]
177
+ internal static void RegisterCustomEditors() {
178
+ RegisterEditorsForRegisteredTypes();
179
+
180
+ EditorApplication.playModeStateChanged += change => {
181
+ if (change == PlayModeStateChange.ExitingEditMode || change == PlayModeStateChange.EnteredPlayMode) {
182
+ RegisterEditorsForRegisteredTypes();
183
+ }
184
+ };
185
+ }
186
+
187
+ #endregion
188
+
189
+ #region Custom Editor Query Methods
190
+
191
+ /// <summary>
192
+ /// Gets all editors of the given custom editor info
193
+ /// </summary>
194
+ /// <param name="editorInfo">The custom editor to grab the editors from</param>
195
+ /// <returns>A list of Airship editors that match the given custom editor</returns>
196
+ internal static IEnumerable<AirshipEditor> GetEditors(CustomEditorInfo editorInfo) {
197
+ var instances = new List<AirshipEditor>();
198
+ foreach (var instance in instanceToAirshipEditor) {
199
+ if (instance.Value.GetType() == editorInfo.EditorType) instances.Add(instance.Value);
200
+ }
201
+
202
+ return instances;
203
+ }
204
+
205
+ internal static Type GetEditorTypeForTypeName(string typeName) {
206
+ if (!UseNewInspector) return null;
207
+
208
+ var pathType = AirshipBuildInfo.Instance.GetTypeByName(typeName);
209
+ if (pathType == null) return null;
210
+
211
+ if (airshipTypeToCustomEditor.TryGetValue(pathType, out var editorType)) {
212
+ return editorType.EditorType;
213
+ }
214
+
215
+ return typeof(DefaultAirshipComponentEditor);
216
+ }
217
+
218
+ internal static bool TryGetEditorForComponent(AirshipComponent component, Type type, out AirshipEditor editor) {
219
+ return instanceToAirshipEditor.TryGetValue(component.GetInstanceID(), out editor);
220
+ }
221
+
222
+ internal static AirshipEditor GetEditorForComponent(AirshipComponent component, Type type, SerializedObject serializedObject) {
223
+ if (instanceToAirshipEditor.TryGetValue(component.GetInstanceID(), out var editor)) {
224
+ editor.serializedObject ??= new AirshipSerializedObject();
225
+ editor.serializedObject.Update(editor, serializedObject, component.script.m_metadata);
226
+ return editor;
227
+ }
228
+
229
+ editor = (AirshipEditor) ScriptableObject.CreateInstance(type);
230
+ editor.serializedObject ??= new AirshipSerializedObject();
231
+ editor.serializedObject.Update(editor, serializedObject, component.script.m_metadata);
232
+ instanceToAirshipEditor.Add(component.GetInstanceID(), editor);
233
+ return editor;
234
+ }
235
+
236
+
237
+ internal static AirshipEditor GetComponentEditorForType(AirshipType airshipType, AirshipComponent component, AirshipSerializedObject serializedObject) {
238
+ if (!airshipType.AirshipBehaviour) return null;
239
+ var editorType = AirshipCustomEditors.GetEditorTypeForTypeName(airshipType.Name);
240
+ var editor = AirshipCustomEditors.GetEditorForComponent(component, editorType, serializedObject);
241
+ return editor;
242
+ }
243
+
244
+ /// <summary>
245
+ /// Get an AirshipEditor for the given serialized property - can be used to embed inline
246
+ /// </summary>
247
+ /// <param name="value"></param>
248
+ /// <returns></returns>
249
+ internal static AirshipEditor GetEditor(AirshipSerializedProperty value) {
250
+ if (!value.isAirshipType) return null;
251
+
252
+ var component = value.objectReferenceValue;
253
+ if (component == null) return null;
254
+
255
+ if (component is AirshipComponent airshipComponent) {
256
+ return GetEditor(airshipComponent);
257
+ };
258
+
259
+ // TODO: In future we'll support Serializable objects & ScriptableObjects through here too.
260
+ return null;
261
+ }
262
+
263
+ /// <summary>
264
+ /// Gets the editor's property decorator for the given luau property decorator
265
+ /// </summary>
266
+ /// <param name="decorator"></param>
267
+ /// <param name="propertyDecorator"></param>
268
+ /// <returns></returns>
269
+ internal static bool TryGetDecorator(LuauMetadataDecoratorElement decorator, out AirshipPropertyDecorator propertyDecorator) {
270
+ if (decoratorNameToEditorType.TryGetValue(decorator.name, out var decoratorType)) {
271
+ if (!typeToEditorPropertyDecorator.TryGetValue(decoratorType, out propertyDecorator)) {
272
+ propertyDecorator = (AirshipPropertyDecorator)ScriptableObject.CreateInstance(decoratorType);
273
+ typeToEditorPropertyDecorator.Add(decoratorType, propertyDecorator);
274
+ }
275
+
276
+ return true;
277
+ }
278
+
279
+ propertyDecorator = default;
280
+ return false;
281
+ }
282
+
283
+ /// <summary>
284
+ /// Get the editor for the given AirshipComponent
285
+ /// </summary>
286
+ /// <param name="component">The component to get the editor for</param>
287
+ /// <returns>The editor, if it exists otherwise null</returns>
288
+ public static AirshipEditor GetEditor(AirshipComponent component) {
289
+ if (component != null && component.script != null) {
290
+ var airshipType = component.GetAirshipType();
291
+
292
+ var serializedObject = new AirshipSerializedObject();
293
+ serializedObject.Update(null, new SerializedObject(component), component.metadata);
294
+
295
+ return GetComponentEditorForType(airshipType, component, serializedObject);
296
+ }
297
+
298
+ return null;
299
+ }
300
+
301
+ #endregion
302
+
303
+ private static void DestroyEditor(int editorId) {
304
+ if (instanceToAirshipEditor.TryGetValue(editorId, out var editor)) {
305
+ instanceToAirshipEditor.Remove(editorId);
306
+ Object.DestroyImmediate(editor);
307
+ }
308
+ }
309
+
310
+ /// <summary>
311
+ /// Destroy the editor for the given airship component
312
+ /// </summary>
313
+ /// <param name="component">The airship component</param>
314
+ internal static void DestroyEditor(AirshipComponent component) {
315
+ if (component.script != null && component.metadata != null && !component) {
316
+ DestroyEditor(component.GetInstanceID());
317
+ }
318
+ }
319
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: a116e7f80e094234913b006e1a0ed2e9
3
+ timeCreated: 1759552753