protected void OnEnable()
		{
			this.tracker.AddOnNewDetectedDelegate(this.OnNewDetected);
						
			if (this._ignoreList.Count == 0)
				return;
			
			// Unless this is a AreaTargetTracker. Stop here.
			if (this.tracker.area == null)
				return;
						
			// Sync the ignore list with the TargetTracker by removing any ignore targetables.				
			var areaListCopy = new TargetList(this.tracker.area);
			for (int i = 0; i < areaListCopy.Count; i++)
			{
				this.currentTargetable = areaListCopy[i].targetable;
				if (this.currentTargetable == null)
					continue;
				
				if (this._ignoreList.Contains(this.currentTargetable))
				{
					this.tracker.area.Remove(this.currentTargetable);
				}
			}
		}
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PathologicalGames.Target"/> struct.
        /// </summary>
        /// <param name='transform'>
        /// Transform that has a Targetable component
        /// </param>
        /// <param name='targetTracker'>
        /// Target tracker that detected this Target
        /// </param>
        public Target(Transform transform, TargetTracker targetTracker)
        {
            // Subtle but important difference with this constructure overload is
            //	it allows targetable to be 'null' which is used to avoid missing
            //	component exceptions in Area.
            this.gameObject = transform.gameObject;
            this.transform  = transform;

            this.targetable = transform.GetComponent <Targetable>();

            this.targetTracker = targetTracker;

            // The targetTracker arg could also be a derived type. If it is. populate more.
            // Also handle colliders to make the struct easier to use when trying to figure
            //	 out what collider triggered the OnHit event.
            this.eventTrigger = null;
            this.collider     = null;
            this.collider2D   = null;
            this.eventTrigger = targetTracker as EventTrigger;
            if (this.eventTrigger != null)
            {
                this.collider   = this.eventTrigger.coll;
                this.collider2D = this.eventTrigger.coll2D;
            }

            this.fireController = null;
        }
Beispiel #3
0
        protected void OnEnable()
        {
            this.tracker.AddOnNewDetectedDelegate(this.OnNewDetected);

            if (this._ignoreList.Count == 0)
            {
                return;
            }

            // Unless this is a AreaTargetTracker. Stop here.
            if (this.tracker.area == null)
            {
                return;
            }

            // Sync the ignore list with the TargetTracker by removing any ignore targetables.
            var areaListCopy = new TargetList(this.tracker.area);

            for (int i = 0; i < areaListCopy.Count; i++)
            {
                this.currentTargetable = areaListCopy[i].targetable;
                if (this.currentTargetable == null)
                {
                    continue;
                }

                if (this._ignoreList.Contains(this.currentTargetable))
                {
                    this.tracker.area.Remove(this.currentTargetable);
                }
            }
        }
Beispiel #4
0
 public Target(Target otherTarget)
 {
     this.gameObject     = otherTarget.gameObject;
     this.transform      = otherTarget.transform;
     this.targetable     = otherTarget.targetable;
     this.targetTracker  = otherTarget.targetTracker;
     this.fireController = otherTarget.fireController;
     this.projectile     = otherTarget.projectile;
 }
Beispiel #5
0
        protected void Awake()
        {
            this.startingColor = this.GetComponent <Renderer>().material.color;

            this.targetable = this.GetComponent <Targetable>();
            this.targetable.AddOnDetectedDelegate(this.OnDetected);
            this.targetable.AddOnNotDetectedDelegate(this.OnNotDetected);

            this.targetable.AddOnHitDelegate(this.OnHit);
        }
    protected void Awake()
    {
        this.startingColor = this.GetComponent<Renderer>().material.color;
			
        this.targetable = this.GetComponent<Targetable>();
        this.targetable.AddOnDetectedDelegate(this.OnDetected);
        this.targetable.AddOnNotDetectedDelegate(this.OnNotDetected);

        this.targetable.AddOnHitDelegate(this.OnHit);
    }
Beispiel #7
0
        /// <summary>
        /// Add the specified targetable.
        /// Performs some checks to make sure the targetable is valid for the Area.
        /// </summary>
        /// <param name='targetable'>
        /// If set to <c>true</c> targetable.
        /// </param>
        public void Add(Targetable targetable)
        {
            // Get a target struct which will also cache information, such as the Transfrom,
            //   GameObject and ITargetable component
            // Note this uses the targetable overload which has no component lookups so this
            //	is light.
            var target = new Target(targetable, this.targetTracker);

            // Run the main Add overload.
            this.Add(target);
        }
Beispiel #8
0
        /// <summary>
        /// Remove a Targetable
        /// </summary>
        /// <param name="xform">The transform component of the target to remove</param>
        /// <returns>True if somethign was removed</returns>
        public bool Remove(Targetable targetable)
        {
            // Fillout the struct directly to avoid internal GetComponent calls.
            var target = new Target();

            target.gameObject = targetable.gameObject;
            target.transform  = targetable.transform;
            target.targetable = targetable;

            return(this.Remove(target));
        }
