码迷,mamicode.com
首页 > 编程语言 > 详细

Unity基础-编辑器

时间:2019-05-06 14:16:12      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:nal   typeof   加载   point   layout   option   ide   base   pre   

编辑器

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基础-编辑器

标签:nal   typeof   加载   point   layout   option   ide   base   pre   

原文地址:https://www.cnblogs.com/carious/p/10819294.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!