Beispiel #1
0
    public static CatchAction getAction(GameObject gameObject, float speed)
    {
        CatchAction action = CreateInstance <CatchAction>();

        action.gameObject = gameObject;
        action.speed      = speed;
        return(action);
    }
Beispiel #2
0
    public static CatchAction GetCatchAction(float speed, Transform target, Animator ani)
    {
        CatchAction currentAction = ScriptableObject.CreateInstance <CatchAction>();

        currentAction.speed    = speed;
        currentAction.target   = target;
        currentAction.animator = ani;
        return(currentAction);
    }
Beispiel #3
0
    protected new void Start()
    {
        sceneController = Director.getInstance().currentSceneController as FirstSceneController;
        sceneController.patrolActionManager = this;
        player = sceneController.getPlayer();

        patrolAction = PatrolAction.getAction(new Vector3(Random.Range(-1, 1f), Random.Range(-1, 1f)), speed);
        catchAction  = CatchAction.getAction(player, speed);
    }
        /// <summary>
        /// Execute code snippets with retry mechanism.
        /// </summary>
        /// <param name="action">Code snippets that will be invoked whenever a retry condition is encountered.</param>
        /// <param name="catchAction">Code snippets that will be invoked whenever an exception is caught.
        /// <example>Default: <code>Console.WriteLine</code></example>
        /// </param>
        /// <param name="retryCount">The number of subsequent retry attempts, not including the very first execution.</param>
        /// <param name="retryInterval">The time interval between retries in milliseconds.</param>
        public static void Execute(Action <int> action, CatchAction <Exception, int> catchAction = null, int retryCount = 1, int retryInterval = 0)
        {
            if (action == null)
            {
                return;
            }

            if (retryCount < 0)
            {
                retryCount = 0;
            }

            if (retryInterval < 0)
            {
                retryInterval = 0;
            }

            if (catchAction == null)
            {
                catchAction = delegate(Exception e, int i) { Console.WriteLine("Count {0} failed: {1}", i.ToString(), e.ToString()); };
            }

            bool succeeded = false;

            int count = 0;

            while (count <= retryCount && !succeeded)
            {
                try
                {
                    action(count);
                    succeeded = true;
                }
                catch (Exception e)
                {
                    try
                    {
                        catchAction(e, count);
                    }
                    catch
                    {
                    }

                    count++;
                    Thread.Sleep(retryInterval);
                }
            }
        }
Beispiel #5
0
 public bool OnReleased(CatchAction action) => false;
Beispiel #6
0
 public void getTarget(GameObject target)
 {
     action.destroy = true;
     action         = CatchAction.GetCatchAction(runSpeed, target.transform, animator);
     this.RunAction(this.gameObject, action, this);
 }
Beispiel #7
0
 public void CatchPlayer(GameObject patrol)
 {
     catchAction = CatchAction.getAction(player, speed);
     this.RunAction(patrol, catchAction, this);
 }