Esempio n. 1
0
    //public _Personality Personality;

    void Start()
    {
        int random = Random.Range(1, 4);

        switch (random)
        {
        case 1:
        {
            Actitude = BehaviourLibrary.Behaviour.NORMAL;
            break;
        }

        case 2:
        {
            Actitude = BehaviourLibrary.Behaviour.NERVOUS;
            break;
        }

        case 3:
        {
            Actitude = BehaviourLibrary.Behaviour.ELEGANT;
            break;
        }
        }
    }
        public void Setup()
        {
            var isThiefNearTreasureConditional = new Conditional(IsThiefNearTreasure);
            var makethiefFleeAction = new BehaviourAction(MakeThiefFlee);
            var sequence = new Sequence(new Inverter(isThiefNearTreasureConditional), makethiefFleeAction);

            var chooseCastleAction = new BehaviourAction(ChooseACastleToFlyTo);
            var flytoCastleAction = new BehaviourAction(FlyToCastle);
            var fightAction = new BehaviourAction(FightGuards);
            var strongEnoughConditional = new Conditional(StrongEnough);
            var takeGold = new BehaviourAction(TakeGold);
            var flytoHomeAction = new BehaviourAction(FlyToHome);
            var storeRobingsAction = new BehaviourAction(StoreGold);
            var secondSequence = new Sequence(chooseCastleAction, flytoCastleAction, fightAction, strongEnoughConditional, takeGold,
                                    flytoHomeAction, storeRobingsAction);
            var rootSelector = new RootSelector(SwitchNodes, sequence, secondSequence);
            _behaviour = new Behaviour(rootSelector);
        }
        private void Setup()
        {
            var tooClose = new Conditional(isTooClose);
            var targetMoved = new Conditional(hasTargetMoved);
            var pathFound = new Conditional(hasPathBeenFound);
            var reachedCell = new Conditional(hasReachedCell);
            var reachedTarget = new Conditional(hasReachedTarget);
            var isNewPath = new Conditional(hasNewPath);

            //setup all actions and their delegate functions
            BehaviourAction moveToCell = new BehaviourAction(moveTowardsCell);
            BehaviourAction calcPath = new BehaviourAction(calculatePath);
            BehaviourAction initPathfinder = new BehaviourAction(initializePathfinder);
            BehaviourAction getNextCell = new BehaviourAction(getNextPathCell);
            BehaviourAction setPath = new BehaviourAction(setNewPath);
            BehaviourAction getPath = new BehaviourAction(getCurrentPath);
            BehaviourAction updatePosition = new BehaviourAction(updateTargetPosision);
            BehaviourAction reset = new BehaviourAction(resetPathfinder);
            BehaviourAction animate = new BehaviourAction(updateAnimation);

            //setup an initilization branch
            var initialize = new Sequence(initPathfinder, calcPath);

            //if the target has moved, reset and calculate a new path
            var ifMovedCreateNewPath = new Selector(new Inverter(targetMoved), new Inverter(reset), calcPath);
            var ifPathFoundGetPath = new Selector(new Inverter(pathFound), getPath);
            var ifPathNewUseIt = new Selector(new Inverter(isNewPath), setPath);
            var ifReachedCellGetNext = new Selector(new Inverter(reachedCell), getNextCell);
            var ifNotReachedTargetMoveTowardsCell = new Selector(reachedTarget, moveToCell);

            var follow = new Selector(new Inverter(tooClose), updatePosition, ifMovedCreateNewPath, ifPathFoundGetPath,
                ifPathNewUseIt, ifReachedCellGetNext, ifNotReachedTargetMoveTowardsCell, animate);

            var root = new RootSelector(SwitchBehaviours, initialize, follow);

            //set a reference to the root
            _behaviour = new Behaviour(root);
        }
 public void RandomPersonality()
 {
     Protocol = (BehaviourLibrary.Behaviour)Random.Range(0, 2);
 }