Skip to content

Commit

Permalink
modified and added remove methods for CenterBase
Browse files Browse the repository at this point in the history
  • Loading branch information
michael811125 committed Jun 30, 2023
1 parent 2257009 commit a9856c5
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 17 deletions.
16 changes: 16 additions & 0 deletions Assets/OxGFrame/AgencyCenter/Scripts/Runtime/Common/CenterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ public void Register(int id, TClass @class)
this._cache.Add(id, @class);
}

public void Remove<UClass>() where UClass : TClass
{
System.Type type = typeof(UClass);
int hashCode = type.GetHashCode();

this.Remove(hashCode);
}

public void Remove(int id)
{
if (this.HasInCache(id))
{
this._cache.Remove(id);
}
}

protected TClass GetFromCache(int id)
{
if (!this.HasInCache(id))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

Expand All @@ -22,7 +22,7 @@ enum PlayMode
[SerializeField]
private PlayMode _playMode = PlayMode.Normal;
[SerializeField]
private int frameRate = 30;
private int _frameRate = 30;
[SerializeField]
private bool _ignoreTimeScale = true;

Expand Down Expand Up @@ -86,6 +86,11 @@ public void SetIgnoreScale(bool ignore)
this._ignoreTimeScale = ignore;
}

public void SetFrameRate(int frameRate)
{
this._frameRate = frameRate;
}

