Example #1
0
        private void Save()
        {
            dirty     = false;
            note.text = text;

            if (text.Length == 0 && !isNew)
            {
                Delete();
                return;
            }

            if (!inScene)
            {
                if (isNew)
                {
                    isNew = false;
                    EditorNotes.Settings.notes.Add(note);
                    EditorNotes.Settings.UpdateCache();
                    EditorApplication.RepaintProjectWindow();
                }

                EditorUtility.SetDirty(EditorNotes.Settings);
            }
            else
            {
                if (container == null)
                {
                    GameObject go = new GameObject(EditorNotes.NotesContainerObjName)
                    {
                        tag       = "EditorOnly",
                        hideFlags = HideFlags.HideInHierarchy
                    };
                    container = go.AddComponent <NotesContainer>();
                    if (go.scene != targetGO.scene)
                    {
                        EditorSceneManager.MoveGameObjectToScene(go, targetGO.scene);
                    }
                    EditorNotes.UpdateSceneCache();
                }

                if (isNew)
                {
                    isNew = false;
                    container.notes.Add(note);
                    container.UpdateCache();
                    EditorApplication.RepaintHierarchyWindow();
                }

                EditorSceneManager.MarkSceneDirty(container.gameObject.scene);
            }
        }
Example #2
0
        private void UpdateNoteWidow()
        {
            if (dirty && targetObj != null && targetObj != Selection.activeObject)
            {
                if (EditorUtility.DisplayDialog("EdNotes", "Unsaved changes in the object's notes. Save now?", "Yes", "No"))
                {
                    Save();
                }
            }

            Repaint();
            inScene      = false;
            dirty        = false;
            isNew        = false;
            container    = null;
            note         = null;
            text         = "";
            GC_Head.text = "";

            if (Selection.activeObject == null)
            {
                return;
            }

            targetObj    = Selection.activeObject;
            targetGUID   = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(targetObj));
            targetGO     = Selection.activeGameObject;
            GC_Head.text = targetObj.name;

            if (targetGO != null && targetGO.scene.IsValid())
            {
                inScene   = true;
                container = EditorNotes.GetContainer(targetGO.scene);
                if (container != null)
                {
                    foreach (Note n in container.notes)
                    {
                        if (n.targetObj == targetGO)
                        {
                            note = n; break;
                        }
                    }
                }
            }
            else
            {
                List <Note> notesList = EditorNotes.Settings.notes;
                if (notesList != null)
                {
                    foreach (Note n in notesList)
                    {
                        if (n.targetGUID == targetGUID)
                        {
                            note = n; break;
                        }
                    }
                }
            }

            if (note == null)
            {
                isNew = true;
                note  = new Note()
                {
                    targetObj  = targetObj,
                    targetGUID = targetGUID,
                    text       = ""
                };
            }

            text = note.text;
        }