DropItem3D.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using UnityEngine;
  2. using System.Collections;
  3. public class DropItem3D
  4. {
  5. private DropItemType itemType;
  6. private Vector3 bornPos;
  7. private float lifeTime;
  8. private GameObject itemGo;
  9. public DropItem3D(Vector3 pos,DropItemType type,int animIdx)
  10. {
  11. itemGo = ResourceMgr.Instance.GetGoFromPool(Constants.ModelPath, BattleDropMgr.drop_gold_prefab_name);
  12. itemType = type;
  13. bornPos = pos;
  14. lifeTime = 1.5f;
  15. if (itemGo != null)
  16. {
  17. itemGo.transform.SetParent(BattleDropMgr.Instance.Root.transform);
  18. itemGo.transform.localPosition = pos;
  19. itemGo.transform.localScale = new Vector3(2, 2, 2);
  20. }
  21. //PlayAnim(animIdx);
  22. }
  23. public bool IsValid(float deltatime)
  24. {
  25. if (itemGo == null) return false;
  26. lifeTime -= deltatime;
  27. return lifeTime>0;
  28. }
  29. public void Dispose()
  30. {
  31. if (itemGo != null)
  32. {
  33. ResourceMgr.Instance.RecycleGO(Constants.ModelPath, BattleDropMgr.drop_gold_prefab_name, itemGo);
  34. itemGo = null;
  35. }
  36. }
  37. void PlayAnim(int animIdx)
  38. {
  39. if (itemGo == null) return;
  40. Animator animator = itemGo.GetComponent<Animator>();
  41. if (animator == null) return;
  42. string animName = "Drop" + animIdx;
  43. animator.Play(animName);
  44. }
  45. }