private IEnumerator Track(TrackingPair pair) { while (true) { var currentFsmState = pair.fsmIntrospection.State; isDirty = true; #if PLAYMAKER if (pair.view != null) { pair.view.SetState(currentFsmState); } #endif while (currentFsmState == pair.fsmIntrospection.State) { #if PLAYMAKER if (pair.view != null) { UpdatePlayMakerBreakpoints(pair); pair.view.Fsm.Update(); } #endif yield return(null); } } }
public bool CanShowView(TrackingPair pair) { #if UNITY_EDITOR && PLAYMAKER return(pair.targetFsm != null && pair.fsmPrefab != null && pair.fsmIntrospection != null); #else return(false); #endif }
public void DestroyView(TrackingPair pair) { #if PLAYMAKER if (pair.view == null) { return; } Destroy(pair.view.gameObject); #endif }
public void ShowView(TrackingPair pair) { #if PLAYMAKER if (pair.view != null || !CanShowView(pair)) { return; } var go = Instantiate(pair.fsmPrefab.gameObject); go.transform.parent = transform; var fsm = go.GetComponent <PlayMakerFSM>(); if (fsm == null) { Debug.LogFormat(gameObject, "fsmPrefab does not have a PlayMakerFSM on it"); Destroy(go); return; } fsm.Fsm.ManualUpdate = true; // Sanity check that states line up var fsmStates = fsm.FsmStates.Select(s => s.Name).ToList(); var intersectingStates = pair.fsmIntrospection.AllStates.Intersect(fsmStates).ToList(); if (fsmStates.Count != pair.fsmIntrospection.AllStates.Count || intersectingStates.Count != pair.fsmIntrospection.AllStates.Count) { Debug.LogErrorFormat(gameObject, "Generated FSM and PlayMakerFSM do not have the same set of states"); Destroy(go); return; } go.AddComponent <FsmViewerPrefabInstance>(); pair.view = fsm; #endif }
private void DiscoverTrackingPairs() { #if UNITY_EDITOR // Discover all FSMs on this game object var owners = GetComponents <MonoBehaviour>().Where(b => b is IHaveBaseFsm).ToList(); foreach (var owner in owners) { var fsms = (owner as IHaveBaseFsm).BaseFsms; if (fsms == null) { continue; } foreach (var fsm in fsms) { var pair = new TrackingPair { fsmOwner = owner, targetFsm = fsm, fsmIntrospection = fsm as IFsmIntrospectionSupport, fsmDebug = fsm as IFsmDebugSupport, }; if (pair.fsmIntrospection == null) { continue; } if (pair.fsmDebug != null) { pair.fsmDebug.OnBreakpointHit += OnFsmBreakpointHit; pair.fsmDebug.OnBreakpointSet += OnFsmBreakpointSet; pair.fsmDebug.OnBreakpointsReset += OnFsmBreakpointsReset; } tracking.Add(pair); } } // Collect all prefab FSMs var prefabs = new Dictionary <string, PlayMakerCodeGenerator>(); foreach (var guid in tracking.Select(p => p.fsmIntrospection.GeneratedFromPrefabGUID)) { if (string.IsNullOrEmpty(guid)) { continue; } var path = AssetDatabase.GUIDToAssetPath(guid); if (string.IsNullOrEmpty(path)) { continue; } var gen = AssetDatabase.LoadAssetAtPath(path, typeof(PlayMakerCodeGenerator)); if (gen == null) { continue; } prefabs[guid] = gen as PlayMakerCodeGenerator; } foreach (var pair in tracking) { var guid = pair.fsmIntrospection.GeneratedFromPrefabGUID; if (string.IsNullOrEmpty(guid)) { continue; } prefabs.TryGetValue(guid, out pair.fsmPrefab); } #endif }
private void UpdatePlayMakerBreakpoints(TrackingPair pair) { tempBreakpoints.Clear(); pair.wantEnterBreakpoints.Clear(); foreach (var state in pair.view.FsmStates) { if (state.IsBreakpoint) { pair.wantEnterBreakpoints.Add(state); } } // Find and remove new/removed breakpoints bool isDirty = false; foreach (var breakpoint in pair.wantEnterBreakpoints) { if (!pair.currentEnterBreakpoints.Contains(breakpoint)) { tempBreakpoints.Add(breakpoint); isDirty = true; } } foreach (var breakpoint in pair.currentEnterBreakpoints) { if (pair.wantEnterBreakpoints.Contains(breakpoint)) { tempBreakpoints.Add(breakpoint); } else { isDirty = true; } } if (isDirty) { var b = pair.currentEnterBreakpoints; pair.currentEnterBreakpoints = tempBreakpoints; tempBreakpoints = b; if (pair.fsmDebug == null) { Debug.LogWarningFormat("Cannot set breakpoint on {0}, IFsmDebugSupport was not enabled in compiler options", pair.targetFsm.GetType().Name); } else { pair.settingPlayMakerBreakpoint = true; pair.fsmDebug.ResetBreakpoints(); foreach (var breakpoint in pair.currentEnterBreakpoints) { pair.fsmDebug.SetOnEnterBreakpoint( pair.fsmIntrospection.EnumStateFromString(breakpoint.Name)); } pair.settingPlayMakerBreakpoint = false; } isDirty = false; } }