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));
            }
        }
    }
  • 相关阅读:
    Unity3D读取assetbundle
    Unity3D 发布成exe之后黑屏
    Unity3D优化总结
    Unity3D中中 rect[2] == rt->GetGLWidth() && rect[3] == rt->GetGLHeight()错误的原因及解决方法
    C# mysql 插入数据,中文乱码的解决方法
    WPF Canvas做自动缩放时获取控件的实际高度
    面向对象
    常用模块介绍
    python异常处理,多线程,多进程
    python生成器,递归调用
  • 原文地址:https://www.cnblogs.com/CloudLiu/p/10746062.html
Copyright © 2011-2022 走看看