using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using WS;
///对象池定时销毁编辑器
public class GamePoolTimerEditor : EditorWindow
{
[MenuItem("Tools/Framework/对象池定时销毁编辑")]
public static void ShowVoice()
{
GamePoolTimerEditor window = EditorWindow.GetWindow("对象池定时销毁编辑");
window.Show();
}
///所有数据
private List Config = new List();
///路径
private string path;
///滑杆
private Vector2 pos;
///临时数据
private PoolClear tmpdata = new PoolClear();
private void OnEnable()
{
path = $"{Application.dataPath}/Resources/Config/Framework/PoolClear.txt";
if (ConfigHelper.ConfigExists(path))
{
Config = ConfigHelper.FileLoadConfig>(path);
}
}
private void OnGUI()
{
EditorGUILayout.BeginHorizontal();
DrawPoolClearView(tmpdata);
if (GUILayout.Button("添加", GUILayout.Width(100)))
{
if (Config.Exists(p => p.Name == tmpdata.Name))
{
ShowNotification(new GUIContent($"物体:{tmpdata.Name} 已存在"), 2);
}
else
{
Config.Add(tmpdata);
tmpdata = new PoolClear();
}
}
EditorGUILayout.EndHorizontal();
pos = EditorGUILayout.BeginScrollView(pos);
for (int i = 0; i < Config.Count; i++)
{
EditorGUILayout.BeginHorizontal();
DrawPoolClearView(Config[i]);
if (GUILayout.Button("删除", GUILayout.Width(100)))
{
Config.RemoveAt(i);
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.BeginHorizontal();
GUILayout.Label("");
if (GUILayout.Button("保存", GUILayout.Width(100)))
{
ConfigHelper.SaveConfig(Config, path);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.EndScrollView();
}
///绘制PoolClear
private void DrawPoolClearView(PoolClear data)
{
GUILayout.Label("物体名称:", GUILayout.Width(60));
data.Name = EditorGUILayout.TextField(data.Name);
GUILayout.Label("持续保存数量:", GUILayout.Width(80));
data.CullSave = EditorGUILayout.IntField(data.CullSave);
GUILayout.Label("清理间隔时间:", GUILayout.Width(80));
data.CullTime = EditorGUILayout.IntField(data.CullTime);
GUILayout.Label("每次清理数量:", GUILayout.Width(80));
data.CullNextCount = EditorGUILayout.IntField(data.CullNextCount);
}
}