Would abuse of inheriting from extended MonoBehaviour hurt the performance?

public class ExtendedMonoBehavior : MonoBehaviour
{
private static bool _isServer;
public static bool isServer
{
get
{
if (_isServer == default(bool))
{
if (UnityEngine.Object.FindObjectOfType(typeof(Server)) != default(UnityEngine.Object))
{
_isServer = true;
}
else
{
_isServer = false;
}
}

            return _isServer;
        }
    }

    private static EventDispatcher _eventDispatcherComponent;
    public static EventDispatcher eventDispatcherComponent
    {
        get
        {
            if (_eventDispatcherComponent == default(EventDispatcher))
            {
                _eventDispatcherComponent = (EventDispatcher)UnityEngine.Object.FindObjectOfType(typeof(EventDispatcher));
                if (_eventDispatcherComponent == default(EventDispatcher))
                {
                    throw new System.Exception("Can't find EventDispatcher in your scene");
                }
            }

            return _eventDispatcherComponent;
        }
    }

    public static T[] ConvertToArray<T>(IList list)
    {
        T[] ret = new T[list.Count];
        list.CopyTo(ret, 0);
        return ret;
    }

    public static Dictionary<GameObject, GameObjectParameters> networkedGameObjectsWithParameters = new Dictionary<GameObject, GameObjectParameters>();
    public static Dictionary<NetworkPlayer, NetworkPlayerParameters> networkPlayersWithParameters = new Dictionary<NetworkPlayer, NetworkPlayerParameters>();

    public static IControllable controlledComponent=default(IControllable); // client only
}

so on and so forth… of course i have all my scripts inheriting from it.
I could put them into other script using extension methods instead.
would that make me cry in the long run?

I honestly hope not, because ive done something similar but with CharacterMotor. Realistically speaking though, its just an inherited class. The only performance problems would be caused with bad coding practices.

1 Answer

1

There’s no technical reason that this shouldn’t be ok. It will make your code more complex over time, but that’s down to being strict with your code standards.