275 lines
10 KiB
C#
275 lines
10 KiB
C#
using Thousandto.Plugins.Common.UniScene;
|
|
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
using Thousandto.Core.Base;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Thousandto.DIY.UniScene
|
|
{
|
|
public class FlyTeleportEditor : EditorWindow
|
|
{
|
|
[MenuItem("Ares/FlyTeleportEditor")]
|
|
static void Init()
|
|
{
|
|
if (!Application.isPlaying)
|
|
{
|
|
UnityEngine.Debug.LogError("运行模式下才能使用飞行传送编辑器!");
|
|
return;
|
|
}
|
|
var win = (FlyTeleportEditor)EditorWindow.GetWindow(typeof(FlyTeleportEditor));
|
|
win.wantsMouseMove = true;
|
|
win.Show();
|
|
|
|
win.CheckRootGo();
|
|
FlyTeleportDataManager.Load();
|
|
var mapDatas = FlyTeleportDataManager.Find(EditorSceneManager.GetActiveScene().name);
|
|
if (mapDatas != null)
|
|
{
|
|
for (int i = 0; i < mapDatas.Count; ++i)
|
|
{
|
|
win.CreatePath(mapDatas[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
private GameObject RootGo = null;
|
|
private FlyTeleportScriptEditor FlyEditor = null;
|
|
|
|
void CreatePath(FlyTeleportCfgData data)
|
|
{
|
|
var ObjName = string.Format("{0}_{1}", data.MapName, data.ID);
|
|
var trans = RootGo.transform.Find(ObjName);
|
|
GameObject go = null;
|
|
if (trans != null)
|
|
{
|
|
go = trans.gameObject;
|
|
}
|
|
else
|
|
{
|
|
go = new GameObject(ObjName);
|
|
}
|
|
go.transform.parent = RootGo.transform;
|
|
|
|
//清除所有子节点
|
|
while (go.transform.childCount > 0)
|
|
{
|
|
GameObject.DestroyImmediate(go.transform.GetChild(0).gameObject);
|
|
}
|
|
FlyTeleportEditorScript script = UnityUtils.RequireComponent<FlyTeleportEditorScript>(go);
|
|
script.InitWithData(data);
|
|
|
|
for (int i = 0; i < data.PathNodes.Count; ++i)
|
|
{
|
|
var nodeGo = new GameObject(string.Format("Node_{0}", i + 1));
|
|
nodeGo.transform.parent = go.transform;
|
|
UnityUtils.Reset(nodeGo.transform);
|
|
|
|
var nodeScript = UnityUtils.RequireComponent<FlyTeleportNodeScript>(nodeGo);
|
|
nodeScript.InitWithData(data.PathNodes[i]);
|
|
}
|
|
}
|
|
|
|
public int RandomID()
|
|
{
|
|
var childs = RootGo.transform.GetComponentsInChildren<FlyTeleportEditorScript>();
|
|
while (true)
|
|
{
|
|
int id = UnityEngine.Random.Range(10000, int.MaxValue);
|
|
bool b = false;
|
|
for (int i = 0; i < childs.Length; ++i)
|
|
{
|
|
if (childs[i].ID == id)
|
|
{
|
|
b = true;
|
|
}
|
|
}
|
|
if (!b)
|
|
{
|
|
return id;
|
|
}
|
|
}
|
|
}
|
|
|
|
void CreateNewPath()
|
|
{
|
|
var mapName = EditorSceneManager.GetActiveScene().name;
|
|
var id = RandomID();
|
|
var objName = string.Format("{0}_{1}", mapName, id);
|
|
var go = new GameObject(objName);
|
|
go.transform.parent = RootGo.transform;
|
|
|
|
//清除所有子节点
|
|
while (go.transform.childCount > 0)
|
|
{
|
|
GameObject.DestroyImmediate(go.transform.GetChild(0).gameObject);
|
|
}
|
|
FlyTeleportEditorScript script = UnityUtils.RequireComponent<FlyTeleportEditorScript>(go);
|
|
script.ID = id;
|
|
script.MapName = mapName;
|
|
}
|
|
|
|
void CheckRootGo()
|
|
{
|
|
if (RootGo == null)
|
|
{
|
|
RootGo = GameObject.Find("[FlyTeleportRoot]");
|
|
if (RootGo == null)
|
|
{
|
|
RootGo = new GameObject("[FlyTeleportRoot]");
|
|
}
|
|
}
|
|
}
|
|
|
|
//先将脚本上数据设置到数据管理器里边,然后再进行保存
|
|
public void Save()
|
|
{
|
|
var dataTable = FlyTeleportDataManager.DatasTable;
|
|
var mapTable = FlyTeleportDataManager.MapDatasTable;
|
|
|
|
for (int i = 0; i < RootGo.transform.childCount; ++i)
|
|
{
|
|
FlyTeleportEditorScript script = RootGo.transform.GetChild(i).GetComponent<FlyTeleportEditorScript>();
|
|
if (script != null)
|
|
{
|
|
script.CalculatePathNodePercent();
|
|
FlyTeleportCfgData pathData = FlyTeleportDataManager.Find(script.ID);
|
|
if (pathData == null)
|
|
{
|
|
pathData = new FlyTeleportCfgData();
|
|
dataTable.Add(script.ID, pathData);
|
|
|
|
if (!mapTable.ContainsKey(script.MapName))
|
|
{
|
|
List<FlyTeleportCfgData> datas = new List<FlyTeleportCfgData>();
|
|
datas.Add(pathData);
|
|
mapTable.Add(script.MapName, datas);
|
|
}
|
|
else
|
|
{
|
|
mapTable[script.MapName].Add(pathData);
|
|
}
|
|
}
|
|
|
|
pathData.ID = script.ID;
|
|
pathData.MapName = script.MapName;
|
|
pathData.Length = script.Length;
|
|
|
|
pathData.PathNodes = new List<FlyTeleportNodeCfgData>();
|
|
for (int j = 0; j < script.transform.childCount; ++j)
|
|
{
|
|
var nodeScript = script.transform.GetChild(j).GetComponent<FlyTeleportNodeScript>();
|
|
if (nodeScript == null)
|
|
continue;
|
|
|
|
var nodeData = new FlyTeleportNodeCfgData();
|
|
nodeData.EnterAnim = nodeScript.EnterAnim;
|
|
nodeData.EnterAnimSpeed = nodeScript.EnterAnimSpeed;
|
|
nodeData.EnterIsLoop = nodeScript.EnterIsLoop;
|
|
nodeData.LeaveAnim = nodeScript.LeaveAnim;
|
|
nodeData.LeaveAnimSpeed = nodeScript.LeaveAnimSpeed;
|
|
nodeData.LeaveIsLoop = nodeScript.LeaveIsLoop;
|
|
nodeData.WaitTime = nodeScript.WaitTime;
|
|
nodeData.MoveTime = nodeScript.MoveTime;
|
|
nodeData.MoveCurve = nodeScript.MoveCurve;
|
|
nodeData.Distance = nodeScript.Distance;
|
|
nodeData.Percent = nodeScript.Percent;
|
|
nodeData.BreakPoint = nodeScript.BreakPoint;
|
|
nodeData.Pos = nodeScript.transform.position;
|
|
nodeData.CameraYaw = nodeScript.CameraYaw;
|
|
nodeData.CameraPitch = nodeScript.CameraPitch;
|
|
nodeData.CameraFlowDis = nodeScript.CameraFlowDis;
|
|
nodeData.CameraOffsetX = nodeScript.CameraOffsetX;
|
|
nodeData.CameraOffsetY = nodeScript.CameraOffsetY;
|
|
nodeData.CameraCurve = nodeScript.CameraCurve;
|
|
|
|
nodeData.CameraShake = nodeScript.CameraShake;
|
|
nodeData.ShakePower = nodeScript.ShakePower;
|
|
nodeData.ShakeTime = nodeScript.ShakeTime;
|
|
nodeData.ShakeType = nodeScript.ShakeType;
|
|
nodeData.ShakeCurve = nodeScript.ShakeCurve;
|
|
nodeData.CameraBlur = nodeScript.CameraBlur;
|
|
nodeData.BlurWaitTime = nodeScript.BlurWaitTime;
|
|
nodeData.BlurStart = nodeScript.BlurStart;
|
|
nodeData.BlurEnd = nodeScript.BlurEnd;
|
|
nodeData.BlurTime = nodeScript.BlurTime;
|
|
nodeData.VfxType = nodeScript.VfxType;
|
|
nodeData.VfxID = nodeScript.VfxID;
|
|
nodeData.VfxIsLoop = nodeScript.VfxIsLoop;
|
|
nodeData.VfxLifeTime = nodeScript.VfxLifeTime;
|
|
nodeData.VfxSlot = nodeScript.VfxSlot;
|
|
pathData.PathNodes.Add(nodeData);
|
|
}
|
|
}
|
|
}
|
|
FlyTeleportDataManager.Save();
|
|
AssetDatabase.SaveAssets();
|
|
}
|
|
|
|
void OnGUI()
|
|
{
|
|
CheckRootGo();
|
|
|
|
EditorGUILayout.BeginVertical();
|
|
if (GUILayout.Button("载入"))
|
|
{
|
|
CheckRootGo();
|
|
FlyTeleportDataManager.Load();
|
|
var mapDatas = FlyTeleportDataManager.Find(EditorSceneManager.GetActiveScene().name);
|
|
if (mapDatas != null)
|
|
{
|
|
for (int i = 0; i < mapDatas.Count; ++i)
|
|
{
|
|
CreatePath(mapDatas[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (GUILayout.Button("创建新传送"))
|
|
{
|
|
CreateNewPath();
|
|
}
|
|
|
|
if (GUILayout.Button("保存"))
|
|
{
|
|
Save();
|
|
}
|
|
|
|
if (FlyEditor == null)
|
|
{
|
|
FlyEditor = new FlyTeleportScriptEditor();
|
|
}
|
|
FlyEditor.OnGUI();
|
|
EditorGUILayout.EndVertical();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (!Application.isPlaying)
|
|
{
|
|
Close();
|
|
return;
|
|
}
|
|
if (FlyEditor == null)
|
|
{
|
|
FlyEditor = new FlyTeleportScriptEditor();
|
|
}
|
|
if (Selection.activeGameObject != null)
|
|
{
|
|
var script = Selection.activeGameObject.GetComponent<FlyTeleportEditorScript>();
|
|
if (FlyEditor._target != script)
|
|
{
|
|
FlyEditor.SetTarget(script);
|
|
this.Repaint();
|
|
}
|
|
}
|
|
FlyEditor.UpdateEditor();
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
GameObject.DestroyImmediate(RootGo);
|
|
}
|
|
}
|
|
}
|