少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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<CustomPositions> m_CustomNpcPositions;
    [SerializeField] List<Vector3> m_NpcPositions;
 
    public List<Vector3> 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<Vector3> 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<HazyMapNpcScriptableObject>();
        string _path = StringUtility.Contact("Assets/ResourcesOut/Refdata/ScriptableObject/SoHazyMapNpc/",
                                      "SoHazyMapNpc_",
                                      ".asset");
        AssetDatabase.CreateAsset(_config, _path);
        AssetDatabase.Refresh();
        ProjectWindowUtil.ShowCreatedAsset(_config);
    }
}
#endif