Пример #1
0
        // set other Actor as target
        public void SetTarget(Actor2D otherActor, float targetDistance, bool newDetermination = false)
        {
            if (_determined == true && newDetermination == false)
            {
                return;
            }
            _determined = newDetermination;

            DisableTarget();

            if (otherActor == null)
            {
                return;
            }

            type                  = TargetType.Actor;
            _otherActor           = otherActor;
            _targetTransform      = otherActor.transform;
            targetReachedDistance = targetDistance;
            _isReached            = false;
            _determined           = newDetermination;

            _otherActor.stateChanged += Actor_StateChanged;

            _calculatePathAtNextPossibility = true;
        }
Пример #2
0
        public Actor2D GetNearestActor()
        {
            UpdateList();

            if (actors.Count == 0)
            {
                return(null);
            }

            Vector2 position      = _transform.position;
            Actor2D nearestActor  = actors[0];
            float   foundDistance = (position - nearestActor.position2D).sqrMagnitude;

            for (int i = 1; i < actors.Count; i++)
            {
                float newDistance = (position - actors[i].position2D).sqrMagnitude;
                if (newDistance < foundDistance)
                {
                    foundDistance = newDistance;
                    nearestActor  = actors[i];
                }
            }

            return(nearestActor);
        }
Пример #3
0
 void OnTriggerExit2D(Collider2D other)
 {
     if (other.tag == Tag)
     {
         Actor2D actor = other.GetComponent <Actor2D>();
         RemoveActor(actor);
     }
 }
		// ================================================================================
		//  unity methods
		// --------------------------------------------------------------------------------

		void Awake()
		{
			_transform = transform;

			_actor = GetComponent<Actor2D>();
			if (_actor != null)
				_actor.stateChanged += ActorStateChanged;
		}
Пример #5
0
        // ================================================================================
        //  constructor
        // --------------------------------------------------------------------------------

        public ActorTarget(Actor2D protagonist, Transform protagonistTransform)
        {
            _protagonist          = protagonist;
            _protagonistTransform = protagonistTransform;

            _ticker = Random.Range(0, _maxTicker);

            _path = new Vector2Path(80);
        }
		void Awake()
		{
			if (source == null)
				source = GetComponent<AudioSource>();

			_actor = GetComponent<Actor2D>();

			source.loop = true;
			source.Stop();
		}
        // ================================================================================
        //  unity methods
        // --------------------------------------------------------------------------------

        void Awake()
        {
            _transform = transform;

            _actor = GetComponent <Actor2D>();
            if (_actor != null)
            {
                _actor.stateChanged += ActorStateChanged;
            }
        }
Пример #8
0
        void Awake()
        {
            if (source == null)
            {
                source = GetComponent <AudioSource>();
            }

            _actor = GetComponent <Actor2D>();

            source.loop = true;
            source.Stop();
        }
Пример #9
0
        // ================================================================================
        //  private methods
        // --------------------------------------------------------------------------------

        private void RemoveActor(Actor2D actor)
        {
            if (actor != null && actors.Contains(actor))
            {
                actors.Remove(actor);

                actor.stateChanged -= Actor_StateChanged;

                if (sensorEvent != null)
                {
                    sensorEvent(SensorEvent.ActorLeft, actor);
                }
            }
        }
Пример #10
0
        public void TakeAction(Actor2D targetActor)
        {
            if (!isAlive)
            {
                return;
            }

            _actionTimer = new Timer(action.cooldown);
            isMoving     = false;

            // update look direction
            SetLookDirectionToTarget(targetActor.position2D);

            state = ActorState.TakingAction;

            action.Execute();
        }
Пример #11
0
        // other actor as new target, e.g. enemy or friendly unit to be healed
        public void SetTarget(Actor2D otherActor, bool determined = false)
        {
            if (!isAlive)
            {
                return;
            }

            if (action != null)
            {
                target.SetTarget(otherActor, action.range * 0.9f, determined);
            }

            if (state == ActorState.Idle)
            {
                state = ActorState.Moving;
            }
        }
Пример #12
0
        void OnTriggerEnter2D(Collider2D other)
        {
            if (other.tag == Tag)
            {
                Actor2D actor = other.GetComponent <Actor2D>();
                if (actor != null && !actors.Contains(actor) && actor.isAlive)
                {
                    actors.Add(actor);

                    actor.stateChanged += Actor_StateChanged;

                    if (sensorEvent != null)
                    {
                        sensorEvent(SensorEvent.ActorDetected, actor);
                    }
                }
            }
        }
