This repository was archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathGameModeEditor.cs
More file actions
111 lines (87 loc) · 3.69 KB
/
Copy pathGameModeEditor.cs
File metadata and controls
111 lines (87 loc) · 3.69 KB
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
//-----------------------------------------------------------------------
// <copyright>
// Copyright (c) 2018 wanderer. All rights reserved.
// </copyright>
// <describe> #GameMode的编辑器类# </describe>
// <email> dutifulwanderer@gmail.com </email>
// <time> #2018年6月25日 12点23分# </time>
//-----------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.Profiling;
using System.Reflection;
using System.Linq;
namespace Wanderer.GameFramework
{
[CustomEditor(typeof(GameMode))]
public class GameModeEditor : Editor
{
private GameMode _gameMode;
////Color.cyan;
private Color _defaultColor;
//资源加载模块的颜色
private Color _resourceColor = new Color(0.851f, 0.227f, 0.286f, 1.0f);
//可操作模块的颜色
private Color _operationColor = new Color(0.953f, 0.424f, 0.129f, 1.0f);
//状态模块的颜色
private Color _stateColor = new Color(0.141f, 0.408f, 0.635f, 1.0f);
//配置表模块的颜色
private Color _dataTableColor = new Color(0.989f, 0.686f, 0.090f, 1.0f);
//数据节点模块的颜色
private Color _nodeDataColor = new Color(0.435f, 0.376f, 0.667f, 1.0f);
//步骤模块的颜色
private Color _stepColor = new Color(0.439f, 0.631f, 0.624f, 1.0f);
//调试模块的颜色
private Color _debugColor = new Color(1f, 0.100f, 0.888f, 1.0f);
//所有的模块
private List<ModuleEditorBase> _listModuleEditors;
private void OnEnable()
{
_listModuleEditors = new List<ModuleEditorBase>();
_gameMode = target as GameMode;
_defaultColor = GUI.color;
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
//从unity编译管线获取到当前所有的程序集的信息
UnityEditor.Compilation.Assembly[] unityAssemblys = UnityEditor.Compilation.CompilationPipeline.GetAssemblies();
for (int i = 0; i < unityAssemblys.Length; i++)
{
string assemblyName = unityAssemblys[i].name;
Assembly assembly = assemblies.Where(x => x.GetName().Name.Equals(assemblyName)).ElementAt(0);
foreach (var item in assembly.GetTypes())
{
CustomModuleEditor attar = item.GetCustomAttribute<CustomModuleEditor>();
if (attar != null && item.BaseType == typeof(ModuleEditorBase))
{
ModuleEditorBase module = Activator.CreateInstance(item, attar.Name, attar.Color, _gameMode) as ModuleEditorBase;
_listModuleEditors.Add(module);
}
}
}
}
private void OnDisable()
{
if (_listModuleEditors == null)
return;
for (int i = 0; i < _listModuleEditors.Count; i++)
{
_listModuleEditors[i].OnClose();
}
_listModuleEditors.Clear();
}
public override void OnInspectorGUI()
{
if (_gameMode == null || _listModuleEditors == null)
return;
GUILayout.BeginVertical();
for (int i = 0; i < _listModuleEditors.Count; i++)
{
_listModuleEditors[i].OnInspectorGUI();
}
GUILayout.EndVertical();
//EditorUtility.SetDirty(_gameMode);
}
}
}