123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- //肾小球
- public class BloodManager : MonoBehaviour {
- [SerializeField]
- private Transform noramlPointParent;//正常路径的父节点
- private WayPoint[] wayPoints;//正常的血液循环路径
- [SerializeField]
- private BloodItemConfig[] configs;//血液配置
- [SerializeField]
- private float rate;//血液产生的速度
- private List<UnityEngine.Object> objects;
- private int max_length;
- [SerializeField]
- private Transform orginalPoint;//出生点
- void Start () {
- InitConfig();
- InitWayPoint();
-
- }
- private void InitConfig()
- {
- objects = new List<Object>();
- for (int i = 0; i< configs.Length; i++)
- {
- for (int j = 0; j < configs[i].creawteRate; j++)
- {
- objects.Add(configs[i].asset);
- }
- }
- max_length = objects.Count;
- }
- public void StartCreate()
- {
- InvokeRepeating("Create", 1, rate);
- }
- public void StopCreate()
- {
- CancelInvoke("Create");
- for (int i = 0; i < configs.Length; i++)
- {
- //PrefabManager.Instance.RemovePrefab(objects[i].name);
- }
- }
- private void InitWayPoint()
- {
- if(noramlPointParent == null)
- {
- wayPoints = new WayPoint[0];
- return;
- }
- wayPoints = noramlPointParent.GetComponentsInChildren<WayPoint>();
- }
-
- //
- void Update () {
-
- }
- //产生血液
- private void Create()
- {
- //CDebug.Log("Create");
- if(!this.enabled)
- {
- return;
- }
- if(!this.gameObject.activeInHierarchy)
- {
- return;
- }
- var index = Random.Range(0, max_length -1);
- GameObject c_obj = PrefabManager.Instance.GetPrefab(objects[index].name, objects[index]);
- c_obj.transform.rotation = orginalPoint.rotation;
- c_obj.transform.position = orginalPoint.position + orginalPoint.up * Random.Range(-1.0f,1.0f) * 0.05f;
- //c_obj.transform.position = orginalPoint.position;
- c_obj.SetActive(true);
- BloodItem item = c_obj.GetComponent<BloodItem>();
- item.SetMoveDir(Vector3.right);
- }
- public enum BloodItemType
- {
- Erythrocyte,//红细胞
- MineralSalt,//无机盐
- Urea,//尿素
- Water,//水
- Glucose,//葡萄糖
- Protein,//蛋白质
- }
- [System.Serializable]
- public class BloodItemConfig
- {
- public UnityEngine.Object asset;
- public float creawteRate;
- public BloodItemType mTYpe;
- }
-
- }
|