Skip to content

Commit

Permalink
v1.0.132
Browse files Browse the repository at this point in the history
CodeGenKit: 增加 TabCustomCode(misakiMeiii 提供) ActionKit: 增加 StartCurrentScene(misakiMeiii 提供建议,已包含示例和文档) QFramework.cs: 增加 UnRegisterWhenCurrentSceneUnloaded(misakiMeiii 提供建议,已包含示例和文档)
  • Loading branch information
liangxiegame committed May 12, 2024
1 parent 93190db commit e30403f
Show file tree
Hide file tree
Showing 16 changed files with 314 additions and 86 deletions.
Binary file modified QFramework.Toolkits.unitypackage
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Id": "",
"Version": "v1.0.131",
"Version": "v1.0.132",
"Type": 0,
"AccessRight": 0,
"DownloadUrl": "",
Expand All @@ -11,10 +11,10 @@
],
"DocUrl": "https://liangxiegame.com",
"Readme": {
"version": "v1.0.131",
"content": "补充文档",
"version": "v1.0.132",
"content": "CodeGenKit: 增加 TabCustomCode(misakiMeiii 提供)\nActionKit: 增加 StartCurrentScene(misakiMeiii 提供建议,已包含示例和文档)\nQFramework.cs: 增加 UnRegisterWhenCurrentSceneUnloaded(misakiMeiii 提供建议,已包含示例和文档)",
"author": "liangxie",
"date": "2024 年 05 月 0816:34",
"date": "2024 年 05 月 1220:27",
"PackageId": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,22 @@
* Contributor
* TastSong https://github.com/TastSong
* 京产肠饭 https://gitee.com/JingChanChangFan/hk_-unity-tools
* 猫叔(一只皮皮虾) https://space.bilibili.com/656352/
* 猫叔(一只皮皮虾) https://space.bilibili.com/656352/
* misakiMeiii https://github.com/misakiMeiii
* New一天
* 幽飞冷凝雪~冷
*
* Community
* QQ Group: 623597263
* Latest Update: 2024.1.4 14:56 remove BindablePropertyUnRegister
*
* Latest Update: 2024.5.12 20:17 add UnRegisterWhenCurrentSceneUnloaded(Suggested by misakiMeiii)
****************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace QFramework
{
Expand Down Expand Up @@ -56,14 +60,14 @@ public interface IArchitecture

IUnRegister RegisterEvent<T>(Action<T> onEvent);
void UnRegisterEvent<T>(Action<T> onEvent);

void Deinit();
}

public abstract class Architecture<T> : IArchitecture where T : Architecture<T>, new()
{
private bool mInited = false;


public static Action<T> OnRegisterPatch = architecture => { };

Expand All @@ -88,13 +92,14 @@ static void MakeSureArchitecture()

OnRegisterPatch?.Invoke(mArchitecture);

foreach (var model in mArchitecture.mContainer.GetInstancesByType<IModel>().Where(m=>!m.Initialized))
foreach (var model in mArchitecture.mContainer.GetInstancesByType<IModel>().Where(m => !m.Initialized))
{
model.Init();
model.Initialized = true;
}

foreach (var system in mArchitecture.mContainer.GetInstancesByType<ISystem>().Where(m=>!m.Initialized))

foreach (var system in mArchitecture.mContainer.GetInstancesByType<ISystem>()
.Where(m => !m.Initialized))
{
system.Init();
system.Initialized = true;
Expand All @@ -109,13 +114,15 @@ static void MakeSureArchitecture()
public void Deinit()
{
OnDeinit();
foreach (var system in mContainer.GetInstancesByType<ISystem>().Where(s=>s.Initialized)) system.Deinit();
foreach (var model in mContainer.GetInstancesByType<IModel>().Where(m=>m.Initialized)) model.Deinit();
foreach (var system in mContainer.GetInstancesByType<ISystem>().Where(s => s.Initialized)) system.Deinit();
foreach (var model in mContainer.GetInstancesByType<IModel>().Where(m => m.Initialized)) model.Deinit();
mContainer.Clear();
mArchitecture = null;
}

protected virtual void OnDeinit() { }
protected virtual void OnDeinit()
{
}

private IOCContainer mContainer = new IOCContainer();

Expand Down Expand Up @@ -185,7 +192,6 @@ protected virtual TResult DoQuery<TResult>(IQuery<TResult> query)
public IUnRegister RegisterEvent<TEvent>(Action<TEvent> onEvent) => mTypeEventSystem.Register<TEvent>(onEvent);

public void UnRegisterEvent<TEvent>(Action<TEvent> onEvent) => mTypeEventSystem.UnRegister<TEvent>(onEvent);

}

public interface IOnEvent<T>
Expand Down Expand Up @@ -216,7 +222,7 @@ public interface IController : IBelongToArchitecture, ICanSendCommand, ICanGetSy
#region System

public interface ISystem : IBelongToArchitecture, ICanSetArchitecture, ICanGetModel, ICanGetUtility,
ICanRegisterEvent, ICanSendEvent, ICanGetSystem,ICanInit
ICanRegisterEvent, ICanSendEvent, ICanGetSystem, ICanInit
{
}

Expand All @@ -233,15 +239,18 @@ public abstract class AbstractSystem : ISystem

public void Deinit() => OnDeinit();

protected virtual void OnDeinit(){}
protected virtual void OnDeinit()
{
}

protected abstract void OnInit();
}

#endregion

#region Model

public interface IModel : IBelongToArchitecture, ICanSetArchitecture, ICanGetUtility, ICanSendEvent,ICanInit
public interface IModel : IBelongToArchitecture, ICanSetArchitecture, ICanGetUtility, ICanSendEvent, ICanInit
{
}

Expand All @@ -257,7 +266,9 @@ public abstract class AbstractModel : IModel
void ICanInit.Init() => OnInit();
public void Deinit() => OnDeinit();

protected virtual void OnDeinit(){}
protected virtual void OnDeinit()
{
}

protected abstract void OnInit();
}
Expand Down Expand Up @@ -431,7 +442,7 @@ public static class CanSendQueryExtension
public static TResult SendQuery<TResult>(this ICanSendQuery self, IQuery<TResult> query) =>
self.GetArchitecture().SendQuery(query);
}

