Skip to content

Commit

Permalink
added Default API and modified (GSIFrame and AgencyCenter)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael811125 committed Aug 5, 2023
1 parent c6725d5 commit ddd8fc6
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,6 @@ using OxGFrame.AgencyCenter.APICenter;

public class #SCRIPTNAME# : CenterBase<#SCRIPTNAME#, APIBase>
{
#region Default API
public static void Add<T>() where T : APIBase, new()
{
GetInstance().Register<T>();
}

public static void Add<T>(int apiId) where T : APIBase, new()
{
GetInstance().Register<T>(apiId);
}

public static void Add(int apiId, APIBase apiBase)
{
GetInstance().Register(apiId, apiBase);
}

public static T Find<T>() where T : APIBase
{
return GetInstance().Get<T>();
}

public static T Find<T>(int apiId) where T : APIBase
{
return GetInstance().Get<T>(apiId);
}
#endregion

public #SCRIPTNAME#()
{
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,6 @@ using OxGFrame.AgencyCenter.EventCenter;

public class #SCRIPTNAME# : CenterBase<#SCRIPTNAME#, EventBase>
{
#region Default API
public static void Add<T>() where T : EventBase, new()
{
GetInstance().Register<T>();
}

public static void Add<T>(int eventId) where T : EventBase, new()
{
GetInstance().Register<T>(eventId);
}

public static void Add(int eventId, EventBase eventBase)
{
GetInstance().Register(eventId, eventBase);
}

public static T Find<T>() where T : EventBase
{
return GetInstance().Get<T>();
}

public static T Find<T>(int eventId) where T : EventBase
{
return GetInstance().Get<T>(eventId);
}
#endregion

public #SCRIPTNAME#()
{
/*
Expand Down
27 changes: 27 additions & 0 deletions Assets/OxGFrame/AgencyCenter/Scripts/Runtime/Common/CenterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,33 @@ protected static TCenter GetInstance()
return _instance;
}

#region Default API
public static void Add<UClass>() where UClass : TClass, new()
{
GetInstance().Register<UClass>();
}

public static void Add<UClass>(int id) where UClass : TClass, new()
{
GetInstance().Register<UClass>(id);
}

public static void Add(int id, TClass @class)
{
GetInstance().Register(id, @class);
}

public static UClass Find<UClass>() where UClass : TClass
{
return GetInstance().Get<UClass>();
}

public static UClass Find<UClass>(int id) where UClass : TClass
{
return GetInstance().Get<UClass>(id);
}
#endregion

public UClass Get<UClass>() where UClass : TClass
{
System.Type type = typeof(UClass);
Expand Down
36 changes: 36 additions & 0 deletions Assets/OxGFrame/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# CHANGELOG

## [2.7.1] - 2023-08-05
- Added Default API in GSIManagerBase (protected GetInstance() method).
```
public static int GetCurrentId()
public static U GetStage<U>() where U : GSIBase
public static U GetStage<U>(int id) where U : GSIBase
public static void AddStage<U>() where U : GSIBase, new()
public void AddStage<U>(int id) where U : GSIBase, new()
public static void AddStage(int id, GSIBase gameStage)
public static void ChangeStage<U>(bool force = false) where U : GSIBase
public static void ChangeStage(int id, bool force = false)
public static void Start()
public static void Update(float dt = 0.0f)
```
- Added Default API in CenterBase (removed Default API from subtype).
```
public static void Add<UClass>() where UClass : TClass, new()
public static void Add<UClass>(int id) where UClass : TClass, new()
public static void Add(int id, TClass @class)
public static UClass Find<UClass>() where UClass : TClass
public static UClass Find<UClass>(int id) where UClass : TClass
```

## [2.7.0] - 2023-08-03
- Added AssetPatcher.GetPresetAppPackages() method.
- Added [Sort Tail Rules (A-Z)] ContextMenu for BindCodeSetting.
Expand Down
71 changes: 65 additions & 6 deletions Assets/OxGFrame/GSIFrame/Scripts/Runtime/GSIManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace OxGFrame.GSIFrame

private static readonly object _locker = new object();
private static T _instance = null;
public static T GetInstance()
protected static T GetInstance()
{
if (_instance == null)
{
Expand All @@ -24,10 +24,70 @@ public static T GetInstance()
return _instance;
}

#region Default API
public static int GetCurrentId()
{
return GetInstance()._currentId;
}

public static U GetStage<U>() where U : GSIBase
{
return GetInstance().GetGameStage<U>();
}

public static U GetStage<U>(int id) where U : GSIBase
{
return GetInstance().GetGameStage<U>(id);
}

public static void AddStage<U>() where U : GSIBase, new()
{
GetInstance().AddGameStage<U>();
}

public void AddStage<U>(int id) where U : GSIBase, new()
{
GetInstance().AddGameStage<U>(id);
}

public static void AddStage(int id, GSIBase gameStage)
{
GetInstance().AddGameStage(id, gameStage);
}

public static void ChangeStage<U>(bool force = false) where U : GSIBase
{
if (force) GetInstance().ChangeGameStageForce<U>();
else GetInstance().ChangeGameStage<U>();
}

public static void ChangeStage(int id, bool force = false)
{
if (force) GetInstance().ChangeGameStageForce(id);
else GetInstance().ChangeGameStage(id);
}

/// <summary>
/// Call by main MonoBehaviour (Start)
/// </summary>
public static void Start()
{
GetInstance().OnStart();
}

/// <summary>
/// Call by main MonoBehaviour (Update)
/// </summary>
/// <param name="dt"></param>
public static void Update(float dt = 0.0f)
{
GetInstance().OnUpdate(dt);
}
#endregion

public GSIManagerBase()
{
this._dictGameStage = new Dictionary<int, GSIBase>();

this._currentId = 0;
this._currentGameStage = null;
}
Expand All @@ -36,7 +96,6 @@ public GSIManagerBase()
{
this._dictGameStage.Clear();
this._dictGameStage = null;

this._currentGameStage = null;
}

Expand Down Expand Up @@ -219,15 +278,15 @@ protected void ReleaseGameStage()
}

/// <summary>
/// 子類實作, 並且透過主要的 MonoBehaviour Start 調用
/// Call by Main MonoBehaviour (Start)
/// </summary>
public virtual void OnStart() { }

/// <summary>
/// 子類實作, 並且透過主要的 MonoBehaviour Update 調用
/// Call by Main MonoBehaviour (Update)
/// </summary>
/// <param name="dt"></param>
public virtual void OnUpdate(float dt = 0.0f)
public virtual void OnUpdate(float dt)
{
this.UpdateGameStage(dt);
}
Expand Down
27 changes: 0 additions & 27 deletions Assets/OxGFrame/Samples~/APICenterDemo/Scripts/APICenterExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,6 @@

public class APICenterExample : CenterBase<APICenterExample, APIBase>
{
#region Default API
public static void Add<T>() where T : APIBase, new()
{
GetInstance().Register<T>();
}

public static void Add<T>(int apiId) where T : APIBase, new()
{
GetInstance().Register<T>(apiId);
}

public static void Add(int apiId, APIBase apiBase)
{
GetInstance().Register(apiId, apiBase);
}

public static T Find<T>() where T : APIBase
{
return GetInstance().Get<T>();
}

public static T Find<T>(int apiId) where T : APIBase
{
return GetInstance().Get<T>(apiId);
}
#endregion

public APICenterExample()
{
// easy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,6 @@

public class EventCenterExample : CenterBase<EventCenterExample, EventBase>
{
#region Default API
public static void Add<T>() where T : EventBase, new()
{
GetInstance().Register<T>();
}

public static void Add<T>(int eventId) where T : EventBase, new()
{
GetInstance().Register<T>(eventId);
}

public static void Add(int eventId, EventBase eventBase)
{
GetInstance().Register(eventId, eventBase);
}

public static T Find<T>() where T : EventBase
{
return GetInstance().Get<T>();
}

public static T Find<T>(int eventId) where T : EventBase
{
return GetInstance().Get<T>(eventId);
}
#endregion

public EventCenterExample()
{
// easy
Expand Down
19 changes: 7 additions & 12 deletions Assets/OxGFrame/Samples~/GSIFrameDemo/Scripts/GSIFrameDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public class GSIFrameDemo : MonoBehaviour

void Start()
{
GSIManagerExample.GetInstance().OnStart();
GSIManagerExample.Start();
}

void Update()
{
GSIManagerExample.GetInstance().OnUpdate(Time.deltaTime);
GSIManagerExample.Update(Time.deltaTime);

if (Keyboard.current.numpad0Key.wasReleasedThisFrame)
{
Expand All @@ -24,32 +24,27 @@ void Update()

if (Keyboard.current.numpad1Key.wasReleasedThisFrame)
{
if (this.forceMode) GSIManagerExample.GetInstance().ChangeGameStageForce<StartupStageExample>();
else GSIManagerExample.GetInstance().ChangeGameStage<StartupStageExample>();
GSIManagerExample.ChangeStage<StartupStageExample>(this.forceMode);
}

if (Keyboard.current.numpad2Key.wasReleasedThisFrame)
{
if (this.forceMode) GSIManagerExample.GetInstance().ChangeGameStageForce<LogoStageExample>();
else GSIManagerExample.GetInstance().ChangeGameStage<LogoStageExample>();
GSIManagerExample.ChangeStage<LogoStageExample>(this.forceMode);
}

if (Keyboard.current.numpad3Key.wasReleasedThisFrame)
{
if (this.forceMode) GSIManagerExample.GetInstance().ChangeGameStageForce<PatchStageExample>();
else GSIManagerExample.GetInstance().ChangeGameStage<PatchStageExample>();
GSIManagerExample.ChangeStage<PatchStageExample>(this.forceMode);
}

if (Keyboard.current.numpad4Key.wasReleasedThisFrame)
{
if (this.forceMode) GSIManagerExample.GetInstance().ChangeGameStageForce<LoginStageExample>();
else GSIManagerExample.GetInstance().ChangeGameStage<LoginStageExample>();
GSIManagerExample.ChangeStage<LoginStageExample>(this.forceMode);
}

if (Keyboard.current.numpad5Key.wasReleasedThisFrame)
{
if (this.forceMode) GSIManagerExample.GetInstance().ChangeGameStageForce<EnterStageExample>();
else GSIManagerExample.GetInstance().ChangeGameStage<EnterStageExample>();
GSIManagerExample.ChangeStage<EnterStageExample>(this.forceMode);
}
}
}
2 changes: 1 addition & 1 deletion Assets/OxGFrame/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.michaelo.oxgframe",
"displayName": "OxGFrame",
"description": "The OxGFrame is a framework based on Unity for accelerating game development. Supports multi-platform Win, Android, iOS, WebGL.",
"version": "2.7.0",
"version": "2.7.1",
"unity": "2021.3",
"license": "MIT",
"samples": [
Expand Down
11 changes: 10 additions & 1 deletion ProjectSettings/SceneTemplateSettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"templatePinStates": [],
"templatePinStates": [
{
"templateId": "Empty",
"isEnabled": false
},
{
"templateId": "Standard (URP)",
"isEnabled": true
}
],
"dependencyTypeInfos": [
{
"userAdded": false,
Expand Down
Loading

0 comments on commit ddd8fc6

Please sign in to comment.