using System; using System.Collections.Generic; using System.Linq; using System.Text; using Thousandto.Code.Center; using UnityEditor; using UnityEngine; namespace Assets.Editor.DIY { public class PoolEditor : EditorWindow { [MenuItem("Funcell/MiniEasyTools/缓存池查看")] static void Init() { var win = (PoolEditor)EditorWindow.GetWindow(typeof(PoolEditor)); win.titleContent = new GUIContent("缓存池查看"); win.Show(); } private Shader _selectShader = null; private bool _showUsed = false; private Vector2 _scrollPos = Vector2.zero; private void OnGUI() { if (Application.isPlaying) { if (GameCenter.IsInitialized) { _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos); if (GUILayout.Button(_showUsed ? "未使用材质" : "已使用材质")) { _showUsed = !_showUsed; } if (_showUsed) { var mlist = GameCenter.MaterialManager.MatPool.UsedMaterials; for (int i = 0; i < mlist.Count; i++) { try { EditorGUILayout.ObjectField(i.ToString(), mlist[i], typeof(Material), true); if (GUILayout.Button("...")) { AssetDatabase.CreateAsset(mlist[i], "Assets/" + mlist[i].name+".mat"); } } catch (Exception ex) { Debug.LogError("EditorGUILayout.ObjectField::" + _selectShader.name + ";;;" + i.ToString()); Debug.LogException(ex); } } } else { if (_selectShader == null) { var e = GameCenter.MaterialManager.MatPool.Pool.GetEnumerator(); while (e.MoveNext()) { try { if (GUILayout.Button(e.Current.Key.name + " -- " + e.Current.Value.Stack.Count)) { _selectShader = Shader.Find(e.Current.Key.name); } } catch (Exception ex) { Debug.LogError("11111111111::" + e.Current.Key.name); Debug.LogException(ex); } } e.Dispose(); } else { if (GUILayout.Button("向上")) { _selectShader = null; } if (_selectShader) { var mlist = GameCenter.MaterialManager.MatPool.Pool[_selectShader]; if (mlist != null && mlist.Stack != null) { for (int i = 0; i < mlist.Stack.Count; i++) { try { EditorGUILayout.ObjectField(i.ToString(), mlist.Stack[i], typeof(Material), true); } catch (Exception ex) { Debug.LogError("EditorGUILayout.ObjectField::" + _selectShader.name + ";;;" + i.ToString()); Debug.LogException(ex); } } } } } } EditorGUILayout.EndScrollView(); } } } } }