public interface ICanInit
{
bool Initialized { get; set; }
Expand Down Expand Up @@ -486,7 +497,11 @@ public abstract class UnRegisterTrigger : UnityEngine.MonoBehaviour
{
private readonly HashSet<IUnRegister> mUnRegisters = new HashSet<IUnRegister>();

public void AddUnRegister(IUnRegister unRegister) => mUnRegisters.Add(unRegister);
public IUnRegister AddUnRegister(IUnRegister unRegister)
{
mUnRegisters.Add(unRegister);
return unRegister;
}

public void RemoveUnRegister(IUnRegister unRegister) => mUnRegisters.Remove(unRegister);

Expand Down Expand Up @@ -516,26 +531,58 @@ private void OnDisable()
UnRegister();
}
}

public class UnRegisterCurrentSceneUnloadedTrigger : UnRegisterTrigger
{
private static UnRegisterCurrentSceneUnloadedTrigger mDefault;

public static UnRegisterCurrentSceneUnloadedTrigger Get
{
get
{
if (!mDefault)
{
mDefault = new GameObject("UnRegisterCurrentSceneUnloadedTrigger")
.AddComponent<UnRegisterCurrentSceneUnloadedTrigger>();
}

return mDefault;
}
}

private void Awake()
{
DontDestroyOnLoad(this);
hideFlags = HideFlags.HideInHierarchy;
SceneManager.sceneUnloaded += OnSceneUnloaded;
}

private void OnDestroy() => SceneManager.sceneUnloaded -= OnSceneUnloaded;
void OnSceneUnloaded(Scene scene) => UnRegister();
}
#endif

