public void SetEditorInitialState()
        {
            if (!GameManager.useEditorGameStateAsset)
            {
                GameManager.useEditorGameStateAsset = true;
                EditorPrefs.SetBool(GameManagerEditor.UseEditorGameStateKey + Application.productName, GameManager.useEditorGameStateAsset);
            }
            if (GameManager.editorGameStateAsset == null)
            {
                string         statePath     = string.Empty;
                GameStateAsset state         = null;
                var            searchResults = AssetDatabase.FindAssets("state1 t:ScriptableObject");
                foreach (string item in searchResults)
                {
                    string o = AssetDatabase.GUIDToAssetPath(item);
                    if (EditorTools.TrimmAllPath(o).ToLower() == "state1.asset")
                    {
                        statePath = o;
                        state     = AssetDatabase.LoadAssetAtPath <GameStateAsset>(o);
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(statePath))
                {
                    var guid = AssetDatabase.AssetPathToGUID(statePath);
                    GameManager.editorGameStateAsset = state;
                    EditorPrefs.SetString(GameManagerEditor.EditorGameStateKey + Application.productName, guid);
                }
            }
        }
예제 #2
0
 private void InvokeOnActivated(GameStateAsset o)
 {
     OnActivated.Invoke(o);
     foreach (GameManagerProxy p in items)
     {
         p.OnActivated.Invoke(o);
     }
 }
예제 #3
0
 private void InvokeOnChangeRequest(GameStateAsset o, GameStateAsset n)
 {
     OnChangeRequest.Invoke(o, n);
     foreach (GameManagerProxy p in items)
     {
         p.OnChangeRequest.Invoke(o, n);
     }
 }
예제 #4
0
        public IEnumerator DoForceChange(GameStateAsset s)
        {
            bool result = false;

            do
            {
                yield return(new WaitForEndOfFrame());

                GameManager.Instance.ChangeGameState(s, out result);
            }while(!result);
            DoForceChangeCoroutine = null;
        }
예제 #5
0
        private void AddAccess(GameStateAsset s, string stackTrace)
        {
            GMStateAccess a = new GMStateAccess();

            a.name       = s.name;
            a.time       = Time.time;
            a.stackTrace = stackTrace;
            accesses.AddFirst(a);
            if (accesses.Count > accessesLogged)
            {
                accesses.RemoveLast();
            }
        }
예제 #6
0
        private void StateInStart()
        {
            ProccessRequests = false;
            current          = next;
            next             = null;

            if (current != null)
            {
                StartCoroutine(StateInC());
            }
            else
            {
                fsm.ChangeState(IDLE_STATE);
            }
        }
예제 #7
0
        public void ForceChangeGameState(GameStateAsset s)
        {
            bool result = false;

            GameManager.Instance.ChangeGameState(s, out result);
            if (result)
            {
                return;
            }
            if (DoForceChangeCoroutine != null)
            {
                Debug.LogError("It can be only one ForceChangeGameState active at any moment.");
                return;
            }
            DoForceChangeCoroutine = StartCoroutine(DoForceChange(s));
        }
예제 #8
0
        private IEnumerator StateOutC()
        {
            string scenes = string.Empty;

            foreach (string s in toUnload)
            {
                SceneManager.UnloadScene(s);
                scenes += " " + s;
            }
            toUnload.Clear();
            Resources.UnloadUnusedAssets();
            InvokeOnUnloaded(current);
            current = null;
            yield return(new WaitForEndOfFrame());

            fsm.ChangeState(IDLE_STATE);
        }
예제 #9
0
        public void ChangeGameState(GameStateAsset s, out bool result)
        {
            if (!ProccessRequests)
            {
                result = false;
                return;
            }
            next = s;
            GetToUnload();
            GetToLoad();
            if (loadMode == GMLoadMode.LEAVE_REPEATED)
            {
                for (int i = toLoad.Count - 1; i >= 0; i--)
                {
                    SceneLoadData sc = toLoad[i];
                    if (toUnload.Contains(sc.scene))
                    {
                        toUnload.Remove(sc.scene);
                        toLoad.RemoveAt(i);
                    }
                }
            }
            InvokeOnChangeRequest(current, next);

            if (current != null)
            {
                fsm.ChangeState(OUT_STATE);
            }
            else
            {
                fsm.ChangeState(IN_STATE);
            }
            string stackTrace = UnityEngine.StackTraceUtility.ExtractStackTrace();

            AddAccess(s, stackTrace);
            _currentGameState = s;
            result            = true;
            return;
        }
예제 #10
0
        public void ChangeGameState(GameStateAsset s)
        {
            bool result = false;

            ChangeGameState(s, out result);
        }
예제 #11
0
        protected override void OnEnable()
        {
            base.OnEnable();
            if (!Application.isPlaying)
            {
                enabledScenes = EditorTools.GetScenesFromBuildSettings(true);
            }
            gameStateAssetsProperty      = serializedObject.FindProperty("gameStateAssets");
            gameManagerSceneNameProperty = serializedObject.FindProperty("gameManagerSceneName");
            directorInProperty           = serializedObject.FindProperty("directorIn");
            directorOutProperty          = serializedObject.FindProperty("directorOut");
            fsmProperty            = serializedObject.FindProperty("fsm");
            buildInitAssetProperty = serializedObject.FindProperty("buildinitAsset");
            loadModeProperty       = serializedObject.FindProperty("loadMode");

            TestIntegrity();
            GetEditorGState();

            gameStateAssetsList = new ReorderableList(serializedObject,
                                                      gameStateAssetsProperty,
                                                      true, true, true, true);
            gameStateAssetsList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                bool isPlaying    = Application.isPlaying;
                bool enteringPlay = EditorApplication.isPlayingOrWillChangePlaymode;

                var   element   = gameStateAssetsList.serializedProperty.GetArrayElementAtIndex(index);
                Color oldcolor  = GUI.backgroundColor;
                bool  itemValid = true;
                if (element.objectReferenceValue != null)
                {
                    if (!isPlaying && !enteringPlay)
                    {
                        GameStateAsset gsa    = element.objectReferenceValue as GameStateAsset;
                        int            sCount = gsa.scenes.Count;
                        for (int i = 0; i < sCount; i++)
                        {
                            string sceneName = EditorTools.TrimmSceneExtension(gsa.scenes[i].scene);
                            if (!enabledScenes.Contains(sceneName))
                            {
                                itemValid = false;
                                valid     = false;
                            }
                        }
                        if (!itemValid)
                        {
                            GUI.backgroundColor = Color.red;
                        }
                    }
                    Rect itemRect = new Rect(rect.x, rect.y, rect.width + 23, rect.height);
                    EditorGUI.ObjectField(itemRect, element.objectReferenceValue, typeof(GameStateAsset), false);
                }
                GUI.backgroundColor = oldcolor;
            };

            gameStateAssetsList.drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "GameState Items");
            };

            gameStateAssetsList.onRemoveCallback = (ReorderableList l) =>
            {
                if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to delete this item?", "Yes", "No"))
                {
                    ReorderableList.defaultBehaviours.DoRemoveButton(l);
                }
            };
            gameStateAssetsList.elementHeight = 16f;
        }
