Compare commits
	
		
			3 Commits
		
	
	
		
			59c1924fab
			...
			b6dbfea477
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| b6dbfea477 | |||
| 93793e1762 | |||
| 810d621fcd | 
@@ -12,9 +12,9 @@ namespace Syntriax.Modules.Movement.Config
 | 
				
			|||||||
    /// </remarks>
 | 
					    /// </remarks>
 | 
				
			||||||
    public class MovementDefinitionFactory : MonoBehaviour
 | 
					    public class MovementDefinitionFactory : MonoBehaviour
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private const string Name = "Movement Definition Factory";
 | 
					        internal const string Name = "Movement Definition Factory";
 | 
				
			||||||
        private const int InitialCapacity = 64;
 | 
					        internal const int InitialCapacity = 64;
 | 
				
			||||||
        private const string ResourceDirectoryToDefinitions = "Modules/Syntriax/Movement/Definitions/";
 | 
					        internal const string ResourceDirectoryToDefinitions = "Modules/Syntriax/Movement/Definitions/";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private static MovementDefinitionFactory _instance = null;
 | 
					        private static MovementDefinitionFactory _instance = null;
 | 
				
			||||||
        public static MovementDefinitionFactory Instance
 | 
					        public static MovementDefinitionFactory Instance
 | 
				
			||||||
@@ -135,14 +135,5 @@ namespace Syntriax.Modules.Movement.Config
 | 
				
			|||||||
                foreach (string monoBehaviours in definition.MonoBehaviours)
 | 
					                foreach (string monoBehaviours in definition.MonoBehaviours)
 | 
				
			||||||
                    MovementFactory.Instance.AddToGameObject(gameObject, monoBehaviours);
 | 
					                    MovementFactory.Instance.AddToGameObject(gameObject, monoBehaviours);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
