Created
September 22, 2012 15:21
-
-
Save SONIC3D/3766504 to your computer and use it in GitHub Desktop.
Unity3D Custom Inspector Editor Extension(C#)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source:http://answers.unity3d.com/questions/133838/extending-the-editor-with-c.html | |
// 这个代码存为LookAtPoint.cs | |
using UnityEngine; | |
using System.Collections; | |
public class LookAtPoint : MonoBehaviour { | |
public Vector3 lookAtPoint; | |
// Use this for initialization | |
void Start () | |
{ | |
lookAtPoint = Vector3.zero; | |
} | |
// Update is called once per frame | |
void Update () | |
{ | |
transform.LookAt(lookAtPoint); | |
} | |
} | |
//=============================================== | |
//下面的代码放在另一个代码文件中,并存放在Editor目录下 | |
using UnityEditor; | |
using UnityEngine; | |
using System.Collections; | |
[CustomEditor(typeof(LookAtPoint))] | |
public class LookAtPointEditor : Editor | |
{ | |
public override void OnInspectorGUI() | |
{ | |
(target as LookAtPoint).lookAtPoint = EditorGUILayout.Vector3Field("Look At Point", target.lookAtPoint); | |
if(GUI.changed) | |
{ | |
EditorUtility.SetDirty(target); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment