Skip to content

AMRC-DPG/DPG-Unity-Common

Repository files navigation

DPG-Unity-Common

Editor

An attribute that will show or hide a variable within the inspector based on another inspector exposed boolean.

conditionalHide.gif

Code example
public class ExampleClass : MonoBehaviour
{
    [SerializeField] private bool isStatic;

#if UNITY_EDITOR
    [ConditionalHide(nameof(isStatic), false, true)]
#endif
    [SerializeField]
    [Min(1f)]
    private float speed = 1f;

    public float GetSpeed => isStatic ? 0f : speed;

    private void Update()
    {
        // Do something with GetSpeed
    }
}

Runtime

Abstract classes to provide singleton pattern logic for the derived class.

Note - If using the Awake() function within the derived class. It must be overriden and call base.Awake() within the derived class' Awake() function.

PersistentSingleton.cs

Makes the object a singleton, and uses Unity's DontDestroyOnLoad() function to provide persistence between scenes.

Singleton.cs

Only makes the object a singleton, and it will be destroyed on load by default.

Code example
public class ExamplePersistentSingletonClass : PersistentSingleton<ExamplePersistentSingletonClass>
{
    protected override void Awake()
    {
        // Custom code here
        
        base.Awake();
    }

    private void Start()
    {
        throw new NotImplementedException();
    }

    private void Update()
    {
        throw new NotImplementedException();
    }
}

public class ExampleSingletonClass : Singleton<ExampleSingletonClass>
{
    protected override void Awake()
    {
        // Custom code
        
        base.Awake();
    }

    private void Start()
    {
        throw new NotImplementedException();
    }

    private void Update()
    {
        throw new NotImplementedException();
    }
}

About

Unity package for common project functionality.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages