更改文件架构
This commit is contained in:
28
Packages/Common~/Scripts/Mono/Mono.cs
Normal file
28
Packages/Common~/Scripts/Mono/Mono.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
namespace BITKit
|
||||
{
|
||||
public abstract class Mono : MonoBehaviour, IMonoProxy
|
||||
{
|
||||
protected virtual void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
protected virtual void Start()
|
||||
{
|
||||
}
|
||||
protected virtual void Update()
|
||||
{
|
||||
}
|
||||
protected virtual void FixedUpdate()
|
||||
{
|
||||
}
|
||||
protected virtual void LateUpdate()
|
||||
{
|
||||
}
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/Mono/Mono.cs.meta
Normal file
11
Packages/Common~/Scripts/Mono/Mono.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13003171a12d81c4eaee9c516471992a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
99
Packages/Common~/Scripts/Mono/MonoAction.cs
Normal file
99
Packages/Common~/Scripts/Mono/MonoAction.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UIElements;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
#endif
|
||||
namespace BITKit
|
||||
{
|
||||
[System.Serializable]
|
||||
public struct InvokeMonoAction : IAction
|
||||
{
|
||||
public MonoBehaviour monoBehaviour;
|
||||
public void Excute()
|
||||
{
|
||||
(monoBehaviour as IAction).Excute();
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
public struct InvokeUnityEvent : IAction
|
||||
{
|
||||
public UnityEvent unityEvent;
|
||||
public void Excute()
|
||||
{
|
||||
unityEvent.Invoke();
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
public struct ExitApplation : IAction
|
||||
{
|
||||
public void Excute()
|
||||
{
|
||||
BITAppForUnity.Exit();
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
public struct DebugText : IAction
|
||||
{
|
||||
[SerializeReference, SubclassSelector] public References text;
|
||||
|
||||
public void Excute()
|
||||
{
|
||||
Debug.Log(text);
|
||||
}
|
||||
}
|
||||
public class MonoAction : MonoBehaviour, IAction
|
||||
{
|
||||
[SerializeReference, SubclassSelector] public List<IAction> actions;
|
||||
CancellationToken cancellationToken;
|
||||
void Start()
|
||||
{
|
||||
cancellationToken = gameObject.GetCancellationTokenOnDestroy();
|
||||
}
|
||||
public async void Excute()
|
||||
{
|
||||
try
|
||||
{
|
||||
await UniTask.SwitchToMainThread(cancellationToken);
|
||||
foreach (var x in actions)
|
||||
{
|
||||
x.Excute();
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
[CustomEditor(typeof(MonoAction))]
|
||||
public class MonoActinoInspector : BITInspector<MonoAction>
|
||||
{
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
CreateSubTitle("Settings");
|
||||
var actions = root.Create<PropertyField>();
|
||||
var button = root.Create<Button>();
|
||||
actions.bindingPath = nameof(MonoAction.actions);
|
||||
|
||||
button.text = "Excute";
|
||||
|
||||
button.clicked += agent.Excute;
|
||||
return root;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
11
Packages/Common~/Scripts/Mono/MonoAction.cs.meta
Normal file
11
Packages/Common~/Scripts/Mono/MonoAction.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7c307dd96b0ae44db43b135d73ae46a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
40
Packages/Common~/Scripts/Mono/MonoEvents.cs
Normal file
40
Packages/Common~/Scripts/Mono/MonoEvents.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
namespace BITKit
|
||||
{
|
||||
public class MonoEvents : Mono
|
||||
{
|
||||
public UnityEvent OnAwake = new();
|
||||
public UnityEvent OnStart = new();
|
||||
public UnityEvent<float> OnUpdate = new();
|
||||
public UnityEvent<float> OnFixexUpdate = new();
|
||||
public UnityEvent<float> OnLateUpdate = new();
|
||||
public UnityEvent OnDestroyComponent = new();
|
||||
protected override void Awake()
|
||||
{
|
||||
OnAwake.Invoke();
|
||||
}
|
||||
protected override void Start()
|
||||
{
|
||||
OnStart.Invoke();
|
||||
}
|
||||
protected override void Update()
|
||||
{
|
||||
OnUpdate.Invoke(Time.deltaTime);
|
||||
}
|
||||
protected override void FixedUpdate()
|
||||
{
|
||||
OnFixexUpdate.Invoke(Time.deltaTime);
|
||||
}
|
||||
protected override void LateUpdate()
|
||||
{
|
||||
OnLateUpdate.Invoke(Time.deltaTime);
|
||||
}
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
OnDestroyComponent.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/Mono/MonoEvents.cs.meta
Normal file
11
Packages/Common~/Scripts/Mono/MonoEvents.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e8903c9eaac98b4788b121973994a29
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user