133 lines
4.7 KiB
C#
133 lines
4.7 KiB
C#
using Thousandto.Cfg.Data;
|
|
using Thousandto.Code.Logic;
|
|
using Thousandto.Core.Asset;
|
|
using Thousandto.Core.Base;
|
|
using Thousandto.DIY;
|
|
using Thousandto.Editor.Excel;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace Thousandto.Editor.ModelEditor
|
|
{
|
|
class ModelSelectTextureEditor : EditorWindow
|
|
{
|
|
public static void Open(MyAction<string> callBack)
|
|
{
|
|
if (!Application.isPlaying)
|
|
{
|
|
UnityEngine.Debug.LogError("运行模式下才能播放特效,所以先运行起来!");
|
|
return;
|
|
}
|
|
var win = (ModelSelectTextureEditor)EditorWindow.GetWindow(typeof(ModelSelectTextureEditor));
|
|
win._selectCallBack = callBack;
|
|
win.Show();
|
|
win.Init();
|
|
}
|
|
|
|
//[MenuItem("Ares/ModelSelectTextureEditor")]
|
|
//public static void Open()
|
|
//{
|
|
// var win = (ModelSelectTextureEditor)EditorWindow.GetWindow(typeof(ModelSelectTextureEditor));
|
|
// win.Show();
|
|
// win.Init();
|
|
//}
|
|
|
|
private List<Texture> _texList = new List<Texture>();
|
|
private string _serchName = string.Empty;
|
|
private Vector2 _scrollPos = Vector2.zero;
|
|
private MyAction<string> _selectCallBack = null;
|
|
private void Init()
|
|
{
|
|
OnDestroy();
|
|
|
|
var texPath = Application.dataPath + "/GameAssets/Resources/Texture/Shader";
|
|
if (Directory.Exists(texPath))
|
|
{
|
|
DirectoryInfo direction = new DirectoryInfo(texPath);
|
|
FileInfo[] filesTga = direction.GetFiles("*.tga", SearchOption.AllDirectories);
|
|
FileInfo[] filesPng = direction.GetFiles("*.png", SearchOption.AllDirectories);
|
|
FileInfo[] filesJpg = direction.GetFiles("*.jpg", SearchOption.AllDirectories);
|
|
FileInfo[] filesExr = direction.GetFiles("*.exr", SearchOption.AllDirectories);
|
|
FileInfo[] filesDds = direction.GetFiles("*.dds", SearchOption.AllDirectories);
|
|
var fileList = new List<FileInfo>();
|
|
fileList.AddRange(filesTga);
|
|
fileList.AddRange(filesPng);
|
|
fileList.AddRange(filesJpg);
|
|
fileList.AddRange(filesExr);
|
|
fileList.AddRange(filesDds);
|
|
|
|
for (int i = 0; i < fileList.Count; ++i)
|
|
{
|
|
var path = fileList[i].FullName;
|
|
path = path.Replace('\\', '/');
|
|
path = path.Substring(path.IndexOf("Assets"));
|
|
var tex = AssetDatabase.LoadAssetAtPath<Texture>(path);
|
|
if (tex != null)
|
|
{
|
|
_texList.Add(tex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
var buttonColor = new Color(1f, 1f, 1f, 0f);
|
|
_serchName = EditorGUILayout.TextField("搜索", _serchName);
|
|
_scrollPos = GUILayout.BeginScrollView(_scrollPos);
|
|
var rect = new Rect();
|
|
rect.size = new Vector2(100, 100);
|
|
var count = (int)(this.position.width / 110);
|
|
int index = 0;
|
|
for (int i = 0; i < _texList.Count; ++i)
|
|
{
|
|
if(string.IsNullOrEmpty(_serchName) || _texList[i].name.Contains(_serchName))
|
|
{
|
|
rect.position = new Vector2(20 + index % count * 110, 50 + index / count * 130);
|
|
GUI.color = Color.white;
|
|
GUI.Box(rect, _texList[i]);
|
|
GUI.color = buttonColor;
|
|
if (GUI.Button(rect, ""))
|
|
{
|
|
if(_selectCallBack != null)
|
|
{
|
|
_selectCallBack(_texList[i].name);
|
|
}
|
|
Close();
|
|
return;
|
|
}
|
|
GUI.color = Color.white;
|
|
GUI.Label(rect, _texList[i].name);
|
|
++index;
|
|
}
|
|
}
|
|
GUILayout.BeginVertical();
|
|
GUILayout.Space((index / count + 1) * 200f);
|
|
GUILayout.BeginVertical();
|
|
GUILayout.EndScrollView();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
for (int i = 0; i < _texList.Count; ++i)
|
|
{
|
|
Resources.UnloadAsset(_texList[i]);
|
|
}
|
|
_texList.Clear();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!Application.isPlaying)
|
|
{
|
|
Close();
|
|
}
|
|
}
|
|
}
|
|
}
|