示例#1
0
    // ステート更新
    public bool update()
    {
        if (init_ != null)
        {
            init_();
            init_ = null;
        }

        // 終わった?
        if (action_ == null || action_() == false || bForceStop_ == true)
        {
            if (onPost_ != null)
            {
                onPost_();
            }

            // 強制終了時は次のステートは実行しない
            if (bForceStop_ == true)
            {
                return(false);
            }

            if (nextState_ != null)
            {
                GlobalStateUpdater.getInstance().add(nextState_);
            }
            return(false);   // このステート自体は終了
        }
        return(true);
    }
示例#2
0
    // ステート開始
    static public GlobalState start(System.Func <bool> action, System.Action post = null)
    {
        var state = new GlobalState(action, post);

        GlobalStateUpdater.getInstance().add(state);
        return(state);
    }
示例#3
0
    // 一定間隔コール
    //  waitSec: 間隔
    //  count  : 繰り返し数。マイナス値で無限に回る(actionがfalseを返したら終了)
    static public GlobalState interval(float waitSec, int count, System.Func <bool> action)
    {
        float curSec  = 0.0f;
        bool  infinit = (count < 0);
        var   state   = new GlobalState(
            () => {
            curSec += Time.deltaTime;
            if (curSec >= waitSec)
            {
                curSec -= waitSec;
                action();
                if (infinit == false)
                {
                    count--;
                    if (count == 0)
                    {
                        return(false);
                    }
                }
                return(action());
            }
            return(true);
        },
            null
            );

        GlobalStateUpdater.getInstance().add(state);
        return(state);
    }
示例#4
0
    // 並列監視
    static public GlobalState parallel(params GlobalState[] observeStates)
    {
        int counter = 0;

        foreach (var s in observeStates)
        {
            s.FinishCallback = () => {
                counter--;
            };
            counter++;
        }
        var state = new GlobalState(() => {
            return(counter > 0);
        }, null);

        GlobalStateUpdater.getInstance().add(state);
        return(state);
    }
示例#5
0
    // 指定時間だけループ
    static public GlobalState time(float sec, System.Func <float, float, bool> action)
    {
        float curSec = 0.0f;
        var   state  = new GlobalState(
            () => {
            curSec += Time.deltaTime;
            if (curSec >= sec)
            {
                action(sec, 1.0f);
                return(false);
            }
            return(action(curSec, curSec / sec));
        },
            null
            );

        GlobalStateUpdater.getInstance().add(state);
        return(state);
    }
示例#6
0
    // 間を置く
    static public GlobalState wait(float waitSec, System.Func <bool> action)
    {
        float t     = 0.0f;
        var   state = new GlobalState(
            () => {
            t += Time.deltaTime;
            if (t >= waitSec)
            {
                return(false);
            }
            return(true);
        },
            () => {
            start(action);
        }
            );

        GlobalStateUpdater.getInstance().add(state);
        return(state);
    }
示例#7
0
 public void setUpdater(GlobalStateUpdater updater)
 {
     updater_ = updater;
 }