拡大
- インスペクター拡張開発インスペクター
- トップメニューバー
- ポップアップ
- シーンエディター、エディターのメインシーンページ
特別なディレクトリ
- 複数のディレクトリが自動的にマージされます。これらはすべて特別なディレクトリです。
- 重複する名前は上書きされます
- ゲーム ロジックを UnityEditor に含めることはできません。そうしないと、正しくパッケージ化されません。
ビューア
拡張子 1 はエディターに属していません
using System;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class Numberical {
public float Atk;
public float Def;
}
public enum Profression {
Warrior=0,
Wizard,
}
public class SimpleInspector : MonoBehaviour
{
[HideInInspector]
public int ID;
[SerializeField]
private string ShowID;
public Numberical Num;
[Space(50)]
[Header("年龄")]
[Tooltip("不要填写大约150的年龄")]
[Range(0,150)]
public int Age;
[Multiline(5)]
public string NickName;
[TextArea(5,8)]
public string Decripttion;
public Color Flag;
public Texture Tex;
public List<string> Tags;
public Profression Pro;
[ContextMenu("输出攻防比")]
public void PrintADProportion() {
Debug.Log("攻防比:"+Num.Atk/Num.Def);
}
[ContextMenuItem("输出国家", "OutCountry")]
[Tooltip("右键看看")]
public string Country;
public void OutCountry() {
Debug.Log(Country);
}
}
拡張 2 ディスプレイ開発
using System.Collections.Generic;
using UnityEngine;
public enum PlayerProfression {
Warrior = 0,
Wizard=1,
}
public enum PlayerLoveColor {
Green=1,
Red=2,
Pink=4,
}
[AddComponentMenu("自定义控制器/玩家控制器",1)]
[ExecuteInEditMode]
[RequireComponent(typeof(BoxCollider))]
public class Player : MonoBehaviour
{
public int ID;
public string Name;
public float Atk;
public bool isMan;
public Vector3 HeadDir;
public Color Hair;
public GameObject Weapon;
public Texture Cloth;
public PlayerProfression Pro;
public PlayerLoveColor LoveColor;
public List<string> Items;
private void Update() {
Debug.Log("Update");
}
}
- ビューアの高度な変更、プラグインのプログラミング
- Editor ディレクトリにプラグイン開発スクリプトを作成します。
- エディターのスクリプトを元のスクリプトに関連付けます
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(Player))]
public class PlayerEditor : Editor
{
private Player _Component;
private void OnEnable() {
_Component = target as Player;
}
private void OnDisable() {
_Component = null;
}
public override void OnInspectorGUI() {
EditorGUILayout.LabelField("人物相关属性");
_Component.ID=EditorGUILayout.IntField("玩家ID",_Component.ID);
_Component.Hair = EditorGUILayout.ColorField("头发颜色", _Component.Hair);
_Component.Name = EditorGUILayout.TextField("玩家名字", _Component.Name);
_Component.isMan = EditorGUILayout.Toggle("是否位男性", _Component.isMan);
_Component.HeadDir = EditorGUILayout.Vector3Field("头发方向", _Component.HeadDir);
_Component.Atk = EditorGUILayout.FloatField("攻击力", _Component.Atk);
_Component.Weapon = EditorGUILayout.ObjectField("持有武器", _Component.Weapon, typeof
(GameObject),true)as GameObject;
_Component.Cloth = EditorGUILayout.ObjectField("衣服材质贴图", _Component.Cloth, typeof
(Texture), false) as Texture;
_Component.Pro = (PlayerProfression)EditorGUILayout.EnumPopup("玩家职业", _Component.Pro);
_Component.LoveColor = (PlayerLoveColor)EditorGUILayout.EnumFlagsField("玩家喜欢的颜色",
_Component.LoveColor);
serializedObject.Update();
SerializedProperty sp = serializedObject.FindProperty("Items");
EditorGUILayout.PropertyField(sp, new GUIContent("道具信息"), true);
serializedObject.ApplyModifiedProperties();
_Component.Atk = EditorGUILayout.Slider(new GUIContent("玩家攻击力"), _Component.Atk, 0,100);
if (_Component.Atk > 80) {
EditorGUILayout.HelpBox("攻击力太高了", MessageType.Error);
}
if (_Component.Atk < 20) {
EditorGUILayout.HelpBox("攻击力太低了", MessageType.Warning);
}
GUILayout.Button("来个按钮");
GUILayout.Button("来个按钮");
EditorGUILayout.BeginHorizontal();
GUILayout.Button("来个按钮");
GUILayout.Button("来个按钮");
EditorGUILayout.EndHorizontal();
if (GUILayout.Button("测试点击")) {
Debug.Log("测试点击");
}
}
}
トップメニュー
トップメニュー
using UnityEngine;
using UnityEditor;
public class Menu
{
[MenuItem("工具/导出AB资源包")]
static void BuildAB() {
Debug.Log("导出AB资源包");
Debug.Log(Application.persistentDataPath);
}
}
窓
using UnityEngine;
using UnityEditor;
public class PopWindow : EditorWindow
{
[MenuItem("工具/创建窗口")]
static void OpenWindow() {
PopWindow window= GetWindow<PopWindow>(false,"弹窗",true);
window.minSize = new Vector2(400, 300);
window.maxSize = new Vector2(800, 600);
}
private void OnEnable() {
Debug.Log("Enable");
}
private void OnDisable() {
Debug.Log("DisEnable");
}
private void Update() {
Debug.Log("Update");
}
private void OnGUI() {
GUILayout.Button("来个按钮");
GUILayout.Button("来个按钮");
EditorGUILayout.BeginHorizontal();
GUILayout.Button("来个按钮");
GUILayout.Button("来个按钮");
EditorGUILayout.EndHorizontal();
if (GUILayout.Button("测试点击")) {
Debug.Log("测试点击");
}
}
private void OnHierarchyChange() {
Debug.Log("HierarchyChange");
}
private void OnProjectChange() {
Debug.Log("ProjectChange");
}
private void OnSelectionChange() {
Debug.Log(Selection.activeGameObject.name);
}
}
シーンビュー拡張機能
- スクリプトがオブジェクトでハングアップする
- 拡張プラグインプログラミング
- ウィンドウの永続ビット選択状態
- エディター状態では、ラインはカメラではなくエディター GUI インターフェイスから出力されます。
- ウィンドウを開く必要があります。開かないと、インターフェイスが新しく作成されたオブジェクトに直接切り替わり、編集が停止します。
- ウィンドウを開いてボードを選択したままにしてください