196 lines
7.5 KiB
C#
196 lines
7.5 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 ModelSelectVfxEditor : EditorWindow
|
|
{
|
|
public static void Open(RoleSkinModelType skinType, int modelID, MyAction<int> callBack)
|
|
{
|
|
if (!Application.isPlaying)
|
|
{
|
|
UnityEngine.Debug.LogError("运行模式下才能播放特效,所以先运行起来!");
|
|
return;
|
|
}
|
|
var win = (ModelSelectVfxEditor)EditorWindow.GetWindow(typeof(ModelSelectVfxEditor));
|
|
win._selectCallBack = callBack;
|
|
win._skinType = skinType;
|
|
win._modelID = modelID;
|
|
win.Show();
|
|
win.Init();
|
|
}
|
|
|
|
private List<GameObject> _vfxList = new List<GameObject>();
|
|
private List<Camera> _cameras = new List<Camera>();
|
|
private List<RenderTexture> _renderTargets = new List<RenderTexture>();
|
|
private List<int> _vfxIDList = new List<int>();
|
|
|
|
private Vector2 _scrollPos = Vector2.zero;
|
|
private MyAction<int> _selectCallBack = null;
|
|
private RoleSkinModelType _skinType = RoleSkinModelType.PlayerBody;
|
|
private int _modelID = 0;
|
|
|
|
private GameObject _rootGo = null;
|
|
private void Init()
|
|
{
|
|
OnDestroy();
|
|
|
|
_rootGo = new GameObject("[ModelEditorVfxRoot]");
|
|
UnityUtils.Reset(_rootGo.transform);
|
|
|
|
string path = string.Empty;
|
|
switch (_skinType)
|
|
{
|
|
case RoleSkinModelType.PlayerBody://角色身体
|
|
path = Application.dataPath + "/GameAssets/Resources/VFX/Player/Body";
|
|
_modelID = _modelID / 100;
|
|
break;
|
|
case RoleSkinModelType.PlayerWeapon://角色武器
|
|
path = Application.dataPath + "/GameAssets/Resources/VFX/Player/Weapon";
|
|
_modelID = _modelID / 100;
|
|
break;
|
|
case RoleSkinModelType.PlayerMount://角色坐骑
|
|
path = Application.dataPath + "/GameAssets/Resources/VFX/Mount";
|
|
_modelID = -1;
|
|
break;
|
|
case RoleSkinModelType.MonsterBody://怪物,npc主体
|
|
path = Application.dataPath + "/GameAssets/Resources/VFX/Monster";
|
|
_modelID = -1;
|
|
break;
|
|
case RoleSkinModelType.CollectionBody://采集物主体
|
|
path = Application.dataPath + "/GameAssets/Resources/VFX/Object";
|
|
_modelID = -1;
|
|
break;
|
|
case RoleSkinModelType.DrapItem:////掉落物品
|
|
path = Application.dataPath + "/GameAssets/Resources/VFX/Object";
|
|
_modelID = -1;
|
|
break;
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(path) && Directory.Exists(path))
|
|
{
|
|
DirectoryInfo direction = new DirectoryInfo(path);
|
|
FileInfo[] fileList = direction.GetFiles("*.prefab", SearchOption.AllDirectories);
|
|
for (int i = 0; i < fileList.Length; ++i)
|
|
{
|
|
var prePath = fileList[i].FullName;
|
|
prePath = prePath.Replace('\\', '/');
|
|
prePath = prePath.Substring(path.IndexOf("VFX/"));
|
|
prePath = prePath.Replace(".prefab", "");
|
|
var go = ResourcesEx.Load(prePath) as GameObject;
|
|
if (go != null)
|
|
{
|
|
var instGo = GameObject.Instantiate(go) as GameObject;
|
|
instGo.transform.parent = _rootGo.transform;
|
|
UnityUtils.Reset(instGo.transform);
|
|
_vfxList.Add(instGo);
|
|
instGo.transform.localPosition = new Vector3(2000f + i * 100f, 2000f, 0f);
|
|
|
|
GameObject cameraGo = new GameObject(string.Format("camera_{0}", instGo.name));
|
|
cameraGo.transform.parent = _rootGo.transform;
|
|
cameraGo.transform.localPosition = new Vector3(2000f + i * 100f, 2000f, -1f);
|
|
|
|
var camera = UnityUtils.RequireComponent<Camera>(cameraGo);
|
|
camera.farClipPlane = 500;
|
|
camera.clearFlags = CameraClearFlags.SolidColor;
|
|
camera.backgroundColor = new Color(0.176f, 0.176f, 0.176f, 1f);
|
|
camera.enabled = true;
|
|
_cameras.Add(camera);
|
|
|
|
var temTex = RenderTexture.GetTemporary(256, 256, 32, RenderTextureFormat.RGB565);
|
|
temTex.name = "RenderTexture82";
|
|
temTex.antiAliasing = 1;
|
|
camera.targetTexture = temTex;
|
|
_renderTargets.Add(temTex);
|
|
|
|
instGo.name = instGo.name.Replace("(Clone)", "");
|
|
var nameParamArray = instGo.name.Split('_');
|
|
_vfxIDList.Add(int.Parse(nameParamArray[2]));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
var buttonColor = new Color(1f, 1f, 1f, 0f);
|
|
_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 < _vfxList.Count; ++i)
|
|
{
|
|
if (_modelID < 0 || _vfxIDList[i] / 100 == _modelID)
|
|
{
|
|
rect.position = new Vector2(20 + index % count * 110, 50 + index / count * 130);
|
|
GUI.color = Color.white;
|
|
GUI.Box(rect, _renderTargets[i]);
|
|
GUI.color = buttonColor;
|
|
if (GUI.Button(rect, ""))
|
|
{
|
|
if (_selectCallBack != null)
|
|
{
|
|
_selectCallBack(_vfxIDList[i]);
|
|
}
|
|
Close();
|
|
return;
|
|
}
|
|
GUI.color = Color.white;
|
|
GUI.Label(rect, _vfxList[i].name);
|
|
++index;
|
|
}
|
|
}
|
|
GUILayout.BeginVertical();
|
|
GUILayout.Space((index / count + 1) * 200f);
|
|
GUILayout.BeginVertical();
|
|
GUILayout.EndScrollView();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
for (int i = 0; i < _vfxList.Count; ++i)
|
|
{
|
|
GameObject.DestroyImmediate(_vfxList[i]);
|
|
}
|
|
_vfxList.Clear();
|
|
_vfxIDList.Clear();
|
|
|
|
for (int i = 0; i < _cameras.Count; ++i)
|
|
{
|
|
GameObject.DestroyImmediate(_cameras[i].gameObject);
|
|
}
|
|
_cameras.Clear();
|
|
|
|
for (int i = 0; i < _renderTargets.Count; ++i)
|
|
{
|
|
RenderTexture.ReleaseTemporary(_renderTargets[i]);
|
|
}
|
|
_renderTargets.Clear();
|
|
|
|
GameObject.DestroyImmediate(_rootGo);
|
|
_rootGo = null;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!Application.isPlaying)
|
|
{
|
|
Close();
|
|
}
|
|
Repaint();
|
|
}
|
|
}
|
|
}
|