Example #1
0
    public virtual void SetState(string id)
    {
        if (_current != null)
        {
            _current.BeforeSwitch(this, id);
        }

        string temp      = (_current != null) ? _current.id : null;
        Type   stateType = Type.GetType(id, false, true);

        if (stateType == null)
        {
            throw new UnityException("unknown state : " + id);
        }
        ConstructorInfo stateConstructor = stateType.GetConstructor(Type.EmptyTypes);
        object          stateObject      = stateConstructor.Invoke(new object[] {});

        if (stateObject is FageState)
        {
            _current = (FageState)stateObject;
        }
        else
        {
            throw new UnityException();
        }

        if (_current != null)
        {
            _current.AfterSwitch(this, temp);
        }
    }
Example #2
0
    public virtual void SetState(string id)
    {
        if (_current != null) {
            _current.BeforeSwitch (this, id);
        }

        string temp = (_current != null) ? _current.id : null;
        Type stateType = Type.GetType (id, false, true);
        if (stateType == null) {
            throw new UnityException ("unknown state : " + id);
        }
        ConstructorInfo stateConstructor = stateType.GetConstructor (Type.EmptyTypes);
        object stateObject = stateConstructor.Invoke (new object[]{});
        if (stateObject is FageState) {
            _current = (FageState)stateObject;
        } else {
            throw new UnityException ();
        }

        if (_current != null) {
            _current.AfterSwitch (this, temp);
        }
    }