Exemplo n.º 1
0
 public void Initialize(ThinkingPlaceable p)
 {
     currentHealth     = originalHealth = p.hitPoints;
     anchorPosition    = p.pType == Placeable.PlaceableType.Unit ? unitAnchorPosition : nonUnitAnchorPosition;
     barColor          = p.faction == Placeable.Faction.Player ? red : blue;
     transformToFollow = p.transform;
 }
Exemplo n.º 2
0
        private void AddPlaceableToList(ThinkingPlaceable p)
        {
            allThinkingPlaceables.Add(p);

            if (p.faction == Placeable.Faction.Player)
            {
                allPlayers.Add(p);

                if (p.pType == Placeable.PlaceableType.Unit)
                {
                    playerUnits.Add(p);
                }
                else
                {
                    playerBuildings.Add(p);
                }
            }
            else if (p.faction == Placeable.Faction.Opponent)
            {
                allOpponents.Add(p);

                if (p.pType == Placeable.PlaceableType.Unit)
                {
                    opponentUnits.Add(p);
                }
                else
                {
                    opponentBuildings.Add(p);
                }
            }
            else
            {
                Debug.LogError("Error in adding a Placeable in one of the player/opponent lists");
            }
        }
Exemplo n.º 3
0
        private void RemovePlaceableFromList(ThinkingPlaceable p)
        {
            allThinkingPlaceables.Remove(p);

            if (p.faction == Placeable.Faction.Player)
            {
                allPlayers.Remove(p);

                if (p.pType == Placeable.PlaceableType.Unit)
                {
                    playerUnits.Remove(p);
                }
                else
                {
                    playerBuildings.Remove(p);
                }
            }
            else if (p.faction == Placeable.Faction.Opponent)
            {
                allOpponents.Remove(p);

                if (p.pType == Placeable.PlaceableType.Unit)
                {
                    opponentUnits.Remove(p);
                }
                else
                {
                    opponentBuildings.Remove(p);
                }
            }
            else
            {
                Debug.LogError("Error in removing a Placeable from one of the player/opponent lists");
            }
        }
 public void RemoveHealthUI(ThinkingPlaceable p)
 {
     if (p.healthBar)
     {
         Destroy(p.healthBar.gameObject);
     }
 }
        public void AddHealthUI(ThinkingPlaceable p)
        {
            var healthBar = Instantiate(healthBarPrefab, healthBarContainer);

            p.healthBar = healthBar;
            healthBar.Initialize(p);
        }
Exemplo n.º 6
0
 private void OnPlaceableDealtDamage(ThinkingPlaceable p)
 {
     if (p.target.state != ThinkingPlaceable.States.Dead)
     {
         float newHealth = p.target.SufferDamage(p.damage);
         p.target.healthBar.SetHealth(newHealth);
     }
 }
Exemplo n.º 7
0
        public void AddHealthUI(ThinkingPlaceable p)
        {
            GameObject newUIObject = Instantiate <GameObject>(healthBarPrefab, p.transform.position, Quaternion.identity, healthBarContainer);

            p.healthBar = newUIObject.GetComponent <HealthBar>(); //store the reference in the ThinkingPlaceable itself
            p.healthBar.Initialise(p);

            healthBars.Add(p.healthBar);
        }
Exemplo n.º 8
0
        public void Initialise(ThinkingPlaceable p)
        {
            originalHP        = currentHP = p.hitPoints;
            transformToFollow = p.transform;

            bar.GetComponent <Image>().color = (p.faction == Placeable.Faction.Player) ? red : blue;

            wholeWidget.transform.localPosition = new Vector3(0f,
                                                              (p.pType == Placeable.PlaceableType.Unit) ? 3f : 6f,
                                                              (p.pType == Placeable.PlaceableType.Unit) ? 0f : -2f);                                                           //set the vertical position based on the type of Placeable
            wholeWidget.SetActive(false);
        }
Exemplo n.º 9
0
        private void OnProjectileFired(ThinkingPlaceable p)
        {
            Vector3 adjTargetPos = p.target.transform.position;

            adjTargetPos.y = 1.5f;
            Quaternion rot = Quaternion.LookRotation(adjTargetPos - p.projectileSpawnPoint.position);

            Projectile prj = Instantiate <GameObject>(p.projectilePrefab, p.projectileSpawnPoint.position, rot).GetComponent <Projectile>();

            prj.target = p.target;
            prj.damage = p.damage;
            allProjectiles.Add(prj);
        }
Exemplo n.º 10
0
        private bool FindClosestInList(Vector3 p, List <ThinkingPlaceable> list, out ThinkingPlaceable t)
        {
            t = null;
            bool  targetFound        = false;
            float closestDistanceSqr = Mathf.Infinity; //anything closer than here becomes the new designated target

            for (int i = 0; i < list.Count; i++)
            {
                float sqrDistance = (p - list[i].transform.position).sqrMagnitude;
                if (sqrDistance < closestDistanceSqr)
                {
                    t = list[i];
                    closestDistanceSqr = sqrDistance;
                    targetFound        = true;
                }
            }

            return(targetFound);
        }
Exemplo n.º 11
0
        public void RemoveHealthUI(ThinkingPlaceable p)
        {
            healthBars.Remove(p.healthBar);

            Destroy(p.healthBar.gameObject);
        }
Exemplo n.º 12
0
 public virtual void SetTarget(ThinkingPlaceable t)
 {
     target   = t;
     t.OnDie += TargetIsDead;
 }
Exemplo n.º 13
0
 public override void SetTarget(ThinkingPlaceable t)
 {
     base.SetTarget(t);
 }
Exemplo n.º 14
0
        private IEnumerator Dispose(ThinkingPlaceable p)
        {
            yield return(new WaitForSeconds(3f));

            Destroy(p.gameObject);
        }