Unity之Editor编辑器之创建路径菜单以及更改Transform面板属性

首先创建名字为Editor的Folder(文件夹),

第一种编辑模式:在该文件夹下创建名为BuildeAsset的脚本文件,初始代码如下

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;//引入命名空间



public class BuildAsset : MonoBehaviour {
    [MenuItem("Itools/Builde1", false, 50)]//在窗口创建菜单栏
    public static void BuildBundle1()
    {

    }
    [MenuItem("Itools/Builde2", false, 100)]
    public static void BuildBundle2()
    {

    }

}

窗口创建菜单路径实现效果如下:

第二种编辑模式:在该文件夹下创建名为TransformEditor的脚本文件,更改Transform类的属性字段初始代码如下

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(Transform))]//定义可编辑对象为Transform
public class TransformEditor : Editor {

    Transform trans;
    private void OnEnable()
    {
        trans = (Transform)target;//被检查的对象是Transform;
    }
    public override void OnInspectorGUI()
    {
        EditorGUILayout.BeginVertical();//垂直布局
        trans.localPosition = EditorGUILayout.Vector3Field("Position", trans.localPosition);//三维输入
        trans.localEulerAngles = EditorGUILayout.Vector3Field("Rotation", trans.localEulerAngles);
        trans.localScale  = EditorGUILayout.Vector3Field("Scale", trans.localScale);
////新增一个Worldposition
        trans.position = EditorGUILayout.Vector3Field("WorldPosition", trans.position);
        EditorGUILayout.EndVertical();
    }
}

效果如下:可以对Transform进行更改:

相关知识借鉴:https://www.iqiyi.com/v_19rr0dxd6s.html

 

 

 

 

展开阅读全文

没有更多推荐了,返回首页