码迷,mamicode.com
首页 > 编程语言 > 详细

UNITY

时间:2018-08-06 10:26:56      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:text   play   spl   src   简单   editor   unity   position   bmc   

来自:https://blog.csdn.net/cheng624/article/details/70859054

多看看别人的代码是没有坏处的,即使学不了人家的大框架,偶尔拾起一些小东西也是可以的。

最近扒了一下DoTween(声明一下源码是自己反编译的,只为学习),看见了如何在Scene场景中添加标注和坐标轴,具体做法是,在你的脚本Editor中,比如你重定义某个mono脚本的Inspector显示中,加入OnSceneGUI函数,使用Handles进行操作。

 

 1 void OnSceneGUI()
 2     {
 3         if (_target.nodes.Count > 0)
 4         {
 5             //allow path adjustment undo:
 6             Undo.RecordObject(_target, "Adjust Path");
 7  
 8             //path begin and end labels:
 9             Handles.Label(_target.nodes[0], "" + _target.name + "‘ Begin");
10             Handles.Label(_target.nodes[_target.nodes.Count - 1], "" + _target.name + "‘ End");
11  
12             //node handle display:
13             for (int i = 0; i < _target.nodes.Count; i++)
14             {
15                 _target.nodes[i] = Handles.PositionHandle(_target.nodes[i], Quaternion.identity);
16                 if (i != 0 || i != _target.nodes.Count - 1)
17                     Handles.Label(_target.nodes[i], i.ToString());
18             }
19             if (GUI.changed)
20             {
21                 EditorUtility.SetDirty(_target);
22             }
23         }
24         
25     }

 

代码很简单,只是记录方法而已,具体的效果:

 

技术分享图片

给开始和结束点添加了一个label, 每个节点添加了一个坐标轴和一个序号。其中蓝色的线使用Gizmos画的,可自行度娘。

UNITY

标签:text   play   spl   src   简单   editor   unity   position   bmc   

原文地址:https://www.cnblogs.com/timeObjserver/p/9428669.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!