Skip to content

Commit c26a528

Browse files
committed
Merge pull request #5 from mr-kelly/master
docs ~ and some api
2 parents c9d4b53 + d799c89 commit c26a528

File tree

25 files changed

+382
-115
lines changed

25 files changed

+382
-115
lines changed
File renamed without changes.

Assets/CosmosEngine/Editor/CosmosEngineEditor/CBuildTools.cs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,8 @@ struct XVersionControlInfo
3131

3232
static int PushedAssetCount = 0;
3333

34-
public event Action<UnityEngine.Object, string, string> BeforeBuildAssetBundleEvent;
35-
36-
// 鉤子函數, 動態改變某些打包行為
37-
public static bool HookFunc(System.Type classType, string funcName, params object[] args)
38-
{
39-
if (classType == null)
40-
{
41-
return false;
42-
}
43-
44-
MethodInfo methodInfo = classType.GetMethod(funcName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
45-
if (methodInfo == null)
46-
{
47-
return false;
48-
}
49-
50-
CBase.Log("HookFunc- {0}:{1}", classType.Name, funcName);
51-
methodInfo.Invoke(null, args);
52-
53-
return true;
54-
}
34+
public static event Action<UnityEngine.Object, string, string> BeforeBuildAssetBundleEvent;
35+
public static event Action<UnityEngine.Object, string, string> AfterBuildAssetBundleEvent;
5536

5637
#region 打包功能
5738
public static string MakeSureExportPath(string path, BuildTarget buildTarget)
@@ -154,7 +135,11 @@ public static uint BuildAssetBundle(Object asset, string path, BuildTarget build
154135
string relativePath = path;
155136
path = MakeSureExportPath(path, buildTarget);
156137

157-
if ((prefabType == PrefabType.None && AssetDatabase.GetAssetPath(asset) == string.Empty) ||
138+
if (asset is Texture)
139+
{
140+
asset = asset; // Texutre不复制拷贝一份
141+
}
142+
else if ((prefabType == PrefabType.None && AssetDatabase.GetAssetPath(asset) == string.Empty) ||
158143
(prefabType == PrefabType.ModelPrefabInstance))
159144
{
160145
tmpObj = (GameObject)GameObject.Instantiate(asset);
@@ -166,8 +151,8 @@ public static uint BuildAssetBundle(Object asset, string path, BuildTarget build
166151
asset = PrefabUtility.GetPrefabParent(asset);
167152
}
168153

169-
170-
HookFunc(typeof(CBuildTools), "BeforeBuildAssetBundle", asset, path, relativePath);
154+
if (BeforeBuildAssetBundleEvent != null)
155+
BeforeBuildAssetBundleEvent(asset, path, relativePath);
171156

172157
uint crc;
173158
BuildPipeline.BuildAssetBundle(
@@ -186,8 +171,8 @@ public static uint BuildAssetBundle(Object asset, string path, BuildTarget build
186171

187172
CBase.Log("生成文件: {0}", path);
188173

189-
190-
HookFunc(typeof(CBuildTools), "AfterBuildAssetBundle", asset, path, relativePath);
174+
if (AfterBuildAssetBundleEvent != null)
175+
AfterBuildAssetBundleEvent(asset, path, relativePath);
191176

192177
return crc;
193178
}

Assets/CosmosEngine/Editor/CosmosEngineEditor/CBuild_UI.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ public partial class CBuild_UI : AutoBuildBase
2929
public override string GetDirectory() { return "UI"; }
3030
public override string GetExtention() { return "*.unity"; }
3131

32-
public static event Action<CBuild_UI> Custom_BeginExport;
32+
public static event Action<CBuild_UI> BeginExportEvent;
33+
public static event Action<CBuild_UI, string, string, GameObject> ExportCurrentUIEvent;
34+
public static event Action ExportUIMenuEvent;
35+
public static event Action<CBuild_UI> EndExportEvent;
36+
3337

3438
public static string GetBuildRelPath(string uiName)
3539
{
@@ -39,7 +43,12 @@ public static string GetBuildRelPath(string uiName)
3943
public void ExportCurrentUI()
4044
{
4145
CreateTempPrefab();
42-
if (!CBuildTools.HookFunc(typeof(CBuild_UI), "Custom_ExportCurrentUI", this, UIScenePath, UIName, TempPanelObject))
46+
47+
if (ExportCurrentUIEvent != null)
48+
{
49+
ExportCurrentUIEvent(this, UIScenePath, UIName, TempPanelObject);
50+
}
51+
else
4352
{
4453
CBuildTools.BuildAssetBundle(TempPanelObject, GetBuildRelPath(UIName));
4554
}
@@ -48,7 +57,10 @@ public void ExportCurrentUI()
4857

4958
public override void BeginExport()
5059
{
51-
CBuildTools.HookFunc(typeof(CBuild_UI), "Custom_BeginExport", this);
60+
if (BeginExportEvent != null)
61+
{
62+
BeginExportEvent(this);
63+
}
5264
}
5365

5466
public override void Export(string path)
@@ -65,7 +77,10 @@ public override void Export(string path)
6577

6678
public override void EndExport()
6779
{
68-
CBuildTools.HookFunc(typeof(CBuild_UI), "Custom_EndExport", this);
80+
if (EndExportEvent != null)
81+
{
82+
EndExportEvent(this);
83+
}
6984

7085
}
7186

@@ -208,8 +223,9 @@ public static void CreateUI()
208223
[MenuItem("CosmosEngine/UI/Export Current UI %&U")]
209224
public static void ExportUIMenu()
210225
{
211-
CBuildTools.HookFunc(typeof(CBuild_UI), "Custom_ExportUIMenu");
212-
226+
if (ExportUIMenuEvent != null)
227+
ExportUIMenuEvent();
228+
213229
CBuild_UI uiBuild = new CBuild_UI();
214230
if (!uiBuild.CheckUI(true))
215231
return;

Assets/CosmosEngine/Scripts/Utils/CCollisionDetector.cs.meta renamed to Assets/CosmosEngine/Editor/CosmosEngineEditor/CTestTools.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/CosmosEngine/Scripts/BaseModules/UI/CUIManager.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public class CUIManager : ICModule
3030
public Dictionary<string, CUILoadState> UIWindows = new Dictionary<string, CUILoadState>();
3131
public bool UIRootLoaded = false;
3232

33-
public event System.Action<string> OpenWindowEvent;
34-
public event System.Action<string> CloseWindowEvent;
33+
public static event Action<CUIController> OnOpenEvent;
34+
public static event Action<CUIController> OnCloseEvent;
3535

3636
private CUIManager()
3737
{
@@ -164,7 +164,8 @@ void OnDynamicWindowCallback(CUIController _ui, object[] _args)
164164
originArgs[i - 2] = _args[i];
165165

166166
InitWindow(_instanceUIState, uiBase, true, originArgs);
167-
OnUIWindowLoaded(_instanceUIState, uiBase);
167+
OnUIWindowLoadedCallbacks(_instanceUIState, uiBase);
168+
168169
}
169170

170171
public void CloseWindow(Type t)
@@ -179,9 +180,6 @@ public void CloseWindow<T>()
179180

180181
public void CloseWindow(string name)
181182
{
182-
if (CloseWindowEvent != null)
183-
CloseWindowEvent(name);
184-
185183
CUILoadState uiState;
186184
if (!UIWindows.TryGetValue(name, out uiState))
187185
{
@@ -195,6 +193,9 @@ public void CloseWindow(string name)
195193
}
196194

197195
uiState.UIWindow.gameObject.SetActive(false);
196+
197+
if (OnCloseEvent != null)
198+
OnCloseEvent(uiState.UIWindow);
198199
uiState.UIWindow.OnClose();
199200

200201
if (!uiState.IsStaticUI)
@@ -315,7 +316,7 @@ IEnumerator LoadUIAssetBundle(string path, string name, CUILoadState openState)
315316

316317
uiBase.UIName = uiBase.UITemplateName = openState.Name;
317318
InitWindow(openState, uiBase, openState.OpenWhenFinish, openState.OpenArgs);
318-
OnUIWindowLoaded(openState, uiBase);
319+
OnUIWindowLoadedCallbacks(openState, uiBase);
319320

320321
}
321322

@@ -382,16 +383,18 @@ public void CallUI<T>(Action<T, object[]> callback, params object[] args) where
382383

383384
void OnOpen(CUILoadState uiState, params object[] args)
384385
{
385-
if (OpenWindowEvent != null)
386-
OpenWindowEvent(uiState.UIType);
387-
388386
CUIController uiBase = uiState.UIWindow;
389387
uiBase.OnPreOpen();
390388
if (uiBase.gameObject.activeSelf)
389+
{
391390
uiBase.OnClose();
391+
}
392392
else
393393
uiBase.gameObject.SetActive(true);
394394

395+
396+
if (OnOpenEvent != null)
397+
OnOpenEvent(uiBase);
395398
uiBase.OnOpen(args);
396399
}
397400

@@ -407,7 +410,7 @@ void InitWindow(CUILoadState uiState, CUIController uiBase, bool open, params ob
407410
}
408411

409412
}
410-
void OnUIWindowLoaded(CUILoadState uiState, CUIController uiBase)
413+
void OnUIWindowLoadedCallbacks(CUILoadState uiState, CUIController uiBase)
411414
{
412415
//if (openState.OpenWhenFinish) // 加载完打开 模式下,打开时执行回调
413416
{

Assets/CosmosEngine/Scripts/Bridges/CNGUIBridge.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void CreateUIRoot()
5555
CBase.Assert(UiRoot);
5656
UiRoot.scalingStyle = UIRoot.Scaling.ConstrainedOnMobiles;
5757
UiRoot.manualHeight = 1920;
58+
UiRoot.manualWidth = 1080;
5859

5960
GameObject panelRootObj = new GameObject("PanelRoot");
6061
CTool.SetChild(panelRootObj.transform, uiRootobj.transform);

Assets/CosmosEngine/Scripts/Utils/CTabReader.cs.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/CosmosEngine/Scripts/Utils/ICTabReadble.cs.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor/CosmosEngineEditor.meta renamed to Assets/CosmosEngine/Tests.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

0 commit comments

Comments
 (0)