Skip to content

Interface

Aprius edited this page Aug 29, 2024 · 5 revisions

IGameObjectSource

Interface/contract for a type that is considered a GameObject source.Such as Components/IComponents, which are attached to GameObjects, so therefore are a source of a GameObject.

IComponent

Base contract for any interface contract that should be considered a Component

flowchart LR

IGameObjectSource --- IComponent --> IGameObjectSource
IComponent --- IGameObjectSource

linkStyle 0,2 stroke:none
Loading

ILoadComponent

A special interface that allows you to deploy OnloadComponents method, when this button load component in header script in Inspector will work, you can perform setups like Auto Binding Component here so that when clicking on this button everything will everything will Setup automatically avoids the error due to pulling

image

For components that do not deploy ILoadComponent, when clicking the button it does not perform anything, just announced that this component does not deploy ILoadComponent

image

IVisitable

Provide an Accept method with a visitor parameter

public abstract class Entity : MonoBehaviour, IVisitable 
{
    public void Accept(IVisitor visitor) => visitor.Visit(this);
}

IVisitor

Provide an Visit method with a visitable parameter

public class Item : MonoBehaviour, IVisitor
{
    public void Visit<T>(T visitable) where T : Component, IVisitable
    {
        if (visitable is Entity entity)
        {
            // todo take item
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        other.TryGetComponent<IVisitable>(out var visitable);
        visitable?.Accept(this);
    }
}

IEventTrigger

Represents a mechanism for triggering an event.

public sealed class FakeEvent : IEventTrigger
{
    public bool HasBeenTriggered { get; private set; }
    public void Trigger() => HasBeenTriggered = true;
}
Clone this wiki locally