using UnityEngine;
|
using System.Collections.Generic;
|
using System;
|
|
#if UNITY_EDITOR
|
using UnityEditor;
|
using System.IO;
|
#endif
|
|
public class SoMapObjectGenerate : ScriptableObject
|
{
|
public List<int> missionList = new List<int>();
|
public List<GenerateNPC> generateNPCList = new List<GenerateNPC>();
|
|
[Serializable]
|
public class GenerateNPC
|
{
|
public List<NpcInfo> npcList = new List<NpcInfo>();
|
}
|
|
[Serializable]
|
public class NpcInfo
|
{
|
public int npcID;
|
public Vector3 position;
|
public Vector3 rotation;
|
}
|
}
|
|
#if UNITY_EDITOR
|
[CustomEditor(typeof(SoMapObjectGenerate))]
|
public class SoMapObjectGenerateEditor : Editor
|
{
|
private int m_MissionID;
|
private int m_NpcID;
|
private Vector3 m_BornPos;
|
private Vector3 m_BornDir;
|
private Dictionary<int, bool> m_FoldOut = new Dictionary<int, bool>();
|
private static readonly GUIContent _line = new GUIContent("--------------------------------------------------------------------------------");
|
|
[MenuItem("程序/地图对象生成配置")]
|
static void CreateSoMapObjectGenerate()
|
{
|
SoMapObjectGenerate _config = CreateInstance<SoMapObjectGenerate>();
|
string _createName = string.Format(ScriptableObjectLoader.SoMapObjectGenerate_Suffix,
|
DateTime.UtcNow.ToFileTimeUtc());
|
string _path = ResourcesPath.ResourcesOutPath + "refdata/ScriptableObject/SoMapObjectGenerate/";
|
if (Directory.Exists(_path) == false)
|
{
|
Directory.CreateDirectory(_path);
|
}
|
_path = StringUtility.Contact(ResourcesPath.ResourcesOutAssetPath,
|
"refdata/ScriptableObject/SoMapObjectGenerate/",
|
_createName,
|
".asset");
|
AssetDatabase.CreateAsset(_config, _path);
|
AssetDatabase.Refresh();
|
ProjectWindowUtil.ShowCreatedAsset(_config);
|
}
|
|
public override void OnInspectorGUI()
|
{
|
serializedObject.Update();
|
|
SoMapObjectGenerate _target = target as SoMapObjectGenerate;
|
EditorGUILayout.BeginHorizontal();
|
m_MissionID = EditorGUILayout.IntField("任务ID", m_MissionID);
|
if (GUILayout.Button("增加任务刷怪信息"))
|
{
|
if (m_MissionID != 0)
|
{
|
_target.missionList.Add(m_MissionID);
|
_target.generateNPCList.Add(new SoMapObjectGenerate.GenerateNPC());
|
}
|
}
|
EditorGUILayout.EndHorizontal();
|
|
int _deleteIndex = -1;
|
int _deleteNpcIndex = -1;
|
|
for (int i = 0; i < _target.missionList.Count; ++i)
|
{
|
if (m_FoldOut.ContainsKey(_target.missionList[i]) == false)
|
{
|
m_FoldOut.Add(_target.missionList[i], true);
|
}
|
|
EditorGUILayout.BeginHorizontal();
|
|
m_FoldOut[_target.missionList[i]] = EditorGUILayout.Foldout(m_FoldOut[_target.missionList[i]], "任务: " + _target.missionList[i]);
|
|
if (GUILayout.Button("删除"))
|
{
|
_deleteIndex = i;
|
}
|
|
EditorGUILayout.EndHorizontal();
|
|
if (m_FoldOut[_target.missionList[i]])
|
{
|
m_MissionID = EditorGUILayout.IntField("任务ID", m_MissionID);
|
if (GUILayout.Button("修改任务ID"))
|
{
|
if (m_MissionID != 0)
|
{
|
_target.missionList[i] = m_MissionID;
|
}
|
}
|
|
m_NpcID = EditorGUILayout.IntField("NpcID", m_NpcID);
|
m_BornPos = EditorGUILayout.Vector3Field("出生点(客户端坐标)", m_BornPos);
|
m_BornDir = EditorGUILayout.Vector3Field("旋转", m_BornDir);
|
|
if (GUILayout.Button("增加NPC信息"))
|
{
|
if (m_NpcID != 0)
|
{
|
SoMapObjectGenerate.NpcInfo _npcInfo = new SoMapObjectGenerate.NpcInfo();
|
_npcInfo.npcID = m_NpcID;
|
_npcInfo.position = m_BornPos;
|
_npcInfo.rotation = m_BornDir;
|
|
_target.generateNPCList[i].npcList.Add(_npcInfo);
|
}
|
}
|
|
EditorGUI.indentLevel += 1;
|
|
for (int j = 0; j < _target.generateNPCList[i].npcList.Count; ++j)
|
{
|
EditorGUILayout.BeginHorizontal();
|
EditorGUILayout.BeginVertical();
|
_target.generateNPCList[i].npcList[j].npcID = EditorGUILayout.IntField("NpcID", _target.generateNPCList[i].npcList[j].npcID);
|
_target.generateNPCList[i].npcList[j].position = EditorGUILayout.Vector3Field("出生点(客户端坐标)", _target.generateNPCList[i].npcList[j].position);
|
_target.generateNPCList[i].npcList[j].rotation = EditorGUILayout.Vector3Field("朝向", _target.generateNPCList[i].npcList[j].rotation);
|
EditorGUILayout.EndVertical();
|
EditorGUILayout.BeginVertical();
|
if (GUILayout.Button("删除", GUILayout.Height(50)))
|
{
|
_deleteNpcIndex = j;
|
}
|
EditorGUILayout.EndVertical();
|
EditorGUILayout.EndHorizontal();
|
if (j != _target.generateNPCList[i].npcList.Count - 1)
|
{
|
EditorGUILayout.LabelField(_line);
|
}
|
}
|
|
if (_deleteNpcIndex != -1)
|
{
|
_target.generateNPCList[i].npcList.RemoveAt(_deleteNpcIndex);
|
}
|
|
EditorGUI.indentLevel -= 1;
|
}
|
}
|
|
if (_deleteIndex >= 0)
|
{
|
_target.missionList.RemoveAt(_deleteIndex);
|
_target.generateNPCList.RemoveAt(_deleteIndex);
|
}
|
|
if (GUI.changed)
|
{
|
EditorUtility.SetDirty(target);
|
serializedObject.ApplyModifiedProperties();
|
}
|
|
}
|
}
|
#endif
|