#if UNITY_EDITOR
 | 
					 | 
				
			||||||
        public void SaveMovementDefinition(MovementDefinition definition)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            string jsonText = JsonUtility.ToJson(definition, true);
 | 
					 | 
				
			||||||
            string path = $"Assets/Resources/{ResourceDirectoryToDefinitions}{definition.Name}.json";
 | 
					 | 
				
			||||||
            System.IO.File.WriteAllText(path, jsonText);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,7 +72,7 @@ namespace Syntriax.Modules.Movement.Config
 | 
				
			|||||||
            return gameObject.AddComponent(Types[name]);
 | 
					            return gameObject.AddComponent(Types[name]);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public string GetTypeName(Type type)
 | 
					        public static string GetTypeName(Type type)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (string.IsNullOrEmpty(type.Namespace))
 | 
					            if (string.IsNullOrEmpty(type.Namespace))
 | 
				
			||||||
                return type.Name;
 | 
					                return type.Name;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										8
									
								
								Editor.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Editor.meta
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					fileFormatVersion: 2
 | 
				
			||||||
 | 
					guid: 2d295c54744337740b623590636ad11a
 | 
				
			||||||
 | 
					folderAsset: yes
 | 
				
			||||||
 | 
					DefaultImporter:
 | 
				
			||||||
 | 
					  externalObjects: {}
 | 
				
			||||||
 | 
					  userData: 
 | 
				
			||||||
 | 
					  assetBundleName: 
 | 
				
			||||||
 | 
					  assetBundleVariant: 
 | 
				
			||||||
							
								
								
									
										102
									
								
								Editor/DefinitionCreatorEditor.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								Editor/DefinitionCreatorEditor.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,102 @@
 | 
				
			|||||||
 | 
					using UnityEngine;
 | 
				
			||||||
 | 
					using UnityEditor;
 | 
				
			||||||
 | 
					using UnityEditorInternal;
 | 
				
			||||||
 | 
					using Syntriax.Modules.Movement.Config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Syntriax.Modules.Movement.Editor
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public class DefinitionCreatorEditor : EditorWindow
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        ReorderableList list;
 | 
				
			||||||
 | 
					        public MovementDefinition movementDefinition = new MovementDefinition();
 | 
				
			||||||
 | 
					        private SerializedObject serializedObject;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [MenuItem("Syntriax/Modules/Movement/Definition Creator")]
 | 
				
			||||||
 | 
					        private static void ShowWindow()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var window = GetWindow<DefinitionCreatorEditor>();
 | 
				
			||||||
 | 
					            window.titleContent = new GUIContent("Definition Creator");
 | 
				
			||||||
 | 
					            window.Reset();
 | 
				
			||||||
 | 
					            window.Show();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private void Reset()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            movementDefinition.Name = "Example Movement Definition";
 | 
				
			||||||
 | 
					            movementDefinition.MovementConfigs = new MovementConfig[] { new MovementConfig(MovementFactory.GetTypeName(typeof(Implementations.GroundMovement1D)), 5f) };
 | 
				
			||||||
 | 
					            movementDefinition.MonoBehaviours = new string[] { MovementFactory.GetTypeName(typeof(MovementController)) };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            serializedObject = new SerializedObject(this);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private void OnEnable() => serializedObject = new SerializedObject(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private void OnGUI()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            GUILayout.Space(10);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            SerializedProperty movementDefinitionProperty = serializedObject.FindProperty("movementDefinition");
 | 
				
			||||||
 | 
					            SerializedProperty movementName = movementDefinitionProperty.FindPropertyRelative("Name");
 | 
				
			||||||
 | 
					            SerializedProperty movementMovementConfigs = movementDefinitionProperty.FindPropertyRelative("MovementConfigs");
 | 
				
			||||||
 | 
					            SerializedProperty movementMonoBehaviours = movementDefinitionProperty.FindPropertyRelative("MonoBehaviours");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // EditorGUILayout.PropertyField(movementDefinitionProperty, new GUIContent("New Movement Definition"), true);
 | 
				
			||||||
 | 
					            EditorGUILayout.PropertyField(movementName);
 | 
				
			||||||
 | 
					            EditorGUILayout.PropertyField(movementMovementConfigs, true);
 | 
				
			||||||
 | 
					            EditorGUILayout.PropertyField(movementMonoBehaviours);
 | 
				
			||||||
 | 
					            serializedObject.ApplyModifiedProperties();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            GUILayout.Space(10);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            bool createButtonPressed = GUILayout.Button("Create");
 | 
				
			||||||
 | 
					            GUILayout.Label($"Will be saved to Assets/Resources/{MovementDefinitionFactory.ResourceDirectoryToDefinitions}{movementName.stringValue}.json");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            GUILayout.Space(10);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            GUILayout.Label("Tip: MovementConfigs->TypeName and MonoBehaviours have the same naming system");
 | 
				
			||||||
 | 
					            GUILayout.Label("If under a namespace: \"Namespace.ClassName\"");
 | 
				
			||||||
 | 
					            GUILayout.Label("If not under a namespace: \"ClassName\"");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (!createButtonPressed)
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (string.IsNullOrWhiteSpace(movementName.stringValue))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                EditorUtility.DisplayDialog("Empty Name Field", "Name field must be not empty", "OK");
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            string resourceDirectoryToDefinitions = MovementDefinitionFactory.ResourceDirectoryToDefinitions;
 | 
				
			||||||
 | 
					            string[] folders = resourceDirectoryToDefinitions.Split('/');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            string currentPath = "Assets/Resources";
 | 
				
			||||||
 | 
					            CreateSubFolder("Assets", "Resources");
 | 
				
			||||||
 | 
					            foreach (string folder in folders)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                CreateSubFolder(currentPath, folder);
 | 
				
			||||||
 | 
					                currentPath += $"/{folder}";
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            currentPath += $"/{movementName.stringValue}.json";
 | 
				
			||||||
 | 
					            SaveMovementDefinition(movementDefinition);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private void CreateSubFolder(string parentFolder, string subFolder)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (!AssetDatabase.IsValidFolder($"{parentFolder}/{subFolder}"))
 | 
				
			||||||
 | 
					                AssetDatabase.CreateFolder(parentFolder, subFolder);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public void SaveMovementDefinition(MovementDefinition definition)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            string jsonText = JsonUtility.ToJson(definition, true);
 | 
				
			||||||
 | 
					            string path = $"Assets/Resources/{MovementDefinitionFactory.ResourceDirectoryToDefinitions}{definition.Name}.json";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (!EditorUtility.DisplayDialog("Conflict", $"\"{path}\" already exists, do you want to overwrite?", "Overwrite", "Cancel"))
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            System.IO.File.WriteAllText(path, jsonText);
 | 
				
			||||||
 | 
					            AssetDatabase.Refresh();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										11
									
								
								Editor/DefinitionCreatorEditor.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Editor/DefinitionCreatorEditor.cs.meta
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					fileFormatVersion: 2
 | 
				
			||||||
 | 
					guid: 66c563464d207f24999eef31c43f1fc8
 | 
				
			||||||
 | 
					MonoImporter:
 | 
				
			||||||
 | 
					  externalObjects: {}
 | 
				
			||||||
 | 
					  serializedVersion: 2
 | 
				
			||||||
 | 
					  defaultReferences: []
 | 
				
			||||||
 | 
					  executionOrder: 0
 | 
				
			||||||
 | 
					  icon: {instanceID: 0}
 | 
				
			||||||
 | 
					  userData: 
 | 
				
			||||||
 | 
					  assetBundleName: 
 | 
				
			||||||
 | 
					  assetBundleVariant: 
 | 
				
			||||||
 Submodule ToggleState updated: 463182ab43...6afed7407d
									
								
							
		Reference in New Issue
	
	Block a user