Unity3d根据命名快速捕获场景物体轴心点
using UnityEngine;
using System.Collections;
using UnityEditor;
/// <summary>
/// 根据命名快速捕获场景物体轴心点
/// </summary>
public class QuickGetPivot : EditorWindow
{
/// <summary>
/// 定义变量
/// </summary>
private string ObjectNameString = "";
private GameObject MyGameObject; //存储场景gameObject
private int[] IntArray = new int[] { 0, 1, 2, 3, 4 };
//顶部特效
private int HeadInt = 0;
private int BottomFootstepsInt = 0;
private int HipChestInt = 0;
private int HandFootInt = 0;
private int WeaponInt = 0;
private int NormalSpecialInt = 0;
private string[] Head_String = new string[] { "Choose A Effect", "Head_C_EffectPoint", "Head_T_EffectPoint" };
private string[] BottomFootsteps_String = new string[] { "Choose A Effect", "Bottom_EffectPoint", "Footsteps_EffectPoint" };
private string[] HipChest_String = new string[] { "Choose A Effect", "Hip_EffectPoint", "Chest_EffectPoint" };
private string[] HandFoot_String = new string[] { "Choose A Effect", "Hand_L_EffectPoint", "Hand_R_EffectPoint", "Foot_L_EffectPoint", "Foot_R_EffectPoint" };
private string[] Weapon_String = new string[] { "Choose A Effect", "Weapon01_EffectPoint", "Weapon02_EffectPoint", "Weapon03_EffectPoint" };
private string[] NormalSpecial_String = new string[] { "Choose A Effect", "Normal_HurtPoint", "Special_HurtPoint" };
/// <summary>Im
/// 创建、显示窗体
/// </summary>
[@MenuItem("Custom/Effect/QuickGetPivot")]
private static void Init()
{
QuickGetPivot window = (QuickGetPivot)GetWindow(typeof(QuickGetPivot), true, "QuickGetPivot");
window.Show();
}
/// <summary>
/// 显示窗体里面的内容
/// </summary>
private void OnGUI()
{
//EffectPopup
HeadInt = EditorGUILayout.IntPopup("顶部特效", HeadInt, Head_String, IntArray);
BottomFootstepsInt = EditorGUILayout.IntPopup("底部特效", BottomFootstepsInt, BottomFootsteps_String, IntArray);
HipChestInt = EditorGUILayout.IntPopup("骨骼特效", HipChestInt, HipChest_String, IntArray);
HandFootInt = EditorGUILayout.IntPopup("手脚特效", HandFootInt , HandFoot_String, IntArray);
WeaponInt = EditorGUILayout.IntPopup("武器特效", WeaponInt , Weapon_String, IntArray);
NormalSpecialInt = EditorGUILayout.IntPopup("受击特效", NormalSpecialInt, NormalSpecial_String, IntArray);
if (GUILayout.Button("Get Object Pivot"))
{
GetSceneObjectPivot();
}
}
/// <summary>
/// 在场景中获取物轴心点
/// </summary>
///
private void GetSceneObjectPivot()
{
//控制台输出ObjectNameString
switch(HeadInt)
{
case 1:
ObjectNameString = "Head_C_EffectPoint";
break;
case 2:
ObjectNameString = "Head_T_EffectPoint";
break;
}
switch(BottomFootstepsInt)
{
case 1:
ObjectNameString = "Bottom_EffectPoint";
break;
case 2:
ObjectNameString = "Footsteps_EffectPoint";
break;
}
switch(HipChestInt)
{
case 1:
ObjectNameString = "Hip_EffectPoint";
break;
case 2:
ObjectNameString = "Chest_EffectPoint";
break;
}
switch(HandFootInt)
{
case 1:
ObjectNameString = "Hand_L_EffectPoint";
break;
case 2:
ObjectNameString = "Hand_R_EffectPoint";
break;
case 3:
ObjectNameString = "Foot_L_EffectPoint";
break;
case 4:
ObjectNameString = "Foot_R_EffectPoint";
break;
}
switch(WeaponInt)
{
case 1:
ObjectNameString = "Weapon01_EffectPoint";
break;
case 2:
ObjectNameString = "Weapon02_EffectPoint";
break;
case 3:
ObjectNameString = "Weapon03_EffectPoint";
break;
}
switch(NormalSpecialInt)
{
case 1:
ObjectNameString = "Normal_HurtPoint";
break;
case 2:
ObjectNameString = "Special_HurtPoint";
break;
}
if("" != ObjectNameString)
{
MyGameObject = GameObject.Find(ObjectNameString);
if(null != MyGameObject)
{
Selection.activeTransform = MyGameObject.transform;
}
else
{
Debug.LogWarning("No Such Object In Scene!");
Selection.activeTransform = null;
}
HeadInt = 0;
BottomFootstepsInt = 0;
HipChestInt = 0;
HandFootInt = 0;
WeaponInt = 0;
NormalSpecialInt = 0;
ObjectNameString = "";
Debug.Log (ObjectNameString);
}
else
{
Debug.LogWarning("Choose A Effect First!");
}
}
}