예제 #1
0
파일: FSMSentence.cs 프로젝트: pb0/ID0_Test
    // return true to change state
    public FSMToken.ExcuteResult Excute(int index, ref int lastToken, FSMHandle handle, Stack<State> stack, object externalArg)
    {
        FSMToken.ExcuteResult excuteResult = null;
        object lastRetVal = externalArg;

        foreach (var token in tokens)
        {
            if (tokens.IndexOf(token) < index)
            {
                continue;
            }

            {
                excuteResult = token.Excute(lastRetVal, handle, stack);
                lastRetVal = excuteResult.retVal;

                if (token.name == FSMKeywords.Sleep)
                {
                    lastToken = tokens.IndexOf(token);
                }
            }

            if (excuteResult.stopSentence)
            {
                break;
            }
        }

        return excuteResult;
    }
예제 #2
0
    public override ExcuteResult Excute(object lastRetVal, FSMHandle handle, Stack<State> stack)
    {
        if (methodInfo == null)
        {
            Debug.LogError(name + " has no method");
        }

        object retValue = Excute(ToParam(lastRetVal), handle, stack);

        ExcuteResult ret = new ExcuteResult();
        if (methodInfo.ReturnType == typeof(Boolean))
        {
            if (retValue is bool && (bool)retValue == false)
            {
                ret.stopParagraph = false;
                ret.stopSentence = true;
            }
        }
        else
        {
            ret.retVal = retValue;
        }

        return ret;
    }
예제 #3
0
    public override ExcuteResult Excute(object lastRetVal, FSMHandle handle, Stack<State> stack)
    {
        Dictionary<string, object> variables = null;
        int count = str.Length - str.Replace("$", "").Length;
        foreach (var entity in stack)
        {
            if (--count == 0)
            {
                variables = entity.variables;
                break;
            }
        }
        if (variables == null)
        {
            Debug.LogError("must not be null");
        }

        if (isSetter)
        {
            if (!variables.ContainsKey(name))
            {
                variables.Add(name, lastRetVal);
            }
            else
            {
                variables[name] = lastRetVal;
            }
        }
        ExcuteResult ret = new ExcuteResult();
        ret.retVal = variables[name];
        return ret;
    }
예제 #4
0
파일: State.cs 프로젝트: pb0/ID0_Test
    public void OnCreate(FSMHandle handle, Stack<State> stack, object stateArg)
    {
        variables = new Dictionary<string, object>();
        //LogTool.Log(Name + ".OnCreate");

        paragraph.title.Excute(0, ref lastToken, handle, stack, stateArg);
        ExcuteEvent("create", handle, stack, null);
    }
예제 #5
0
 public override ExcuteResult Excute(object lastRetVal, FSMHandle handle, Stack<State> stack)
 {
     ExcuteResult ret = new ExcuteResult();
     ret.stopParam = lastRetVal;
     ret.stopTokenType = type;
     ret.stopParagraph = true;
     ret.stopSentence = true;
     return ret;
 }
예제 #6
0
 public override ExcuteResult Excute(object lastRetVal, FSMHandle handle, Stack<State> stack)
 {
     if (!string.IsNullOrEmpty(paramName))
     {
         var variables = stack.Peek().variables;
         if (!variables.ContainsKey(paramName))
         {
             variables[paramName] = null;
         }
         variables[paramName] = lastRetVal;
     }
     return new ExcuteResult();
 }
예제 #7
0
 object Excute(object[] parameters, FSMHandle handle, Stack<State> stack)
 {
     object ret = methodInfo.Invoke(handle, parameters);
     if (isNegative)
     {
         if (ret.GetType() == typeof(bool))
         {
             ret = !(bool)ret;
         }
         else
         {
             Debug.LogError("undefined operation");
         }
     }
     return ret;
 }
예제 #8
0
파일: State.cs 프로젝트: pb0/ID0_Test
    public void OnDestroy(FSMHandle handle, Stack<State> stack)
    {
        //LogTool.Log(Name + ".OnDestroy");
        ExcuteEvent("destroy", handle, stack, null);

        foreach (var entity in variables)
        {
            if (entity.Value is Object)
            {
                Object.Destroy(entity.Value as Object);
            }
            else
            {
                TryDestroy(entity);
            }
        }
        variables = null;
    }
예제 #9
0
파일: FSM.cs 프로젝트: pb0/ID0_Test
    public FSM(string path, FSMHandle handle)
    {
        this.handle = handle;
        stack = new Stack<State>();

        FSMPage page = FSMParser.Get(path, handle.GetType());
        //Debug.LogWarning(page);

        this.name = path;
        this.initStateName = page.InitStateName;

        states = new Dictionary<string, State>();
        foreach (var entity in page.Paragraphs)
        {
            states.Add(entity.Key, new State(entity.Value, this));
        }
        SetState(initStateName, null);
    }
예제 #10
0
    public FiniteStateMachine(StateAction[] stateActions, TransientAction[] openingActions, TransientAction[] closingActions, T startingState)
    {
        int nrOfStates = Enum.GetValues(typeof(T)).Length;

        if (stateActions.Length != nrOfStates)
        {
            throw new Exception("Invalid number of state actions, " + nrOfStates + "expected, " + stateActions.Length + " recieved.");
        }
        if (openingActions.Length != nrOfStates)
        {
            throw new Exception("Invalid number of opening actions, " + nrOfStates + "expected, " + openingActions.Length + " recieved.");
        }
        if (closingActions.Length != nrOfStates)
        {
            throw new Exception("Invalid number of closing actions, " + nrOfStates + "expected, " + closingActions.Length + " recieved.");
        }

        this.stateActions   = stateActions;
        this.openingActions = openingActions;
        this.closingActions = closingActions;

        handle = new FSMHandle(startingState);
    }