Beispiel #9
0
        private void RegisterTargetable()
        {
            Targetable component = base.GetComponent <Targetable>();

            if (component == null)
            {
                return;
            }
            component.AddOnHitDelegate(new Targetable.OnHitDelegate(this.OnHitDelegate));
            component.AddOnDetectedDelegate(new Targetable.OnDetectedDelegate(this.OnDetectedDelegate));
            component.AddOnNotDetectedDelegate(new Targetable.OnNotDetectedDelegate(this.OnNotDetectedDelegate));
        }
Beispiel #10
0
        // Init by copy
        public Target(Target otherTarget)
        {
            this.gameObject = otherTarget.gameObject;
            this.transform  = otherTarget.transform;
            this.targetable = otherTarget.targetable;

            this.targetTracker  = otherTarget.targetTracker;
            this.fireController = otherTarget.fireController;
            this.eventTrigger   = otherTarget.eventTrigger;

            this.collider   = otherTarget.collider;
            this.collider2D = otherTarget.collider2D;
        }
Beispiel #11
0
 public Target(Transform transform, TargetTracker targetTracker)
 {
     this.gameObject    = transform.gameObject;
     this.transform     = transform;
     this.targetable    = this.transform.GetComponent <Targetable>();
     this.targetTracker = targetTracker;
     if (targetTracker is Projectile)
     {
         this.projectile = (Projectile)targetTracker;
     }
     else
     {
         this.projectile = null;
     }
     this.fireController = null;
 }
