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 pathModuleEditorBase.cs
More file actions
109 lines (98 loc) · 3.34 KB
/
Copy pathModuleEditorBase.cs
File metadata and controls
109 lines (98 loc) · 3.34 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
//-----------------------------------------------------------------------
// <copyright>
// Copyright (c) 2018 wanderer. All rights reserved.
// </copyright>
// <describe> #模块编辑器的基础类# </describe>
// <email> dutifulwanderer@gmail.com </email>
// <time> #2018年12月15日 17点21分# </time>
//-----------------------------------------------------------------------
using System.Collections;
using System.Collections.Generic;
using System.IO;
using LitJson;
using UnityEditor;
using UnityEngine;
namespace Wanderer.GameFramework
{
public abstract class ModuleEditorBase
{
#region property
//名称
protected string _name;
//主颜色
protected Color _mainColor;
//默认颜色
protected Color _defaultColor;
//主类
protected GameMode _gameMode;
//展开
protected bool _isExpand;
#endregion
public ModuleEditorBase(string name, Color mainColor, GameMode gameMode)
{
_name = name;
_mainColor = mainColor;
_defaultColor = GUI.color;
_gameMode = gameMode;
_isExpand = true;
}
//默认绘制界面
public virtual void OnInspectorGUI()
{
if (EditorApplication.isCompiling)
{
EditorUtility.DisplayProgressBar("", "Compiling, please wait...", 1.0f);
}
else
{
EditorUtility.ClearProgressBar();
GUI.color = _mainColor;
GUILayout.BeginVertical("Box");
GUI.color = _defaultColor;
GUILayout.BeginHorizontal();
GUILayout.Space(12);
_isExpand = EditorGUILayout.Foldout(_isExpand, _name, true);
GUILayout.EndHorizontal();
if (_isExpand)
OnDrawGUI();
GUILayout.EndVertical();
}
}
//绘制界面
public abstract void OnDrawGUI();
//关闭界面
public abstract void OnClose();
//保存配置文件
protected virtual void SaveConfig()
{
if (_gameMode == null || _gameMode.ConfigAsset == null)
return;
if (_gameMode.ConfigJsonData == null)
return;
string configPath = AssetDatabase.GetAssetPath(_gameMode.ConfigAsset);
File.WriteAllText(configPath, _gameMode.ConfigJsonData.ToJson());
AssetDatabase.Refresh();
EditorUtility.SetDirty(_gameMode);
}
//检测是否有对应的key
protected virtual void CheckConfig(string key, object value)
{
if (!_gameMode.ConfigJsonData.ContainsKey(key))
{
_gameMode.ConfigJsonData[key] = new JsonData(value);
SaveConfig();
}
}
//无配置文件错误提示
protected virtual bool NoConfigError()
{
bool result = false;
if (_gameMode == null || _gameMode.ConfigJsonData == null)
{
EditorGUILayout.HelpBox("No config file!", MessageType.Error);
result = true;
}
return result;
}
}
}