Esempio n. 1
0
 /// <summary>
 /// Called after <see cref="IUtilityAIClient.Stop"/>.
 /// </summary>
 protected override void OnStop()
 {
     if (_lbHandle != null)
     {
         _lbHandle.Stop();
         _lbHandle = null;
     }
 }
 protected override void OnStop()
 {
     if (this._lbHandle != null)
     {
         this._lbHandle.Stop();
         this._lbHandle = null;
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Called after <see cref="M:Apex.AI.Components.IUtilityAIClient.Stop" />.
 /// </summary>
 protected override void OnStop()
 {
     if (_lbHandle == null)
     {
         return;
     }
     _lbHandle.Stop();
     _lbHandle = null;
 }
Esempio n. 4
0
        private void Update()
        {
            if (Input.GetKeyUp(KeyCode.Alpha1))
            {
                _counter = 0;

                //Here we schedule some work to repeat 4 times, i.e. it will execute a total of 5 times.
                var action = new RepeatableAction(DoWork, 4);

                //Here we schedule the action to start as soon as possible and repeat at the default interval of the load balancer.
                ExamplesLoadBalancer.examplesBalancer.Add(action);
            }
            else if (Input.GetKeyUp(KeyCode.Alpha2))
            {
                //Here we create an action using an anonymous method. We also do not specify a repetition count, instead we control the life time in the method.
                int counter = 0;
                var action  = new RepeatableAction(
                    (t) =>
                {
                    Debug.Log("Execution " + ++counter + " done after " + t.ToString() + " seconds");
                    return(counter < 5);
                });

                //Here we schedule the action to take place after a short delay of 3 seconds or as soon after that delay as possible.
                //It will then repeat with an interval of 2 seconds.
                ExamplesLoadBalancer.examplesBalancer.Add(action, 2f, 3f);
            }
            else if (Input.GetKeyUp(KeyCode.Alpha3))
            {
                //Here we create an action using an anonymous method. We also do not specify a repetition count, and instruct it to continue indefinitely.
                //The only way to stop it is to use the handle returned from the load balancer when the action is added.
                int counter = 0;
                var action  = new RepeatableAction(
                    (t) =>
                {
                    Debug.Log("Execution " + ++counter + " done after " + t.ToString() + " seconds");
                    return(true);
                });

                //Here we schedule the action to take as soon as possible.
                //It will then repeat with an interval of 2 seconds.
                _handle = ExamplesLoadBalancer.examplesBalancer.Add(action, 2f);
            }
            else if (Input.GetKeyUp(KeyCode.Alpha4))
            {
                //Here we stop the action initiated in 3 above
                if (_handle != null)
                {
                    _handle.Stop();
                }
            }
        }
 private void Update()
 {
     if (Input.GetKeyUp(KeyCode.F))
     {
         var unit = this.GetUnitFacade();
         _followHandle = unit.Follow(target);
     }
     else if (Input.GetKeyUp(KeyCode.S))
     {
         var unit = this.GetUnitFacade();
         unit.Stop();
         _followHandle.Stop();
     }
 }
        protected override void OnStart()
        {
            float single = this.startDelayMin;

            if (single != this.startDelayMax)
            {
                single = UnityEngine.Random.Range(single, this.startDelayMax);
            }
            float single1 = this.executionIntervalMin;

            if (single1 != this.executionIntervalMax)
            {
                single1 = UnityEngine.Random.Range(single1, this.executionIntervalMax);
            }
            this._lbHandle = AILoadBalancer.aiLoadBalancer.Add(this, single1, single);
        }
Esempio n. 7
0
        /// <summary>Starts the AI.</summary>
        protected override void OnStart()
        {
            float minStartDelay = startDelayMin;

            if (minStartDelay.IsNotAlmost(startDelayMax))
            {
                minStartDelay = UnityEngine.Random.Range(minStartDelay, startDelayMax);
            }
            float executionInterval = executionIntervalMin;

            if (executionInterval.IsNotAlmost(executionIntervalMax))
            {
                executionInterval = UnityEngine.Random.Range(executionInterval, executionIntervalMax);
            }
            _lbHandle = AILoadBalancer.aiLoadBalancer.Add(this, executionInterval, minStartDelay);
        }
Esempio n. 8
0
        /// <summary>
        /// Starts the AI.
        /// </summary>
        protected override void OnStart()
        {
            var delay = this.startDelayMin;

            if (delay != this.startDelayMax)
            {
                delay = UnityEngine.Random.Range(delay, this.startDelayMax);
            }

            var interval = this.executionIntervalMin;

            if (interval != this.executionIntervalMax)
            {
                interval = UnityEngine.Random.Range(interval, this.executionIntervalMax);
            }

            _lbHandle = AILoadBalancer.aiLoadBalancer.Add(this, interval, delay);
        }
Esempio n. 9
0
        private void StartPoll()
        {
            //Obviously this assumes there is only a single grid
            var grid = GridManager.instance.GetGrid(_unit.position);

            _lastPollTime = Time.time;

            _pollHandle = LoadBalancer.defaultBalancer.Execute((ignored) =>
            {
                if (grid.HasSectionsChangedSince(_unit.position, _lastPollTime))
                {
                    _unit.MoveTo(_destination, false);
                    _pollHandle = null;
                    return(false);
                }

                return(true);
            });
        }
        private void Update()
        {
            if (Input.GetKeyUp(KeyCode.Alpha1))
            {
                //So here we create a long running action which will complete the DoWork call but only use 3 ms per frame, hence spreading it out across numerous frames.
                var action = new LongRunningAction(DoWork, 3);

                //We schedule it to run each frame if possible
                _handle = ExamplesLoadBalancer.extraBalancer.Add(action, 0f);
            }
            else if (Input.GetKeyUp(KeyCode.Alpha2))
            {
                //Here we stop the action initiated in 3 above
                if (_handle != null)
                {
                    _handle.Stop();
                }
            }
        }