Пример #1
0
 protected virtual void End(string reason)
 {
     if ((UnityEngine.Object)driver != (UnityEngine.Object)null)
     {
         KSelectable component = driver.GetComponent <KSelectable>();
         if ((UnityEngine.Object)component != (UnityEngine.Object)null)
         {
             component.SetStatusItem(Db.Get().StatusItemCategories.Main, null, null);
         }
     }
     StateMachine.Instance sMI      = GetSMI();
     StateMachine.Instance instance = sMI;
     instance.OnStop = (Action <string, StateMachine.Status>)Delegate.Remove(instance.OnStop, new Action <string, StateMachine.Status>(OnStateMachineStop));
     sMI.StopSM(reason);
     if (!((UnityEngine.Object)driver == (UnityEngine.Object)null))
     {
         lastDriver = driver;
         driver     = null;
         if (onEnd != null)
         {
             onEnd(this);
         }
         if (onExit != null)
         {
             onExit(this);
         }
         driver = null;
     }
 }
Пример #2
0
    public virtual void Begin(Precondition.Context context)
    {
        if ((UnityEngine.Object)driver != (UnityEngine.Object)null)
        {
            Debug.LogErrorFormat("Chore.Begin driver already set {0} {1} {2}, provider {3}, driver {4} -> {5}", id, GetType(), choreType.Id, provider, driver, context.consumerState.choreDriver);
        }
        if ((UnityEngine.Object)provider == (UnityEngine.Object)null)
        {
            Debug.LogErrorFormat("Chore.Begin provider is null {0} {1} {2}, provider {3}, driver {4}", id, GetType(), choreType.Id, provider, driver);
        }
        driver = context.consumerState.choreDriver;
        StateMachine.Instance sMI      = GetSMI();
        StateMachine.Instance instance = sMI;
        instance.OnStop = (Action <string, StateMachine.Status>)Delegate.Combine(instance.OnStop, new Action <string, StateMachine.Status>(OnStateMachineStop));
        KSelectable component = driver.GetComponent <KSelectable>();

        if ((UnityEngine.Object)component != (UnityEngine.Object)null)
        {
            component.SetStatusItem(Db.Get().StatusItemCategories.Main, GetStatusItem(), this);
        }
        sMI.StartSM();
        if (onBegin != null)
        {
            onBegin(this);
        }
    }
    protected virtual void Activate()
    {
        active = true;
        gameObject.SetActive(true);
        state_machine_instance = state_machine.GetStateMachineInstance();
        state_machine_instance.SetCallbacks(parameter_callbacks);

        state_machine_routine = StartCoroutine(StateMachineCoroutine());
    }
Пример #4
0
        /// <summary>
        /// Restores door animation progress based on how far it got when saved.
        /// </summary>
        /// <param name="smi">The state machine instance to update.</param>
        private static void RestoreDoorAnimProgress(StateMachine.Instance smi)
        {
            var tracker = smi.Get <AnimationTrackerComponent>();

            if (tracker != null)
            {
                string state = smi.GetCurrentState().name;
                float  pct   = tracker.GetPositionPercent(state);
                if (pct > 0.0f)
                {
                    smi.Get <KBatchedAnimController>()?.SetPositionPercent(pct);
                }
                tracker.EnterState(state);
            }
        }
    protected virtual void Awake()
    {
        state_machine_instance = state_machine.GetStateMachineInstance();

        parameter_callbacks = new Dictionary <Parameter, Func <bool> >();
        foreach (ParameterCallback pc in parameter_callback_list)
        {
            pc.Init(this);
            parameter_callbacks.Add(pc.GetParameter(), pc.callback);
        }
        state_machine_instance.SetCallbacks(parameter_callbacks);

        state_coroutines = new Dictionary <State, Func <IEnumerator> >();
        foreach (StateCoroutine sc in state_coroutine_list)
        {
            sc.Init(this);
            state_coroutines.Add(sc.GetState(), sc.coroutine);
        }
    }
Пример #6
0
 /// <summary>
 /// Clears the saved progress of a door animation.
 /// </summary>
 /// <param name="smi">The state machine instance to update.</param>
 /// <param name="oldState">The state name of the instance, prior to the Exit.</param>
 private static void ClearDoorAnimProgress(StateMachine.Instance smi, string oldState)
 {
     // smi.GetCurrentState().name reports the state AFTER the exit
     smi.Get <AnimationTrackerComponent>()?.ExitState(oldState);
 }
 public static int PosToCell(StateMachine.Instance smi)
 {
     return(PosToCell(smi.transform.GetPosition()));
 }