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++)
- {
-
- }
- }
- private void InitWayPoint()
- {
- if(noramlPointParent == null)
- {
- wayPoints = new WayPoint[0];
- return;
- }
- wayPoints = noramlPointParent.GetComponentsInChildren<WayPoint>();
- }
-
-
- void Update () {
-
- }
-
- private void 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.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;
- }
-
- }
|