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

    四类
    1.  ScriptableObject   只有菜单
    2.  ScriptableWizard  向导对话框 简单的输入 响应一下确认按钮
    3.  EditorWindow       编辑对话框
    4.  Editor                     


    绘制ui函数的各种空间
    GUI
    GUILayout
    EditorGUI             Editor下专用的各种控件,动画曲线什么的
    EditorGUILayout

    ScriptableWizard  
        OnWizardUpdate()
        OnWizardCreate()
        ScriptableWizard.DisplayWizard("Title", typeof(ClassName), "BtnName");
        

    EditorWindow   
        OnInspectorUpdate每帧检查   需要的时候调用 Repaint()
        OnGUI() 在需要的时候调用
        会响应 Enable,Update等常规事件 
        Repaint(); 重新绘制编辑器

    Editor 可以用来自定义某个组件的Inspector编辑界面
                   [CustomEditor(typeof(XXX))]
                   public class XXXInspector : Editor {
                也可以用来做一些复杂的界面

    用一个静态方法打开
        [MenuItem("KingsoftTools/Skill/伤害组件监视")]
        static void Init()
        {
            EditorWindow.GetWindow(typeof(BuffInspector));
        }

    EditorWindow  常用方法整理
    描述实现
    自定义图片以及显示Texture2D dataImg = new Texture2D(256, 256);
    绘图。。。 。。。
    一个点一个点设置颜色...
    dataImg.Apply();  //必须调用 apply函数才会改变Texture2D
    EditorGUI.DrawPreviewTexture(...) //绘制到编辑器
    显示文本EditorGUILayout.LabelField("xxxxxxxxxxxx");
    //富文本
    GUIStyle sytle = new GUIStyle();
    sytle.richText = true;
    EditorGUILayout.LabelField("xx<color=red>X</color>xx", sytle);
    保存设置EditorPrefs 或 PlayerPrefs
    选择列表GUILayout.SelectionGrid(int selected, 内容[] texts, int xCount, params GUILayoutOption[] options)
    内容可以是String,Texture,GUIContent
    蒙版选择EditorGUILayout.MaskField(string label, int mask, string[] displayedOptions)
    可以用来选择使用的层级
    按钮if (GUILayout.Button("XXX"))
    {
        ... ...
    }
    水平排列GUILayout.BeginHorizontal();
    ... ...
    GUILayout.EndHorizontal();
    滚动条val = GUILayout.HorizontalSlider(float value, float leftValue, float rightValue);
    val = GUILayout.VerticalSlider(float value, float leftValue, float rightValue);
    选择文件EditorUtility.OpenFolderPanel(string title, string folder, string defaultName);
    选择文件夹EditorUtility.OpenFilePanel(string title, string directory, string extension);
    图片格式改动TextureImporter texInfo = (TextureImporter)AssetImporter.GetAtPath(TexturePath);
    ... ...
    AssetDatabase.ImportAsset(TexturePath, ImportAssetOptions.ForceUpdate);
    勾选框isShowInfo = EditorGUILayout.Toggle("显示生成信息", isShowInfo);





    LayerMask(选择层级,多选框式)
    35
     
    1
        List<string> layers;
    2
        List<int> layerNumbers;
    3
        LayerMask LayerMaskField(string label)
    4
        {
    5
            if (layers == null || layerNumbers == null)
    6
            {
    7
                layers = new List<string>();
    8
                layerNumbers = new List<int>();
    9
                for (int i = 0; i < 32; i++)
    10
                {
    11
                    string layerName = LayerMask.LayerToName(i);
    12
                    if (layerName != "" && layerName != "UI")
    13
                    {
    14
                        layers.Add(layerName);
    15
                        layerNumbers.Add(i);
    16
                    }
    17
                }
    18
            }
    19
    20
            int maskWithoutEmpty = 0;
    21
            for (int i = 0; i < layerNumbers.Count; i++)
    22
            {
    23
                if (((1 << layerNumbers[i]) & layerMask.value) > 0)
    24
                    maskWithoutEmpty |= (1 << i);
    25
            }
    26
            maskWithoutEmpty = EditorGUILayout.MaskField(label, maskWithoutEmpty, layers.ToArray());
    27
            int mask = 0;
    28
            for (int i = 0; i < layerNumbers.Count; i++)
    29
            {
    30
                if ((maskWithoutEmpty & (1 << i)) > 0)
    31
                    mask |= (1 << layerNumbers[i]);
    32
            }
    33
            layerMask.value = mask;
    34
            return layerMask;
    35
        }














  • 相关阅读:
    使用 v-cloak 防止页面加载时出现 vuejs 的变量名
    Jackson 解析json数据之忽略解析字段注解@JsonIgnoreProperties
    java.lang.IllegalStateException: Cannot run without an instance id.
    沪牌-上海牌照-拍牌经验分享: 我是如何三次拍中的?
    沪牌学院-沪拍拍课堂4: 实拍前的演练
    沪牌学院-沪拍拍课堂3: 网络优化
    沪牌学院-沪拍拍课堂2: 出价策略
    沪牌学院-沪拍拍课堂1: 估价策略
    如何将 DVD 转成 ISO
    雅虎天气-城市代码列表
  • 原文地址:https://www.cnblogs.com/Hichy/p/7892268.html
Copyright © 2011-2022 走看看