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); } } }
private void InvokeOnActivated(GameStateAsset o) { OnActivated.Invoke(o); foreach (GameManagerProxy p in items) { p.OnActivated.Invoke(o); } }
private void InvokeOnChangeRequest(GameStateAsset o, GameStateAsset n) { OnChangeRequest.Invoke(o, n); foreach (GameManagerProxy p in items) { p.OnChangeRequest.Invoke(o, n); } }
public IEnumerator DoForceChange(GameStateAsset s) { bool result = false; do { yield return(new WaitForEndOfFrame()); GameManager.Instance.ChangeGameState(s, out result); }while(!result); DoForceChangeCoroutine = null; }
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(); } }
private void StateInStart() { ProccessRequests = false; current = next; next = null; if (current != null) { StartCoroutine(StateInC()); } else { fsm.ChangeState(IDLE_STATE); } }
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)); }
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); }
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; }
public void ChangeGameState(GameStateAsset s) { bool result = false; ChangeGameState(s, out result); }
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; }
private int gameStatesComparer(GameStateAsset a, GameStateAsset b) { return(string.Compare(a.name, b.name)); }
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); }