Beispiel #12
0
        /// <summary>
        /// Use like List<Targetable>.Remove to remove the passed targetable from the ignore
        /// list and add it to the TargetTracker
        /// </summary>
        /// <param name='targetable'>
        /// Targetable.
        /// </param>
        public void Remove(Targetable targetable)
        {
            if (targetable == null)
            {
                return;
            }

            // Does nothing if there is nothing to remove.
            this._ignoreList.Remove(targetable);

            // Don't affect the TargetTracker if this is disabled. If disabled, all
            //	 are added back to the Area anyway and OnEnable only Remove is done.
            if (this.enabled && this.tracker.area != null)
            {
                // The TargetTracker will handle preventing multiples from being added
                this.tracker.area.Add(targetable);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Uses a physics test based on the largest bounds dimension to see if the targetable's
        /// collider is in range of this Area.
        /// This has to use the largest dimension for non-uniform sized colliders. It avoids
        /// situations where the object is inside but not added. the check is still a radius
        /// though, so a long object that is oriented in a way that doesn't cross in to the
        /// Area will still return true.
        /// </summary>
        /// <returns>
        /// <param name='targetable'>
        /// Targetable.
        /// </param>
        public bool IsInRange(Targetable targetable)
        {
            if (this.coll != null)
            {
                Vector3 size     = this.coll.bounds.size;
                float   testSize = Mathf.Max(Mathf.Max(size.x, size.y), size.z);
                var     colls    = new List <Collider>(Physics.OverlapSphere(this.transform.position, testSize));
                return(colls.Contains(this.coll));
            }
            else if (this.coll2D != null)
            {
                var coll2Ds = new List <Collider2D>();
                var box2d   = this.coll2D as BoxCollider2D;
                if (box2d != null)
                {
                    var     pos2D      = new Vector2(this.transform.position.x, this.transform.position.y);
                    Vector2 worldPos2D = box2d.offset + pos2D;
                    Vector2 extents    = box2d.size * 0.5f;

                    var pntA = worldPos2D + extents;
                    var pntB = worldPos2D - extents;

                    coll2Ds.AddRange(Physics2D.OverlapAreaAll(pntA, pntB));
                }
                else
                {
                    var circ2D = this.coll2D as CircleCollider2D;
                    if (circ2D != null)
                    {
                        coll2Ds.AddRange
                        (
                            Physics2D.OverlapCircleAll(this.transform.position, circ2D.radius * 2)
                        );
                    }
                }

                return(coll2Ds.Contains(this.coll2D));
            }
            Debug.Log("IsInRange returning false due to no collider set. This may be fine.");
            return(false);
        }
        public Target(Transform transform, TargetTracker targetTracker)
        {
            this.gameObject = transform.gameObject;
            this.transform  = transform;
            this.targetable = this.transform.GetComponent <Targetable>();

            this.targetTracker = targetTracker;

            // The targetTracker arg could also be a projectile because it is derrived
            //   from a TargetTracker
            if (targetTracker is Projectile)
            {
                this.projectile = (Projectile)targetTracker;
            }
            else
            {
                this.projectile = null;
            }

            this.fireController = null;
        }
Beispiel #15
0
        /// <summary>
        /// Use like List<Targetable>.Add() to add the passed targetable to the ignore
        ///  list and remove it from the TargetTracker
        /// </summary>
        /// <param name='targetable'>
        /// Targetable.
        /// </param>
        public void Add(Targetable targetable)
        {
            if (targetable == null)
            {
                return;
            }

            // Only add this once.
            if (!this._ignoreList.Contains(targetable))
            {
                this._ignoreList.Add(targetable);
            }

            // Don't affect the TargetTracker if this is disabled. It will sync OnEnable
            if (this.enabled &&
                this.tracker != null &&
                this.tracker.area != null &&
                targetable.trackers.Contains(this.tracker))
            {
                // Removing multiple times doesn't hurt and lets the inspector use this.
                this.tracker.area.Remove(targetable);
            }
        }
Beispiel #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PathologicalGames.Target"/> struct.
        /// This is the most efficient constructor because it just stores references to
        /// caches that the Targetable already holds.
        /// </summary>
        /// <param name='targetable'>
        /// Targetable.
        /// </param>
        /// <param name='targetTracker'>
        /// Target tracker that detected the targetable.
        /// </param>
        public Target(Targetable targetable, TargetTracker targetTracker)
        {
            this.gameObject = targetable.go;
            this.transform  = targetable.transform;

            this.targetable = targetable;

            this.targetTracker = targetTracker;

            // The targetTracker arg could also be serived type. If it is. populate more.
            // Also handle colliders to make the struct easier to use when trying to figure
            //	 out what collider triggered the OnHit event.
            this.eventTrigger = null;
            this.collider     = null;
            this.collider2D   = null;
            this.eventTrigger = targetTracker as EventTrigger;
            if (this.eventTrigger != null)
            {
                this.collider   = this.eventTrigger.coll;
                this.collider2D = this.eventTrigger.coll2D;
            }

            this.fireController = null;
        }
		/// <summary>
		/// Use like List<Targetable>.Add() to add the passed targetable to the ignore 
		///  list and remove it from the TargetTracker
		/// </summary>
		/// <param name='targetable'>
		/// Targetable.
		/// </param>
		public void Add(Targetable targetable) 
		{
			if (targetable == null)
				return;
			
			// Only add this once.
			if (!this._ignoreList.Contains(targetable))
				this._ignoreList.Add(targetable);

			// Don't affect the TargetTracker if this is disabled. It will sync OnEnable
			if (this.enabled && 
			    this.tracker != null && 
			    this.tracker.area != null && 
			    targetable.trackers.Contains(this.tracker))
			{
				// Removing multiple times doesn't hurt and lets the inspector use this.
				this.tracker.area.Remove(targetable);
			}
		}
Beispiel #18
0
 /// <summary>
 /// Remove a Targetable
 /// </summary>
 /// <param name="xform">The transform component of the target to remove</param>
 /// <returns>True if somethign was removed</returns>
 public bool Remove(Targetable targetable)
 {
     return(this.Remove(new Target(targetable, this.targetTracker)));
 }
Beispiel #19
0
 public void RemoveOnHitDelegate(Targetable.OnHitDelegate del)
 {
     this.onHitDelegates = (Targetable.OnHitDelegate)Delegate.Remove(this.onHitDelegates, del);
 }
Beispiel #20
0
 public void RemoveOnNotDetectedDelegate(Targetable.OnNotDetectedDelegate del)
 {
     this.onNotDetectedDelegates = (Targetable.OnNotDetectedDelegate)Delegate.Remove(this.onNotDetectedDelegates, del);
 }
Beispiel #21
0
 public void SetOnHitDelegate(Targetable.OnHitDelegate del)
 {
     this.onHitDelegates = del;
 }
Beispiel #22
0
 public void SetOnNotDetectedDelegate(Targetable.OnNotDetectedDelegate del)
 {
     this.onNotDetectedDelegates = del;
 }
		/// <summary>
		/// Use like List<Targetable>.Remove to remove the passed targetable from the ignore 
		/// list and add it to the TargetTracker
		/// </summary>
		/// <param name='targetable'>
		/// Targetable.
		/// </param>
		public void Remove(Targetable targetable) 
		{
			if (targetable == null)
				return;

			// Does nothing if there is nothing to remove.
			this._ignoreList.Remove(targetable);			
			
			// Don't affect the TargetTracker if this is disabled. If disabled, all 
			//	 are added back to the Area anyway and OnEnable only Remove is done.
			if (this.enabled && this.tracker.area != null)
				// The TargetTracker will handle preventing multiples from being added
				this.tracker.area.Add(targetable);
		}
Beispiel #24
0
 public void AddOnHitColliderDelegate(Targetable.OnHitColliderDelegate del)
 {
     this.onHitColliderDelegates = (Targetable.OnHitColliderDelegate)Delegate.Combine(this.onHitColliderDelegates, del);
 }
Beispiel #25
0
 public void AddOnNotDetectedDelegate(Targetable.OnNotDetectedDelegate del)
 {
     this.onNotDetectedDelegates = (Targetable.OnNotDetectedDelegate)Delegate.Combine(this.onNotDetectedDelegates, del);
 }