zoukankan      html  css  js  c++  java
  • Unity编辑器

    Unity编辑器 - 使用GL绘制控件

    控件较为复杂时,可能造成界面卡顿,在EditorGUI中也可以灵活使用GL绘制来提升性能。
    以绘制线段为例:
    这里写图片描述

    using UnityEngine;
    using UnityEditor;
    
    public class EditorGL {
        private static Material _sLineMat;
    
        static EditorGL() {
            Shader shader = Shader.Find("Hidden/Internal-Colored");
            _sLineMat = new Material(shader);
            _sLineMat.hideFlags = HideFlags.HideAndDontSave;
            _sLineMat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
            _sLineMat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
            _sLineMat.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
            _sLineMat.SetInt("_ZWrite", 0);
        }
    
        public static void DrawVerticalLine(float x, float minY, float maxY, Color color) {
            if (Event.current.type == EventType.Repaint) {
                Color color2 = Handles.color;
                _sLineMat.SetPass(0);
                if (Application.platform == RuntimePlatform.WindowsEditor) {
                    GL.Begin(7);
                }
                else {
                    GL.Begin(1);
                }
                DrawVerticalLineFast(x, minY, maxY, color);
                GL.End();
                Handles.color = color2;
            }
        }
    
        private static void DrawVerticalLineFast(float x, float minY, float maxY, Color color) {
            if (Application.platform == RuntimePlatform.WindowsEditor) {
                GL.Color(color);
                GL.Vertex(new Vector3(x - 0.5f, minY, 0f));
                GL.Vertex(new Vector3(x + 0.5f, minY, 0f));
                GL.Vertex(new Vector3(x + 0.5f, maxY, 0f));
                GL.Vertex(new Vector3(x - 0.5f, maxY, 0f));
            }
            else {
                GL.Color(color);
                GL.Vertex(new Vector3(x, minY, 0f));
                GL.Vertex(new Vector3(x, maxY, 0f));
            }
        }
    }
  • 相关阅读:
    091115 T UI生成的类
    090717 T OOD时的接口
    090713 T 数组不OO
    090723 T Code Generate 的思考
    091101 T IModel
    091018 CH 培训方法论总结
    090615 T 数据库范式
    写程序,逻辑优先!
    091117 T else if 的写法
    091015 CH 培训所想到的
  • 原文地址:https://www.cnblogs.com/CloudLiu/p/10746062.html
Copyright © 2011-2022 走看看