public void ResetAnime()
{
this._dt = 0;
Expand All @@ -103,7 +108,7 @@ private void _AutoRefreshSprite(Sprite sp)

private void _UpdateTextureAnimation(float dt)
{
float fps = this.frameRate;
float fps = this._frameRate;
this._dt += dt;

this._spIdx = Mathf.FloorToInt(this._dt * fps);
Expand Down
2 changes: 1 addition & 1 deletion Assets/OxGFrame/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
}
],
"dependencies": {
"com.unity.scriptablebuildpipeline": "1.21.5"
"com.unity.scriptablebuildpipeline": "1.21.7"
},
"author": {
"name": "MichaelO"
Expand Down
65 changes: 52 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
| [MyBox v1.7.0 or higher](https://github.com/Deadcows/MyBox), Add https://github.com/Deadcows/MyBox.git to Package Manager |
| [HybirdCLR v3.2.0 or higher](https://github.com/focus-creative-games/hybridclr), Add https://github.com/focus-creative-games/hybridclr_unity.git to Package Manager (革命性的程式熱更新方案) **特別推薦** |

### Unity 如果有遇到 Newtonsoft 問題

- 請自行安裝 Add package by name [com.unity.nuget.newtonsoft-json](https://github.com/jilleJr/Newtonsoft.Json-for-Unity/wiki/Install-official-via-UPM)

### 1. 透過 Package Manager 安裝 (Install via git)

Add https://github.com/michael811125/OxGFrame.git?path=Assets/OxGFrame to Package Manager.
Expand Down Expand Up @@ -59,18 +63,12 @@ OxGFrame 是基於 Unity 用於加快遊戲開發的輕量級框架,並且使
### Sub-ThirdParty

- 使用 [UnityWebSocket v2.7.0](https://github.com/psygames/UnityWebSocket) (最佳 WebSocket 解決方案) **特別推薦**
- 使用 [YooAsset v1.4.16](https://github.com/tuyoogame/YooAsset) (強大的資源熱更新方案) **特別推薦**
- 使用 [YooAsset v1.4.17](https://github.com/tuyoogame/YooAsset) (強大的資源熱更新方案) **特別推薦**

※備註 : 會持續更新內建第三方庫。

---

### Unity 低版本如果有遇到 Newtonsoft 問題

- 請自行安裝 [com.unity.nuget.newtonsoft-json](https://github.com/jilleJr/Newtonsoft.Json-for-Unity/wiki/Install-official-via-UPM)

---

## 框架 API

- Hotfixers (using OxGFrame.Hotfixer)
Expand All @@ -97,6 +95,8 @@ OxGFrame 是基於 Unity 用於加快遊戲開發的輕量級框架,並且使
代碼熱修復模塊,使用 [HybridCLR](https://github.com/focus-creative-games/hybridclr) (前身 Huatuo) 革命性的熱更新方案進行整合,相關建置請前往官方文檔進行熟悉。
- 如果相關建置完畢,前往點選 HybridCLR/OxGFrame With HybirdCLR/Complie And Copy To HotfixCollector,將會幫忙拷貝至 HotfixCollector 文件夾,再使用 YooAsset Collector 進行收集打包。

**使用流程詳看 HotfixerDemo (Import frome Package Manager)**

![](https://github.com/michael811125/OxGFrame/blob/master/Docs/img_4.png)
![](https://github.com/michael811125/OxGFrame/blob/master/Docs/img_5.png)
![](https://github.com/michael811125/OxGFrame/blob/master/Docs/img_6.png)
Expand Down Expand Up @@ -154,14 +154,17 @@ OxGFrame 是基於 Unity 用於加快遊戲開發的輕量級框架,並且使
- 允許跳過 Default Package 主下載器的下載階段 (強制邊玩邊下載)。

**檢查 PlayMode 是否初始完成**
- 判斷檢查 AssetPatcher.IsInitialized() 是否初始完成,因為初始完成後,才能開始進行 Bundle 加載
- 判斷檢查 AssetPatcher.IsInitialized() 是否初始完成,因為初始完成後,才能開始進行 Built-in Bundle 的加載與 AssetPatcher.Check(),又或者邊玩邊下載
- 備註 : 區分 Built-in 跟 Patch (視情況自行訂定運作流程)
1. 需自己拆分 Patch 更新前用到的資源 (例如 : LogoUI, PatchUI 等...),需要先打包至 Built-in 作為內置資源。
2. 後續執行 AssetPatcher.Check() 檢查 Patch 更新完成後,就可以讀取更新資源了。

**檢查 Patch 是否更新完成**
- 判斷檢查 AssetPatcher.IsDone() 是否更新完成。

**Patch 執行順序流程**
- 判斷 AssetPathcer.IsInitialized() => 執行 AssetPatcher.Check() => 判斷 AssetPatcher.IsDone() => 完成

**指定特定的 Package 進行資源加載**
- 需先手動進行 AssetPatcher.InitPackage 的初始 (如果 autoUpdate = false,則需要自行另外調用 AssetPatcher.UpdatePackage 進行 Manifest 的更新)。
- 支援特定版本 DLC package 的下載與 DLC package 卸載功能,需手動進行 AssetPatcher.InitDlcPackage,並且指定特定 dlcVersion,對於 dlcVersion 也可以單一固定 dlcVersion,變成只要 DLC 有更新就可以使用固定路徑進行更新。
Expand Down Expand Up @@ -250,7 +253,7 @@ store_link http://
- **不建議在 OnPreClose 時進行相關 Show 的處理,如果有進行的話也沒關係,因為針對 CloseAll 的 API 有提供 disablePreClose 的開關。**
- OnShow : 調用 Show 時,此方法會被激活,並且可以透過帶入的 object 進行數據傳送。
- OnClose : 調用 Close 時,此方法會被激活。
- OnRelease : 當物件 Close And Destroy 時,此方法會被激活。
- OnRelease : 當物件被 Destroy 時,此方法會被激活。

#### 初始順序說明

Expand All @@ -271,15 +274,15 @@ Init Order : OnInit (Once) > OnBind (Once) > OnPreShow (EveryOpen) > OnShow (Eve
- UIBase & SRBase 使用 _Node@XXX
- CPBase 使用 ~Node@XXX

#### 自動生成物件綁定代碼 (Shift + B)
#### 自動生成物件綁定代碼 (Hotkey: Shift+B)

命名規範使用 * 指向 TailName
- UIBase & SRBase
- _Node@XXX*Btn (以此類推)
- CPBase
- ~Node@XXX*Btn (以此類推)

預設組件綁定表 (可從 BindCodeSetting 中自行新增或修改對應綁定組件類型)
預設組件綁定表 (可從 BindCodeSetting 中自行新增或修改 TailName 對應綁定組件類型)

| **Tail Name** | **Component** |
|:-|:-|
Expand Down Expand Up @@ -387,7 +390,7 @@ video_urlset 127.0.0.1/video/

### AgencyCenter

事件代管中心,可以自行實現 TClass 註冊類型,再由自定義管理類統一繼承 CenterBase<TCenter, TClass>,實現簡易事件代管派送 (集中式管理),預設提供以下。
事件代管中心,可以自行實現 TClass 註冊類型,再由自定義管理類統一繼承 CenterBase<TCenter, TClass> (可複製下面 **Center API Template** 作為調用接口),實現簡易事件代管派送 (集中式管理),預設提供以下。

#### EventCenter

Expand Down Expand Up @@ -425,6 +428,8 @@ video_urlset 127.0.0.1/video/
#endregion
```

---

#### APICenter

集中式 API 整合模塊,可以自定義每個 API 的格式進行 Http API 短連接請求,能夠有效的集中管理各型式的 API 格式,使用 Acax (類似 Ajax 方式,請求 API),支援 Async & Sync。
Expand Down Expand Up @@ -461,6 +466,39 @@ video_urlset 127.0.0.1/video/
#endregion
```

---

### Center API Template

```
#region Default API
public static void Add<T>() where T : YOUR_TCLASS, new()
{
GetInstance().Register<T>();
}
public static void Add<T>(int id) where T : YOUR_TCLASS, new()
{
GetInstance().Register<T>(id);
}
public static void Add(int id, YOUR_TCLASS @class)
{
GetInstance().Register(id, @class);
}
public static T Find<T>() where T : YOUR_TCLASS
{
return GetInstance().Get<T>();
}
public static T Find<T>(int id) where T : YOUR_TCLASS
{
return GetInstance().Get<T>(id);
}
#endregion
```

**如果沒有要使用 AgencyCenter 事件模塊,可以直接刪除整個 AgencyCenter。**

※備註 : Right-Click Create/OxGFrame/Agency Center... (Template cs)
Expand All @@ -480,8 +518,9 @@ video_urlset 127.0.0.1/video/
- Singleton: MonoSingleton (MonoBehaviour), NewSingleton (class).
- Requester: RequestAudio, RequestTexture2D, RequestSprite, RequestBytes, RequestText.
- Cacher: ARCCache<TKey, TValue>, LRUCache<TKey, TValue>, LRUKCache<TKey, TValue>.
- TextureAnimation.
- Editor
- RectTransform: RectTransformAdjuster (Shift + R).
- RectTransform: RectTransformAdjuster (Hotkey: Shift+R).
- MissingScriptsFinder.
- SymlinkUtility.

Expand Down

0 comments on commit a9856c5

Please sign in to comment.