private static void CreateAsset(string path = null) { messengerData = ScriptableObject.CreateInstance<MessengerData>(); AssetDatabase.CreateAsset(messengerData, path?? MessengerData.ASSET_PATH); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = messengerData; }
private void ChangeData(MessengerData newData) { messengerDataSerializedObject = newData != null? new SerializedObject(newData) : null; if (messengerDataSerializedObject != null) { list = new ReorderableList(messengerDataSerializedObject, messengerDataSerializedObject.FindProperty("eventTypes"), true, true, true, true); } else { list = new ReorderableList(new System.Collections.Generic.List<string>(), typeof(string), true, true, true, true); } list.drawHeaderCallback += DrawHeader; list.drawElementCallback += DrawElement; list.onAddCallback += AddItem; list.onRemoveCallback += RemoveItem; }
private static void ReplaceAsset() { MessengerData temp = messengerData; messengerData = ScriptableObject.CreateInstance<MessengerData>(); messengerData.eventTypes = temp.eventTypes.ConvertAll(e => e.Clone() as MessengerEventTag); }
private static void LoadAsset() { UnityEngine.Object asset = AssetDatabase.LoadAssetAtPath(MessengerData.ASSET_PATH, typeof(MessengerData)); messengerData = (MessengerData)asset; }
private void OnGUI() { if (messengerDataSerializedObject != null) { messengerDataSerializedObject.Update(); } boxStyle = new GUIStyle(); boxStyle.padding = new RectOffset(5, 5, 5, 5); EditorGUILayout.BeginVertical(boxStyle); EditorGUILayout.BeginHorizontal(); previousData = messengerData; messengerData = EditorGUILayout.ObjectField("Asset", messengerData, typeof(MessengerData), false) as MessengerData; if (GUILayout.Button(createContent, GUILayout.Width(25f))) { var path = EditorUtility.SaveFilePanelInProject("Create new asset", string.Empty, "asset", string.Empty); if (path.Length != 0) { EditorApplication.delayCall += () => OnAssetCreate(path); } } if (previousData != messengerData) { ChangeData(messengerData); previousData = messengerData; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); GUI.enabled = messengerDataSerializedObject != null; scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false); list.DoLayoutList(); GUILayout.EndScrollView(); if (GUILayout.Button(generateFileContent)) { WriteCodeFile(messengerData.name); } EditorGUILayout.EndVertical(); if (messengerDataSerializedObject != null) { messengerDataSerializedObject.ApplyModifiedProperties(); } }
private void OnAssetCreate(string path) { CreateAsset(path); ChangeData(messengerData); previousData = messengerData; }