更改文件架构

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEngine.UIElements;
using UnityEditor;
using UnityEditor.UIElements;
#endif
namespace BITKit
{
public class BITInputSystem
{
[RuntimeInitializeOnLoadMethod]
static void Reload()
{
AllowInput = new();
}
public static ValidHandle AllowInput = new();
}
#if UNITY_EDITOR
public class BITInputSystemEditor : EditorWindow
{
RadioButton allowInput;
[MenuItem("Tools/InputSystemEditor")]
static void Entry()
{
GetWindow<BITInputSystemEditor>().Show();
}
void Start()
{
rootVisualElement.Add(allowInput = new());
}
void Update()
{
if (allowInput is not null)
allowInput.value = BITInputSystem.AllowInput;
}
}
#endif
}

View File

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

View File

@@ -0,0 +1,89 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using System.Linq;
namespace BITKit
{
[System.Serializable]
public class InputActionGroup : IDisposable
{
int lockFile = Guid.NewGuid().GetHashCode();
public bool allowGlobalActivation = true;
public bool isEnabled;
InitializationState state = InitializationState.None;
public ValidHandle allowInput = new();
List<InputAction> actions = new();
public InputActionGroup RegisterCallback(InputActionReference reference, Action<InputAction.CallbackContext> callback)
{
if (reference is null)
{
Debug.LogWarning($"未知的引用");
return this;
}
EnsureConfiguration();
var action = reference.action.Clone();
actions
.Where(x => x.name == action.name)
.CreateOrAddIfEmety(actions, action)
.ForEach(x =>
{
x.RegisterCallback(callback);
});
return this;
}
public void UnRegisterCallback(InputActionReference reference, Action<InputAction.CallbackContext> callback)
{
foreach (var action in actions.Where(x => x.name == reference.action.name))
{
action.UnRegisterCallback(callback);
}
}
void EnsureConfiguration()
{
if (state is not InitializationState.Initialized)
{
Init();
state = InitializationState.Initialized;
}
}
void Init()
{
if (allowGlobalActivation)
BITInputSystem.AllowInput.AddListener(Listen);
allowInput.AddListener(Allow);
}
void Listen(bool allowInput)
{
this.allowInput.SetElements(lockFile, allowInput);
this.allowInput.SetDisableElements(lockFile, !allowInput);
}
void Allow(bool allow)
{
foreach (var action in actions)
{
if (allow)
{
action.Enable();
}
else
{
action.Disable();
}
}
isEnabled = allow;
}
public void Dispose()
{
foreach (var action in actions)
{
action.Disable();
}
actions.Clear();
}
}
}

View File

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

View File

@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using System;
namespace BITKit
{
public static partial class InputSystemExtensions
{
public static InputAction RegisterCallback(this InputAction self, Action<InputAction.CallbackContext> action)
{
self.performed += action;
self.started += action;
self.canceled += action;
return self;
}
public static InputAction UnRegisterCallback(this InputAction self, Action<InputAction.CallbackContext> action)
{
self.performed -= action;
self.started -= action;
self.canceled -= action;
return self;
}
}
}

View File

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