示例#1
0
        /// <summary></summary>
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            _fixedUpdateDrawingList.DoLayoutList();
            _updateDrawingList.DoLayoutList();
            _lateUpdateDrawingList.DoLayoutList();

            if (!Application.isPlaying)
            {
                EditorGUILayout.Space();
                string[] options = new string[] {
                    "Do not bind specified Game Objects on Start", "Bind only specified Game Objects on Start",
                };
                int newValue = EditorGUILayout.Popup("", _loadingState.intValue, options);
                if (newValue != _loadingState.intValue)
                {
                    _loadingState.intValue = newValue;
                }
                EditorGUI.indentLevel += 1;
                for (int i = 0; i < _specialGameObjects.arraySize; i++)
                {
                    GameObject currentGO = (GameObject)_specialGameObjects.GetArrayElementAtIndex(i).objectReferenceValue;
                    if (currentGO == null)
                    {
                        _specialGameObjects.DeleteArrayElementAtIndex(i);
                        i--;
                    }
                    else
                    {
                        GameObject updatedGO = (GameObject)EditorGUILayout.ObjectField(currentGO, typeof(GameObject), true);
                        _specialGameObjects.GetArrayElementAtIndex(i).objectReferenceValue = updatedGO;
                    }
                }
                _specialGameObjects.InsertArrayElementAtIndex(0);
                _specialGameObjects.GetArrayElementAtIndex(0).objectReferenceValue = (GameObject)EditorGUILayout.ObjectField(null, typeof(GameObject), true);

                EditorGUI.indentLevel -= 1;

                string newWrapperPath = EditorGUILayout.DelayedTextField(new GUIContent("Wrappers directory", "The path where wrappers are stored."), _outputWrappers.stringValue);
                if (newWrapperPath != _outputWrappers.stringValue)
                {
                    if (EditorUtility.DisplayDialog("Warning", "If you change FYFY wrappers' directory, all events linked with systems' functions will be lost. Are you sure to continue?", "Yes, remove old directory", "Cancel"))
                    {
                        // remove all wrappers
                        List <MonoBehaviour> currentsComponents = new List <MonoBehaviour>(((MainLoop)target).GetComponents <MonoBehaviour>());
                        foreach (MonoBehaviour currentComponent in currentsComponents)
                        {
                            if (currentComponent != null)
                            {
                                // Check if current component is a system wrapper
                                Type componentType = currentComponent.GetType();
                                if (componentType.FullName.EndsWith("_wrapper"))
                                {
                                    DestroyImmediate(currentComponent);                                      // Because we are in editmode, we don't use GameObjectManager
                                }
                            }
                        }

                        // remove directory
                        if (Directory.Exists(_outputWrappers.stringValue))
                        {
                            Directory.Delete(_outputWrappers.stringValue, true);
                        }
                        if (File.Exists(_outputWrappers.stringValue + ".meta"))
                        {
                            File.Delete(_outputWrappers.stringValue + ".meta");
                        }
                        _outputWrappers.stringValue = newWrapperPath;
                        UnityEngine.Debug.Log("Refresh Data base");
                        AssetDatabase.Refresh();
                    }
                    else
                    {
                        _outputWrappers.stringValue = _outputWrappers.stringValue;                         // reset value
                    }
                }
            }
            else
            {
                MainLoop ml = (MainLoop)target;
                // init monitor if required
                if (_systemsMonitor == null)
                {
                    _systemsMonitor          = new SystemsMonitor(HISTORY_DATA_LENGTH);
                    _fixedUpdateStatsHistory = new Queue <float> (new float[HISTORY_DATA_LENGTH]);
                    _updateStatsHistory      = new Queue <float> (new float[HISTORY_DATA_LENGTH]);
                    _lateUpdateStatsHistory  = new Queue <float> (new float[HISTORY_DATA_LENGTH]);
                }
                if (!EditorApplication.isPaused)
                {
                    _fixedUpdateStatsHistory.Dequeue();
                    _fixedUpdateStatsHistory.Enqueue(ml.fixedUpdateStats);
                    _updateStatsHistory.Dequeue();
                    _updateStatsHistory.Enqueue(ml.updateStats);
                    _lateUpdateStatsHistory.Dequeue();
                    _lateUpdateStatsHistory.Enqueue(ml.lateUpdateStats);
                }

                EditorGUILayout.Space();
                ml.showSystemProfiler = EditorGUILayout.Foldout(ml.showSystemProfiler, "FSystem profiler (ms)");
                if (ml.showSystemProfiler)
                {
                    _systemsMonitor.Draw(_fixedUpdateStatsHistory.ToArray(), _updateStatsHistory.ToArray(), _lateUpdateStatsHistory.ToArray(), 100f);
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Bind tools");
                EditorGUI.indentLevel += 1;
                GameObject tmp = null;
                tmp = EditorGUILayout.ObjectField(new GUIContent("Bind Game Object:", "Drag&Drop a game object you want to dynamically bind."), tmp, typeof(UnityEngine.Object), true) as GameObject;
                if (tmp != null)
                {
                    if (GameObjectManager._gameObjectWrappers.ContainsKey(tmp.GetInstanceID()))
                    {
                        EditorUtility.DisplayDialog("Invalid operation", tmp.name + " is already binded to Fyfy", "Ok", "");
                    }
                    else
                    {
                        GameObjectManager.bind(tmp);
                    }
                }
                tmp = null;
                tmp = EditorGUILayout.ObjectField(new GUIContent("Unbind Game Object:", "Drag&Drop a game object you want to dynamically unbind."), tmp, typeof(UnityEngine.Object), true) as GameObject;
                if (tmp != null)
                {
                    if (!GameObjectManager._gameObjectWrappers.ContainsKey(tmp.GetInstanceID()))
                    {
                        EditorUtility.DisplayDialog("Invalid operation", tmp.name + " is not currently binded to Fyfy", "Ok", "");
                    }
                    else
                    {
                        GameObjectManager.unbind(tmp);
                    }
                }
                EditorGUI.indentLevel -= 1;

                EditorGUILayout.Space();
                ml.showFamilyInspector = EditorGUILayout.Foldout(ml.showFamilyInspector, "Families inspector");
                if (ml.showFamilyInspector)
                {
                    EditorGUI.indentLevel            += 1;
                    ml.showFamilyInspectorFixedUpdate = EditorGUILayout.Foldout(ml.showFamilyInspectorFixedUpdate, "FixedUpdate");
                    if (ml.showFamilyInspectorFixedUpdate)
                    {
                        displayFamilies(FSystemManager._fixedUpdateSystems);
                    }
                    ml.showFamilyInspectorUpdate = EditorGUILayout.Foldout(ml.showFamilyInspectorUpdate, "Update");
                    if (ml.showFamilyInspectorUpdate)
                    {
                        displayFamilies(FSystemManager._updateSystems);
                    }
                    ml.showFamilyInspectorLateUpdate = EditorGUILayout.Foldout(ml.showFamilyInspectorLateUpdate, "LateUpdate");
                    if (ml.showFamilyInspectorLateUpdate)
                    {
                        displayFamilies(FSystemManager._lateUpdateSystems);
                    }
                    EditorGUI.indentLevel -= 1;
                }
                this.Repaint();
            }

            serializedObject.ApplyModifiedProperties();
        }