public static class UnRegisterExtension
{
#if UNITY_5_6_OR_NEWER
public static IUnRegister UnRegisterWhenGameObjectDestroyed(this IUnRegister unRegister,
UnityEngine.GameObject gameObject)

static T GetOrAddComponent<T>(GameObject gameObject) where T : Component
{
var trigger = gameObject.GetComponent<UnRegisterOnDestroyTrigger>();
var trigger = gameObject.GetComponent<T>();

if (!trigger)
{
trigger = gameObject.AddComponent<UnRegisterOnDestroyTrigger>();
trigger = gameObject.AddComponent<T>();
}

trigger.AddUnRegister(unRegister);

return unRegister;
return trigger;
}

public static IUnRegister UnRegisterWhenGameObjectDestroyed(this IUnRegister unRegister,
UnityEngine.GameObject gameObject) =>
GetOrAddComponent<UnRegisterOnDestroyTrigger>(gameObject)
.AddUnRegister(unRegister);

public static IUnRegister UnRegisterWhenGameObjectDestroyed<T>(this IUnRegister self, T component)
where T : UnityEngine.Component =>
self.UnRegisterWhenGameObjectDestroyed(component.gameObject);
Expand All @@ -545,21 +592,12 @@ public static IUnRegister UnRegisterWhenDisabled<T>(this IUnRegister self, T com
self.UnRegisterWhenDisabled(component.gameObject);

public static IUnRegister UnRegisterWhenDisabled(this IUnRegister unRegister,
UnityEngine.GameObject gameObject)
{
var trigger = gameObject.GetComponent<UnRegisterOnDisableTrigger>();

if (!trigger)
{
trigger = gameObject.AddComponent<UnRegisterOnDisableTrigger>();
}

trigger.AddUnRegister(unRegister);

return unRegister;
}


UnityEngine.GameObject gameObject) =>
GetOrAddComponent<UnRegisterOnDisableTrigger>(gameObject)
.AddUnRegister(unRegister);

public static IUnRegister UnRegisterWhenCurrentSceneUnloaded(this IUnRegister self) =>
UnRegisterCurrentSceneUnloadedTrigger.Get.AddUnRegister(self);
#endif


Expand Down Expand Up @@ -738,7 +776,7 @@ public static void AutoRegister()
}
#endif
}

#endregion

#region EasyEvent
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ public static class IActionExtensions
ActionID = self.ActionID,
};
}

public static IActionController StartCurrentScene(this IAction self, Action<IActionController> onFinish = null)
{
return self.Start(ActionKitCurrentScene.SceneComponent, onFinish);
}

public static IActionController StartCurrentScene(this IAction self, Action onFinish)
{
return self.Start(ActionKitCurrentScene.SceneComponent, onFinish);
}

public static IActionController StartGlobal(this IAction self, Action<IActionController> onFinish = null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/****************************************************************************
* Copyright (c) 2016 - 2024 liangxiegame UNDER MIT License
*
* https://qframework.cn
* https://github.com/liangxiegame/QFramework
* https://gitee.com/liangxiegame/QFramework
****************************************************************************/

using UnityEngine;

namespace QFramework
{
public class ActionKitCurrentScene : MonoBehaviour
{
public static ActionKitCurrentScene mSceneComponent = null;

public static ActionKitCurrentScene SceneComponent
{
get
{
if (!mSceneComponent)
{
mSceneComponent = new GameObject("ActionKitCurrentScene").AddComponent<ActionKitCurrentScene>();
}

return mSceneComponent;
}
}

private void Awake() => hideFlags = HideFlags.HideInHierarchy;

private void OnDestroy() => mSceneComponent = null;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,4 @@ public static ICodeScope Custom(this ICodeScope self, string line)
return self;
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace QFramework
{
public class TabCustomCode : ICode
{
private readonly string mLine;

public TabCustomCode(string line)
{
mLine = line;
}

public void Gen(ICodeWriter writer)
{
writer.WriteLine("\t" + mLine);
}
}

public static partial class ICodeScopeExtensions
{
public static ICodeScope TabCustom(this ICodeScope self, string line)
{
self.Codes.Add(new TabCustomCode(line));
return self;
}
}
}

namespace CodeGenKit
{

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e30403f

Please sign in to comment.