Exemple #1
0
        public IEnumerator Follow(Transform target, Actions moveType, float waypointDistance, float searchRadius,
                                  float distanceFromTarget   = DefaultDistanceFromTarget, float maxError = DefaultMaxError,
                                  Func <bool> breakCondition = null, Action onReach = null)
        {
            if (breakCondition == null)
            {
                breakCondition = DefaultBreakCondition;
            }
            if (onReach == null)
            {
                onReach = () => {}
            }
            ;
            Func <bool> predicate =
                () => PlanarDistance(transform.position, target.position) > distanceFromTarget + maxError;

            while (!breakCondition())
            {
                IEnumerator approacher = Approach(target, moveType, waypointDistance, searchRadius, distanceFromTarget,
                                                  maxError);
                yield return(SmartCoroutine.Create(approacher, onCompletion: onReach));

                yield return(new WaitForSeconds(SecondsBeforeResumeFollow));

                yield return(new WaitUntil(predicate));
            }
        }
    }
        protected IEnumerator ImplAttack(IWeapon weapon)
        {
            actor.OnActionBegin(Actions.Attack);
            SmartCoroutine weaponAttack = SmartCoroutine.Create(weapon.Attack());

            yield return(weaponAttack);

            actor.OnActionEnd(Actions.Attack);
            if (weaponAttack.Status == SmartCoroutine.Result.WasExited)
            {
                yield return(SmartCoroutine.Exit);
            }
        }
Exemple #3
0
        IEnumerator AttackRoutine()
        {
            bool attackFailed = false;

            do
            {
                if (weapon.CanAttack)
                {
                    yield return(SmartCoroutine.Create(controller.Attack(weapon), () => attackFailed = true));
                }
                else
                {
                    yield return(null);
                }
            }while (!attackFailed);
        }
Exemple #4
0
        public static SmartCoroutine Create(IEnumerator coroutine, Action onExit = null, Action onCompletion = null)
        {
            SmartCoroutine smartCoroutine = coroutine as SmartCoroutine;

            if (smartCoroutine == null)
            {
                return(new SmartCoroutine(coroutine, onExit, onCompletion));
            }
            else
            {
                if (onExit != null)
                {
                    smartCoroutine.exitCallbacks.Add(onExit);
                }
                if (onCompletion != null)
                {
                    smartCoroutine.completionCallbacks.Add(onCompletion);
                }
                return(smartCoroutine);
            }
        }
Exemple #5
0
 void Update()
 {
     if (!Controller.SetupComplete)
     {
         return;
     }
     if ((CurrentActions & Actions.Jump) == 0)
     {
         if (Input.GetButtonDown("Jump"))
         {
             StartCoroutine(Controller.Jump());
         }
         else
         {
             Vector3 direction =
                 Vector3.Normalize(new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")));
             if (Input.GetButton("Walk"))
             {
                 Controller.SlowMove(direction);
             }
             else if (Input.GetButton("Sprint"))
             {
                 Controller.FastMove(direction);
             }
             else
             {
                 Controller.NormalMove(direction);
             }
         }
     }
     if ((CurrentActions & Actions.Attack) == 0 && equippedWeapon.CanAttack && Input.GetButtonDown("Fire1"))
     {
         StartCoroutine(SmartCoroutine.Create(Controller.Attack(equippedWeapon)));
     }
     Controller.Turn(Input.GetAxis("Mouse X"));
 }