This commit is contained in:
CortexCore
2023-10-24 23:38:22 +08:00
parent 2c4710bc5d
commit bd40165ade
152 changed files with 3681 additions and 1531 deletions

View File

@@ -1,17 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RotaryHeart.Lib.SerializableDictionary;
using UnityEngine.Events;
namespace BITKit
{
public class SubSelectable : MonoBehaviour, ISelectable
{
Selectable root;
public Transform GetTransform() => root.GetTransform();
public void SetSelectionState(SelectionState state)
{
root.SetSelectionState(state);
}
}
}

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@@ -17,17 +18,16 @@ namespace BITKit
}
public interface ISelectable
{
Transform GetTransform();
void SetSelectionState(SelectionState state);
}
public interface ISelectableCallback
{
void OnHover(ISelectable selectable);
void OnActive(ISelectable selectable);
void OnInactive(ISelectable selectable);
}
public interface ISelectableComponent
{
Transform Transform { get; }
void SetSelectionState(SelectionState state);
event Action OnNone;
event Action OnHover;
event Action OnActive;
event Action OnInactive;
event Action OnFocus;
event Action OnSelected;
event Action OnEnabled;
event Action OnChecked;
event Action OnRoot;
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit.Selection
{
public interface ISelector
{
bool TryGetCurrentSelectable(out ISelectable selectable);
event Action<ISelectable> OnNone;
event Action<ISelectable> OnHover;
event Action<ISelectable> OnActive;
event Action<ISelectable> OnInactive;
event Action<ISelectable> OnFocus;
event Action<ISelectable> OnSelected;
event Action<ISelectable> OnEnabled;
event Action<ISelectable> OnChecked;
event Action<ISelectable> OnRoot;
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: f51350f9724ab8a41831d6bc51d65bf5
guid: 2dd296d4da4d5fd48adf5c0f97c0b89e
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@@ -6,21 +7,53 @@ namespace BITKit
public class Selectable : MonoBehaviour, ISelectable
{
public Transform GetTransform() => transform;
ISelectableComponent[] components;
void Start()
private void Start()
{
components = GetComponentsInChildren<ISelectableComponent>(true);
foreach (var x in components)
{
x.SetSelectionState(0);
}
OnNone?.Invoke();
}
public Transform Transform => transform;
public void SetSelectionState(SelectionState state)
{
foreach (var x in components)
switch (state)
{
x.SetSelectionState(state);
case SelectionState.None:
OnNone?.Invoke();
break;
case SelectionState.Hover:
OnHover?.Invoke();
break;
case SelectionState.Active:
OnActive?.Invoke();
break;
case SelectionState.Inactive:
OnInactive?.Invoke();
break;
case SelectionState.Focus:
OnFocus?.Invoke();
break;
case SelectionState.Selected:
OnSelected?.Invoke();
break;
case SelectionState.Enabled:
OnEnabled?.Invoke();
break;
case SelectionState.Checked:
OnChecked?.Invoke();
break;
case SelectionState.Root:
OnRoot?.Invoke();
break;
}
}
public event Action OnNone;
public event Action OnHover;
public event Action OnActive;
public event Action OnInactive;
public event Action OnFocus;
public event Action OnSelected;
public event Action OnEnabled;
public event Action OnChecked;
public event Action OnRoot;
}
}

View File

@@ -1,59 +1,46 @@
using System;
using UnityEngine;
using UnityEngine.Events;
namespace BITKit
{
public class SelectableEvent : MonoBehaviour, ISelectableComponent
public class SelectableEvent : MonoBehaviour
{
[Header(nameof(SelectionState.None))]
[SerializeField] UnityEvent OnNone;
[SerializeField] private UnityEvent OnNone;
[Header(nameof(SelectionState.Hover))]
[SerializeField] UnityEvent OnHover;
[SerializeField]private UnityEvent OnHover;
[Header(nameof(SelectionState.Active))]
[SerializeField] UnityEvent OnActive;
[SerializeField]private UnityEvent OnActive;
[Header(nameof(SelectionState.Inactive))]
[SerializeField] UnityEvent OnInactive;
[SerializeField]private UnityEvent OnInactive;
[Header(nameof(SelectionState.Focus))]
[SerializeField] UnityEvent OnFocus;
[SerializeField]private UnityEvent OnFocus;
[Header(nameof(SelectionState.Selected))]
[SerializeField] UnityEvent OnSelected;
[SerializeField]private UnityEvent OnSelected;
[Header(nameof(SelectionState.Enabled))]
[SerializeField] UnityEvent OnEnabled;
[SerializeField]private UnityEvent OnEnabled;
[Header(nameof(SelectionState.Checked))]
[SerializeField] UnityEvent OnChecked;
[SerializeField]private UnityEvent OnChecked;
[Header(nameof(SelectionState.Root))]
[SerializeField] UnityEvent OnRoot;
public void SetSelectionState(SelectionState state)
[SerializeField]private UnityEvent OnRoot;
private void Start()
{
switch (state)
var selectable = GetComponent<ISelectable>();
if (selectable == null)
{
case SelectionState.None:
OnNone.Invoke();
break;
case SelectionState.Hover:
OnHover.Invoke();
break;
case SelectionState.Active:
OnActive.Invoke();
break;
case SelectionState.Inactive:
OnInactive.Invoke();
break;
case SelectionState.Focus:
OnFocus.Invoke();
break;
case SelectionState.Selected:
OnSelected.Invoke();
break;
case SelectionState.Enabled:
OnEnabled.Invoke();
break;
case SelectionState.Checked:
OnChecked.Invoke();
break;
case SelectionState.Root:
OnRoot.Invoke();
break;
Debug.LogError($"No {nameof(ISelectable)} component found on {gameObject.name}");
return;
}
selectable.OnNone += OnNone.Invoke;
selectable.OnHover += OnHover.Invoke;
selectable.OnActive += OnActive.Invoke;
selectable.OnInactive += OnInactive.Invoke;
selectable.OnFocus += OnFocus.Invoke;
selectable.OnSelected += OnSelected.Invoke;
selectable.OnEnabled += OnEnabled.Invoke;
selectable.OnChecked += OnChecked.Invoke;
selectable.OnRoot += OnRoot.Invoke;
}
}
}