// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2020-09-02 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** #if SDK_WECHAT_WASM #define PLAY_PLATFORM_SOUND #endif using UnityEngine; namespace G { public class EntityProp : Entity { private GameCamera script_cam => GameCamera.Instance; public int maxHp = 1; public Transform mydestroy; public Transform[] drop; private int _curHp; private bool _isLife = true; #region Property /// /// /// public override EntityType entityType { get { return EntityType.Drop; } } #endregion #region Method public bool Init(EntityInfo info) { if (info != null) { this.id = info.guid; this.position = info.position; _curHp = maxHp; } return true; } //public override void Dispose() //{ // F.ObjectPool.SpawnPool.Despawn(this.gameObject); //} #endregion #region Unity private System.Collections.IEnumerator Start() { var handle = AssetProxy.Instance.TryGetTemporaryAssetAsync("bt_wood_break"); yield return handle; GetComponent().clip = handle.Result; } private void OnTriggerEnter(Collider other) { if (other.gameObject.layer <= GameLayer.AllyLayer) { return; } float damage = EntityMainPlayer.Instance.damage; switch (other.gameObject.layer) { case GameLayer.NormalAttack: script_cam.Hitcam(); break; case GameLayer.PowerAttack: script_cam.Hitcam2(1f); break; case GameLayer.SkillAttack: script_cam.Hitcam(); break; case GameLayer.PoisonAttack: script_cam.Hitcam(); break; case GameLayer.DeathAttack: script_cam.Hitcam(); break; case GameLayer.GeneralAttack: break; case GameLayer.PierceAttack: break; case GameLayer.CrowdAttack: damage = 2f; break; case GameLayer.PushAttack: break; case GameLayer.RiseupAttack2: break; case GameLayer.BurnAttack: break; case GameLayer.ColdAttack: break; case GameLayer.ShockAttack: break; case GameLayer.DarkAttack: break; } _curHp -= (int)damage; if (_curHp <= 0 && _isLife) { #if !PLAY_PLATFORM_SOUND if (SoundProxy.Instance.fxEnabled && GetComponent()) GetComponent().Play(); #else SoundProxy.PlayFxAsync("bt_wood_break.mp3"); #endif _isLife = false; GetComponent().enabled = false; if (mydestroy) { var destroy = Object.Instantiate(mydestroy, transform.position, transform.rotation); //destroy.GetComponent()["destroy_tower"].speed = 0.3f; Object.Destroy(destroy.gameObject, 3f); } if (Random.value < 0.5f) { var boxId = GameLevel.Instance.stageBoxId; var boxItem = BoxProxy.Instance.GetBoxInfo(boxId); if (boxItem != null) { var coinInfo = boxItem.GetExtraItem(); EnemyHelper.Instance.CreateBox(coinInfo.id, coinInfo.count, this.transform.position); } } else if (drop != null && drop.Length > 0 && drop[0]) { Object.Instantiate(drop[0], transform.position, Quaternion.identity); } EntityManager.Instance.RemoveEntity(this); } } #endregion } }