public static void RunEvent(this KerbalFSM fsm, string name) { foreach (var kfsme in fsm.CurrentState.StateEvents) { if (kfsme.name == name) { fsm.RunEvent(kfsme); } else { Debug.LogError("[assembly: " + Assembly.GetExecutingAssembly().GetName().Name + "]:" + "Event " + name + " not found"); } } }
public void Start() { log = new Log(this.GetType().Name); log.Debug("Start"); if (gui == null) { gui = this.gameObject.AddComponent <MainMenuGui> (); gui.UpdateToolbarStock(); gui.SetVisible(false); } config = readConfig(); KspIssue3838Fix.ApplyFix(config.enableExperimentalEditorExtensionsCompatibility); editorFSM = (KerbalFSM)Refl.GetValue(EditorLogic.fetch, "\u0001"); cursorLocker = Application.platform == RuntimePlatform.WindowsPlayer ? new WinCursorLocker() : (CursorLocker) new UnityLocker(); movementBounds = new Bounds(); if (EditorDriver.editorFacility == EditorFacility.VAB) { movementBounds = config.vab.bounds; } else if (EditorDriver.editorFacility == EditorFacility.SPH) { movementBounds = config.sph.bounds; } if (!config.enforceBounds) { movementBounds = new Bounds(Vector3.zero, Vector3.one * float.MaxValue); } var restartListener = new EventVoid.OnEvent(this.OnEditorRestart); GameEvents.onEditorRestart.Add(restartListener); OnCleanup += () => GameEvents.onEditorRestart.Remove(restartListener); var partEventListener = new EventData <ConstructionEventType, Part> .OnEvent(this.OnPartEvent); GameEvents.onEditorPartEvent.Add(partEventListener); OnCleanup += () => GameEvents.onEditorPartEvent.Remove(partEventListener); if (config.defaultCamera) { SwitchMode(false); ResetCamera(); } }
public void Start() { Log.SetTitle ("this.GetType ().Name"); Log.Debug ("Start"); #if (DEBUG) Log.SetLevel (Log.LEVEL.INFO); Log.Debug ("Start"); gui = null; #endif if (gui == null) { gui = this.gameObject.AddComponent<MainMenuGui> (); gui.UpdateToolbarStock (); gui.SetVisible (false); } readConfig (); KspIssue3838Fix.ApplyFix (config.enableExperimentalEditorExtensionsCompatibility); editorFSM = (KerbalFSM)Refl.GetValue (EditorLogic.fetch, "\u0001"); cursorLocker = Application.platform == RuntimePlatform.WindowsPlayer ? new WinCursorLocker () : (CursorLocker)new UnityLocker (); movementBounds = new Bounds (); if (EditorDriver.editorFacility == EditorFacility.VAB) { movementBounds = config.vab.bounds; } else if (EditorDriver.editorFacility == EditorFacility.SPH) { movementBounds = config.sph.bounds; } if (!config.enforceBounds) { movementBounds = new Bounds (Vector3.zero, Vector3.one * float.MaxValue); } var restartListener = new EventVoid.OnEvent (this.OnEditorRestart); GameEvents.onEditorRestart.Add (restartListener); OnCleanup += () => GameEvents.onEditorRestart.Remove (restartListener); var partEventListener = new EventData<ConstructionEventType, Part>.OnEvent (this.OnPartEvent); GameEvents.onEditorPartEvent.Add (partEventListener); OnCleanup += () => GameEvents.onEditorPartEvent.Remove (partEventListener); if (config.defaultCamera) { SwitchMode (false); ResetCamera (); } }
private void StockProcFairing_st_idle_replacement(bool save, Part part) { var module = part.Module <ModuleProceduralFairing>(); MethodInfo[] m = part.GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo[] fields = module.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (replacement_st_editor_idle == null) { replacement_st_editor_idle = new KFSMState("st_idle"); replacement_st_editor_idle.OnLateUpdate = delegate { MouseFadeUpdate(); }; } foreach (FieldInfo fi in fields) { if (fi.Name == "fsm") { fsm = (KerbalFSM)fi.GetValue(module); FieldInfo[] fsmFields = fsm.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); foreach (FieldInfo fsmFi in fsmFields) { if (fsmFi.Name == "States") { List <KFSMState> States = (List <KFSMState>)fsmFi.GetValue(fsm); foreach (var s in States) { log.debug(string.Format("KFSMState name: {0}", s.name)); if (s.name == "st_idle") { if (save) { saved_st_editor_idle = s; States.Remove(s); fsm.AddState(replacement_st_editor_idle); } else { States.Remove(s); fsm.AddState(saved_st_editor_idle); } break; } } } } fsm.StartFSM("st_idle"); if (!save) { foreach (var p in module.Panels) { p.SetExplodedView(0); p.SetOpacity(1); } } break; } } }
public void SetupFSM() { fsm = new KerbalFSM(); st_stowed = new KFSMState("stowed"); fsm.AddState(st_stowed); st_stowed_locked = new KFSMState("stowed_locked"); fsm.AddState(st_stowed_locked); st_deploying = new KFSMState("deploying"); fsm.AddState(st_deploying); st_deployed = new KFSMState("deployed"); fsm.AddState(st_deployed); st_deployed_locked = new KFSMState("deployed_locked"); fsm.AddState(st_deployed_locked); st_stowing = new KFSMState("stowing"); fsm.AddState(st_stowing); on_deploy = new KFSMEvent("on_deploy") { GoToStateOnEvent = st_deploying }; fsm.AddEvent(on_deploy, st_stowed, st_stowing); on_stow = new KFSMEvent("on_stow") { GoToStateOnEvent = st_stowing }; fsm.AddEvent(on_stow, st_deployed, st_deploying); on_deployed = new KFSMEvent("on_deployed") { GoToStateOnEvent = st_deployed, updateMode = KFSMUpdateMode.UPDATE, OnCheckCondition = (st) => (deployAnimator?.animTime ?? 1) == 1 }; fsm.AddEvent(on_deployed, st_deploying); on_stowed = new KFSMEvent("on_stowed") { GoToStateOnEvent = st_stowed, updateMode = KFSMUpdateMode.UPDATE, OnCheckCondition = (st) => (deployAnimator?.animTime ?? 0) == 0 }; fsm.AddEvent(on_stowed, st_stowing); on_lock_deployed = new KFSMEvent("on_lock_deployed") { GoToStateOnEvent = st_deployed_locked, OnEvent = DisableAnimation }; fsm.AddEvent(on_lock_deployed, st_deployed); on_unlock_deployed = new KFSMEvent("on_unlock_deployed") { GoToStateOnEvent = st_deployed, OnEvent = EnableAnimation }; fsm.AddEvent(on_unlock_deployed, st_deployed_locked); on_lock_stowed = new KFSMEvent("on_lock_stowed") { GoToStateOnEvent = st_stowed_locked, OnEvent = DisableAnimation }; fsm.AddEvent(on_lock_stowed, st_stowed); on_unlock_stowed = new KFSMEvent("on_unlock_stowed") { GoToStateOnEvent = st_stowed, OnEvent = EnableAnimation }; fsm.AddEvent(on_unlock_stowed, st_stowed_locked); //fsm.OnStateChange = (fromSt, toSt, e) => UnityEngine.Debug.LogFormat("Moved from {0} to {1} by {2}", fromSt.name, toSt.name, e.name); CustomizeFSM(); }