/// <summary> /// 根据时间片长短创建 /// </summary> /// <param name="dataSet">数据集</param> dataInfo的数据结构 /// <returns></returns> public NodeObject ProduceModelNode(int mType, NodeData dataInfo) { if (!TrackManager.instance.CheckPushValue()) { dataInfo.mtype = mType; _dataCache.Insert(0, dataInfo); // 时间倒叙 return(null); } // Creat modelnode,生成节点 NodeObject node = PickAvaliableNode((eNodeType)mType); if (node == null) { return(null); } // ToDo: Set node attriInfo,将数据集传给Node(钢琴块)节点 node.ResetDataInfo(dataInfo); // Put on track ,将节点放入轨道 TrackManager.instance.PushValue(node); return(node); }
// 创建一类节点缓存 private void CrateModelNodePool(int mType, GameObject prefabe, int num) { if (_nodePool.ContainsKey(mType)) { Debug.LogWarning("Already contain this type node cache " + mType); return; } if (prefabe == null) { Debug.LogError("Created failed ,node resource is a null value"); return; } List <NodeObject> list = new List <NodeObject>(); _nodePool.Add(mType, list); for (int i = 0; i < num; ++i) { eNodeType eType = (eNodeType)mType; NodeObject node = CreateEmptyNode(eType, prefabe); //list.Add(node); RecoverNode(node); } }
/// <summary> /// /// </summary> /// <param name="eType"></param> /// <param name="prefab">源资源prefab</param> /// <returns></returns> private NodeObject CreateEmptyNode(eNodeType eType, UnityEngine.Object prefab) { if (prefab == null) { return(null); } NodeObject node = null; GameObject go = GameObject.Instantiate(prefab) as GameObject; go.name = prefab.name; switch (eType) { case eNodeType.Normal: node = go.GetComponent <NormalNode>(); if (node == null) { node = go.AddComponent <NormalNode>(); } node.eType = eNodeType.Normal; break; case eNodeType.Len: node = go.GetComponent <NormalNode>(); if (node == null) { node = go.AddComponent <NormalNode>(); } node.eType = eNodeType.Len; break; case eNodeType.Combine: node = go.GetComponent <NormalNode>(); if (node == null) { node = go.AddComponent <NormalNode>(); } node.eType = eNodeType.Combine; break; default: node = go.GetComponent <NormalNode>(); if (node == null) { node = go.AddComponent <NormalNode>(); } node.eType = eNodeType.Normal; break; } node.Init(); node.SetParent(cacheRoot); //node.SetActive(false); return(node); }
// 更新不由引擎驱动,而是由Game驱动 public void Update() { int count = _dataCache.Count; for (int i = count - 1; i >= 0; --i) { if (!TrackManager.instance.CheckPushValue()) { break; } NodeData dataInfo = _dataCache[i]; int mType = dataInfo.mtype; NodeObject obj = ProduceModelNode(mType, dataInfo); if (obj != null) { _dataCache.RemoveAt(i); } } }
public void RecoverNode(NodeObject node) { eNodeType eType = node.eType; int mType = (int)eType; List <NodeObject> list = null; if (!_nodePool.TryGetValue(mType, out list)) { GameObject.Destroy(node); Debug.LogError("RecoverNode failed not contain this type pool"); return; } node.Disappear(); node.SetParent(cacheRoot); node.position = Vector3.zero; list.Add(node); }
private NodeObject PickAvaliableNode(eNodeType eType) { int mType = (int)eType; List <NodeObject> list = null; NodeObject node = null; if (!_nodePool.TryGetValue(mType, out list)) { GameObject prefabe = _prefabList[mType]; if (prefabe == null) { Debug.LogError("Not contain this type prefab " + mType); return(null); } CrateModelNodePool(mType, prefabe, m_CacheDefualtNum); } int count = list.Count; if (count <= 0) { Object prefabe = _prefabList[mType]; if (prefabe == null) { Debug.LogError("Not contain this type prefab@@@@@@ " + mType); return(null); } node = CreateEmptyNode(eType, prefabe); return(node); } node = list[0]; list.RemoveAt(0); return(node); }