美术有可以直接在Editor下操作Transform,我想去修正他们编辑的数值,所以我就得监听Transform。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
using UnityEngine; using System.Collections; using UnityEditor; using System.Reflection; [CustomEditor(typeof(Transform))] public class TransformEditor :Editor { [InitializeOnLoadMethod] static void IInitializeOnLoadMethod() { TransformEditor.onPostion =delegate(Transform transform) { Debug.Log(string.Format("transform = {0} positon = {1}",transform.name,transform.localPosition)); }; TransformEditor.onRotation =delegate(Transform transform) { Debug.Log(string.Format("transform = {0} rotation = {1}",transform.name,transform.localRotation.eulerAngles)); }; TransformEditor.onScale =delegate(Transform transform) { Debug.Log(string.Format("transform = {0} scale = {1}",transform.name,transform.localScale)); }; } public delegate void Change(Transform transform); static public Change onPostion; static public Change onRotation; static public Change onScale; private Editor editor; private Transform transform; private Vector3 startPostion =Vector3.zero; private Vector3 startRotation =Vector3.zero; private Vector3 startScale =Vector3.zero; void OnEnable() { transform = target as Transform; editor = Editor.CreateEditor(target, Assembly.GetAssembly(typeof(Editor)).GetType("UnityEditor.TransformInspector",true)); startPostion = transform.localPosition; startRotation = transform.localRotation.eulerAngles; startScale = transform.localScale; } public override void OnInspectorGUI () { editor.OnInspectorGUI(); if(GUI.changed) { if(startPostion != transform.localPosition) { if(onPostion != null) onPostion(transform); } if(startRotation != transform.localRotation.eulerAngles) { if(onRotation != null) onRotation(transform); } if(startScale != transform.localScale) { if(onScale != null) onScale(transform); } startPostion = transform.localPosition; startRotation = transform.localRotation.eulerAngles; startScale = transform.localScale; } } } |
- 本文固定链接: https://www.xuanyusong.com/archives/4018
- 转载请注明: 雨松MOMO 于 雨松MOMO程序研究院 发表
捐 赠写博客不易,如果您想请我喝一杯星巴克的话?就进来看吧!
为什么只能通知一个对象,就是最后选择的对象,不能通知多个选择对象
你好 MoMo,我想监测:当移动Scene面板下GameObject时,监测Transform的值,做一些操作,有没有什么方法?你这个脚本拖动Scene下的GameObject并不会打印Log。
if(GUI.change){}
这个我试了,当直接拖动Scene下物体时,不会执行到if(GUI.change){ }里面去。
他这个我修改了下,不过遇到个新问题,就是选择多个对象进行修改的时候,只有一个对象会进行变化
这个地方可以修改下,但是只会通知当个对象,不能通知多个对象
[给力][给力][给力][给力][给力]
[给力][给力][给力]
好久不见你啊。。
我不是一直关注着你啊。。你的博客和文章都加了RSS了