Unity基础-编辑器

Posted carious

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity基础-编辑器相关的知识,希望对你有一定的参考价值。

编辑器

Special Folders

Hidden Folder(start with .)
Standard Assets:第一批加载的文件
Editor:只在编辑下才能使用,
Plugins
Resources:原生资源
Editor Default Resources
Gizmos:Gizmos资源
StreamingAssets:自定义资源

编辑器功能扩展-EditorWindow

自定义一个编辑器窗口界面
Unity的编辑器的UI操作都很难用,继承EditorWindow
在OnGUI中绘制UI,触发并显示出来

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class MyWindow : EditorWindow {

    string myString = "Hello World";
    bool groupEnabled;
    bool myBool = true;
    float myFloat = 1.23f;

    // Add menu item named"My Window" to the Window menu
    [MenuItem("Window/My Window")]
    public static void ShowWindow()
    {
        // Show existing window instance.If one doesn't exist,make one.
        EditorWindow.GetWindow(typeof(MyWindow));
    }

    // 每一帧都会触发
    private void OnGUI()
    {
        GUILayout.Label("Base Settings", EditorStyles.boldLabel);
        myString = EditorGUILayout.TextField("Text Field", myString);

        groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Settings", groupEnabled);
        myBool = EditorGUILayout.Toggle("Toggle", myBool);
        myFloat = EditorGUILayout.Slider("Slider", myFloat, -3, 3);
        EditorGUILayout.EndToggleGroup(); 
    }
}

技术图片

编辑器功能的扩展-EditorWindow

自定义一个编辑器窗口界面
Unity的编辑器UI操作都很难用
继承EditorWindow在O你GUI中汇正UI触发并显示出来

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(LookAtPoint))]     // 对于LookAtPoint的Custom
public class LookAtPointEditor : Editor {

    void OnInspectorGUI()
    {
        LookAtPoint lp = target as LookAtPoint;
        lp.lookAtPoint = EditorGUILayout.Vector3Field("Look At Point", lp.lookAtPoint);
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }

    private void OnSceneGUI()
    {
        LookAtPoint lp = target as LookAtPoint;
        lp.lookAtPoint = Handles.PositionHandle(lp.lookAtPoint, Quaternion.identity);   // 坐标系
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
}

以上是关于Unity基础-编辑器的主要内容,如果未能解决你的问题,请参考以下文章

unity shader学习笔记 shader基础结构以及Properties面板

Unity基础-编辑器

Unity编辑器扩展

Unity中timeline出现脚本错误怎么解决

Unity编辑器拓展(GraphView制作对话系统编辑器)

Unity 编辑器开发SceneView GUI控制