更改文件架构

This commit is contained in:
CortexCore
2023-06-07 18:38:07 +08:00
parent 93292b1a59
commit ed84166723
720 changed files with 297 additions and 65 deletions

View File

@@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public interface IMonoProxy
{
}
public class MonoProxy : Mono
{
[SerializeReference, SubclassSelector] public IMonoProxy proxy;
BehaviorUpdater updater = new();
protected override void Awake()
{
updater.Init(proxy);
updater.OnAwake();
}
protected override void Start()
{
updater.OnStart();
}
protected override void Update()
{
updater.OnUpdate(Time.deltaTime);
}
protected override void FixedUpdate()
{
updater.OnFixedUpdate(Time.fixedDeltaTime);
}
protected override void LateUpdate()
{
updater.OnLateUpdate(Time.deltaTime);
}
protected override void OnDestroy()
{
updater.OnDestroy();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 27745a46fda75cf4da1766691754f81a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,68 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit.StateMachine
{
[System.Serializable]
public abstract class MonoStateMachine<TState> : IStateMachine<TState>, IMonoProxy, IStart, IUpdate
where TState : IState
{
[Header(Constant.Header.Settings)]
public string name;
[Header(Constant.Header.Settings)]
[SerializeField, SerializeReference, SubclassSelector]
TState currentState;
public TState CurrentState
{
get => currentState;
set => currentState = value;
}
[Header(Constant.Header.Components)]
[SerializeReference, SubclassSelector] public List<TState> states = new();
public IDictionary<Type, TState> StateDictonary { get; } = new Dictionary<Type, TState>();
public IStateMachine<TState> StateMachine => this as IStateMachine<TState>;
TState tempState;
public virtual void OnStart()
{
foreach (var state in states)
{
//state.TransitionState = InternalTransitionState;
state.Initialize();
StateDictonary.Add(state.GetType(), state);
}
if (states.Count > 0)
{
var index = states[0];
StateMachine.TransitionState(index);
}
}
public virtual void ExitState()
{
CurrentState?.OnStateExit(CurrentState, null);
CurrentState = default;
}
public virtual void RecoveryState()
{
if (tempState is not null)
{
StateMachine.TransitionState(tempState);
}
else
{
StateMachine.TransitionState(states[0]);
}
}
public virtual void OnUpdate(float deltaTime)
{
CurrentState?.OnStateUpdate();
}
void InternalTransitionState(IState state)
{
if (state is TState tState)
{
StateMachine.TransitionState(tState);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2abc8d2959200da4294a6177cc85c5ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4a6bdba3a8f279a47964bd670e2f323e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BITKit;
using BITKit.StateMachine;
namespace BITKit.StateMachine.Tests
{
public interface ITestState : IState { }
[System.Serializable]
public class TestState : ITestState
{
public void Initialize()
{
}
public void OnStateEnter(IState old)
{
}
public void OnStateExit(IState old, IState newState)
{
}
public void OnStateUpdate()
{
}
}
[System.Serializable]
public class TestState1 : TestState { }
[System.Serializable]
public class TestState2 : TestState { }
[System.Serializable]
public class TestState3 : TestState { }
[System.Serializable]
public class TestMonoStateMachine : MonoStateMachine<ITestState>
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c82bd284d724df344b3c6dcd823bb04d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: