103 lines
3.0 KiB
C#
103 lines
3.0 KiB
C#
|
|
|||
|
using UnityEngine;
|
|||
|
using System.Collections;
|
|||
|
using UnityEditor;
|
|||
|
using System.IO;
|
|||
|
|
|||
|
|
|||
|
public class NPCEditor : Editor
|
|||
|
{
|
|||
|
public GameObject EffectObj;
|
|||
|
|
|||
|
[MenuItem("ProTool/NPCEditor/InitNpcRoot")]
|
|||
|
public static void InitNpcRoot()
|
|||
|
{
|
|||
|
var npcEditorRoot = AssetDatabase.LoadAssetAtPath("Assets/Project3D/Tool/Editor/NPCEditor/NPCEditorRoot.prefab", typeof(GameObject));
|
|||
|
var npcEditorGO = GameObject.Instantiate(npcEditorRoot) as GameObject;
|
|||
|
|
|||
|
npcEditorGO.GetComponent<NPCEditorRoot>().curSceneID = GetSceneID();
|
|||
|
}
|
|||
|
|
|||
|
private static int GetSceneID()
|
|||
|
{
|
|||
|
string curScene = EditorApplication.currentScene.Substring(EditorApplication.currentScene.LastIndexOf('/') + 1);
|
|||
|
curScene = curScene.Substring(0, curScene.IndexOf('.'));
|
|||
|
|
|||
|
StreamReader streamReader = new StreamReader(Application.dataPath + "/../../Public/PublicTables/SceneClass.txt");
|
|||
|
while (!streamReader.EndOfStream)
|
|||
|
{
|
|||
|
var lineStr = streamReader.ReadLine();
|
|||
|
var lineSplit = lineStr.Split('\t');
|
|||
|
if (lineSplit.Length > 7)
|
|||
|
{
|
|||
|
if (lineSplit[3] == curScene)
|
|||
|
{
|
|||
|
return int.Parse(lineSplit[0]);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
[MenuItem("ProTool/NPCEditor/ExportData")]
|
|||
|
public static void ExportData()
|
|||
|
{
|
|||
|
GameObject curObj = Selection.activeGameObject;
|
|||
|
if (null == curObj)
|
|||
|
{
|
|||
|
Debug.LogError("pleas choose the npcEditor root");
|
|||
|
return;
|
|||
|
}
|
|||
|
NPCEditorRoot curRoot = curObj.GetComponent<NPCEditorRoot>();
|
|||
|
if (null == curRoot)
|
|||
|
{
|
|||
|
Debug.LogError("the object is not a npcEditor root");
|
|||
|
return;
|
|||
|
}
|
|||
|
string SavePath = Application.dataPath + "/Data/";
|
|||
|
if (!Directory.Exists(SavePath))
|
|||
|
{
|
|||
|
Directory.CreateDirectory(SavePath);
|
|||
|
}
|
|||
|
|
|||
|
string SaveFile = Application.dataPath + "/../../Public/PublicTables/SceneNpc.txt";
|
|||
|
curRoot.ExportData(SaveFile);
|
|||
|
AssetDatabase.Refresh();
|
|||
|
Debug.Log(SavePath + "保存完毕");
|
|||
|
|
|||
|
/*
|
|||
|
string curPath = "";//= BundleManager.GetGUIDataName(target.name);
|
|||
|
|
|||
|
* */
|
|||
|
}
|
|||
|
|
|||
|
[MenuItem("ProTool/NPCEditor/ImportData")]
|
|||
|
public static void ImportData()
|
|||
|
{
|
|||
|
GameObject curObj = Selection.activeGameObject;
|
|||
|
if (null == curObj)
|
|||
|
{
|
|||
|
Debug.LogError("pleas choose the npcEditor root");
|
|||
|
return;
|
|||
|
}
|
|||
|
NPCEditorRoot curRoot = curObj.GetComponent<NPCEditorRoot>();
|
|||
|
if (null == curRoot)
|
|||
|
{
|
|||
|
Debug.LogError("the object is not a npcEditor root");
|
|||
|
return;
|
|||
|
}
|
|||
|
string curPath = Application.dataPath + "/../../Public/PublicTables/SceneNpc.txt";
|
|||
|
if (!File.Exists(curPath))
|
|||
|
{
|
|||
|
EditorUtility.DisplayDialog("提示", "文件 " + curPath + " 不存在,无法加载", "确定");
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
curRoot.ImportData(curPath);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|