예제 #11
0
파일: State.cs 프로젝트: pb0/ID0_Test
 public void OnExit(FSMHandle handle, Stack<State> stack)
 {
     ExcuteEvent("exit", handle, stack, null);
 }
예제 #12
0
파일: State.cs 프로젝트: pb0/ID0_Test
 private bool Excute(FSMSentence sentence, int tokenIndex, FSMHandle handle, Stack<State> stack, object externalArg)
 {
     FSMToken.ExcuteResult excuteResult = sentence.Excute(tokenIndex, ref lastToken, handle, stack, externalArg);
     if (excuteResult == null)
     {
         Debug.LogError("excuteResult null on " + sentence + ", token:" + tokenIndex);
     }
     if (excuteResult.stopParagraph)
     {
         if (excuteResult.stopTokenType == FSMToken.E_TokenType.ChangeState)
         {
             string nextState = excuteResult.stopParam as string;
             fsm.SetState(nextState, excuteResult.stopParamArg);
         }
         else if (excuteResult.stopTokenType == FSMToken.E_TokenType.PushState)
         {
             string nextState = excuteResult.stopParam as string;
             fsm.PushState(nextState, excuteResult.stopParamArg);
         }
         else if (excuteResult.stopTokenType == FSMToken.E_TokenType.PopState)
         {
             fsm.PopState();
         }
         else if (excuteResult.stopTokenType == FSMToken.E_TokenType.SetTimer)
         {
             float? waitTime = Cast.To<float>(excuteResult.stopParam);
             SetTimer(waitTime.Value, handle, stack);
         }
         else if (excuteResult.stopTokenType == FSMToken.E_TokenType.Sleep)
         {
             float? waitTime = Cast.To<float>(excuteResult.stopParam);
             Sleep(waitTime.Value, handle, stack);
         }
         else
         {
             Debug.LogError("why stop in stopParam " + excuteResult.stopParam + "(" + excuteResult.stopParam.GetType() + ")");
         }
     }
     return excuteResult.stopParagraph;
 }
예제 #13
0
파일: State.cs 프로젝트: pb0/ID0_Test
 public void Update(FSMHandle handle, Stack<State> stack)
 {
     foreach (var sentence in paragraph.sentences)
     {
         //LogTool.Log("[sentence] " + sentence);
         bool stop = Excute(sentence, 0, handle, stack, null);
         if (stop)
         {
             lastSentence = sentence;
             return;
         }
     }
 }
예제 #14
0
 public override ExcuteResult Excute(object lastRetVal, FSMHandle handle, Stack<State> stack)
 {
     ExcuteResult ret = new ExcuteResult();
     ret.retVal = name;
     return ret;
 }
예제 #15
0
파일: State.cs 프로젝트: pb0/ID0_Test
 public void OnTimer(FSMHandle handle, Stack<State> stack)
 {
     ExcuteEvent("timer", handle, stack, null);
 }
예제 #16
0
파일: State.cs 프로젝트: pb0/ID0_Test
 public void OnEvent(string eventName, FSMHandle handle, Stack<State> stack, object eventArg)
 {
     ExcuteEvent(eventName, handle, stack, eventArg);
 }
예제 #17
0
파일: State.cs 프로젝트: pb0/ID0_Test
 private void SetTimer(float waitTime, FSMHandle handle, Stack<State> stack)
 {
     remainTimeForTimer = waitTime;
     routineForTimer = delegate()
     {
         if (fsm.IsCurrentState(this))
         {
             Debug.LogWarning("OnTimer~~");
             this.OnTimer(handle, stack);
         }
     };
 }
예제 #18
0
파일: FSMToken.cs 프로젝트: pb0/ID0_Test
 public abstract ExcuteResult Excute(object lastRetVal, FSMHandle handle, Stack<State> stack);
예제 #19
0
파일: State.cs 프로젝트: pb0/ID0_Test
    private void Sleep(float waitTime, FSMHandle handle, Stack<State> stack)
    {
        Assert.IsTrue(!isWaiting);

        isWaiting = true;
        remainTimeForSleep = waitTime;

        routineForSleep = delegate()
        {
            isWaiting = false;
            if (fsm.IsCurrentState(this))
            {
                FSMSentence sentence = lastSentence;
                int token = lastToken;
                if (sentence.HasToken(token + 1))
                {
                    Excute(sentence, token + 1, handle, stack, null);
                }
            }
        };
    }
예제 #20
0
파일: Automaton.cs 프로젝트: pb0/ID0_Test
 public void InitFSM(string scriptPath, FSMHandle handle, bool enableLog)
 {
     fsm = new FSM(scriptPath, handle);
     fsm.EnableLog(enableLog);
 }
예제 #21
0
파일: State.cs 프로젝트: pb0/ID0_Test
    private void ExcuteEvent(string eventName, FSMHandle handle, Stack<State> stack, object externalArg)
    {
        if (isWaiting)
        {
            return;
        }

        if (paragraph.events.ContainsKey(eventName))
        {
            var sentence = paragraph.events[eventName];
            bool stop = Excute(sentence, 0, handle, stack, externalArg);
            if (stop)
            {
                lastSentence = sentence;
                return;
            }
        }
    }