static SimpleNoteManager GetInstance()
        {
            SimpleNoteManager _instance = FindObjectOfType <SimpleNoteManager>();

            //Delete the old implementation
            if (_instance != null)
            {
                if (_instance.hideFlags == HideFlags.HideInHierarchy)
                {
                    System.Type       type        = _instance.GetType();
                    GameObject        destination = new GameObject("NoteManager");
                    SimpleNoteManager copy        = destination.AddComponent <SimpleNoteManager>();
                    // Copied fields can be restricted with BindingFlags
                    System.Reflection.FieldInfo[] fields = type.GetFields();
                    foreach (System.Reflection.FieldInfo field in fields)
                    {
                        Debug.Log("Are you here?");
                        field.SetValue(copy, field.GetValue(_instance));
                    }
                    DestroyImmediate(_instance.gameObject);
                    _instance = copy;
                }
            }
            return(_instance);
        }
        public static void AddRemoveNote()
        {
            if (!Selection.activeObject)
            {
                Debug.Log("No Game Object Selected");
            }
            else
            {
                foreach (GameObject obj in Selection.gameObjects)
                {
                    if (SimpleNoteManager.Instance == null)
                    {
                        SimpleNoteManager.Init();
                    }
                    if (SimpleNoteManager.Instance.getIndexGameObjectNote(obj) != -1)
                    {
                        SimpleNoteManager.Instance.gameObjectNote.RemoveAt(SimpleNoteManager.Instance.getIndexGameObjectNote(obj));
                    }
                    else
                    {
                        SimpleNoteManager.Instance.gameObjectNote.Add(new SimpleNoteManager.GameObjectNote(obj, obj.name, "Note"));
                    }
#if UNITY_5_0 || UNITY_5_1 || UNITY_5_2
#else
                    UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
#endif
                    EditorUtility.SetDirty(SimpleNoteManager.Instance);
                }
            }
        }
        public static SimpleNoteManager Init()
        {
            SimpleNoteManager _instance = GetInstance();

            if (_instance == null)
            {
                GameObject instance = new GameObject("NoteManager");
                //instance.hideFlags = HideFlags.HideInHierarchy;
                _instance = instance.AddComponent <SimpleNoteManager>();
            }
            return(_instance);
        }
示例#4
0
        static SimpleNoteManager GetInstance()
        {
            SimpleNoteManager _instance = FindObjectOfType <SimpleNoteManager>();

            if (_instance == null)
            {
                GameObject instance = new GameObject("NoteManager");
                instance.hideFlags = HideFlags.HideInHierarchy;
                _instance          = instance.AddComponent <SimpleNoteManager>();
            }
            return(_instance);
        }
        public override void OnInspectorGUI()
        {
            if (monoBehaviour == null)
            {
                monoBehaviour = (MonoBehaviour)target;
            }
            SimpleNoteAttribute attribute = (SimpleNoteAttribute)PropertyAttribute.GetCustomAttribute(monoBehaviour.GetType(), typeof(SimpleNoteAttribute));

            if (attribute != null)
            {
                //Check if note stored to manager;
                if (SimpleNoteManager.Instance == null)
                {
                    SimpleNoteManager.Init();
                }
                if (SimpleNoteManager.Instance.getIndexAttributeScriptNote(monoBehaviour.gameObject, monoBehaviour) == -1)
                {
                    if (string.IsNullOrEmpty(attribute.title) && string.IsNullOrEmpty(attribute.note))
                    {
                        SimpleNoteManager.Instance.attScriptNote.Add(new SimpleNoteManager.AttributeScriptNote(monoBehaviour.gameObject, monoBehaviour, title, note));
                    }
                    else
                    {
                        SimpleNoteManager.Instance.attScriptNote.Add(new SimpleNoteManager.AttributeScriptNote(monoBehaviour.gameObject, monoBehaviour, attribute.title, attribute.note));
                        title = attribute.title;
                        note  = attribute.note;
                    }
                }
                if (index == -1)
                {
                    index = SimpleNoteManager.Instance.getIndexAttributeScriptNote(monoBehaviour.gameObject, monoBehaviour);
                }

                GUIStyle textField = new GUIStyle(EditorStyles.textField);
                textField.fontStyle = FontStyle.Bold;
                if (GUI.GetNameOfFocusedControl() != "Title" + monoBehaviour.gameObject.GetInstanceID())
                {
                    textField.normal = EditorStyles.label.normal;
                }

                EditorGUILayout.BeginHorizontal();
                title = EditorGUILayout.TextField(title, textField);
                //EditorPrefs.SetString(monoBehaviour.GetInstanceID() + "-SimpleNote-Title", title);
                if (SimpleNoteManager.Instance.attScriptNote[index].note.title != title)
                {
                    SimpleNoteManager.Instance.attScriptNote[index].note.title = title;
                }
                EditorGUILayout.EndHorizontal();

                GUIStyle textArea = new GUIStyle(EditorStyles.textArea);
                textArea.richText = true;
                if (GUI.GetNameOfFocusedControl() != "Note" + monoBehaviour.gameObject.GetInstanceID())
                {
                    textArea.normal = EditorStyles.label.normal;
                }

                EditorGUILayout.BeginHorizontal();

                note = EditorGUILayout.TextArea(note, textArea);
                //EditorPrefs.SetString(monoBehaviour.GetInstanceID() + "-SimpleNote-Note", note);
                if (SimpleNoteManager.Instance.attScriptNote[index].note.note != note)
                {
                    SimpleNoteManager.Instance.attScriptNote[index].note.note = note;
                }

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();
                EditorGUI.DrawRect(GUILayoutUtility.GetLastRect(), SimpleNoteData.Instance.getBgColor1);
            }

            DrawDefaultInspector();
        }