Skip to content

Instantly share code, notes, and snippets.

@SONIC3D
Created September 22, 2012 15:21
Show Gist options
  • Save SONIC3D/3766504 to your computer and use it in GitHub Desktop.
Save SONIC3D/3766504 to your computer and use it in GitHub Desktop.
Unity3D Custom Inspector Editor Extension(C#)
// 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