架构大更

This commit is contained in:
SoulliesOfficial
2026-03-20 11:56:50 -04:00
parent e60ef64d01
commit d09b58fd80
3663 changed files with 15232012 additions and 105579 deletions

View File

@@ -1,93 +1,96 @@
using System;
using UnityEngine;
namespace Lean.Common
{
/// <summary>This is the base class for all components that need to implement some kind of special logic when selected. You can do this manually without this class, but this makes it much easier.
/// NOTE: This component will register and unregister the associated LeanSelectable in OnEnable and OnDisable.</summary>
/// <summary>
/// This is the base class for all components that need to implement some kind of special logic when selected. You can
/// do this manually without this class, but this makes it much easier.
/// NOTE: This component will register and unregister the associated LeanSelectable in OnEnable and OnDisable.
/// </summary>
public abstract class LeanSelectableBehaviour : MonoBehaviour
{
[System.NonSerialized]
private LeanSelectable selectable;
{
[NonSerialized] private LeanSelectable selectable;
/// <summary>This tells you which LeanSelectable is currently associated with this component.</summary>
public LeanSelectable Selectable
{
get
{
if (selectable == null)
{
Register();
}
/// <summary>This tells you which LeanSelectable is currently associated with this component.</summary>
public LeanSelectable Selectable
{
get
{
if (selectable == null) Register();
return selectable;
}
}
return selectable;
}
}
/// <summary>This method allows you to manually register the LeanSelectable this component is associated with. This is useful if you're manually spawning and attaching children from code.</summary>
[ContextMenu("Register")]
public void Register()
{
Register(GetComponentInParent<LeanSelectable>());
}
protected virtual void Start()
{
if (selectable == null) Register();
}
/// <summary>This method allows you to manually register the LeanSelectable this component is associated with.</summary>
public void Register(LeanSelectable newSelectable)
{
if (newSelectable != selectable)
{
// Unregister existing
Unregister();
protected virtual void OnEnable()
{
Register();
}
// Register a new one?
if (newSelectable != null)
{
selectable = newSelectable;
protected virtual void OnDisable()
{
Unregister();
}
selectable.OnSelected.AddListener(OnSelected);
selectable.OnDeselected.AddListener(OnDeselected);
}
}
}
/// <summary>
/// This method allows you to manually register the LeanSelectable this component is associated with. This is
/// useful if you're manually spawning and attaching children from code.
/// </summary>
[ContextMenu("Register")]
public void Register()
{
Register(GetComponentInParent<LeanSelectable>());
}
/// <summary>This method allows you to manually register the LeanSelectable this component is associated with. This is useful if you're changing the associated LeanSelectable.</summary>
[ContextMenu("Unregister")]
public void Unregister()
{
if (selectable != null)
{
selectable.OnSelected.RemoveListener(OnSelected);
selectable.OnDeselected.RemoveListener(OnDeselected);
/// <summary>This method allows you to manually register the LeanSelectable this component is associated with.</summary>
public void Register(LeanSelectable newSelectable)
{
if (newSelectable != selectable)
{
// Unregister existing
Unregister();
selectable = null;
}
}
// Register a new one?
if (newSelectable != null)
{
selectable = newSelectable;
protected virtual void OnEnable()
{
Register();
}
selectable.OnSelected.AddListener(OnSelected);
selectable.OnDeselected.AddListener(OnDeselected);
}
}
}
protected virtual void Start()
{
if (selectable == null)
{
Register();
}
}
/// <summary>
/// This method allows you to manually register the LeanSelectable this component is associated with. This is
/// useful if you're changing the associated LeanSelectable.
/// </summary>
[ContextMenu("Unregister")]
public void Unregister()
{
if (selectable != null)
{
selectable.OnSelected.RemoveListener(OnSelected);
selectable.OnDeselected.RemoveListener(OnDeselected);
protected virtual void OnDisable()
{
Unregister();
}
selectable = null;
}
}
/// <summary>Called when selection begins.</summary>
protected virtual void OnSelected(LeanSelect select)
{
}
/// <summary>Called when selection begins.</summary>
protected virtual void OnSelected(LeanSelect select)
{
}
/// <summary>Called when this is deselected.</summary>
protected virtual void OnDeselected(LeanSelect select)
{
}
}
/// <summary>Called when this is deselected.</summary>
protected virtual void OnDeselected(LeanSelect select)
{
}
}
}