Ejemplo n.º 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;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
		}
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 8
0
        void Awake()
        {
            if (source == null)
            {
                source = GetComponent <AudioSource>();
            }

            _actor = GetComponent <Actor2D>();

            source.loop = true;
            source.Stop();
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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);
                    }
                }
            }
        }
Ejemplo n.º 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;
		}
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
		}
Ejemplo n.º 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;
		}
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 21
0
        // ================================================================================
        //  constructor
        // --------------------------------------------------------------------------------

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

            _ticker = Random.Range(0, _maxTicker);

            _path = new Vector2Path(80);
        }
Ejemplo n.º 22
0
        void Awake()
        {
            Actor2D actor = GetComponent <Actor2D>();

            actor.movementSpeed += Random.Range(1f, multiplier);
        }
Ejemplo n.º 23
0
        void Start()
        {
            Actor2D actor = GetComponent <Actor2D>();

            actor.target.SetPathField(FindObjectOfType <LevelGrid>());
        }
Ejemplo n.º 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);
			}
		}