Exemple #1
0
    IEnumerator ChangeSequece(TStateID next, StateInitParam initParam)
    {
        StateResult stateResult = null;

        if (currentState)
        {
            currentState.TermStart();
            while (!currentState.IsFinished)
            {
                yield return(null);
            }
            stateResult = currentState.GetResult();
            GameObject.Destroy(currentState.gameObject);
            currentState = null;
        }

        GameObject prefab = statePrefabs.Find(N => N.stateID.Equals(next)).statePrefab;
        GameObject gob    = GameObject.Instantiate(prefab, this.transform);

        currentState = gob.GetComponent <StateBase>();

        Debug.Log(currentState.GetType().ToString());

        if (initParam != null)
        {
            Type[]   types      = null;
            object[] parameters = null;
            if (stateResult != null)
            {
                types      = new Type[] { initParam.GetType(), stateResult.GetType() };
                parameters = new object[] { initParam, stateResult };
            }
            else
            {
                types      = new Type[] { initParam.GetType() };
                parameters = new object[] { initParam };
            }
            var methodInfo = currentState.GetType().GetMethod("InitState", types);
            methodInfo?.Invoke(currentState, parameters);
        }


        currentState.PrepareStart();
        while (!currentState.IsPrepared)
        {
            yield return(null);
        }
    }
Exemple #2
0
 virtual public void InitState(StateInitParam param)
 {
 }
Exemple #3
0
 public void SetState(TStateID seq, StateInitParam initParam)
 {
     StartCoroutine(ChangeSequece(seq, initParam));
 }