LoadComponent

Raise

This Event is raised for every player when the game just loaded all the Components of the Player.

It is usually only called one time for each player around the time he joined

Usage

This event should be used to add new Components to the Player that can be accessed later

LoadComponentEvent

EventArgsTypeDescription

Player

SynapsePlayer

The SynapsePlayer Component of the Player

PlayerGameObject

GameObject

The Game Object of the Player

AddComponent<TComponent>()

Method

Adds the Component to the Player Game Object if possible

public class LoadComponentEvent : PlayerEvent
{
    public LoadComponentEvent(GameObject game,SynapsePlayer player) : base(player)
    {
        PlayerGameObject = game;
    }

    public GameObject PlayerGameObject { get; }

    public TComponent AddComponent<TComponent>() where TComponent : Component
    {
        var comp = (TComponent)PlayerGameObject.GetComponent(typeof(TComponent));
        if (comp == null)
            return PlayerGameObject.AddComponent<TComponent>();

        return comp;
    }
}

Last updated