Пример #1
0
    public virtual bool SetState <StateType>() where StateType : StateOld, new()
    {
        bool success;

        foreach (StateOld state in stateList)
        {
            if (state is StateType)
            {
                success = SetState(state);
                break;
            }
        }
        StateOld stateComponent = GetComponent <StateType>();

        if (stateComponent)
        {
            stateComponent.Initialize(this);
            stateList.Add(stateComponent);
            success = SetState(stateComponent);
            return(success);
        }
        StateOld newState = gameObject.AddComponent <StateType>();

        newState.Initialize(this);
        stateList.Add(newState);
        success = SetState(newState);
        return(success);
    }
Пример #2
0
    public virtual bool SetOrInitializeState(StateOld state)
    {
        bool success = false;

        if (state && state != currentState)
        {
            StateOld oldState = currentState;
            currentState = state;
            if (oldState)
            {
                oldState.ExitState();
            }
            if (stateList.Contains(currentState))
            {
                currentState.EnterState();
            }
            else
            {
                currentState.Initialize(this);
                stateList.Add(currentState);
            }
            success = true;
        }
        return(success);
    }
Пример #3
0
    private void visualize(GameObject gameObject, Vector3[] groundVertices, Vector3 offset, float height = 10)
    {
        Stack <StateOld> StateStack   = new Stack <StateOld>();
        StateOld         currentState = new StateOld(gameObject, groundVertices);

        for (int i = 0; i < axiom.Length; i++)
        {
            char symbol = axiom[i];
            if (symbol != '[' && symbol != ']')
            {
                if (symbol == 'E')
                {
                    VisualizerOld.extrude(currentState, height);
                }
                else if (symbol == 'x')
                {
                    VisualizerOld.scale(currentState, 0.6f, 1, 1);
                }
                else if (symbol == 'y')
                {
                    VisualizerOld.scale(currentState, 1, 0.4f, 1);
                }
                else if (symbol == 'z')
                {
                    VisualizerOld.scale(currentState, 1, 1, 0.9f);
                }
                else if (symbol == 'X')
                {
                    VisualizerOld.translate(currentState, 0.2f, 0, 0);
                }
                else if (symbol == 'Y')
                {
                    VisualizerOld.translate(currentState, 0, -1, 0);
                }
                else if (symbol == 'Z')
                {
                    VisualizerOld.translate(currentState, 0, 0, 0.2f);
                }
            }
            else if (axiom[i] == '[')
            {
                StateStack.Push(currentState.clone());
            }
            else if (axiom[i] == ']')
            {
                currentState = StateStack.Pop();
            }
        }

        if (offset != null)
        {
            gameObject.transform.Translate(offset);
        }
    }
Пример #4
0
    public virtual bool SetState(StateOld state)
    {
        //print(state.name);
        bool success = false;

        if (state && state != currentState)
        {
            StateOld oldState = currentState;
            currentState = state;
            if (oldState)
            {
                oldState.ExitState();
            }
            currentState.EnterState();
            success = true;
        }
        return(success);
    }
Пример #5
0
 public void setState(StateOld state)
 {
     //print(state);
     SetState(state);
 }
Пример #6
0
 public void visualize(GameObject gameObject, Vector3[] groundVertices, Vector3 offset, float height = 10)
 {
     if (!useOldVisualizerAndState)
     {
         Stack <State> StateStack   = new Stack <State>();
         State         currentState = new State(gameObject, groundVertices);
         for (int i = 0; i < axiom.Length; i++)
         {
             char symbol = axiom[i];
             if (symbol != '[' && symbol != ']')
             {
                 if (symbol == 'E')
                 {
                     //  Debug.Log("Y PRE EXTRUDE: " + currentState.getTop()[0].y);
                     Visualizer.extrude(currentState, height);
                     //  Debug.Log("Y POST EXTRUDE: " + currentState.getTop()[0].y);
                 }
                 else if (symbol == 'x')
                 {
                     Visualizer.scale(currentState, new Vector3(0.6f, 1, 1));
                 }
                 else if (symbol == 'y')
                 {
                     // Debug.Log("Y PRE SCALE: " + currentState.getTop()[0].y);
                     Visualizer.scale(currentState, new Vector3(1, 0.4f, 1));
                     // Debug.Log("Y POST SCALE: " + currentState.getTop()[0].y);
                 }
                 else if (symbol == 'z')
                 {
                     Visualizer.scale(currentState, new Vector3(1, 1, 0.9f));
                 }
                 else if (symbol == 'X')
                 {
                     Visualizer.translate(currentState, new Vector3(1, 0, 0));
                 }
                 else if (symbol == 'Y')
                 {
                     //  Debug.Log("Y PRE TRANSLATE: " + currentState.getTop()[0].y);
                     Visualizer.translate(currentState, new Vector3(0, -3, 0));
                     //  Debug.Log("Y POST TRANSLATE: " + currentState.getTop()[0].y);
                 }
                 else if (symbol == 'Z')
                 {
                     Visualizer.translate(currentState, new Vector3(0, 0, 0.2f));
                 }
             }
             else if (axiom[i] == '[')
             {
                 StateStack.Push(currentState.clone());
             }
             else if (axiom[i] == ']')
             {
                 currentState = StateStack.Pop();
             }
         }
     }
     else
     {
         Stack <StateOld> StateStack   = new Stack <StateOld>();
         StateOld         currentState = new StateOld(gameObject, groundVertices);
         for (int i = 0; i < axiom.Length; i++)
         {
             char symbol = axiom[i];
             if (symbol != '[' && symbol != ']')
             {
                 if (symbol == 'E')
                 {
                     VisualizerOld.extrude(currentState, height);
                 }
                 else if (symbol == 'x')
                 {
                     VisualizerOld.scale(currentState, 0.6f, 1, 1);
                 }
                 else if (symbol == 'y')
                 {
                     VisualizerOld.scale(currentState, 1, 0.4f, 1);
                 }
                 else if (symbol == 'z')
                 {
                     VisualizerOld.scale(currentState, 1, 1, 0.9f);
                 }
                 else if (symbol == 'X')
                 {
                     VisualizerOld.translate(currentState, 0.2f, 0, 0);
                 }
                 else if (symbol == 'Y')
                 {
                     VisualizerOld.translate(currentState, 0, -1, 0);
                 }
                 else if (symbol == 'Z')
                 {
                     VisualizerOld.translate(currentState, 0, 0, 0.2f);
                 }
             }
             else if (axiom[i] == '[')
             {
                 StateStack.Push(currentState.clone());
             }
             else if (axiom[i] == ']')
             {
                 currentState = StateStack.Pop();
             }
         }
     }
     if (offset != null)
     {
         gameObject.transform.Translate(offset);
     }
 }