Exemple #1
0
    // Show/Hide HPBar HUD
    private void OnEnable()
    {
        // if data has sprite name key,
        const string SPRITENAME_KEY = "SpriteName";

        if (MonsterDatatable.Data [EnemyName].hasKey(SPRITENAME_KEY))
        {
            string SpriteName = MonsterDatatable.Data [EnemyName] [SPRITENAME_KEY];
            View.sprite = SpriteCollection.GetSpriteByName(SpriteName);
        }

        Data = new PawnDataModel(this);

        // if data has Speed key,
        const string SPEED_KEY = "Speed";

        if (MonsterDatatable.Data [EnemyName].hasKey(SPEED_KEY))
        {
            Data.Velocity  = Vector3.down * MonsterDatatable.Data [EnemyName] [SPEED_KEY].AsFloat;
            Data.Velocity += Data.Acceleration;
        }

        // if data has HP key,
        const string HP_KEY = "HP";

        if (MonsterDatatable.Data [EnemyName].hasKey(HP_KEY))
        {
            Data.MaxHP = MonsterDatatable.Data [EnemyName] [HP_KEY].AsFloat;
            Data.HP    = Data.MaxHP;

            if (null != HPBarHUD)
            {
                HPBarHUD.transform.SetParent(Game.Instance.HUDCanvas.transform);
                HPBarHUD.gameObject.SetActive(true);
            }
        }
        else
        {
            Data.IsInvincible = true;
            if (null != HPBarHUD)
            {
                HPBarHUD.gameObject.SetActive(false);
            }
        }

        // TODO: add hit radius key to data
        Data.HitRadius = 0.25F;

        // if data has missile key,
        const string MISSILE_KEY = "Missile";

        if (MonsterDatatable.Data [EnemyName].hasKey(MISSILE_KEY))
        {
            const string DELAY_KEY = "Delay";
            float        Delay     = MonsterDatatable.Data [EnemyName] [MISSILE_KEY] [DELAY_KEY].AsFloat;

            if (Delay > 0)
            {
                ShootDelay = new WaitForSeconds(Delay);
                StartCoroutine(SpawnMissile());
            }
        }

        const string DROPRATING_KEY = "DropItemRating";

        if (MonsterDatatable.Data [EnemyName].hasKey(DROPRATING_KEY))
        {
            Data.DropItemRating = MonsterDatatable.Data [EnemyName] [DROPRATING_KEY].AsFloat;
        }

        const string SCOREGAIN_KEY = "Score";

        if (MonsterDatatable.Data [EnemyName].hasKey(SCOREGAIN_KEY))
        {
            Data.ScoreGain = MonsterDatatable.Data [EnemyName] [SCOREGAIN_KEY].AsInt;
        }
    }
Exemple #2
0
 private void OnEnable()
 {
     Data       = new PawnDataModel(this);
     Data.MaxHP = 1.0F;
     Data.HP    = Data.MaxHP;
 }