예제 #1
0
        private static void Update()
        {
            if (selectionChanged == false)
            {
                return;
            }

            selectionChanged = false;

            if (Selection.activeObject != wrapper)
            {
                string fn = AssetDatabase.GetAssetPath(Selection.activeInstanceID);
                if (fn.ToLower().EndsWith(FILE_EXTENSION))
                {
                    if (wrapper == null)
                    {
                        wrapper           = ScriptableObject.CreateInstance <StateJsonFileWrapper>();
                        wrapper.hideFlags = HideFlags.DontSave;
                    }

                    wrapper.FileName       = fn;
                    Selection.activeObject = wrapper;

                    UnityEditor.Editor[] editor = Resources.FindObjectsOfTypeAll <StateJsonFileWrapperInspector>();

                    if (editor.Length > 0)
                    {
                        editor[0].Repaint();
                    }
                }
            }
        }
예제 #2
0
        public override void OnInspectorGUI()
        {
            StateJsonFileWrapper wrapper = (StateJsonFileWrapper)target;

            RenderHeader(wrapper);

            if (!File.Exists(wrapper.FileName))
            {
                return;
            }

            // Display Json
            bool dirty = false;

            this.leftScrollPos = EditorGUILayout.BeginScrollView(this.leftScrollPos, GUI.skin.box);
            {
                var updatedAt = File.GetLastWriteTimeUtc(wrapper.FileName);
                if (this.fileText == null || updatedAt.CompareTo(this.lastUpdatedAt) > 0)
                {
                    this.lastUpdatedAt = updatedAt;
                    this.fileText      = File.ReadAllText(wrapper.FileName);
                    this.fileJson      = Json.Deserialize(this.fileText);
                }

                if (this.fileJson is Dictionary <string, object> )
                {
                    dirty = RenderJsonDictionary(new string[0] {
                    }, this.fileJson as Dictionary <string, object>);
                }
                else if (this.fileJson is List <object> )
                {
                    dirty = RenderJsonArray(new string[0] {
                    }, "", this.fileJson as List <object>);
                }
                else
                {
                    EditorGUILayout.LabelField(this.fileText);
                }
            }
            EditorGUILayout.EndScrollView();

            if (dirty)
            {
                string content = Json.Serialize(this.fileJson);
                File.WriteAllText(wrapper.FileName, content);
                AssetDatabase.Refresh();
            }
        }
예제 #3
0
        private void RenderHeader(StateJsonFileWrapper wrapper)
        {
            EditorGUILayout.LabelField("Shown by Unidux.StateJsonEditor", EditorStyles.boldLabel);
            EditorGUILayout.BeginHorizontal(GUIStyle.none);
            EditorGUILayout.LabelField(wrapper.FileName, EditorStyles.miniLabel);

            if (File.Exists("/usr/bin/open"))
            {
                if (GUILayout.Button("OpenFile", EditorStyles.miniButton))
                {
                    System.Diagnostics.Process.Start("/usr/bin/open", wrapper.FileName);
                }
                if (GUILayout.Button("OpenDir", EditorStyles.miniButton))
                {
                    System.Diagnostics.Process.Start("/usr/bin/open", Path.GetDirectoryName(wrapper.FileName));
                }
            }
            EditorGUILayout.EndHorizontal();
        }