using System.Collections; using System.Collections.Generic; using UnityEngine; using System; #if UNITY_EDITOR using UnityEditor; #endif public class HazyMapNpcScriptableObject : ScriptableObject { [SerializeField] NpcInfo[] m_MapNpcInfos; public NpcInfo[] GetAllNpcInfos() { return m_MapNpcInfos; } #if UNITY_EDITOR public void Save(int index, Vector3 position) { if (m_MapNpcInfos != null && index < m_MapNpcInfos.Length) { m_MapNpcInfos[index] = new NpcInfo() { npcId = m_MapNpcInfos[index].npcId, npcType = m_MapNpcInfos[index].npcType, position = position, }; } } #endif [Serializable] public struct NpcInfo { public int npcId; public E_NpcType npcType; public Vector3 position; } } #if UNITY_EDITOR [CustomEditor(typeof(HazyMapNpcScriptableObject))] public class HazyMapNpcInspector : Editor { [SerializeField] int index = 0; public override void OnInspectorGUI() { var npcConfig = target as HazyMapNpcScriptableObject; index = EditorGUILayout.IntField("Index", index); var dropRect = GUILayoutUtility.GetRect(0f, 100f, GUILayout.ExpandWidth(true)); var style = new GUIStyle(GUI.skin.box); style.normal.textColor = Color.white; style.alignment = TextAnchor.MiddleCenter; GUI.Box(dropRect, "拖动物体至此可赋值位置", style); if (dropRect.Contains(Event.current.mousePosition)) { switch (Event.current.type) { case EventType.DragUpdated: DragAndDrop.activeControlID = GUIUtility.GetControlID(FocusType.Passive); DragAndDrop.visualMode = DragAndDropVisualMode.Copy; break; case EventType.DragPerform: DragAndDrop.activeControlID = GUIUtility.GetControlID(FocusType.Passive); DragAndDrop.AcceptDrag(); Event.current.Use(); if (DragAndDrop.objectReferences != null && DragAndDrop.objectReferences.Length > 0) { var obj = DragAndDrop.objectReferences[0]; if(obj is GameObject) { var go = obj as GameObject; npcConfig.Save(index, go.transform.position); } } break; } } base.OnInspectorGUI(); } [MenuItem("策划工具/生成缥缈仙域Npc配置")] static void Create() { var _config = CreateInstance(); string _path = StringUtility.Contact("Assets/ResourcesOut/Refdata/ScriptableObject/SoHazyMapNpc/", "SoHazyMapNpc_", ".asset"); AssetDatabase.CreateAsset(_config, _path); AssetDatabase.Refresh(); ProjectWindowUtil.ShowCreatedAsset(_config); } } #endif