赞
踩
[MenuItem("Tools/MyWindow")]//菜单栏的路径
static void Openwindow()
{
TestEditorWindow window = GetWindow<TestEditorWindow>("我的测试小窗口");
window.Show();//窗口显示
window.minSize=new Vector2(800,600);//窗口的最大最小的是多少
}
Color colorField = Color.green;
string inpustr = "";//默认输入的字符串
bool istoggle = false;
float sliderValue;
MonsterName monster = MonsterName.小怪;
Vector3 pos;
GameObject obj;
private void OnGUI()
{
EditorGUILayout.BeginVertical();//开始确定垂直方向的排列
#region
colorField = EditorGUILayout.ColorField(colorField, GUILayout.Width(300), GUILayout.Height(20));
EditorGUILayout.BeginHorizontal();//开始水平布局
GUILayout.Label("StreammingAssets是特殊文件夹", GUILayout.Width(300), GUILayout.Height(50));
if (GUILayout.Button("StreammingAssets", GUILayout.Width(300), GUILayout.Height(50)))//编辑器状态下点击Button响应
{
Debug.Log(Application.streamingAssetsPath);
}
EditorGUILayout.EndHorizontal();//结束水平布局
EditorGUILayout.BeginHorizontal();//有开始,就要有结束
GUILayout.Label("Resources是特殊文件夹", GUILayout.Width(300), GUILayout.Height(50));
if(GUILayout.Button("Resources",GUILayout.Width(300),GUILayout.Height(50)))
{
Debug.Log("Resources");
}
EditorGUILayout.EndHorizontal();
#endregion
#region
EditorGUILayout.BeginHorizontal();
//inpustr = EditorGUILayout.TextField(inpustr);//文本输入框字段
inpustr = EditorGUILayout.TextArea(inpustr);//多行文本
istoggle = EditorGUILayout.Toggle(istoggle, "Toggle");
if (istoggle)
{
if (GUILayout.Button("保存", GUILayout.Height(50)))
{
FileStream fs;
//一定先要有streamingAssets文件夹
string path = Application.streamingAssetsPath + "/MyText.txt";
if (!File.Exists(path))
{
fs = File.Create(path);
}
else
{
//fs = File.Open(path, FileMode.Append);//每次内容追加到最后面
fs = File.Open(path, FileMode.Truncate);//替换【覆盖原有的内容】
}
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(inpustr);
sw.Flush();//刷新
sw.Close();//关闭资源
fs.Close();//关闭资源
}
}
sliderValue = GUILayout.HorizontalSlider(sliderValue, 0, 1);
GUILayout.Label("SilderValue"+sliderValue.ToString());
// GameObject.Find("Audio Source").GetComponent<AudioSource>().volume = sliderValue;
monster = (MonsterName)EditorGUILayout.EnumPopup(monster, GUILayout.Width(200));
GUILayout.Label("Monster"+monster.ToString());
EditorGUILayout.EndHorizontal();
//保存下来的位置
pos = EditorGUILayout.Vector3Field("坐标", pos);//赋值vector3
// GameObject.Find("Cube").transform.position = pos;
//参数一:字段前的标签 名字
//参数二:字段显示的对象 对象的变量名字
//参数三 :可以分配的类型对象 泛型的类型
//参数四:允许分配场景的对象 true (允许选择场景中的对象)
obj = EditorGUILayout.ObjectField("选择对象", obj, typeof(GameObject), true) as GameObject;
if(obj != null)
{
obj.transform.position = pos;
}
#endregion
EditorGUILayout.EndVertical();//结束垂直方向的排列
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。