Ejemplo n.º 1
0
 public static void Register(EditorCellRenderer r)
 {
     if (!_rendererList.Contains(r))
     {
         _rendererList.Add(r);
     }
     SceneView.onSceneGUIDelegate -= OnSceneGUIDelegate;
     SceneView.onSceneGUIDelegate += OnSceneGUIDelegate;
 }
Ejemplo n.º 2
0
        // Change to invalidation
        public static void Invalidate()
        {
            if (_cells.Count == 0)
            {
                for (int i = 0; i < _rendererList.Count; i++)
                {
                    if (_rendererList[i])
                    {
                        Object.DestroyImmediate(_rendererList[i].gameObject);
                    }
                }
                _rendererList.Clear();
                return;
            }

            if (_material == null)
            {
                var shader = Shader.Find(ShaderName);
                if (shader == null)
                {
                    Debug.LogError("Failed to find shader " + ShaderName);
                    return;
                }
                _material = new Material(shader)
                {
                    hideFlags = HideFlags.DontSave
                };
            }
            _material.SetFloat("_Size", CellSize);

            for (var i = _rendererList.Count - 1; i >= 0; i--)
            {
                if (!_rendererList[i])
                {
                    _rendererList.RemoveAt(i);
                }
            }

            int requiredRendererCount = Mathf.CeilToInt(_cells.Count / (float)(UseCPU() ? (MAX_VERTS - 4) / 4 : MAX_VERTS));

            //Debug.Log(string.Format("{0} = {1}", _cells.Count, requiredRendererCount));
            for (int i = 0; i < requiredRendererCount; i++)
            {
                if (_rendererList.Count <= i)
                {
                    _rendererList.Add(GetNewRenderer());
                }
                if (_rendererList[i] == null)
                {
                    _rendererList[i] = GetNewRenderer();
                }

                EditorCellRenderer renderer = _rendererList[i];
                renderer.Clear();
                renderer.SetData(TRS, _material);
            }
            for (int i = _rendererList.Count - 1; i >= requiredRendererCount; i--)
            {
                Object.DestroyImmediate(_rendererList[i].gameObject);
                _rendererList.RemoveAt(i);
            }

            if (requiredRendererCount == 0)
            {
                return;
            }


            var activeRenderer = _rendererList[0];
            int index          = 0;

            for (int i = 0; i < _cells.Count; i++)
            {
                var cell = _cells[i];
                activeRenderer.QueueCell(cell);
                if (activeRenderer.VertCount > (UseCPU() ? MAX_VERTS - 4 : MAX_VERTS))
                {
                    index++;
                    activeRenderer = _rendererList[index];
                }
            }

            for (int i = 0; i < _rendererList.Count; i++)
            {
                _rendererList[i].Finalise();
            }

            _lastAliveTime = EditorApplication.timeSinceStartup;
            _dirty         = false;

            SceneView.onSceneGUIDelegate -= OnSceneGUIDelegate;
            SceneView.onSceneGUIDelegate += OnSceneGUIDelegate;
            SceneView.RepaintAll();
        }