using System.Collections; using System.Collections.Generic; using UnityEngine; using System; #if UNITY_EDITOR using UnityEditor; #endif public class HazyMapNpcScriptableObject : ScriptableObject { [SerializeField, Header("订制次数")] int[] m_CustomCounts; [SerializeField, Header("订制位置")] List m_CustomNpcPositions; [SerializeField] List m_NpcPositions; public List GetNpcPositions(int count) { if (m_CustomCounts != null && m_CustomCounts.Length > 0 && m_CustomNpcPositions != null) { var index = Array.IndexOf(m_CustomCounts, count); if (index != -1 && index < m_CustomNpcPositions.Count) { return m_CustomNpcPositions[index].positions; } } return m_NpcPositions; } #if UNITY_EDITOR public void Save(int index, Vector3 position) { if (m_NpcPositions != null && index < m_NpcPositions.Count) { m_NpcPositions[index] = position; } } #endif [Serializable] public struct CustomPositions { public List positions; } } #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