using System; using UnityEngine; namespace UnityAtoms.BaseAtoms { /// /// Different types of Event Reference usages. /// public class AtomBaseVariableEventReferenceUsage { public const int EVENT = 0; public const int EVENT_INSTANCER = 1; public const int COLLECTION_ADDED_EVENT = 2; public const int COLLECTION_REMOVED_EVENT = 3; public const int LIST_ADDED_EVENT = 4; public const int LIST_REMOVED_EVENT = 5; public const int COLLECTION_INSTANCER_ADDED_EVENT = 6; public const int COLLECTION_INSTANCER_REMOVED_EVENT = 7; public const int LIST_INSTANCER_ADDED_EVENT = 8; public const int LIST_INSTANCER_REMOVED_EVENT = 9; } /// /// Event Reference of type `AtomBaseVariable`. Inherits from `AtomBaseEventReference<AtomBaseVariable, AtomBaseVariableEvent, AtomBaseVariableEventInstancer>`. /// [Serializable] public sealed class AtomBaseVariableBaseEventReference : AtomBaseEventReference< AtomBaseVariable, AtomBaseVariableEvent, AtomBaseVariableEventInstancer>, IGetEvent { /// /// Get or set the Event used by the Event Reference. /// /// The event of type `E`. public override AtomBaseVariableEvent Event { get { switch (_usage) { case (AtomBaseVariableEventReferenceUsage.COLLECTION_ADDED_EVENT): return _collection != null ? _collection.Added : null; case (AtomBaseVariableEventReferenceUsage.COLLECTION_REMOVED_EVENT): return _collection != null ? _collection.Removed : null; case (AtomBaseVariableEventReferenceUsage.LIST_ADDED_EVENT): return _list != null ? _list.Added : null; case (AtomBaseVariableEventReferenceUsage.LIST_REMOVED_EVENT): return _list != null ? _list.Removed : null; case (AtomBaseVariableEventReferenceUsage.COLLECTION_INSTANCER_ADDED_EVENT): return _collectionInstancer != null ? _collectionInstancer.Added : null; case (AtomBaseVariableEventReferenceUsage.COLLECTION_INSTANCER_REMOVED_EVENT): return _collectionInstancer != null ? _collectionInstancer.Removed : null; case (AtomBaseVariableEventReferenceUsage.LIST_INSTANCER_ADDED_EVENT): return _listInstancer != null ? _listInstancer.Added : null; case (AtomBaseVariableEventReferenceUsage.LIST_INSTANCER_REMOVED_EVENT): return _listInstancer != null ? _listInstancer.Removed : null; case (AtomBaseVariableEventReferenceUsage.EVENT_INSTANCER): return _eventInstancer != null ? _eventInstancer.Event : null; case (AtomBaseVariableEventReferenceUsage.EVENT): default: return _event; } } set { switch (_usage) { case (AtomBaseVariableEventReferenceUsage.COLLECTION_ADDED_EVENT): { _collection.Added = value; break; } case (AtomBaseVariableEventReferenceUsage.COLLECTION_REMOVED_EVENT): { _collection.Removed = value; break; } case (AtomBaseVariableEventReferenceUsage.LIST_ADDED_EVENT): { _list.Added = value; break; } case (AtomBaseVariableEventReferenceUsage.LIST_REMOVED_EVENT): { _list.Removed = value; break; } case (AtomBaseVariableEventReferenceUsage.COLLECTION_INSTANCER_ADDED_EVENT): { _collectionInstancer.Added = value; break; } case (AtomBaseVariableEventReferenceUsage.COLLECTION_INSTANCER_REMOVED_EVENT): { _collectionInstancer.Removed = value; break; } case (AtomBaseVariableEventReferenceUsage.LIST_INSTANCER_ADDED_EVENT): { _listInstancer.Added = value; break; } case (AtomBaseVariableEventReferenceUsage.LIST_INSTANCER_REMOVED_EVENT): { _listInstancer.Removed = value; break; } case (AtomBaseVariableEventReferenceUsage.EVENT): { _event = value; break; } default: throw new NotSupportedException($"Event not reassignable for usage {_usage}."); } } } /// /// Collection used if `Usage` is set to `COLLECTION_ADDED_EVENT` or `COLLECTION_REMOVED_EVENT`. /// [SerializeField] private AtomCollection _collection = default(AtomCollection); /// /// List used if `Usage` is set to `LIST_ADDED_EVENT` or `LIST_REMOVED_EVENT`. /// [SerializeField] private AtomList _list = default(AtomList); /// /// Collection Instancer used if `Usage` is set to `COLLECTION_INSTANCER_ADDED_EVENT` or `COLLECTION_INSTANCER_REMOVED_EVENT`. /// [SerializeField] private AtomCollectionInstancer _collectionInstancer = default(AtomCollectionInstancer); /// /// List Instancer used if `Usage` is set to `LIST_INSTANCER_ADDED_EVENT` or `LIST_INSTANCER_REMOVED_EVENT`. /// [SerializeField] private AtomListInstancer _listInstancer = default(AtomListInstancer); } }