- 最后登录
- 2017-5-15
- 注册时间
- 2012-3-1
- 阅读权限
- 90
- 积分
- 32973
- 纳金币
- 32806
- 精华
- 12
|
是不是您已经对每次将大堆的GameObject移动到原点几经感到厌烦了呢?
来看看下面的代码是如何为unity3d添加新功能的吧
代码:
using UnityEditor;
using UnityEngine;
class MoveToOrigin {
/// <summary>
/// Moves the selected game object(s) to (0, 0, 0).
/// <summary>
/// <remarks>Keyboard shortcut: cmd-0 (Mac), ctrl-0 (Windows).</remarks>
[MenuItem ("GameObject/Move To Origin %0")]
static void MenuMoveToOrigin () {
// Move each selected transform to (0, 0, 0)
foreach (Transform t in Selection.transforms) {
Undo.RegisterUndo(t, "Move " + t.name);
t.position = Vector3.zero;
Debug.Log("Moving " + t.name + " to origin");
}
}
/// <summary>
/// Validates the "Move To Origin" menu item.
/// </summary>
/// <remarks>The menu item will be disabled if no transform is selected.</remarks>
[MenuItem ("GameObject/Move To Origin %0", ***e)]
static bool ValidateMoveToOrigin () {
return Selection.activeTransform != null;
}
}
将此代码命名为MoveToOrigin.cs
并且在你的工程下建立名为Editor的文件夹,并将MoveToOrigin.cs放入其中
你将会在GameObject菜单下发现Move To Origin选项
现在选中一个或多个GameObject然后按cmd+0(Mac系统)/ctrl+0(Windows)
所有选中物体都移动到了原点位置 |
|