예제 #12
0
 private int gameStatesComparer(GameStateAsset a, GameStateAsset b)
 {
     return(string.Compare(a.name, b.name));
 }
예제 #13
0
        protected override void DrawCustomEditor()
        {
            valid = true;
            base.DrawCustomEditor();
            if (Application.isPlaying)
            {
                EditorGUILayout.LabelField(new GUIContent("State Changes: ", "List of logged changes to GameState."));
                Rect tblRect = GUILayoutUtility.GetRect(0, Screen.width, 18, 18);
                GUI.Box(tblRect, string.Empty);
                EditorGUI.LabelField(new Rect(tblRect.x, tblRect.y, tblRect.width / 2, tblRect.height), "GameState");
                EditorGUI.LabelField(new Rect(tblRect.x + (tblRect.width / 2), tblRect.y, tblRect.width / 2, tblRect.height), "Time");

                int l = GameManager.Instance.accesses.Count;
                if (l > 0)
                {
                    var e = GameManager.Instance.accesses.First;
                    while (e != null)
                    {
                        Rect ar = GUILayoutUtility.GetRect(0, Screen.width, 18, 18);
                        GUI.Box(ar, string.Empty);
                        EditorGUI.LabelField(new Rect(ar.x, ar.y, ar.width / 2, ar.height), e.Value.name);
                        EditorGUI.LabelField(new Rect(ar.x + (ar.width / 2), ar.y, ar.width / 2, ar.height), e.Value.time.ToString());
                        if (EditorTools.InspectorClicked(ar, Event.current))
                        {
                            Debug.Log("stacktrace for ChangeState to " + e.Value.name + ":\n " + e.Value.stackTrace + " \n------\n");
                        }
                        e = e.Next;
                    }
                }
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                GameManager.accessesLogged = EditorGUILayout.DelayedIntField(new GUIContent("Accesses Logged: ", "Maximun number of accesses to ChangeState that are logged."), GameManager.accessesLogged);
                if (EditorGUI.EndChangeCheck())
                {
                    SetEditorGState();
                }
            }
            GUILayout.Space(20);
            EditorGUILayout.PropertyField(gameManagerSceneNameProperty, new GUIContent("GM Scene"));
            GUILayout.Space(10);
            EditorGUILayout.PropertyField(loadModeProperty, new GUIContent("Load Mode"));

            GUILayout.Space(10);

            EditorGUILayout.PropertyField(buildInitAssetProperty, new GUIContent("Build Initial State"));
            EditorGUI.BeginChangeCheck();
            Rect r  = GUILayoutUtility.GetRect(0, Screen.width, 16, 16);
            Rect r1 = new Rect(r.x, r.y, r.width * 0.385f, r.height);
            Rect r2 = new Rect(r.x + (r.width * 0.385f), r.y, r.width * 0.615f, r.height);

            GameManager.useEditorGameStateAsset = GUI.Toggle(r1, GameManager.useEditorGameStateAsset, new GUIContent("Editor Initial State", "Initial State to load when the GameManager Starts on Editor (saved locally)"), GUI.skin.button);
            GameManager.editorGameStateAsset    = EditorGUI.ObjectField(r2, GameManager.editorGameStateAsset, typeof(GameStateAsset), false) as GameStateAsset;
            if (EditorGUI.EndChangeCheck())
            {
                SetEditorGState();
            }

            GUILayout.Space(10);

            gameStateAssetsList.DoLayoutList();
            if (!valid)
            {
                GUIStyle style = GUI.skin.box;
                style.wordWrap = true;
                GUIContent c = new GUIContent("Some of the selected scenes for this GameState are not added to the Build Settings.");
                float      h = style.CalcHeight(c, Screen.width);
                EditorGUILayout.HelpBox("Some of the selected scenes for this GameState are not added to the Build Settings.", MessageType.Error);

                GUILayout.Space(40 - h);
            }
            else
            {
                GUILayout.Space(40);
            }

            if (GUILayout.Button("Get GameStateAssets"))
            {
                string[] guids = AssetDatabase.FindAssets("t:GameStateAsset");

                gameStateAssetsProperty.ClearArray();
                foreach (string guid in guids)
                {
                    string         aPath = AssetDatabase.GUIDToAssetPath(guid);
                    GameStateAsset o     = AssetDatabase.LoadAssetAtPath <GameStateAsset>(aPath);
                    gameStateAssetsProperty.InsertArrayElementAtIndex(0);
                    gameStateAssetsProperty.GetArrayElementAtIndex(0).objectReferenceValue = o;
                }
                serializedObject.ApplyModifiedProperties();
                (target as GameManager).gameStateAssets.Sort(gameStatesComparer);
                serializedObject.ApplyModifiedProperties();
            }
            GUILayout.Space(20);
        }
 public void ChangeGameState(GameStateAsset s)
 {
     GameManager.Instance.ChangeGameState(s);
 }