Пример #13
0
        public void DisableTarget()
        {
            type = TargetType.None;

            if (_otherActor != null)
            {
                _otherActor.stateChanged -= Actor_StateChanged;
                _otherActor = null;
            }
            _targetTransform = null;

            // path parameters
            _hasPath = false;
            _calculatePathAtNextPossibility = false;

            _isReached = true;

            _determined = false;
        }
		// ================================================================================
		//  Unity methods
		// --------------------------------------------------------------------------------

		private void Awake()
		{
			_actor = GetComponent<Actor2D>();
			if (_actor != null)
				_actor.stateChanged += ActorStateChangedHandler;

			if (displayObject != null)
				_animator = displayObject.GetComponentInChildren<Animator>();

			if (displayObject != null)
			{
				GatherRendererMaterials();
			}
			else
			{
				Debug.Log("Actor " + gameObject.name + " has AnimationController but no display object assigned");
			}

			_isInitialized = true;
		}
Пример #15
0
        // ================================================================================
        //  Unity methods
        // --------------------------------------------------------------------------------

        private void Awake()
        {
            _actor = GetComponent <Actor2D>();
            if (_actor != null)
            {
                _actor.stateChanged += ActorStateChangedHandler;
            }

            if (displayObject != null)
            {
                _animator = displayObject.GetComponentInChildren <Animator>();
            }

            if (displayObject != null)
            {
                GatherRendererMaterials();
            }
            else
            {
                Debug.Log("Actor " + gameObject.name + " has AnimationController but no display object assigned");
            }

            _isInitialized = true;
        }
Пример #16
0
        // ================================================================================
        //  public methods
        // --------------------------------------------------------------------------------

        public Actor2D GetMostWoundedActor()
        {
            UpdateList();

            if (actors.Count == 0)
            {
                return(null);
            }

            Actor2D targetActor = actors[0];
            float   woundAmount = targetActor.health.missingAmount;

            for (int i = 1; i < actors.Count; i++)
            {
                float newHealthAmount = actors[i].health.missingAmount;
                if (newHealthAmount > woundAmount)
                {
                    woundAmount = newHealthAmount;
                    targetActor = actors[i];
                }
            }

            return(targetActor);
        }
Пример #17
0
		public void TakeAction(Actor2D targetActor)
		{
			if (!isAlive)
				return;

			_actionTimer = new Timer(action.cooldown);
			isMoving = false;

			// update look direction
			SetLookDirectionToTarget(targetActor.position2D);

			state = ActorState.TakingAction;

			action.Execute();
		}
Пример #18
0
		// other actor as new target, e.g. enemy or friendly unit to be healed
		public void SetTarget(Actor2D otherActor, bool determined = false)
		{
			if (!isAlive)
				return;

			if (action != null)
			{
				target.SetTarget(otherActor, action.range * 0.9f, determined);
			}

			if (state == ActorState.Idle)
				state = ActorState.Moving;
		}
Пример #19
0
        public void DisableTarget()
        {
            type = TargetType.None;

            if (_otherActor != null)
            {
                _otherActor.stateChanged -= Actor_StateChanged;
                _otherActor = null;
            }
            _targetTransform = null;

            // path parameters
            _hasPath = false;
            _calculatePathAtNextPossibility = false;

            _isReached = true;

            _determined = false;
        }
Пример #20
0
        // set other Actor as target
        public void SetTarget(Actor2D otherActor, float targetDistance, bool newDetermination = false)
        {
            if (_determined == true && newDetermination == false)
            {
                return;
            }
            _determined = newDetermination;

            DisableTarget();

            if (otherActor == null)
                return;

            type = TargetType.Actor;
            _otherActor = otherActor;
            _targetTransform = otherActor.transform;
            targetReachedDistance = targetDistance;
            _isReached = false;
            _determined = newDetermination;

            _otherActor.stateChanged += Actor_StateChanged;

            _calculatePathAtNextPossibility = true;
        }
Пример #21
0
        // ================================================================================
        //  constructor
        // --------------------------------------------------------------------------------

        public ActorTarget(Actor2D protagonist, Transform protagonistTransform)
        {
            _protagonist = protagonist;
            _protagonistTransform = protagonistTransform;

            _ticker = Random.Range(0, _maxTicker);

            _path = new Vector2Path(80);
        }
Пример #22
0
        void Awake()
        {
            Actor2D actor = GetComponent <Actor2D>();

            actor.movementSpeed += Random.Range(1f, multiplier);
        }
Пример #23
0
        void Start()
        {
            Actor2D actor = GetComponent <Actor2D>();

            actor.target.SetPathField(FindObjectOfType <LevelGrid>());
        }
Пример #24
0
		// ================================================================================
		//  private methods
		// --------------------------------------------------------------------------------

		private void RemoveActor(Actor2D actor)
		{
			if (actor != null && actors.Contains(actor))
			{
				actors.Remove(actor);

				actor.stateChanged -= Actor_StateChanged;

				if (sensorEvent != null)
					sensorEvent(SensorEvent.ActorLeft, actor);
			}
		}