少年修仙传客户端代码仓库
client_linchunjie
2019-04-17 11997ece0dc4980eba3dd8889d37adb8376e14cb
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
106
107
108
109
110
111
112
113
114
115
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
 
[CreateAssetMenu(menuName = "Config/WindowConfig")]
public class WindowConfig : ScriptableObject
{
 
    public WindowTable[] windows;
 
    [NonSerialized] public Dictionary<string, List<string>> parentChildrenTable = new Dictionary<string, List<string>>();
    [NonSerialized] public List<string> childWindows = new List<string>();
 
    static WindowConfig config;
    public static WindowConfig Get()
    {
        if (config == null)
        {
            config = BuiltInLoader.LoadScriptableObject<WindowConfig>("WindowConfig");
            for (int i = 0; i < config.windows.Length; i++)
            {
                var table = config.windows[i];
                var children = config.parentChildrenTable[table.parent] = new List<string>();
                for (int j = 0; j < table.orderTables.Length; j++)
                {
                    children.Add(table.orderTables[j].window);
                }
 
                config.childWindows.AddRange(children);
            }
        }
 
        return config;
    }
 
    public static void Release()
    {
        config = null;
    }
 
    public bool FindChildWindow(string _parent, int _order, out string _child)
    {
        for (int i = 0; i < windows.Length; i++)
        {
            var table = windows[i];
            if (table.parent == _parent)
            {
                for (int j = 0; j < table.orderTables.Length; j++)
                {
                    if (table.orderTables[j].order == _order)
                    {
                        _child = table.orderTables[j].window;
                        return true;
                    }
                }
            }
        }
 
        _child = string.Empty;
        return false;
    }
 
    public bool FindParentWindow(string _child, out string _parent)
    {
        for (int i = 0; i < windows.Length; i++)
        {
            var table = windows[i];
            for (int j = 0; j < table.orderTables.Length; j++)
            {
                var orderTable = table.orderTables[j];
                if (orderTable.window == _child)
                {
                    _parent = table.parent;
                    return true;
                }
            }
        }
 
        _parent = string.Empty;
        return false;
    }
 
    public List<string> FindChildWindows(string _parent)
    {
        if (parentChildrenTable.ContainsKey(_parent))
        {
            return parentChildrenTable[_parent];
        }
        else
        {
            return null;
        }
    }
 
    public bool IsChildWindow(string _name)
    {
        return childWindows.Contains(_name);
    }
 
    [Serializable]
    public struct WindowTable
    {
        public string parent;
        public OrderTable[] orderTables;
    }
 
    [Serializable]
    public struct OrderTable
    {
        public int order;
        public string window;
    }
 
}