Unity Scene为每一个游戏物体进行扩展编辑
2个月前还在忙碌的找实习工作,看见招聘信息上面有一条熟悉扩展Unity编辑器,配合美工编程. 自己动手写完这个代码时候,发现写代码就像弹钢琴多么神奇.
TestEdit类:
using UnityEngine; using System.Collections; using UnityEditor; [CustomEditor(typeof(Test))] public class TestEditor : Editor { void OnSceneGUI() { Test test = (Test)target; //绘制文本框 Handles.Label(test.transform.position + Vector3.up * 2 ,test.transform.name + ":" + test.transform.position.ToString()); //开始绘制GUI Handles.BeginGUI(); //规定GUI显示区域 GUILayout.BeginArea(new Rect(100, 100, 100, 100)); if (GUILayout.Button("变大")) { test.transform.localScale = new Vector3(test.transform.localScale.x+1, test.transform.localScale.y+1, test.transform.localScale.z+1); } if (GUILayout.Button("向前移动")) { test.Move(); } GUILayout.Label("我在编辑Scene视图"); GUILayout.EndArea(); Handles.EndGUI(); } }
Test类:
using UnityEngine; using System.Collections; public class Test : MonoBehaviour { public void Move() { this.transform.Translate(Vector3.up * 10 * Time.deltaTime); } }
如果你感兴趣,你可以把你妹妹介绍给我