BloodManager.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. //肾小球
  5. public class BloodManager : MonoBehaviour {
  6. [SerializeField]
  7. private Transform noramlPointParent;//正常路径的父节点
  8. private WayPoint[] wayPoints;//正常的血液循环路径
  9. [SerializeField]
  10. private BloodItemConfig[] configs;//血液配置
  11. [SerializeField]
  12. private float rate;//血液产生的速度
  13. private List<UnityEngine.Object> objects;
  14. private int max_length;
  15. [SerializeField]
  16. private Transform orginalPoint;//出生点
  17. void Start () {
  18. InitConfig();
  19. InitWayPoint();
  20. }
  21. private void InitConfig()
  22. {
  23. objects = new List<Object>();
  24. for (int i = 0; i< configs.Length; i++)
  25. {
  26. for (int j = 0; j < configs[i].creawteRate; j++)
  27. {
  28. objects.Add(configs[i].asset);
  29. }
  30. }
  31. max_length = objects.Count;
  32. }
  33. public void StartCreate()
  34. {
  35. InvokeRepeating("Create", 1, rate);
  36. }
  37. public void StopCreate()
  38. {
  39. CancelInvoke("Create");
  40. for (int i = 0; i < configs.Length; i++)
  41. {
  42. //PrefabManager.Instance.RemovePrefab(objects[i].name);
  43. }
  44. }
  45. private void InitWayPoint()
  46. {
  47. if(noramlPointParent == null)
  48. {
  49. wayPoints = new WayPoint[0];
  50. return;
  51. }
  52. wayPoints = noramlPointParent.GetComponentsInChildren<WayPoint>();
  53. }
  54. //
  55. void Update () {
  56. }
  57. //产生血液
  58. private void Create()
  59. {
  60. //CDebug.Log("Create");
  61. if(!this.enabled)
  62. {
  63. return;
  64. }
  65. if(!this.gameObject.activeInHierarchy)
  66. {
  67. return;
  68. }
  69. var index = Random.Range(0, max_length -1);
  70. GameObject c_obj = PrefabManager.Instance.GetPrefab(objects[index].name, objects[index]);
  71. c_obj.transform.rotation = orginalPoint.rotation;
  72. c_obj.transform.position = orginalPoint.position + orginalPoint.up * Random.Range(-1.0f,1.0f) * 0.05f;
  73. //c_obj.transform.position = orginalPoint.position;
  74. c_obj.SetActive(true);
  75. BloodItem item = c_obj.GetComponent<BloodItem>();
  76. item.SetMoveDir(Vector3.right);
  77. }
  78. public enum BloodItemType
  79. {
  80. Erythrocyte,//红细胞
  81. MineralSalt,//无机盐
  82. Urea,//尿素
  83. Water,//水
  84. Glucose,//葡萄糖
  85. Protein,//蛋白质
  86. }
  87. [System.Serializable]
  88. public class BloodItemConfig
  89. {
  90. public UnityEngine.Object asset;
  91. public float creawteRate;
  92. public BloodItemType mTYpe;
  93. }
  94. }