JUtils
A unity utilities library
JUtils.Optional< T > Struct Template Reference

A struct useful for showing in the inspector if the value is optional, and does not have to be set. Also allows for quicker checks if the value is set More...

Public Member Functions

 Optional (T initialValue)
 

Static Public Member Functions

static implicit operator bool (Optional< T > optional)
 
static implicit operator T (Optional< T > optional)
 

Properties

bool enabled [get]
 
value [get]
 

Detailed Description

A struct useful for showing in the inspector if the value is optional, and does not have to be set. Also allows for quicker checks if the value is set

namespace Example
{
public class OptionalExample : MonoBehaviour
{
[SerializeField] private Optional&#60;HealthComponent> _healthComponent;
private void Start()
{
HealthComponent hc = _healthComponent ? _healthComponent : GetComponent&#60;HealthComponent>();
hc.Damage(10);
}
}
}
Optional(T initialValue)
Definition: Optional.cs:34

Constructor & Destructor Documentation

◆ Optional()

JUtils.Optional< T >.Optional ( initialValue)
inline

Member Function Documentation

◆ operator bool()

static implicit JUtils.Optional< T >.operator bool ( Optional< T >  optional)
inlinestatic

◆ operator T()

static implicit JUtils.Optional< T >.operator T ( Optional< T >  optional)
inlinestatic

Property Documentation

◆ enabled

bool JUtils.Optional< T >.enabled
get

◆ value

T JUtils.Optional< T >.value
get

The documentation for this struct was generated from the following file: