Example #1
0
    /* Doesn't work
     * public List<IEnumerable<T>> getTypes<T>() where T : SpaceObject
     * {
     *  if (typeof(T) == typeof(SpaceObject))
     *  {
     *      return (List<IEnumerable<T>>)getTypes(true, true, true, true);
     *  }
     *  else if (typeof(T) == typeof(NonInteractiveObject))
     *  {
     *      return (List<IEnumerable<T>>)getTypes(false, false, false, true);
     *  }
     *  else if (typeof(T) == typeof(InteractiveObject))
     *  {
     *      return (List<IEnumerable<T>>)getTypes(true, true, true, false);
     *  }
     *  else if (typeof(T) == typeof(DestructableObject))
     *  {
     *      return (List<IEnumerable<T>>)getTypes(true, true, false, false);
     *  }
     *  else if (typeof(T) == typeof(IndestructableObject))
     *  {
     *      return (List<IEnumerable<T>>)getTypes(false, false, true, false);
     *  }
     *  else if (typeof(T) == typeof(Player))
     *  {
     *      return (List<IEnumerable<T>>)getTypes(true, false, false, false);
     *  }
     *  else if (typeof(T).IsSubclassOf(typeof(NonInteractiveObject))
     *  {
     *      List<IEnumerable<T>> items = new List<IEnumerable<T>>();
     *      foreach (T item in theNonInteractives)
     *      {
     *          if (item.GetType().IsSubclassOf(typeof(T)) || item.GetType() == typeof(T))
     *          {
     *              items[0].Add(item);
     *          }
     *      }
     *      return items;
     *  }
     * }
     */

    //The following methods remove or add the given DestructableObject to the correct list.
    public void RemoveFromGame(DestructableObject remove)
    {
        if (remove.GetType() == typeof(Player))
        {
            remove.DestroyThis();
        }
        else
        {
            removeDestructables.Add(remove);
        }
    }
Example #2
0
    void Update()
    {
        //if this has no owner then it should not exist, so destory it
        if (owner == null)
        {
            Destroy(this.gameObject);
        }
        //if the owner of this is not active, hide this
        else if (!owner.active || !owner.gameObject.activeInHierarchy)
        {
            Vector3 scale = transform.localScale;
            scale.x = 0;
            transform.localScale = scale;
        }
        else
        {
            //update the scale of front image baised on the owner's health
            Vector3 scale = healthFront.transform.localScale;
            if (owner.maxHealth <= 0)
            {
                owner.DestroyThis();
                Destroy(this.gameObject);
                return;
            }
            scale.x = owner.health / owner.maxHealth;
            healthFront.transform.localScale = scale;

            //update the alpha of the front image baised on Options
            Color color = frontSpriteRenderer.color;
            color.a = Options.Get().healthBarAlpha;
            frontSpriteRenderer.color = color;

            //update the alpha of the back image baised on Options
            color   = backSpriteRenderer.color;
            color.a = Options.Get().healthBarAlpha / 2.0f;
            backSpriteRenderer.color = color;

            //move this HealthBar to always be ontop of its owner
            Vector3 pos = owner.position;
            pos.z = transform.position.z;
            transform.position = pos;
        }
    }