Skip to content
This repository has been archived by the owner on Mar 25, 2020. It is now read-only.

ComponentBase

pointcache edited this page Jan 15, 2017 · 2 revisions

Self registers in ComponentPool

public class ComponentBase : MonoBehaviour
{
    [NotEditableString]
    public string ID;

    public virtual void OnEnable()
    {
        ComponentPoolSystem.Register(this);
    }
    public virtual void OnDisable()
    {
        ComponentPoolSystem.Unregister(this);
        _entity = null;
    }

    Entity _entity;
    public Entity Entity
    {
        get
        {
            if ((object)_entity == null)
                _entity = getEntityRecursive(transform);
            return _entity;
        }
    }
    Entity getEntityRecursive(Transform tr)
    {
        if ((object)tr == null)
        {
            return null;
        }
        Entity ec = tr.gameObject.GetComponent<Entity>();
        if ((object)ec != null)
        {
            return ec;
        }
        else
            return getEntityRecursive(tr.parent);
    }
}
public class SerializedData { }
Clone this wiki locally