private void CheckUpdate() { ObjectGPUInstancingMgr.GetInstance().UpdateClipper(); CheckVisible(); DrawGPUInstancings(); }
public void Clear() { if (m_IsInited) { ClearVisibleSceneMap(); DestoryInstancingMap(); ObjectGPUInstancingMgr.GetInstance().ClearClipper(this); if (m_ObjectsMap != null) { m_ObjectsMap.Clear(); } if (m_ObjectsList != null) { m_ObjectsList.Clear(); } ClearChgQueue(); m_Selector = null; #if UNITY_EDITOR this.VisibleCount = 0; this.KdTreeVisibleCount = 0; this.GPUInstancingGroupCount = 0; #endif m_IsInited = false; } }
// 多场景加载 private void Refresh() { ObjectGPUInstancingMgr.GetInstance().Refresh(); ClearChgQueue(); ClearVisibleSceneMap(); DestoryInstancingMap(true); }
void CheckVisible() { #if UNITY_EDITOR this.VisibleCount = ObjectGPUInstancingMgr.GetInstance().VisibleCount; this.KdTreeVisibleCount = ObjectGPUInstancingMgr.GetInstance().KdTreeVisibleCount; this.VisibleNodePoolCount = NsLib.Utils.AbstractPool <VisibleNode> .PoolItemCount; this.GPUInstancingGroupCount = m_GPUInstancingMap.Count; #endif // 处理循环数据 if (m_ChgQueue == null) { ObjectGPUInstancingMgr.GetInstance().UptoVisibleQueue(ref m_ChgQueue); } printQueue(); }
// 多线程执行 protected override void Execute() { #if UNITY_EDITOR #if !UNITY_5_3 && !UNITY_5_6 //m_Sampler.Begin(); UnityEngine.Profiling.Profiler.BeginThreadProfiling("KdTreeThreadGroup", "KdTreeThread"); #else //UnityEngine.Profiler.BeginSample("KdTreeThreadSampler"); #endif #endif ObjectGPUInstancingMgr.GetInstance()._ThreadRun(); #if UNITY_EDITOR #if !UNITY_5_3 && !UNITY_5_6 UnityEngine.Profiling.Profiler.EndThreadProfiling(); //m_Sampler.End(); #else //UnityEngine.Profiler.EndSample(); #endif #endif }
void Start() { Renderer[] rs = GetComponentsInChildren <Renderer> (); if (rs != null && rs.Length > 0) { var clipper = ObjectGPUInstancingMgr.GetInstance().Clipper; if (clipper != null) { clipper.ReBuild(rs, true); //ObjectGPUInstancingMgr.GetInstance ().UpdateClipper (); } else { clipper = GameObject.FindObjectOfType <KdTreeCameraClipper> (); if (clipper != null) { clipper.ReBuild(rs, false); } } } }
public void ReBuild(IList <Renderer> targetObjects, bool isAddMode = false) { if (!m_IsInited || isAddMode) { if (targetObjects != null && targetObjects.Count > 0) { ObjectGPUInstancingMgr.GetInstance().RegisterClipper(this); m_IsInited = true; if (m_ObjectsMap == null) { m_ObjectsMap = new Dictionary <int, Renderer> (targetObjects.Count); } else { if (!isAddMode) { m_ObjectsMap.Clear(); } } if (m_ObjectsList == null) { m_ObjectsList = new List <int> (targetObjects.Count); } else { if (!isAddMode) { m_ObjectsList.Clear(); m_ObjectsList.Capacity = targetObjects.Count; } } bool isNew = false; for (int i = 0; i < targetObjects.Count; ++i) { var item = targetObjects [i]; if (item == null) { continue; } int instanceId = item.GetInstanceID(); if (!m_ObjectsMap.ContainsKey(instanceId)) { m_ObjectsMap.Add(instanceId, item); m_ObjectsList.Add(instanceId); isNew = true; } if (this.AutoSetVisible || (this.OpenGPUInstancing && ObjectGPUInstancingMgr.SupportGPUInstancing)) { var gameObj = item.gameObject; if (gameObj.activeSelf) { gameObj.SetActive(false); } } } if (isAddMode && isNew) { AddBuildClear(); } ObjectGPUInstancingMgr.GetInstance().Build(m_UseThread); } } }