- 最后登录
- 2019-12-2
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 34660
- 纳金币
- 38268
- 精华
- 111
|
这段时间有关注unity3d插件方面的应用,写了个小插件批量更改Project或Hierarchy里的Tag或Layer,废话不多说,直接贴代码:
//-----------------------------------------------------------------
// ChangeTagOrLayer (7-24-2011)
// Created by LKP
// QQ: 121063550
//-----------------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEditor;
/// <summary>
/// 批量更改场景中的Tag或Layer
/// 使用方法: 在Assets文件夹下创建Editor文件夹,将复制或拷贝该代码保存成ChangeTagOrLayer.cs放入Editor文件夹,
/// 在Hierarchy或Project中选择多个物体后,选择菜单上的Custom -> Change Tag Of Selected Objects,
/// 选择要更改的Tag 或 Layer,点击Set Tag 或 Set Layer,批量更改Tag/Layer成功
/// </summary>
public class ChangeTagOrLayer : EditorWindow
{
/// <summary>
/// 存储的Tag值
/// </summary>
private static string tagStr = string.Empty;
/// <summary>
/// 存储Layer值
/// </summary>
private static int layInt = 0;
/// <summary>
/// 创建、显示窗体
/// </summary>
[@MenuItem("Custom/ChangeTagOrLayer")]
private static void Init()
{
ChangeTagOrLayer window = (ChangeTagOrLayer)GetWindow(typeof(ChangeTagOrLayer), ***e, "ChangeTagOrLayer");
window.Show();
}
/// <summary>
/// 显示窗体里面的内容
/// </summary>
private void OnGUI()
{
tagStr = EditorGUILayout.TagField("Tag for Objects:", tagStr);
if (GUILayout.Button("Set Tag"))
SetTags();
layInt = EditorGUILayout.LayerField("Layer for Objects:", layInt);
if (GUILayout.Button("Set Layer"))
SetLayers();
}
/// <summary>
/// 设置所选GameObject的Tag
/// </summary>
private static void SetTags()
{
foreach (GameObject go in Selection.gameObjects)
go.tag = tagStr;
}
/// <summary>
/// 设置所选GameObject的Layer
/// </summary>
private static void SetLayers()
{
foreach (GameObject go in Selection.gameObjects)
go.layer = layInt;
}
}
|
|