Esempio n. 1
0
        public static BTFsm CreateFromOtherTemplate(BTFsm targetFsm, BTTemplate source)
        {
            for (int i = 0; i < source.totalEvent.Count; i++)
            {
                BTEvent.Create(targetFsm, source.totalEvent[i]);
            }

            for (int i = 0; i < source.totalState.Count; i++)
            {
                BTState.Create(targetFsm, source.totalState[i]);
            }
            for (int i = 0; i < source.totalState.Count; i++)
            {
                var state = targetFsm.totalState[i];
                state.ReFindEvent();
            }

            for (int i = 0; i < source.totalVariable.Count; i++)
            {
                BTVariable.Create(targetFsm, source.totalVariable[i]);
            }

            targetFsm.startEvent = targetFsm.FindGlobalEvent(source.startEvent.Name);

            return(targetFsm);
        }
Esempio n. 2
0
        public static BTFsm CreateFromOwnerTemplate(BTFsm targetFsm, BTTemplate source)
        {
            for (int i = 0; i < source.totalEvent.Count; i++)
            {
                targetFsm.totalEvent[i].Owner = targetFsm;
            }
            targetFsm.totalState.Clear();

            for (int i = 0; i < source.totalState.Count; i++)
            {
                BTState.Create(targetFsm, source.totalState[i]);
            }

            for (int i = 0; i < targetFsm.totalState.Count; i++)
            {
                var state = targetFsm.totalState[i];
                for (int j = 0; j < state.totalEvent.Count; j++)
                {
                    if (state.totalEvent[j].TargetState != null)
                    {
                        state.totalEvent[j].TargetState = targetFsm.FindState(state.totalEvent[j].TargetState.Name);
                    }
                }
            }
            targetFsm.totalVariable.Clear();
            for (int i = 0; i < source.totalVariable.Count; i++)
            {
                BTVariable.Create(targetFsm, source.totalVariable[i]);
            }

            targetFsm.startEvent = targetFsm.FindGlobalEvent(targetFsm.startEvent.Name);
            return(targetFsm);
        }
Esempio n. 3
0
        // Use this for initialization
        void Start()
        {
            var btFsm   = gameObject.AddComponent <BTFsm>();
            var btEvent = btFsm.CreateStartEvent();
            var btState = BTState.Create <BTState>(btFsm);

            btState.Name        = "Dynamic1State";
            btEvent.TargetState = btState;
            btState.Bounds      = new Rect(250, 200, 100, 100);



            var btState1 = BTState.Create <BTState> (btFsm);

            btState1.Name   = "Dynamic2State";
            btState1.Bounds = new Rect(400, 200, 100, 100);

            var privateEvent = BTEvent.Create(btState);

            privateEvent.Name        = "Finish";
            privateEvent.TargetState = btState1;

            var privateEvent2 = BTEvent.Create(btState1);

            privateEvent2.Name        = "Finish";
            privateEvent2.TargetState = btState;

            var waitAction = BTAction.CreateAction <WaitingAction>(btState);

            waitAction.time = 1;
            var waitAction1 = BTAction.CreateAction <WaitingAction>(btState1);

            waitAction1.time = 1;
        }
Esempio n. 4
0
        public static BTEvent Create(BTState Owner)
        {
            var btEvent = new BTEvent();

            btEvent.Owner = Owner.Owner;
            Owner.totalEvent.Add(btEvent);
            return(btEvent);
        }
Esempio n. 5
0
        public static T CreateAction <T>(BTState parentState) where T : BTAction
        {
            var action = XScriptableObject.CreateInstance <T>();

            action.Owner = parentState;
            parentState.totalActions.Add(action);
            return(action);
        }
Esempio n. 6
0
        public static BTEvent Create(BTState Owner, BTEvent source)
        {
            var btEvent = new BTEvent();

            btEvent.Owner    = Owner.Owner;
            btEvent.Name     = source.Name;
            btEvent.isGlobal = source.isGlobal;
            Owner.totalEvent.Add(btEvent);
            return(source);
        }
Esempio n. 7
0
 public BTState FindState(BTState targetState)
 {
     for (int i = 0; i < totalState.Count; i++)
     {
         if (totalState[i].Source == targetState)
         {
             return(totalState[i]);
         }
     }
     return(null);
 }
Esempio n. 8
0
        public static BTAction CreateAction(BTAction source, BTState parentState)
        {
//			BTAction action = XScriptableObject.CreateInstance(source.GetType()) as BTAction;
            BTAction action = Instantiate <BTAction>(source);

            action.Name  = source.Name;
            action.Owner = parentState;
            parentState.totalActions.Add(action);


            return(action);
        }
Esempio n. 9
0
 void FireGlobalEvent(BTEvent nextEvent)
 {
     if (currState != null)
     {
         currState.OnExit();
     }
     startEvent = nextEvent;
     currState  = startEvent.TargetState;
     startEvent.OnEnter();
     startEvent.OnExit();
     startEvent.Finish();
     startEvent = null;
     currState.OnEnter();
     //currState.OnEnter();
     //nextState = null;
 }
Esempio n. 10
0
        public static BTState Create(BTFsm parentFsm, BTState source)
        {
            var newState = Instantiate <BTState>(source);

            newState.Source = source;
            newState.Name   = source.Name;
            newState.Owner  = parentFsm;
            newState.Owner.AddNewState(newState);

            newState.totalActions.Clear();
            for (int i = 0; i < source.totalActions.Count; i++)
            {
                BTAction.CreateAction(source.totalActions[i], newState);
            }

            newState.FindEvent(newState.GlobalEvent);

            return(newState);
        }
Esempio n. 11
0
 void Update()
 {
     if (nextState != null)
     {
         if (currState != null)
         {
             currState.OnExit();
         }
         lastState = currState;
         currState = nextState;
         nextState = null;
         currState.OnEnter();
     }
     if (currState == null)
     {
         Debug.LogError("BTFsm Current State is null", gameObject);
         return;
     }
     currState.OnUpdate();
 }
Esempio n. 12
0
        void Reset()
        {
            totalVariable = new List <BTVariable>();
            totalEvent    = new List <BTEvent>();
            totalState    = new List <BTState>();

            var startEvent = CreateStartEvent();

            startEvent.TargetState             = BTState.Create <BTState>(this);
            startEvent.TargetState.GlobalEvent = startEvent;
            startEvent.TargetState.Name        = "GlobalState";

            var type = wuxingogo.Reflection.XReflectionUtils.TryGetClass("BTGenericMenu");

            if (type != null)
            {
                var method = type.GetMethod("AddStateToFsm");
                method.Invoke(null, new System.Object[] { this, startEvent.TargetState });
            }
//			BTGenericMenu.AddStateToFsm( fsm, startEvent.TargetState );
//			BTEditorWindow.instance.Clear();
//			BTEditorWindow.target = fsm;
        }
Esempio n. 13
0
 public bool Equals(BTState other)
 {
     return(Source == other);
 }
Esempio n. 14
0
 public void RemoveState(BTState state)
 {
     totalState.Remove(state);
 }
Esempio n. 15
0
 public void AddNewState(BTState state)
 {
     totalState.Add(state);
 }