unity3dRuntimeTransformGizmos插件使⽤⼀.如何将插件中的世界轴变为本地轴向
1.⾸先到抽象类Gizmo 添加⼀个参数 和⼀个⽅法
private bool _localTransform;
public bool LocalTransform
{
get{return _localTransform;}
set
{
_localTransform =value;
}
}
public void SetGizmoLocalAxes(bool Islocal)
{
List<GameObject> topParents =GetParentsFromControlledObjects(true);
if(Islocal&&topParents.Count >0)
{
_gizmoTransform.right = topParents[0].transform.right;
_gizmoTransform.up = topParents[0].transform.up;
_gizmoTransform.forward = topParents[0].transform.forward;
}
else
{
_gizmoTransform.right = Vector3.right;
_gizmoTransform.up = Vector3.up;
_gizmoTransform.forward = Vector3.forward;
}
}
2.到TranslationGizmoInspectorGUI类添加gui显⽰项,让它能够在⾯板显⽰出来
newBoolValue = EditorGUILayout.ToggleLeft("LocalTransform", _translationGizmo.LocalTransform);
if(newBoolValue != _translationGizmo.LocalTransform)
{
UnityEditorUndoHelper.RecordObjectForInspectorPropertyChange(_translationGizmo);
_translationGizmo.LocalTransform = newBoolValue;
}
3.最后⼀步 还是在Gizmo 类中到 protected int[] GetSortedGizmoAxesIndices()这个⽅法,
把上⾯刚刚写的SetGizmoLocalAxes⽅法引⽤到这个⽅法⾥,写在第⼀⾏
protected int[]GetSortedGizmoAxesIndices()
{
SetGizmoLocalAxes(_localTransform);
//下⾯代码不变
}
这样就ok了
⼆. 点击ui能够选中物体
⼀般场景ui脚本绑定⼀个物体,需要点击ui⾃动选中物体,包括插件的轴和框选范围shader,
(1)第⼀种⽅法
使⽤插件给的固有⽅法
//先清除再增加
FindObjectOfType<EditorObjectSelection>().ClearSelection(true);
FindObjectOfType<EditorObjectSelection>().AddObjectToSelection(gameObject,true);
(2)第⼆种⽅法
我们只需要修改EditorObjectSelection场景中 OnInputDeviceFirstButtonDown⽅法
//增加⼀个参数就可以了 ,私有变公有
public void OnInputDeviceFirstButtonDown(GameObject AddSelect=null)
{
}
最后试⼀试吧,在UI⾥调⽤这个函数
//成功了就给我点个赞吧
FindObjectOfType<EditorObjectSelection().OnInputDeviceFirstButtonDown(gameObject);
三物体的移动旋转缩放变化
继承IRTEditorEventListener接⼝实现
四监听撤销/重做操作
如果开启撤销/重做功能,想要监听时继承IMessageListener接⼝
//重做
MessageListenerDatabase.Instance.RegisterListenerForMessage(MessageType.GizmoTransformOperationWasRedone,this);
//撤销
MessageListenerDatabase.Instance.RegisterListenerForMessage(MessageType.GizmoTransformOperationWasUndone,this);五轴的开始,持续和结束拖拽阶段事件
transform中文翻译
public class NodeGeneration : MonoBehaviour{
public virtual void GizmoTransformDragStart(Gizmo gizmo) {
}
public virtual void GizmoTransforDragUpdate(Gizmo gizmo) {
}
public virtual void GizmoTransformDragEnd(Gizmo gizmo) {
}
public virtual void GizmoRotateDragStart(Gizmo gizmo)
{
}
public virtual void GizmoRotateDragUpdate(Gizmo gizmo) {
}
public virtual void GizmoRotateDragEnd(Gizmo gizmo)
{
}
}
private List<NodeGeneration> modelSelectEvents =new List<NodeGeneration>();
public TranslationGizmo translationGizmo;
public RotationGizmo rotateGizmo;
void Start()
{
FindObjectOfType<EditorObjectSelection>().SelectionChanged +=(tr)=>{
if(tr.SelectedObjects.Count ==0)
{
}
else
{
for(int i =0; i < modelSelectEvents.Count; i++)
{
translationGizmo.GizmoDragStart -= modelSelectEvents[i].GizmoTransformDragStart;
translationGizmo.GizmoDragUpdate -= modelSelectEvents[i].GizmoTransforDragUpdate;                    translationGizmo.GizmoDragEnd -= modelSelectEvents[i].GizmoTransformDragEnd;
rotateGizmo.GizmoDragStart -= modelSelectEvents[i].GizmoRotateDragStart;
rotateGizmo.GizmoDragUpdate -= modelSelectEvents[i].GizmoRotateDragUpdate;
rotateGizmo.GizmoDragEnd -= modelSelectEvents[i].GizmoRotateDragEnd;
}
modelSelectEvents.Clear();
var selelist =FindObjectOfType<EditorObjectSelection>().SelectedGameObjects;
foreach(var sele in selelist)
{
var iteml = sele.GetComponent<NodeGeneration>();
if(iteml && translationGizmo && rotateGizmo)
{
translationGizmo.GizmoDragStart += iteml.GizmoTransformDragStart;
translationGizmo.GizmoDragUpdate += iteml.GizmoTransforDragUpdate;
translationGizmo.GizmoDragEnd += iteml.GizmoTransformDragEnd;
rotateGizmo.GizmoDragStart += iteml.GizmoRotateDragStart;
rotateGizmo.GizmoDragUpdate += iteml.GizmoRotateDragUpdate;
rotateGizmo.GizmoDragEnd += iteml.GizmoRotateDragEnd;
modelSelectEvents.Add(iteml);
}
}
}
};
}
六物体选中事件
FindObjectOfType<EditorObjectSelection>().SelectionChanged +=(tr)=>{}
七改变轴类型 Translate rotation scale…
FindObjectOfType<EditorGizmoSystem>().ChangeActiveGizmo(GizmoType.Rotation); FindObjectOfType<EditorGizmoSystem>().ChangeActiveGizmo(GizmoType.Translation);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。