可以创建一个对话框,然后统一修改某些组件的值
public class Change :ScriptableWizard
{
public int 字段 = 100;
[MenuItem("龙之介工具箱/对话框", false, 100)]
static void ToFly10()
{
ScriptableWizard.DisplayWizard<LongZhiJie.Change>("对话框名", "按钮名");
}
private void OnWizardCreate()
{
GameObject[] gameObjects = Selection.gameObjects;
foreach (GameObject gameObject in gameObjects)
{
LongZhiJie.qf qfs = gameObject.GetComponent<qf>();
Undo.RecordObject(qfs, "qf");
qfs.x = 字段;
}
}
}
几个常用的回调函数
OnWizardCreate() /OnWizardUpdate() /OnWizardOtherButton()
private void OnWizardCreate()
{
}
private void OnWizardUpdate()
{
}
private void OnSelectionChange()
{
}
private void OnWizardOtherButton()
{
}
本地存储变量:
EditorPrefs.GetInt/EditorPrefs.SetInt
public int qf = 100;
private void OnEnable()
{
qf=EditorPrefs.GetInt("qf", qf);
}
private void OnWizardUpdate()
{
EditorPrefs.SetInt("qf", qf);
}
特殊提示:helpString/errorString 进度条 { EditorUtility.DisplayProgressBar(“进度”, “0/” + gameObjects.Length + “完成修改值”, 0); EditorUtility.DisplayProgressBar(“进度”,i +"/" + gameObjects.Length + “完成修改值”, (float)i/gameObjects.Length);
EditorUtility.ClearProgressBar(); }
弹出提示文本 : ShowNotification(new GUIContent(“当前选择了”+Selection.gameObjects.Length + “个游戏物体”));
private void OnWizardUpdate()
{
if(qf<=0)
helpString = "qf最好大于0";
else
{
errorString = "";
}
}
private void OnWizardCreate()
{
GameObject[] gameObjects = Selection.gameObjects;
EditorUtility.DisplayProgressBar("进度", "0/" + gameObjects.Length + "完成修改值", 0);
for(int i=0; i< gameObjects.Length;i++)
{
LongZhiJie.qf qfs = gameObjects[i].GetComponent<qf>();
qfs.x = qf;
EditorUtility.DisplayProgressBar("进度",i +"/" + gameObjects.Length + "完成修改值", (float)i/gameObjects.Length);
}
EditorUtility.ClearProgressBar();
}
private void OnWizardOtherButton()
{
ShowNotification(new GUIContent("当前选择了"+Selection.gameObjects.Length + "个游戏物体"));
}
撤销操作 :
{ Undo.RegisterCreatedObjectUndo(go, “create”);//可以生成物体之后的撤销 Undo.RecordObject(qfs, “qf”);//存储操作,这样就能支持撤回 }
private void OnWizardCreate()
{
Debug.Log("OnWizardCreate");
GameObject[] gameObjects = Selection.gameObjects;
EditorUtility.DisplayProgressBar("进度", "0/" + gameObjects.Length + "完成修改值", 0);
for(int i=0; i< gameObjects.Length;i++)
{
LongZhiJie.qf qfs = gameObjects[i].GetComponent<qf>();
Undo.RecordObject(qfs, "qf");
qfs.x = qf;
EditorUtility.DisplayProgressBar("进度",i +"/" + gameObjects.Length + "完成修改值", (float)i/gameObjects.Length);
}
EditorUtility.ClearProgressBar();
}
public class MyWindow : EditorWindow
{
[MenuItem("Window/mywindow", false, 100)]
static void ShowMyWindow()
{
MyWindow myWindow = EditorWindow.GetWindow<MyWindow>();
myWindow.Show();
}
private string name="";
private void OnGUI()
{
GUILayout.Label("这是我的窗口");
name=GUILayout.TextField(name);
if (GUILayout.Button("创建"))
{
GameObject go = new GameObject(name);
Undo.RegisterCreatedObjectUndo(go, "create");
}
}
}
传送门
编译器扩展-MenuItem
|