示例#2
0
        /// <summary></summary>
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            _fixedUpdateDrawingList.DoLayoutList();
            _updateDrawingList.DoLayoutList();
            _lateUpdateDrawingList.DoLayoutList();

            if (!Application.isPlaying)
            {
                EditorGUILayout.Space();
                string[] options = new string[] {
                    "Do not bind specified Game Objects on Start", "Bind only specified Game Objects on Start",
                };
                int newValue = EditorGUILayout.Popup("", _loadingState.intValue, options);
                if (newValue != _loadingState.intValue)
                {
                    _loadingState.intValue = newValue;
                }
                EditorGUI.indentLevel += 1;
                for (int i = 0; i < _specialGameObjects.arraySize; i++)
                {
                    GameObject currentGO = (GameObject)_specialGameObjects.GetArrayElementAtIndex(i).objectReferenceValue;
                    if (currentGO == null)
                    {
                        _specialGameObjects.DeleteArrayElementAtIndex(i);
                        i--;
                    }
                    else
                    {
                        GameObject updatedGO = (GameObject)EditorGUILayout.ObjectField(currentGO, typeof(GameObject), true);
                        _specialGameObjects.GetArrayElementAtIndex(i).objectReferenceValue = updatedGO;
                    }
                }
                _specialGameObjects.InsertArrayElementAtIndex(0);
                _specialGameObjects.GetArrayElementAtIndex(0).objectReferenceValue = (GameObject)EditorGUILayout.ObjectField(null, typeof(GameObject), true);

                EditorGUI.indentLevel -= 1;
            }
            else
            {
                MainLoop ml = (MainLoop)target;
                // init monitor if required
                if (_systemsMonitor == null)
                {
                    _systemsMonitor          = new SystemsMonitor(HISTORY_DATA_LENGTH);
                    _fixedUpdateStatsHistory = new Queue <float> (new float[HISTORY_DATA_LENGTH]);
                    _updateStatsHistory      = new Queue <float> (new float[HISTORY_DATA_LENGTH]);
                    _lateUpdateStatsHistory  = new Queue <float> (new float[HISTORY_DATA_LENGTH]);
                }
                if (!EditorApplication.isPaused)
                {
                    _fixedUpdateStatsHistory.Dequeue();
                    _fixedUpdateStatsHistory.Enqueue(ml.fixedUpdateStats);
                    _updateStatsHistory.Dequeue();
                    _updateStatsHistory.Enqueue(ml.updateStats);
                    _lateUpdateStatsHistory.Dequeue();
                    _lateUpdateStatsHistory.Enqueue(ml.lateUpdateStats);
                }

                EditorGUILayout.Space();
                ml.showSystemProfiler = EditorGUILayout.Foldout(ml.showSystemProfiler, "FSystem profiler (ms)");
                if (ml.showSystemProfiler)
                {
                    _systemsMonitor.Draw(_fixedUpdateStatsHistory.ToArray(), _updateStatsHistory.ToArray(), _lateUpdateStatsHistory.ToArray(), 100f);
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Bind tools");
                EditorGUI.indentLevel += 1;
                GameObject tmp = null;
                tmp = EditorGUILayout.ObjectField(new GUIContent("Bind Game Object:", "Drag&Drop a game object you want to dynamically bind."), tmp, typeof(UnityEngine.Object), true) as GameObject;
                if (tmp != null)
                {
                    if (GameObjectManager._gameObjectWrappers.ContainsKey(tmp.GetInstanceID()))
                    {
                        EditorUtility.DisplayDialog("Invalid operation", tmp.name + " is already binded to Fyfy", "Ok", "");
                    }
                    else
                    {
                        GameObjectManager.bind(tmp);
                    }
                }
                tmp = null;
                tmp = EditorGUILayout.ObjectField(new GUIContent("Unbind Game Object:", "Drag&Drop a game object you want to dynamically unbind."), tmp, typeof(UnityEngine.Object), true) as GameObject;
                if (tmp != null)
                {
                    if (!GameObjectManager._gameObjectWrappers.ContainsKey(tmp.GetInstanceID()))
                    {
                        EditorUtility.DisplayDialog("Invalid operation", tmp.name + " is not currently binded to Fyfy", "Ok", "");
                    }
                    else
                    {
                        GameObjectManager.unbind(tmp);
                    }
                }
                EditorGUI.indentLevel -= 1;

                EditorGUILayout.Space();
                ml.showFamilyInspector = EditorGUILayout.Foldout(ml.showFamilyInspector, "Families inspector");
                if (ml.showFamilyInspector)
                {
                    EditorGUI.indentLevel            += 1;
                    ml.showFamilyInspectorFixedUpdate = EditorGUILayout.Foldout(ml.showFamilyInspectorFixedUpdate, "FixedUpdate");
                    if (ml.showFamilyInspectorFixedUpdate)
                    {
                        displayFamilies(FSystemManager._fixedUpdateSystems);
                    }
                    ml.showFamilyInspectorUpdate = EditorGUILayout.Foldout(ml.showFamilyInspectorUpdate, "Update");
                    if (ml.showFamilyInspectorUpdate)
                    {
                        displayFamilies(FSystemManager._updateSystems);
                    }
                    ml.showFamilyInspectorLateUpdate = EditorGUILayout.Foldout(ml.showFamilyInspectorLateUpdate, "LateUpdate");
                    if (ml.showFamilyInspectorLateUpdate)
                    {
                        displayFamilies(FSystemManager._lateUpdateSystems);
                    }
                    EditorGUI.indentLevel -= 1;
                }
                this.Repaint();
            }

            serializedObject.ApplyModifiedProperties();
        }