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在OnGUI中绘制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);
        }
    }
}

Profiler

采样
各性能指标
截取内存
连接设备

Gizmos

提供对场景里GameObject的必要调试信息,
充分利用Mono的两个接口:OnDrawGizmos和OnDrawGizmosSelected

 #if UNITY_EDITOR
    private void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawRay(transform.position,transform.TransformDirection(Vector3.forward));
    }
#endif
posted @ 2019-05-06 14:09  cicarius  阅读(236)  评论(0编辑  收藏  举报