Cleaned up code readability, naming style to be consistent

* Add abstract modifier to all generic classes meant not to be instantiated directly as the intent is to specify a pattern for a closed type that can be serialized.
* Added sealed keyword to all closed types. This is an incidental performance improvement for mobile and desktop platforms utilizing il2cpp due to the way unsealed vs sealed virtual methods are handled in generated C++ code.
* Also sealed all inspectors to mark them as closed types.
* Dropped all where constraints to the next line as most of these class declarations break 120-130 characters. This should help improve readability and make this style consistent as it has been in use for the most-complex generic types already, but not for others.
* Dropped all generic type parameters (generally) numbering three or more to the next line to improve readability.
* Where found, added empty lines between property/field declarations in classes to improve readability.
* Extracted several 2x event classes into their own files to match convention established by other event classes.
* Removed unecessary meta files for C# solution.
* Added compiler options file (csc.rsp) file for the Unity project and added global warning ignore for 0649 (Field 'field' is never assigned to, and will always have its default value 'value'). This is necessary since 2018.3 switched the compiler to Roslyn and by design they have decided to not suppress this warning for monobehavior fields that are private, but serialized. This is very widely contested as most developers will not make every field needed to be assigned in the Editor as public (breaks encapsulation, opens surface area for bugs) and this can in some cases generate hundreds if not thousands of warnings. Adding the compiler options file suppresses this warning which also may hide legitimate warnings, but is far the lesser of two evils.
* Moved example scripts not in a namespace to UnityAtoms.Examples.
* Reordered public/private fields and properties to be consistent. Order is as follows; public and private properties followed by public/private fields.
* Renamed private fields to use '_' prefix and marked public fields as private where only used internally. Marked these fields with FormerlySerializedAs attribute to preserve older serialized values already in use.
* Removed redundant initialization of null to reference types as this is their default value.
* Marked implicitly private methods and members without an access modifier as explicitly private.
* Updated unit tests to use new private name field when getting private member field info.
This commit is contained in:
Jeff Campbell 2019-04-07 16:03:16 +02:00
parent 82fe803d48
commit 943451b3d5
170 changed files with 1061 additions and 644 deletions

View File

@ -7,15 +7,22 @@ using UnityEngine;
namespace UnityAtoms
{
public class AtomicTags : MonoBehaviour, ISerializationCallbackReceiver
public sealed class AtomicTags : MonoBehaviour, ISerializationCallbackReceiver
{
public ReadOnlyList<StringConstant> Tags { get; private set; }
private SortedList<string, StringConstant> sortedTags = new SortedList<string, StringConstant>();
private static Dictionary<string, List<GameObject>> taggedGOs = new Dictionary<string, List<GameObject>>();
private static Dictionary<GameObject, AtomicTags> instances = new Dictionary<GameObject, AtomicTags>();
private SortedList<string, StringConstant> _sortedTags = new SortedList<string, StringConstant>();
private static readonly Dictionary<string, List<GameObject>> TaggedGameObjects
= new Dictionary<string, List<GameObject>>();
private static readonly Dictionary<GameObject, AtomicTags> AtomicTagInstances
= new Dictionary<GameObject, AtomicTags>();
public List<StringConstant> _tags = new List<StringConstant>();
#region Serialization
public List<StringConstant> _tags = new List<StringConstant>();
public void OnBeforeSerialize()
{
#if UNITY_EDITOR
@ -24,7 +31,7 @@ namespace UnityAtoms
&& !EditorApplication.isCompiling) return;
#endif
_tags.Clear();
foreach (var kvp in sortedTags)
foreach (var kvp in _sortedTags)
{
_tags.Add(kvp.Value);
}
@ -32,13 +39,13 @@ namespace UnityAtoms
public void OnAfterDeserialize()
{
sortedTags = new SortedList<string, StringConstant>();
_sortedTags = new SortedList<string, StringConstant>();
for (int i = 0; i != _tags.Count; i++)
{
if (_tags[i] == null || _tags[i].Value == null) continue;
if (sortedTags.ContainsKey(_tags[i].Value)) continue;
sortedTags.Add(_tags[i].Value, _tags[i]);
if (_sortedTags.ContainsKey(_tags[i].Value)) continue;
_sortedTags.Add(_tags[i].Value, _tags[i]);
}
}
#endregion
@ -47,11 +54,10 @@ namespace UnityAtoms
private void OnValidate()
{
OnAfterDeserialize(); // removes double values and nulls
_tags = sortedTags.Values.ToList();
_tags = _sortedTags.Values.ToList();
// this null value is just for easier editing and could also be archived with an custom inspector
if(!EditorApplication.isPlaying){ _tags.Add(null); }
}
#endif
@ -59,31 +65,31 @@ namespace UnityAtoms
private void Awake()
{
Tags = new ReadOnlyList<StringConstant>(sortedTags.Values);
Tags = new ReadOnlyList<StringConstant>(_sortedTags.Values);
}
private void OnEnable()
{
if (!instances.ContainsKey(gameObject)) instances.Add(gameObject, this);
if (!AtomicTagInstances.ContainsKey(gameObject)) AtomicTagInstances.Add(gameObject, this);
for (var i = 0; i < Tags.Count; i++)
{
var stringConstant = Tags[i];
if (stringConstant == null) continue;
var atomicTag = stringConstant.Value;
if (!taggedGOs.ContainsKey(atomicTag)) taggedGOs.Add(atomicTag, new List<GameObject>());
taggedGOs[atomicTag].Add(gameObject);
if (!TaggedGameObjects.ContainsKey(atomicTag)) TaggedGameObjects.Add(atomicTag, new List<GameObject>());
TaggedGameObjects[atomicTag].Add(gameObject);
}
}
private void OnDisable()
{
if (instances.ContainsKey(gameObject)) instances.Remove(gameObject);
if (AtomicTagInstances.ContainsKey(gameObject)) AtomicTagInstances.Remove(gameObject);
for (var i = 0; i < Tags.Count; i++)
{
var stringConstant = Tags[i];
if (stringConstant == null) continue;
var atomicTag = stringConstant.Value;
if (taggedGOs.ContainsKey(atomicTag)) taggedGOs[atomicTag].Remove(gameObject);
if (TaggedGameObjects.ContainsKey(atomicTag)) TaggedGameObjects[atomicTag].Remove(gameObject);
}
}
@ -92,54 +98,54 @@ namespace UnityAtoms
public bool HasTag(string atomicTag)
{
if (atomicTag == null) return false;
return sortedTags.ContainsKey(atomicTag);
return _sortedTags.ContainsKey(atomicTag);
}
public void AddTag(StringConstant atomicTag)
{
if (atomicTag == null || atomicTag.Value == null) return;
if (sortedTags.ContainsKey(atomicTag.Value)) return;
sortedTags.Add(atomicTag.Value, atomicTag);
if (_sortedTags.ContainsKey(atomicTag.Value)) return;
_sortedTags.Add(atomicTag.Value, atomicTag);
Tags = new ReadOnlyList<StringConstant>(sortedTags.Values);
Tags = new ReadOnlyList<StringConstant>(_sortedTags.Values);
// Update static accessors:
if (!taggedGOs.ContainsKey(atomicTag.Value)) taggedGOs.Add(atomicTag.Value, new List<GameObject>());
taggedGOs[atomicTag.Value].Add(this.gameObject);
if (!TaggedGameObjects.ContainsKey(atomicTag.Value)) TaggedGameObjects.Add(atomicTag.Value, new List<GameObject>());
TaggedGameObjects[atomicTag.Value].Add(this.gameObject);
}
public void RemoveTag(string atomicTag)
{
if (atomicTag == null) return;
if (sortedTags.ContainsKey(atomicTag)) return;
sortedTags.Remove(atomicTag);
if (_sortedTags.ContainsKey(atomicTag)) return;
_sortedTags.Remove(atomicTag);
Tags = new ReadOnlyList<StringConstant>(sortedTags.Values);
Tags = new ReadOnlyList<StringConstant>(_sortedTags.Values);
// Update static accessors:
if (!taggedGOs.ContainsKey(atomicTag)) return; // this should never happen
taggedGOs[atomicTag].Remove(this.gameObject);
if (!TaggedGameObjects.ContainsKey(atomicTag)) return; // this should never happen
TaggedGameObjects[atomicTag].Remove(this.gameObject);
}
public static GameObject FindByTag(string tag)
{
if (!taggedGOs.ContainsKey(tag)) return null;
return taggedGOs[tag][0];
if (!TaggedGameObjects.ContainsKey(tag)) return null;
return TaggedGameObjects[tag][0];
}
public static GameObject[] FindAllByTag(string tag)
{
if (!taggedGOs.ContainsKey(tag)) return null;
return taggedGOs[tag].ToArray();
if (!TaggedGameObjects.ContainsKey(tag)) return null;
return TaggedGameObjects[tag].ToArray();
}
public static void FindAllByTagNoAlloc(string tag, List<GameObject> output)
{
output.Clear();
if (!taggedGOs.ContainsKey(tag)) return;
for (var i = 0; i < taggedGOs[tag].Count; ++i)
if (!TaggedGameObjects.ContainsKey(tag)) return;
for (var i = 0; i < TaggedGameObjects[tag].Count; ++i)
{
output.Add(taggedGOs[tag][i]);
output.Add(TaggedGameObjects[tag][i]);
}
}
@ -152,8 +158,8 @@ namespace UnityAtoms
/// </returns>
public static AtomicTags GetForGameObject(GameObject go)
{
if (!instances.ContainsKey(go)) return null;
return instances[go];
if (!AtomicTagInstances.ContainsKey(go)) return null;
return AtomicTagInstances[go];
}
/// <summary>
@ -166,8 +172,8 @@ namespace UnityAtoms
/// </returns>
public static ReadOnlyList<StringConstant> GetAtomicTags(GameObject go)
{
if (!instances.ContainsKey(go)) return null;
var atomicTags = instances[go];
if (!AtomicTagInstances.ContainsKey(go)) return null;
var atomicTags = AtomicTagInstances[go];
return atomicTags.Tags;
}
}

View File

@ -1,35 +1,62 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
namespace UnityAtoms {
/// <summary>
/// This is basically an IList without everything that could mutate the list
/// </summary>
public class ReadOnlyList<T> : IEnumerable, IEnumerable<T> {
private readonly IList<T> referenceList;
namespace UnityAtoms
{
/// <summary>
/// This is basically an IList without everything that could mutate the list
/// </summary>
public class ReadOnlyList<T> : IEnumerable<T>
{
private readonly IList<T> _referenceList;
public ReadOnlyList(IList<T> referenceList) { this.referenceList = referenceList; }
public ReadOnlyList(IList<T> referenceList)
{
_referenceList = referenceList;
}
public IEnumerator<T> GetEnumerator() { return referenceList.GetEnumerator(); }
#region IEnumerable<T>
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
public IEnumerator<T> GetEnumerator()
{
return _referenceList.GetEnumerator();
}
public bool Contains(T item) { return referenceList.Contains(item); }
public int IndexOf(T item) { return referenceList.IndexOf(item); }
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void CopyTo(T[] array, int arrayIndex) { referenceList.CopyTo(array, arrayIndex); }
#endregion
public int Count {
get { return referenceList.Count; }
}
public bool Contains(T item)
{
return _referenceList.Contains(item);
}
public bool IsReadOnly {
get { return true; }
}
public int IndexOf(T item)
{
return _referenceList.IndexOf(item);
}
public T this[int index] {
get { return referenceList[index]; }
}
}
public void CopyTo(T[] array, int arrayIndex)
{
_referenceList.CopyTo(array, arrayIndex);
}
}
public int Count
{
get { return _referenceList.Count; }
}
public bool IsReadOnly
{
get { return true; }
}
public T this[int index]
{
get { return _referenceList[index]; }
}
}
}

View File

@ -1,18 +1,22 @@
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms.UI
{
public class UIContainer : MonoBehaviour, IGameEventListener<string>
{
[FormerlySerializedAs("UIStateVariable")]
[SerializeField]
private StringVariable UIStateVariable = null;
[SerializeField]
private List<StringConstant> VisibleForStates = null;
private StringVariable _UIStateVariable;
void Start()
[FormerlySerializedAs("VisibleForStates")]
[SerializeField]
private List<StringConstant> _visibleForStates;
private void Start()
{
StateNameChanged(UIStateVariable.Value);
StateNameChanged(_UIStateVariable.Value);
}
public void OnEventRaised(string stateName)
@ -22,7 +26,7 @@ namespace UnityAtoms.UI
private void StateNameChanged(string stateName)
{
if (VisibleForStates.Exists((state) => state.Value == stateName))
if (_visibleForStates.Exists((state) => state.Value == stateName))
{
GetComponent<CanvasGroup>().alpha = 1f;
GetComponent<CanvasGroup>().blocksRaycasts = true;
@ -38,17 +42,17 @@ namespace UnityAtoms.UI
private void Awake()
{
if (UIStateVariable.Changed != null)
if (_UIStateVariable.Changed != null)
{
UIStateVariable.Changed.RegisterListener(this);
_UIStateVariable.Changed.RegisterListener(this);
}
}
private void OnDestroy()
{
if (UIStateVariable.Changed != null)
if (_UIStateVariable.Changed != null)
{
UIStateVariable.Changed.UnregisterListener(this);
_UIStateVariable.Changed.UnregisterListener(this);
}
}
}

View File

@ -1,148 +1,185 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms
{
public class ConditionalGameActionHelper<T1, GA, C> where GA : GameAction<T1> where C : GameFunction<bool, T1>
[Serializable]
public abstract class ConditionalGameActionHelper<T1, GA, C>
where GA : GameAction<T1>
where C : GameFunction<bool, T1>
{
[FormerlySerializedAs("Condition")]
[SerializeField]
private C Condition = null;
[SerializeField]
private GA Action = null;
[SerializeField]
private VoidAction VoidAction = null;
private C _condition;
[FormerlySerializedAs("Action")]
[SerializeField]
private GA ElseAction = null;
private GA _action;
[FormerlySerializedAs("VoidAction")]
[SerializeField]
private VoidAction ElseVoidAction = null;
private VoidAction _voidAction;
[FormerlySerializedAs("ElseAction")]
[SerializeField]
private GA _elseAction;
[FormerlySerializedAs("ElseVoidAction")]
[SerializeField]
private VoidAction _elseVoidAction;
public void Do(T1 t1)
{
if (Condition == null || Condition.Call(t1))
if (_condition == null || _condition.Call(t1))
{
if (Action != null) { Action.Do(t1); }
if (VoidAction != null) { VoidAction.Do(); }
if (_action != null) { _action.Do(t1); }
if (_voidAction != null) { _voidAction.Do(); }
}
else
{
if (ElseAction != null) { ElseAction.Do(t1); }
if (ElseVoidAction != null) { ElseVoidAction.Do(); }
if (_elseAction != null) { _elseAction.Do(t1); }
if (_elseVoidAction != null) { _elseVoidAction.Do(); }
}
}
}
public class ConditionalGameActionHelper<T1, T2, GA, C> where GA : GameAction<T1, T2> where C : GameFunction<bool, T1, T2>
[Serializable]
public abstract class ConditionalGameActionHelper<T1, T2, GA, C>
where GA : GameAction<T1, T2>
where C : GameFunction<bool, T1, T2>
{
[SerializeField]
private C Condition = null;
[SerializeField]
private GA Action = null;
[SerializeField]
private VoidAction VoidAction = null;
private C _condition;
[SerializeField]
private GA ElseAction = null;
private GA _action;
[SerializeField]
private VoidAction ElseVoidAction = null;
private VoidAction _voidAction;
[SerializeField]
private GA _elseAction;
[SerializeField]
private VoidAction _elseVoidAction;
public void Do(T1 t1, T2 t2)
{
if (Condition == null || Condition.Call(t1, t2))
if (_condition == null || _condition.Call(t1, t2))
{
if (Action != null) { Action.Do(t1, t2); }
if (VoidAction != null) { VoidAction.Do(); }
if (_action != null) { _action.Do(t1, t2); }
if (_voidAction != null) { _voidAction.Do(); }
}
else
{
if (ElseAction != null) { ElseAction.Do(t1, t2); }
if (ElseVoidAction != null) { ElseVoidAction.Do(); }
if (_elseAction != null) { _elseAction.Do(t1, t2); }
if (_elseVoidAction != null) { _elseVoidAction.Do(); }
}
}
}
public class ConditionalGameActionHelper<T1, T2, T3, GA, C> where GA : GameAction<T1, T2, T3> where C : GameFunction<bool, T1, T2, T3>
[Serializable]
public abstract class ConditionalGameActionHelper<T1, T2, T3, GA, C>
where GA : GameAction<T1, T2, T3>
where C : GameFunction<bool, T1, T2, T3>
{
[SerializeField]
private C Condition = null;
[SerializeField]
private GA Action = null;
[SerializeField]
private VoidAction VoidAction = null;
private C _condition;
[SerializeField]
private GA ElseAction = null;
private GA _action;
[SerializeField]
private VoidAction ElseVoidAction = null;
private VoidAction _voidAction;
[SerializeField]
private GA _elseAction;
[SerializeField]
private VoidAction _elseVoidAction;
public void Do(T1 t1, T2 t2, T3 t3)
{
if (Condition == null || Condition.Call(t1, t2, t3))
if (_condition == null || _condition.Call(t1, t2, t3))
{
if (Action != null) { Action.Do(t1, t2, t3); }
if (VoidAction != null) { VoidAction.Do(); }
if (_action != null) { _action.Do(t1, t2, t3); }
if (_voidAction != null) { _voidAction.Do(); }
}
else
{
if (ElseAction != null) { ElseAction.Do(t1, t2, t3); }
if (ElseVoidAction != null) { ElseVoidAction.Do(); }
if (_elseAction != null) { _elseAction.Do(t1, t2, t3); }
if (_elseVoidAction != null) { _elseVoidAction.Do(); }
}
}
}
public class ConditionalGameActionHelper<T1, T2, T3, T4, GA, C> where GA : GameAction<T1, T2, T3, T4> where C : GameFunction<bool, T1, T2, T3, T4>
[Serializable]
public abstract class ConditionalGameActionHelper<T1, T2, T3, T4, GA, C>
where GA : GameAction<T1, T2, T3, T4>
where C : GameFunction<bool, T1, T2, T3, T4>
{
[SerializeField]
private C Condition = null;
[SerializeField]
private GA Action = null;
[SerializeField]
private VoidAction VoidAction = null;
private C _condition;
[SerializeField]
private GA ElseAction = null;
private GA _action;
[SerializeField]
private VoidAction ElseVoidAction = null;
private VoidAction _voidAction;
[SerializeField]
private GA _elseAction;
[SerializeField]
private VoidAction _elseVoidAction;
public void Do(T1 t1, T2 t2, T3 t3, T4 t4)
{
if (Condition == null || Condition.Call(t1, t2, t3, t4))
if (_condition == null || _condition.Call(t1, t2, t3, t4))
{
if (Action != null) { Action.Do(t1, t2, t3, t4); }
if (VoidAction != null) { VoidAction.Do(); }
if (_action != null) { _action.Do(t1, t2, t3, t4); }
if (_voidAction != null) { _voidAction.Do(); }
}
else
{
if (ElseAction != null) { ElseAction.Do(t1, t2, t3, t4); }
if (ElseVoidAction != null) { ElseVoidAction.Do(); }
if (_elseAction != null) { _elseAction.Do(t1, t2, t3, t4); }
if (_elseVoidAction != null) { _elseVoidAction.Do(); }
}
}
}
public class ConditionalGameActionHelper<T1, T2, T3, T4, T5, GA, C> where GA : GameAction<T1, T2, T3, T4, T5> where C : GameFunction<bool, T1, T2, T3, T4, T5>
[Serializable]
public abstract class ConditionalGameActionHelper<T1, T2, T3, T4, T5, GA, C>
where GA : GameAction<T1, T2, T3, T4, T5>
where C : GameFunction<bool, T1, T2, T3, T4, T5>
{
[SerializeField]
private C Condition = null;
[SerializeField]
private GA Action = null;
[SerializeField]
private VoidAction VoidAction = null;
private C _condition;
[SerializeField]
private GA ElseAction = null;
private GA _action;
[SerializeField]
private VoidAction ElseVoidAction = null;
private VoidAction _voidAction;
[SerializeField]
private GA _elseAction;
[SerializeField]
private VoidAction _elseVoidAction;
public void Do(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
{
if (Condition == null || Condition.Call(t1, t2, t3, t4, t5))
if (_condition == null || _condition.Call(t1, t2, t3, t4, t5))
{
if (Action != null) { Action.Do(t1, t2, t3, t4, t5); }
if (VoidAction != null) { VoidAction.Do(); }
if (_action != null) { _action.Do(t1, t2, t3, t4, t5); }
if (_voidAction != null) { _voidAction.Do(); }
}
else
{
if (ElseAction != null) { ElseAction.Do(t1, t2, t3, t4, t5); }
if (ElseVoidAction != null) { ElseVoidAction.Do(); }
if (_elseAction != null) { _elseAction.Do(t1, t2, t3, t4, t5); }
if (_elseVoidAction != null) { _elseVoidAction.Do(); }
}
}
}

View File

@ -4,7 +4,7 @@ using UnityEngine.Events;
namespace UnityAtoms
{
public class CreateEventOnAwake<T, E1, E2, L1, L2, GA1, GA2, UER1, UER2, MH> : MonoBehaviour
public abstract class CreateEventOnAwake<T, E1, E2, L1, L2, GA1, GA2, UER1, UER2, MH> : MonoBehaviour
where E1 : GameEvent<T> where E2 : GameEvent<T, GameObject>
where L1 : GameEventListener<T, GA1, E1, UER1> where L2 : GameEventListener<T, GameObject, GA2, E2, UER2>
where GA1 : GameAction<T> where GA2 : GameAction<T, GameObject>
@ -12,13 +12,16 @@ namespace UnityAtoms
where MH : MonoHook<E1, E2, T, GameObjectGameObjectFunction>
{
public bool CreateEvent = true;
public bool CreateEventWithGameObject = false;
public bool CreateEventWithGameObject;
public List<MH> MonoHooks;
public L1 Listener = null;
public L2 ListenerWithGameObject = null;
void Awake()
public L1 Listener;
public L2 ListenerWithGameObject;
private void Awake()
{
var e1 = CreateEvent ? ScriptableObject.CreateInstance<E1>() : null;
var e2 = CreateEventWithGameObject ? ScriptableObject.CreateInstance<E2>() : null;
@ -39,7 +42,7 @@ namespace UnityAtoms
{
for (int i = 0; MonoHooks != null && i < MonoHooks.Count; ++i)
{
MonoHooks[i].EventWithGORef = e2;
MonoHooks[i].EventWithGameObjectReference = e2;
}
if (ListenerWithGameObject != null)
{

View File

@ -1,66 +1,80 @@
using UnityEngine;
using UnityEngine.Events;
using UnityAtoms.Utils;
using UnityEngine.Serialization;
namespace UnityAtoms
{
public class CreateListOnAwake<T, L, E, TEL, TELR, GA1, GA2, UER> : MonoBehaviour
public abstract class CreateListOnAwake<T, L, E, TEL, TELR, GA1, GA2, UER> : MonoBehaviour
where L : ScriptableObjectList<T, E> where E : GameEvent<T>
where TEL : GameEventListener<T, TELR, E, UER>
where TELR : GameAction<T>
where GA1 : GameAction<L> where GA2 : GameAction<L, GameObject>
where UER : UnityEvent<T>
{
[FormerlySerializedAs("CreateAddedEvent")]
[SerializeField]
private bool CreateAddedEvent = true;
[SerializeField]
private bool CreateRemovedEvent = true;
[SerializeField]
private bool CreateClearedEvent = false;
private bool _createAddedEvent = true;
[FormerlySerializedAs("CreateRemovedEvent")]
[SerializeField]
private TEL AddedListener = null;
[SerializeField]
private TEL RemovedListener = null;
[SerializeField]
private VoidListener ClearedListener = null;
private bool _createRemovedEvent = true;
[FormerlySerializedAs("CreateClearedEvent")]
[SerializeField]
private GA1 OnListCreate = null;
[SerializeField]
private GA2 OnListCreateWithGO = null;
private bool _createClearedEvent;
void Awake()
[FormerlySerializedAs("AddedListener")]
[SerializeField]
private TEL _addedListener;
[FormerlySerializedAs("RemovedListener")]
[SerializeField]
private TEL _removedListener;
[FormerlySerializedAs("ClearedListener")]
[SerializeField]
private VoidListener _clearedListener;
[FormerlySerializedAs("OnListCreate")]
[SerializeField]
private GA1 _onListCreate;
[FormerlySerializedAs("OnListCreateWithGO")]
[SerializeField]
private GA2 _onListCreateWithGO;
private void Awake()
{
var list = DynamicAtoms.CreateList<T, L, E>(CreateAddedEvent, CreateRemovedEvent, CreateClearedEvent);
var list = DynamicAtoms.CreateList<T, L, E>(_createAddedEvent, _createRemovedEvent, _createClearedEvent);
if (list.Added != null)
{
if (AddedListener != null)
if (_addedListener != null)
{
AddedListener.GameEvent = list.Added;
AddedListener.GameEvent.RegisterListener(AddedListener);
_addedListener.GameEvent = list.Added;
_addedListener.GameEvent.RegisterListener(_addedListener);
}
}
if (list.Removed != null)
{
if (RemovedListener != null)
if (_removedListener != null)
{
RemovedListener.GameEvent = list.Removed;
RemovedListener.GameEvent.RegisterListener(RemovedListener);
_removedListener.GameEvent = list.Removed;
_removedListener.GameEvent.RegisterListener(_removedListener);
}
}
if (list.Cleared != null)
{
if (ClearedListener != null)
if (_clearedListener != null)
{
ClearedListener.GameEvent = list.Cleared;
ClearedListener.GameEvent.RegisterListener(ClearedListener);
_clearedListener.GameEvent = list.Cleared;
_clearedListener.GameEvent.RegisterListener(_clearedListener);
}
}
if (OnListCreate != null) { OnListCreate.Do(list); }
if (OnListCreateWithGO != null) { OnListCreateWithGO.Do(list, gameObject); }
if (_onListCreate != null) { _onListCreate.Do(list); }
if (_onListCreateWithGO != null) { _onListCreateWithGO.Do(list, gameObject); }
}
}
}

View File

@ -1,53 +1,69 @@
using UnityEngine;
using UnityEngine.Events;
using UnityAtoms.Utils;
using UnityEngine.Serialization;
namespace UnityAtoms
{
public class CreateVariableOnAwake<T, V, E1, E2, L1, L2, GA1, GA2, GA3, GA4, UER1, UER2> : MonoBehaviour
where V : ScriptableObjectVariable<T, E1, E2> where E1 : GameEvent<T> where E2 : GameEvent<T, T>
where L1 : GameEventListener<T, GA1, E1, UER1> where L2 : GameEventListener<T, T, GA2, E2, UER2>
where GA1 : GameAction<T> where GA2 : GameAction<T, T>
where GA3 : GameAction<V> where GA4 : GameAction<V, GameObject>
where UER1 : UnityEvent<T> where UER2 : UnityEvent<T, T>
public abstract class CreateVariableOnAwake<T, V, E1, E2, L1, L2, GA1, GA2, GA3, GA4, UER1, UER2> : MonoBehaviour
where V : ScriptableObjectVariable<T, E1, E2>
where E1 : GameEvent<T>
where E2 : GameEvent<T, T>
where L1 : GameEventListener<T, GA1, E1, UER1>
where L2 : GameEventListener<T, T, GA2, E2, UER2>
where GA1 : GameAction<T>
where GA2 : GameAction<T, T>
where GA3 : GameAction<V>
where GA4 : GameAction<V, GameObject>
where UER1 : UnityEvent<T>
where UER2 : UnityEvent<T, T>
{
[FormerlySerializedAs("CreateChangedEvent")]
[SerializeField]
private bool CreateChangedEvent = true;
[SerializeField]
private bool CreateChangedWithHistoryEvent = false;
private bool _createChangedEvent = true;
[FormerlySerializedAs("CreateChangedWithHistoryEvent")]
[SerializeField]
private L1 Listener = null;
[SerializeField]
private L2 ListenerWithHistory = null;
private bool _createChangedWithHistoryEvent;
[FormerlySerializedAs("Listener")]
[SerializeField]
private GA3 OnVariableCreate = null;
[SerializeField]
private GA4 OnVariableCreateWithGO = null;
private L1 _listener;
void Awake()
[FormerlySerializedAs("ListenerWithHistory")]
[SerializeField]
private L2 _listenerWithHistory;
[FormerlySerializedAs("OnVariableCreate")]
[SerializeField]
private GA3 _onVariableCreate;
[FormerlySerializedAs("OnVariableCreateWithGO")]
[SerializeField]
private GA4 _onVariableCreateWithGO;
private void Awake()
{
var variable = DynamicAtoms.CreateVariable<T, V, E1, E2>(CreateChangedEvent, CreateChangedWithHistoryEvent);
var variable = DynamicAtoms.CreateVariable<T, V, E1, E2>(_createChangedEvent, _createChangedWithHistoryEvent);
if (variable.Changed != null)
{
if (Listener != null)
if (_listener != null)
{
Listener.GameEvent = variable.Changed;
Listener.GameEvent.RegisterListener(Listener);
_listener.GameEvent = variable.Changed;
_listener.GameEvent.RegisterListener(_listener);
}
}
if (variable.ChangedWithHistory != null)
{
if (ListenerWithHistory != null)
if (_listenerWithHistory != null)
{
ListenerWithHistory.GameEvent = variable.ChangedWithHistory;
ListenerWithHistory.GameEvent.RegisterListener(ListenerWithHistory);
_listenerWithHistory.GameEvent = variable.ChangedWithHistory;
_listenerWithHistory.GameEvent.RegisterListener(_listenerWithHistory);
}
}
if (OnVariableCreate != null) { OnVariableCreate.Do(variable); }
if (OnVariableCreateWithGO != null) { OnVariableCreateWithGO.Do(variable, gameObject); }
if (_onVariableCreate != null) { _onVariableCreate.Do(variable); }
if (_onVariableCreateWithGO != null) { _onVariableCreateWithGO.Do(variable, gameObject); }
}
}
}

View File

@ -5,47 +5,47 @@ namespace UnityAtoms
{
public abstract class GameEvent<T> : ScriptableObject
{
private readonly List<IGameEventListener<T>> eventListeners = new List<IGameEventListener<T>>();
private readonly List<IGameEventListener<T>> _eventListeners = new List<IGameEventListener<T>>();
public void Raise(T item)
{
for (int i = eventListeners.Count - 1; i >= 0; i--)
eventListeners[i].OnEventRaised(item);
for (int i = _eventListeners.Count - 1; i >= 0; i--)
_eventListeners[i].OnEventRaised(item);
}
public void RegisterListener(IGameEventListener<T> listener)
{
if (!eventListeners.Contains(listener))
eventListeners.Add(listener);
if (!_eventListeners.Contains(listener))
_eventListeners.Add(listener);
}
public void UnregisterListener(IGameEventListener<T> listener)
{
if (eventListeners.Contains(listener))
eventListeners.Remove(listener);
if (_eventListeners.Contains(listener))
_eventListeners.Remove(listener);
}
}
public abstract class GameEvent<T1, T2> : ScriptableObject
{
private readonly List<IGameEventListener<T1, T2>> eventListeners = new List<IGameEventListener<T1, T2>>();
private readonly List<IGameEventListener<T1, T2>> _eventListeners = new List<IGameEventListener<T1, T2>>();
public void Raise(T1 item1, T2 item2)
{
for (int i = eventListeners.Count - 1; i >= 0; i--)
eventListeners[i].OnEventRaised(item1, item2);
for (int i = _eventListeners.Count - 1; i >= 0; i--)
_eventListeners[i].OnEventRaised(item1, item2);
}
public void RegisterListener(IGameEventListener<T1, T2> listener)
{
if (!eventListeners.Contains(listener))
eventListeners.Add(listener);
if (!_eventListeners.Contains(listener))
_eventListeners.Add(listener);
}
public void UnregisterListener(IGameEventListener<T1, T2> listener)
{
if (eventListeners.Contains(listener))
eventListeners.Remove(listener);
if (_eventListeners.Contains(listener))
_eventListeners.Remove(listener);
}
}
}

View File

@ -1,25 +1,31 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Serialization;
namespace UnityAtoms
{
public abstract class GameEventListener<T, GA, E, UER> : MonoBehaviour, IGameEventListener<T> where GA : GameAction<T> where E : GameEvent<T> where UER : UnityEvent<T>
public abstract class GameEventListener<T, GA, E, UER> : MonoBehaviour, IGameEventListener<T>
where GA : GameAction<T>
where E : GameEvent<T> where UER : UnityEvent<T>
{
[FormerlySerializedAs("Event")]
[SerializeField]
private E Event = null;
private E _event;
public E GameEvent { get { return Event; } set { Event = value; } }
public E GameEvent { get { return _event; } set { _event = value; } }
[FormerlySerializedAs("UnityEventResponse")]
[SerializeField]
private UER UnityEventResponse = null;
private UER _unityEventResponse;
[FormerlySerializedAs("GameActionResponses")]
[SerializeField]
private List<GA> GameActionResponses = new List<GA>();
private List<GA> _gameActionResponses = new List<GA>();
private void OnEnable()
{
if (Event == null) return;
if (_event == null) return;
GameEvent.RegisterListener(this);
}
@ -30,45 +36,51 @@ namespace UnityAtoms
public void OnEventRaised(T item)
{
if (UnityEventResponse != null) { UnityEventResponse.Invoke(item); }
for (int i = 0; GameActionResponses != null && i < GameActionResponses.Count; ++i)
if (_unityEventResponse != null) { _unityEventResponse.Invoke(item); }
for (int i = 0; _gameActionResponses != null && i < _gameActionResponses.Count; ++i)
{
GameActionResponses[i].Do(item);
_gameActionResponses[i].Do(item);
}
}
}
public abstract class GameEventListener<T1, T2, GA, E, UER> : MonoBehaviour, IGameEventListener<T1, T2> where GA : GameAction<T1, T2> where E : GameEvent<T1, T2> where UER : UnityEvent<T1, T2>
public abstract class GameEventListener<T1, T2, GA, E, UER> : MonoBehaviour, IGameEventListener<T1, T2>
where GA : GameAction<T1, T2>
where E : GameEvent<T1, T2>
where UER : UnityEvent<T1, T2>
{
[FormerlySerializedAs("Event")]
[SerializeField]
private E Event = null;
private E _event;
public E GameEvent { get { return Event; } set { Event = value; } }
public E GameEvent { get { return _event; } set { _event = value; } }
[FormerlySerializedAs("UnityEventResponse")]
[SerializeField]
private UER UnityEventResponse = null;
private UER _unityEventResponse;
[FormerlySerializedAs("GameActionResponses")]
[SerializeField]
private List<GA> GameActionResponses = new List<GA>();
private List<GA> _gameActionResponses = new List<GA>();
private void OnEnable()
{
if (Event == null) return;
if (_event == null) return;
GameEvent.RegisterListener(this);
}
private void OnDisable()
{
if (Event == null) return;
if (_event == null) return;
GameEvent.UnregisterListener(this);
}
public void OnEventRaised(T1 first, T2 second)
{
if (UnityEventResponse != null) { UnityEventResponse.Invoke(first, second); }
for (int i = 0; GameActionResponses != null && i < GameActionResponses.Count; ++i)
if (_unityEventResponse != null) { _unityEventResponse.Invoke(first, second); }
for (int i = 0; _gameActionResponses != null && i < _gameActionResponses.Count; ++i)
{
GameActionResponses[i].Do(first, second);
_gameActionResponses[i].Do(first, second);
}
}
}

View File

@ -5,16 +5,20 @@ using UnityAtoms.Extensions;
namespace UnityAtoms
{
public abstract class ScriptableObjectList<T, E> : ScriptableObject where E : GameEvent<T>
public abstract class ScriptableObjectList<T, E> : ScriptableObject
where E : GameEvent<T>
{
[SerializeField]
private List<T> list = new List<T>();
public E Added;
public E Removed;
public VoidEvent Cleared;
public int Count { get { return list.Count; } }
[SerializeField]
private List<T> list = new List<T>();
public void Add(T item)
{
if (!list.Contains(item))

View File

@ -1,16 +1,23 @@
namespace UnityAtoms
{
public abstract class ScriptableObjectReference<T, V, E1, E2> where E1 : GameEvent<T> where E2 : GameEvent<T, T> where V : ScriptableObjectVariable<T, E1, E2>
public abstract class ScriptableObjectReference<T, V, E1, E2>
where E1 : GameEvent<T>
where E2 : GameEvent<T, T>
where V : ScriptableObjectVariable<T, E1, E2>
{
public bool UseConstant = true;
public bool UseConstant;
public T ConstantValue;
public V Variable;
public ScriptableObjectReference() { }
public ScriptableObjectReference(T value)
protected ScriptableObjectReference()
{
UseConstant = true;
}
protected ScriptableObjectReference(T value) : this()
{
ConstantValue = value;
}

View File

@ -1,18 +1,25 @@
using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms
{
public abstract class SetVariableValue<T, V, R, E1, E2> : VoidAction where E1 : GameEvent<T> where E2 : GameEvent<T, T> where V : ScriptableObjectVariable<T, E1, E2> where R : ScriptableObjectReference<T, V, E1, E2>
public abstract class SetVariableValue<T, V, R, E1, E2> : VoidAction
where E1 : GameEvent<T>
where E2 : GameEvent<T, T>
where V : ScriptableObjectVariable<T, E1, E2>
where R : ScriptableObjectReference<T, V, E1, E2>
{
[FormerlySerializedAs("Variable")]
[SerializeField]
private V Variable = null;
private V _variable;
[FormerlySerializedAs("Value")]
[SerializeField]
private R Value = null;
private R _value;
public override void Do()
{
Variable.Value = Value.Value;
_variable.Value = _value.Value;
}
}
}

View File

@ -1,8 +1,11 @@
using System;
using System;
namespace UnityAtoms
{
public abstract class EquatableScriptableObjectVariable<T, E1, E2> : ScriptableObjectVariable<T, E1, E2> where T : IEquatable<T> where E1 : GameEvent<T> where E2 : GameEvent<T, T>
public abstract class EquatableScriptableObjectVariable<T, E1, E2> : ScriptableObjectVariable<T, E1, E2>
where T : IEquatable<T>
where E1 : GameEvent<T>
where E2 : GameEvent<T, T>
{
protected override bool AreEqual(T t1, T t2)
{

View File

@ -2,7 +2,10 @@ using System;
namespace UnityAtoms
{
public interface IWithApplyChange<T, E1, E2> where T : IEquatable<T> where E1 : GameEvent<T> where E2 : GameEvent<T, T>
public interface IWithApplyChange<T, E1, E2>
where T : IEquatable<T>
where E1 : GameEvent<T>
where E2 : GameEvent<T, T>
{
bool ApplyChange(T amount);
bool ApplyChange(EquatableScriptableObjectVariable<T, E1, E2> amount);

View File

@ -1,15 +1,20 @@
using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms
{
public abstract class ScriptableObjectVariable<T, E1, E2> : ScriptableObjectVariableBase<T>, IWithOldValue<T> where E1 : GameEvent<T> where E2 : GameEvent<T, T>
public abstract class ScriptableObjectVariable<T, E1, E2> : ScriptableObjectVariableBase<T>,
IWithOldValue<T>
where E1 : GameEvent<T>
where E2 : GameEvent<T, T>
{
public override T Value { get { return value; } set { SetValue(value); } }
public override T Value { get { return _value; } set { SetValue(value); } }
public T OldValue { get { return oldValue; } }
public T OldValue { get { return _oldValue; } }
[FormerlySerializedAs("oldValue")]
[SerializeField]
private T oldValue;
private T _oldValue;
public E1 Changed;
@ -25,12 +30,12 @@ namespace UnityAtoms
public bool SetValue(T newValue)
{
if (!AreEqual(value, newValue))
if (!AreEqual(_value, newValue))
{
oldValue = value;
value = newValue;
_oldValue = _value;
_value = newValue;
if (Changed != null) { Changed.Raise(newValue); }
if (ChangedWithHistory != null) { ChangedWithHistory.Raise(value, oldValue); }
if (ChangedWithHistory != null) { ChangedWithHistory.Raise(_value, _oldValue); }
return true;
}

View File

@ -1,33 +1,35 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms
{
public abstract class ScriptableObjectVariableBase<T> : ScriptableObject, IWithValue<T>
{
public virtual T Value { get { return _value; } set { throw new NotImplementedException(); } }
[Multiline]
public string DeveloperDescription = "";
public virtual T Value { get { return value; } set { throw new NotImplementedException(); } }
[FormerlySerializedAs("value")]
[SerializeField]
protected T value;
protected T _value;
protected bool Equals(ScriptableObjectVariableBase<T> other) {
return EqualityComparer<T>.Default.Equals(value, other.value);
return EqualityComparer<T>.Default.Equals(_value, other._value);
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
if (obj.GetType() != GetType()) return false;
return Equals((ScriptableObjectVariableBase<T>) obj);
}
public override int GetHashCode() {
unchecked {
return EqualityComparer<T>.Default.GetHashCode(value);
return EqualityComparer<T>.Default.GetHashCode(_value);
}
}

View File

@ -2,7 +2,6 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Bool/Event x 2", fileName = "BoolBoolEvent", order = CreateAssetMenuUtils.Order.EVENTx2)]
public class BoolBoolEvent : GameEvent<bool, bool> { }
public sealed class BoolBoolEvent : GameEvent<bool, bool> { }
}

View File

@ -3,5 +3,5 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Bool/Constant", fileName = "BoolConstant", order = CreateAssetMenuUtils.Order.CONSTANT)]
public class BoolConstant : ScriptableObjectVariableBase<bool> { }
public sealed class BoolConstant : ScriptableObjectVariableBase<bool> { }
}

View File

@ -2,7 +2,6 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Bool/Event", fileName = "BoolEvent", order = CreateAssetMenuUtils.Order.EVENT)]
public class BoolEvent : GameEvent<bool> { }
public sealed class BoolEvent : GameEvent<bool> { }
}

View File

@ -3,5 +3,5 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Bool/List", fileName = "BoolList", order = CreateAssetMenuUtils.Order.LIST)]
public class BoolList : ScriptableObjectList<bool, BoolEvent> { }
public sealed class BoolList : ScriptableObjectList<bool, BoolEvent> { }
}

View File

@ -1,4 +1,9 @@
namespace UnityAtoms
{
public class BoolListener : GameEventListener<bool, BoolAction, BoolEvent, UnityBoolEvent> { }
public sealed class BoolListener : GameEventListener<
bool,
BoolAction,
BoolEvent,
UnityBoolEvent>
{ }
}

View File

@ -3,5 +3,9 @@ using System;
namespace UnityAtoms
{
[Serializable]
public class BoolReference : ScriptableObjectReference<bool, BoolVariable, BoolEvent, BoolBoolEvent> { }
public sealed class BoolReference : ScriptableObjectReference<
bool,
BoolVariable,
BoolEvent,
BoolBoolEvent> { }
}

View File

@ -1,7 +1,7 @@
using UnityEngine;
using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Bool/Variable", fileName = "BoolVariable", order = CreateAssetMenuUtils.Order.VARIABLE)]
public class BoolVariable : EquatableScriptableObjectVariable<bool, BoolEvent, BoolBoolEvent> { }
public sealed class BoolVariable : EquatableScriptableObjectVariable<bool, BoolEvent, BoolBoolEvent> { }
}

View File

@ -1,5 +1,6 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms
{
@ -7,14 +8,15 @@ namespace UnityAtoms
public class ConditionalBoolGameActionHelper : ConditionalGameActionHelper<bool, BoolAction, BoolBoolFunction> { }
[CreateAssetMenu(menuName = "Unity Atoms/Bool/Conditional", fileName = "ConditionalBoolAction", order = CreateAssetMenuUtils.Order.CONDITIONAL)]
public class ConditionalBoolAction : BoolAction
public sealed class ConditionalBoolAction : BoolAction
{
[FormerlySerializedAs("Conditional")]
[SerializeField]
private ConditionalBoolGameActionHelper Conditional = null;
private ConditionalBoolGameActionHelper _conditional;
public override void Do(bool t1)
{
Conditional.Do(t1);
_conditional.Do(t1);
}
}
}

View File

@ -1,7 +1,13 @@
using UnityEngine;
using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Bool/Set Variable", fileName = "SetBoolVariableValueAction", order = CreateAssetMenuUtils.Order.SET_VARIABLE)]
public class SetBoolVariableValue : SetVariableValue<bool, BoolVariable, BoolReference, BoolEvent, BoolBoolEvent> { }
public sealed class SetBoolVariableValue : SetVariableValue<
bool,
BoolVariable,
BoolReference,
BoolEvent,
BoolBoolEvent>
{ }
}

View File

@ -4,5 +4,5 @@ using UnityEngine.Events;
namespace UnityAtoms
{
[Serializable]
public class UnityBoolEvent : UnityEvent<bool> { }
public sealed class UnityBoolEvent : UnityEvent<bool> { }
}

View File

@ -1,7 +1,7 @@
using UnityEngine;
using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Collider/Event", fileName = "ColliderEvent", order = CreateAssetMenuUtils.Order.EVENT)]
public class ColliderEvent : GameEvent<Collider> { }
public sealed class ColliderEvent : GameEvent<Collider> { }
}

View File

@ -2,7 +2,6 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Collider/Event with GameObject", fileName = "ColliderGameObjectEvent", order = CreateAssetMenuUtils.Order.EVENT_WITH_GO)]
public class ColliderGameObjectEvent : GameEvent<Collider, GameObject> { }
public sealed class ColliderGameObjectEvent : GameEvent<Collider, GameObject> { }
}

View File

@ -2,5 +2,11 @@ using UnityEngine;
namespace UnityAtoms
{
public class ColliderGameObjectListener : GameEventListener<Collider, GameObject, ColliderGameObjectAction, ColliderGameObjectEvent, UnityColliderGameObjectEvent> { }
public sealed class ColliderGameObjectListener : GameEventListener<
Collider,
GameObject,
ColliderGameObjectAction,
ColliderGameObjectEvent,
UnityColliderGameObjectEvent>
{ }
}

View File

@ -5,5 +5,5 @@ using UnityEngine;
namespace UnityAtoms
{
[Serializable]
public class UnityColliderGameObjectEvent : UnityEvent<Collider, GameObject> { }
public sealed class UnityColliderGameObjectEvent : UnityEvent<Collider, GameObject> { }
}

View File

@ -1,7 +1,7 @@
using UnityEngine;
using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Collider2D/Event", fileName = "Collider2DEvent", order = CreateAssetMenuUtils.Order.EVENT)]
public class Collider2DEvent : GameEvent<Collider2D> { }
public sealed class Collider2DEvent : GameEvent<Collider2D> { }
}

View File

@ -2,7 +2,6 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Collider2D/Event with GameObject", fileName = "Collider2DGameObjectEvent", order = CreateAssetMenuUtils.Order.EVENT_WITH_GO)]
public class Collider2DGameObjectEvent : GameEvent<Collider2D, GameObject> { }
public sealed class Collider2DGameObjectEvent : GameEvent<Collider2D, GameObject> { }
}

View File

@ -2,5 +2,11 @@ using UnityEngine;
namespace UnityAtoms
{
public class Collider2DGameObjectListener : GameEventListener<Collider2D, GameObject, Collider2DGameObjectAction, Collider2DGameObjectEvent, UnityCollider2DGameObjectEvent> { }
public sealed class Collider2DGameObjectListener : GameEventListener<
Collider2D,
GameObject,
Collider2DGameObjectAction,
Collider2DGameObjectEvent,
UnityCollider2DGameObjectEvent>
{ }
}

View File

@ -1,7 +1,7 @@
using UnityEngine;
using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Collider2D/List", fileName = "Collider2DList", order = CreateAssetMenuUtils.Order.LIST)]
public class Collider2DList : ScriptableObjectList<Collider2D, Collider2DEvent> { }
public sealed class Collider2DList : ScriptableObjectList<Collider2D, Collider2DEvent> { }
}

View File

@ -2,5 +2,10 @@ using UnityEngine;
namespace UnityAtoms
{
public class Collider2DListener : GameEventListener<Collider2D, Collider2DAction, Collider2DEvent, UnityCollider2DEvent> { }
public sealed class Collider2DListener : GameEventListener<
Collider2D,
Collider2DAction,
Collider2DEvent,
UnityCollider2DEvent>
{ }
}

View File

@ -3,12 +3,16 @@ using UnityEngine;
namespace UnityAtoms
{
public class CreateCollider2DEventOnAwake : CreateEventOnAwake<
Collider2D, Collider2DEvent, Collider2DGameObjectEvent,
Collider2DListener, Collider2DGameObjectListener,
Collider2DAction, Collider2DGameObjectAction,
UnityCollider2DEvent, UnityCollider2DGameObjectEvent,
Collider2DHook
>
public sealed class CreateCollider2DEventOnAwake : CreateEventOnAwake<
Collider2D,
Collider2DEvent,
Collider2DGameObjectEvent,
Collider2DListener,
Collider2DGameObjectListener,
Collider2DAction,
Collider2DGameObjectAction,
UnityCollider2DEvent,
UnityCollider2DGameObjectEvent,
Collider2DHook>
{ }
}

View File

@ -2,5 +2,14 @@ using UnityEngine;
namespace UnityAtoms
{
public class CreateCollider2DListOnAwake : CreateListOnAwake<Collider2D, Collider2DList, Collider2DEvent, Collider2DListener, Collider2DAction, Collider2DListAction, Collider2DListGameObjectAction, UnityCollider2DEvent> { }
public sealed class CreateCollider2DListOnAwake : CreateListOnAwake<
Collider2D,
Collider2DList,
Collider2DEvent,
Collider2DListener,
Collider2DAction,
Collider2DListAction,
Collider2DListGameObjectAction,
UnityCollider2DEvent>
{ }
}

View File

@ -5,5 +5,5 @@ using UnityEngine;
namespace UnityAtoms
{
[Serializable]
public class UnityCollider2DEvent : UnityEvent<Collider2D> { }
public sealed class UnityCollider2DEvent : UnityEvent<Collider2D> { }
}

View File

@ -5,5 +5,5 @@ using UnityEngine;
namespace UnityAtoms
{
[Serializable]
public class UnityCollider2DGameObjectEvent : UnityEvent<Collider2D, GameObject> { }
public sealed class UnityCollider2DGameObjectEvent : UnityEvent<Collider2D, GameObject> { }
}

View File

@ -2,7 +2,6 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Color/Event x 2", fileName = "ColorColorEvent", order = CreateAssetMenuUtils.Order.EVENTx2)]
public class ColorColorEvent : GameEvent<Color, Color> { }
public sealed class ColorColorEvent : GameEvent<Color, Color> { }
}

View File

@ -3,5 +3,5 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Color/Constant", fileName = "ColorConstant", order = CreateAssetMenuUtils.Order.CONSTANT)]
public class ColorConstant : ScriptableObjectVariableBase<Color> { }
public sealed class ColorConstant : ScriptableObjectVariableBase<Color> { }
}

View File

@ -2,7 +2,6 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Color/Event", fileName = "ColorEvent", order = CreateAssetMenuUtils.Order.EVENT)]
public class ColorEvent : GameEvent<Color> { }
public sealed class ColorEvent : GameEvent<Color> { }
}

View File

@ -3,5 +3,5 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Color/List", fileName = "ColorList", order = CreateAssetMenuUtils.Order.LIST)]
public class ColorList : ScriptableObjectList<Color, ColorEvent> { }
public sealed class ColorList : ScriptableObjectList<Color, ColorEvent> { }
}

View File

@ -2,5 +2,10 @@ using UnityEngine;
namespace UnityAtoms
{
public class ColorListener : GameEventListener<Color, ColorAction, ColorEvent, UnityColorEvent> { }
public sealed class ColorListener : GameEventListener<
Color,
ColorAction,
ColorEvent,
UnityColorEvent>
{ }
}

View File

@ -4,5 +4,10 @@ using UnityEngine;
namespace UnityAtoms
{
[Serializable]
public class ColorReference : ScriptableObjectReference<Color, ColorVariable, ColorEvent, ColorColorEvent> { }
public sealed class ColorReference : ScriptableObjectReference<
Color,
ColorVariable,
ColorEvent,
ColorColorEvent>
{ }
}

View File

@ -3,7 +3,7 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Color/Variable", fileName = "ColorVariable", order = CreateAssetMenuUtils.Order.VARIABLE)]
public class ColorVariable : ScriptableObjectVariable<Color, ColorEvent, ColorColorEvent>
public sealed class ColorVariable : ScriptableObjectVariable<Color, ColorEvent, ColorColorEvent>
{
protected override bool AreEqual(Color first, Color second)
{

View File

@ -1,20 +1,22 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms
{
[Serializable]
public class ConditionalColorGameActionHelper : ConditionalGameActionHelper<Color, ColorAction, BoolColorFunction> { }
public sealed class ConditionalColorGameActionHelper : ConditionalGameActionHelper<Color, ColorAction, BoolColorFunction> { }
[CreateAssetMenu(menuName = "Unity Atoms/Color/Conditional", fileName = "ConditionalColorAction", order = CreateAssetMenuUtils.Order.CONDITIONAL)]
public class ConditionalColorAction : ColorAction
public sealed class ConditionalColorAction : ColorAction
{
[FormerlySerializedAs("Conditional")]
[SerializeField]
private ConditionalColorGameActionHelper Conditional = null;
private ConditionalColorGameActionHelper _conditional;
public override void Do(Color t1)
{
Conditional.Do(t1);
_conditional.Do(t1);
}
}
}

View File

@ -3,5 +3,11 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Color/Set Variable", fileName = "SetColorVariableValueAction", order = CreateAssetMenuUtils.Order.SET_VARIABLE)]
public class SetColorVariableValue : SetVariableValue<Color, ColorVariable, ColorReference, ColorEvent, ColorColorEvent> { }
public sealed class SetColorVariableValue : SetVariableValue<
Color,
ColorVariable,
ColorReference,
ColorEvent,
ColorColorEvent>
{ }
}

View File

@ -5,5 +5,5 @@ using UnityEngine;
namespace UnityAtoms
{
[Serializable]
public class UnityColorEvent : UnityEvent<Color> { }
public sealed class UnityColorEvent : UnityEvent<Color> { }
}

View File

@ -3,7 +3,8 @@ using UnityEngine;
namespace UnityAtoms
{
public class GameEventEditor<T, E> : Editor where E : GameEvent<T>
public abstract class GameEventEditor<T, E> : Editor
where E : GameEvent<T>
{
public override void OnInspectorGUI()
{
@ -20,29 +21,29 @@ namespace UnityAtoms
}
[CustomEditor(typeof(BoolEvent))]
public class BoolEventEditor : GameEventEditor<bool, BoolEvent> { }
public sealed class BoolEventEditor : GameEventEditor<bool, BoolEvent> { }
[CustomEditor(typeof(Collider2DEvent))]
public class Collider2DEventEditor : GameEventEditor<Collider2D, Collider2DEvent> { }
public sealed class Collider2DEventEditor : GameEventEditor<Collider2D, Collider2DEvent> { }
[CustomEditor(typeof(ColorEvent))]
public class ColorEventEditor : GameEventEditor<Color, ColorEvent> { }
public sealed class ColorEventEditor : GameEventEditor<Color, ColorEvent> { }
[CustomEditor(typeof(FloatEvent))]
public class FloatEventEditor : GameEventEditor<float, FloatEvent> { }
public sealed class FloatEventEditor : GameEventEditor<float, FloatEvent> { }
[CustomEditor(typeof(GameObjectEvent))]
public class GameObjectEventEditor : GameEventEditor<GameObject, GameObjectEvent> { }
public sealed class GameObjectEventEditor : GameEventEditor<GameObject, GameObjectEvent> { }
[CustomEditor(typeof(IntEvent))]
public class IntGameEventEditor : GameEventEditor<int, IntEvent> { }
public sealed class IntGameEventEditor : GameEventEditor<int, IntEvent> { }
[CustomEditor(typeof(Vector2Event))]
public class Vector2EventEditor : GameEventEditor<Vector2, Vector2Event> { }
public sealed class Vector2EventEditor : GameEventEditor<Vector2, Vector2Event> { }
[CustomEditor(typeof(Vector3Event))]
public class Vector3EventEditor : GameEventEditor<Vector3, Vector3Event> { }
public sealed class Vector3EventEditor : GameEventEditor<Vector3, Vector3Event> { }
[CustomEditor(typeof(VoidEvent))]
public class VoidEventEditor : GameEventEditor<Void, VoidEvent> { }
public sealed class VoidEventEditor : GameEventEditor<Void, VoidEvent> { }
}

View File

@ -5,17 +5,17 @@ namespace UnityAtoms
{
public abstract class ReferenceDrawer : PropertyDrawer
{
private readonly string[] popupOptions =
private static readonly string[] PopupOptions =
{ "Use Constant", "Use Variable" };
private GUIStyle popupStyle;
private static GUIStyle PopupStyle;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (popupStyle == null)
if (PopupStyle == null)
{
popupStyle = new GUIStyle(GUI.skin.GetStyle("PaneOptions"));
popupStyle.imagePosition = ImagePosition.ImageOnly;
PopupStyle = new GUIStyle(GUI.skin.GetStyle("PaneOptions"));
PopupStyle.imagePosition = ImagePosition.ImageOnly;
}
label = EditorGUI.BeginProperty(position, label, property);
@ -30,15 +30,15 @@ namespace UnityAtoms
// Calculate rect for configuration button
Rect buttonRect = new Rect(position);
buttonRect.yMin += popupStyle.margin.top;
buttonRect.width = popupStyle.fixedWidth + popupStyle.margin.right;
buttonRect.yMin += PopupStyle.margin.top;
buttonRect.width = PopupStyle.fixedWidth + PopupStyle.margin.right;
position.xMin = buttonRect.xMax;
// Store old indent level and set it to 0, the PrefixLabel takes care of it
int indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
int result = EditorGUI.Popup(buttonRect, useConstant.boolValue ? 0 : 1, popupOptions, popupStyle);
int result = EditorGUI.Popup(buttonRect, useConstant.boolValue ? 0 : 1, PopupOptions, PopupStyle);
useConstant.boolValue = result == 0;
@ -54,24 +54,24 @@ namespace UnityAtoms
}
[CustomPropertyDrawer(typeof(BoolReference))]
public class BoolReferenceDrawer : ReferenceDrawer { }
public sealed class BoolReferenceDrawer : ReferenceDrawer { }
[CustomPropertyDrawer(typeof(ColorReference))]
public class ColorReferenceDrawer : ReferenceDrawer { }
public sealed class ColorReferenceDrawer : ReferenceDrawer { }
[CustomPropertyDrawer(typeof(FloatReference))]
public class FloatReferenceDrawer : ReferenceDrawer { }
public sealed class FloatReferenceDrawer : ReferenceDrawer { }
[CustomPropertyDrawer(typeof(IntReference))]
public class IntReferenceDrawer : ReferenceDrawer { }
public sealed class IntReferenceDrawer : ReferenceDrawer { }
[CustomPropertyDrawer(typeof(StringReference))]
public class StringReferenceDrawer : ReferenceDrawer { }
public sealed class StringReferenceDrawer : ReferenceDrawer { }
[CustomPropertyDrawer(typeof(Vector2Reference))]
public class Vector2ReferenceDrawer : ReferenceDrawer { }
public sealed class Vector2ReferenceDrawer : ReferenceDrawer { }
[CustomPropertyDrawer(typeof(Vector3Reference))]
public class Vector3ReferenceDrawer : ReferenceDrawer { }
public sealed class Vector3ReferenceDrawer : ReferenceDrawer { }
}
}

View File

@ -16,7 +16,7 @@ namespace UnityAtoms.Extensions
return mb.StartCoroutine(SetTimeout(function, delay));
}
static IEnumerator SetTimeout(Action function, float delay)
private static IEnumerator SetTimeout(Action function, float delay)
{
yield return new WaitForSeconds(delay);
function();
@ -27,7 +27,7 @@ namespace UnityAtoms.Extensions
return mb.StartCoroutine(SetInterval(function, delay));
}
static IEnumerator SetInterval(Action function, float delay)
private static IEnumerator SetInterval(Action function, float delay)
{
while (true && function != null)
{

View File

@ -5,7 +5,6 @@ namespace UnityAtoms.Extensions
{
public static class TransformExtensions
{
/* Finds a child to this transform by name. Searches not only the first level in the
* tree hierarchy of child objects, but all the children, grand children, and so on.
*/

View File

@ -1,20 +1,22 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms
{
[Serializable]
public class ConditionalFloatGameActionHelper : ConditionalGameActionHelper<float, FloatAction, BoolFloatFunction> { }
public sealed class ConditionalFloatGameActionHelper : ConditionalGameActionHelper<float, FloatAction, BoolFloatFunction> { }
[CreateAssetMenu(menuName = "Unity Atoms/Float/Conditional", fileName = "ConditionalFloatAction", order = CreateAssetMenuUtils.Order.CONDITIONAL)]
public class ConditionalFloatAction : FloatAction
public sealed class ConditionalFloatAction : FloatAction
{
[FormerlySerializedAs("Conditional")]
[SerializeField]
private ConditionalFloatGameActionHelper Conditional = null;
private ConditionalFloatGameActionHelper _conditional;
public override void Do(float t1)
{
Conditional.Do(t1);
_conditional.Do(t1);
}
}
}

View File

@ -3,5 +3,5 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Float/Constant", fileName = "FloatConstant", order = CreateAssetMenuUtils.Order.CONSTANT)]
public class FloatConstant : ScriptableObjectVariableBase<float> { }
public sealed class FloatConstant : ScriptableObjectVariableBase<float> { }
}

View File

@ -3,5 +3,5 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Float/Event", fileName = "FloatEvent", order = CreateAssetMenuUtils.Order.EVENT)]
public class FloatEvent : GameEvent<float> { }
public sealed class FloatEvent : GameEvent<float> { }
}

View File

@ -2,7 +2,6 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Float/Event x 2", fileName = "FloatFloatEvent", order = CreateAssetMenuUtils.Order.EVENTx2)]
public class FloatFloatEvent : GameEvent<float, float> { }
public sealed class FloatFloatEvent : GameEvent<float, float> { }
}

View File

@ -3,5 +3,5 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Float/List", fileName = "FloatList", order = CreateAssetMenuUtils.Order.LIST)]
public class FloatList : ScriptableObjectList<float, FloatEvent> { }
public sealed class FloatList : ScriptableObjectList<float, FloatEvent> { }
}

View File

@ -1,4 +1,9 @@
namespace UnityAtoms
{
public class FloatListener : GameEventListener<float, FloatAction, FloatEvent, UnityFloatEvent> { }
public sealed class FloatListener : GameEventListener<
float,
FloatAction,
FloatEvent,
UnityFloatEvent>
{ }
}

View File

@ -3,5 +3,10 @@ using System;
namespace UnityAtoms
{
[Serializable]
public class FloatReference : ScriptableObjectReference<float, FloatVariable, FloatEvent, FloatFloatEvent> { }
public sealed class FloatReference : ScriptableObjectReference<
float,
FloatVariable,
FloatEvent,
FloatFloatEvent>
{ }
}

View File

@ -3,7 +3,7 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Float/Variable", fileName = "FloatVariable", order = CreateAssetMenuUtils.Order.VARIABLE)]
public class FloatVariable : EquatableScriptableObjectVariable<float, FloatEvent, FloatFloatEvent>, IWithApplyChange<float, FloatEvent, FloatFloatEvent>
public sealed class FloatVariable : EquatableScriptableObjectVariable<float, FloatEvent, FloatFloatEvent>, IWithApplyChange<float, FloatEvent, FloatFloatEvent>
{
public bool ApplyChange(float amount)
{

View File

@ -3,5 +3,11 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Float/Set Variable", fileName = "SetFloatVariableValueAction", order = CreateAssetMenuUtils.Order.SET_VARIABLE)]
public class SetFloatVariableValue : SetVariableValue<float, FloatVariable, FloatReference, FloatEvent, FloatFloatEvent> { }
public sealed class SetFloatVariableValue : SetVariableValue<
float,
FloatVariable,
FloatReference,
FloatEvent,
FloatFloatEvent>
{ }
}

View File

@ -4,5 +4,5 @@ using UnityEngine.Events;
namespace UnityAtoms
{
[Serializable]
public class UnityFloatEvent : UnityEvent<float> { }
public sealed class UnityFloatEvent : UnityEvent<float> { }
}

View File

@ -3,5 +3,5 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/GameObject/Event", fileName = "GameObjectEvent", order = CreateAssetMenuUtils.Order.EVENT)]
public class GameObjectEvent : GameEvent<GameObject> { }
public sealed class GameObjectEvent : GameEvent<GameObject> { }
}

View File

@ -2,7 +2,6 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/GameObject/Event x 2", fileName = "GameObjectGameObjectEvent", order = CreateAssetMenuUtils.Order.EVENTx2)]
public class GameObjectGameObjectEvent : GameEvent<GameObject, GameObject> { }
public sealed class GameObjectGameObjectEvent : GameEvent<GameObject, GameObject> { }
}

View File

@ -3,5 +3,5 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/GameObject/List", fileName = "GameObjectList", order = CreateAssetMenuUtils.Order.LIST)]
public class GameObjectList : ScriptableObjectList<GameObject, GameObjectEvent> { }
public sealed class GameObjectList : ScriptableObjectList<GameObject, GameObjectEvent> { }
}

View File

@ -2,5 +2,10 @@ using UnityEngine;
namespace UnityAtoms
{
public class GameObjectListener : GameEventListener<GameObject, GameObjectAction, GameObjectEvent, UnityGameObjectEvent> { }
public sealed class GameObjectListener : GameEventListener<
GameObject,
GameObjectAction,
GameObjectEvent,
UnityGameObjectEvent>
{ }
}

View File

@ -4,5 +4,10 @@ using UnityEngine;
namespace UnityAtoms
{
[Serializable]
public class GameObjectReference : ScriptableObjectReference<GameObject, GameObjectVariable, GameObjectEvent, GameObjectGameObjectEvent> { }
public sealed class GameObjectReference : ScriptableObjectReference<
GameObject,
GameObjectVariable,
GameObjectEvent,
GameObjectGameObjectEvent>
{ }
}

View File

@ -3,7 +3,10 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/GameObject/Variable", fileName = "GameObjectVariable", order = CreateAssetMenuUtils.Order.VARIABLE)]
public class GameObjectVariable : ScriptableObjectVariable<GameObject, GameObjectEvent, GameObjectGameObjectEvent>
public sealed class GameObjectVariable : ScriptableObjectVariable<
GameObject,
GameObjectEvent,
GameObjectGameObjectEvent>
{
protected override bool AreEqual(GameObject first, GameObject second)
{

View File

@ -1,5 +1,6 @@
using UnityEngine;
using UnityEngine;
using UnityAtoms.Extensions;
using UnityEngine.Serialization;
#if UNITY_EDITOR
using UnityAtoms.Logger;
#endif
@ -10,27 +11,30 @@ namespace UnityAtoms
* If no unused GameObject is found a new one is instantiated and added to the GameObjectList.
*/
[CreateAssetMenu(menuName = "Unity Atoms/GameObject/Get Unused GameObject (GameObject - (V3, Quat))", fileName = "GetUnusedGameObject")]
public class GetUnusedGameObject : GameObjectVector3QuaternionFunction
public sealed class GetUnusedGameObject : GameObjectVector3QuaternionFunction
{
[FormerlySerializedAs("List")]
[SerializeField]
private GameObjectList List = null;
private GameObjectList _list;
[FormerlySerializedAs("Prefab")]
[SerializeField]
private GameObject Prefab = null;
private GameObject _prefab;
[FormerlySerializedAs("IsNotUsed")]
[SerializeField]
private BoolGameObjectFunction IsNotUsed = null;
private BoolGameObjectFunction _isNotUsed;
public override GameObject Call(Vector3 position, Quaternion quaternion)
{
if (IsNotUsed == null)
if (_isNotUsed == null)
{
#if UNITY_EDITOR
AtomsLogger.Warning("IsUsed must be defined when using GetUnusedGameObject");
#endif
}
return List.List.GetOrInstantiate(Prefab, position, quaternion, IsNotUsed.Call);
return _list.List.GetOrInstantiate(_prefab, position, quaternion, _isNotUsed.Call);
}
}
}

View File

@ -3,5 +3,11 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/GameObject/Set Variable", fileName = "SetGameObjectVariableValueAction", order = CreateAssetMenuUtils.Order.SET_VARIABLE)]
public class SetGameObjectVariableValue : SetVariableValue<GameObject, GameObjectVariable, GameObjectReference, GameObjectEvent, GameObjectGameObjectEvent> { }
public sealed class SetGameObjectVariableValue : SetVariableValue<
GameObject,
GameObjectVariable,
GameObjectReference,
GameObjectEvent,
GameObjectGameObjectEvent>
{ }
}

View File

@ -5,5 +5,5 @@ using UnityEngine;
namespace UnityAtoms
{
[Serializable]
public class UnityGameObjectEvent : UnityEvent<GameObject> { }
public sealed class UnityGameObjectEvent : UnityEvent<GameObject> { }
}

View File

@ -1,20 +1,22 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms
{
[Serializable]
public class ConditionalIntGameActionHelper : ConditionalGameActionHelper<int, IntAction, BoolIntFunction> { }
public sealed class ConditionalIntGameActionHelper : ConditionalGameActionHelper<int, IntAction, BoolIntFunction> { }
[CreateAssetMenu(menuName = "Unity Atoms/Int/Conditional", fileName = "ConditionalIntAction", order = CreateAssetMenuUtils.Order.CONDITIONAL)]
public class ConditionalIntAction : IntAction
public sealed class ConditionalIntAction : IntAction
{
[FormerlySerializedAs("Conditional")]
[SerializeField]
private ConditionalIntGameActionHelper Conditional = null;
private ConditionalIntGameActionHelper _conditional;
public override void Do(int t1)
{
Conditional.Do(t1);
_conditional.Do(t1);
}
}
}

View File

@ -3,5 +3,5 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Int/Constant", fileName = "IntConstant", order = CreateAssetMenuUtils.Order.CONSTANT)]
public class IntConstant : ScriptableObjectVariableBase<int> { }
public sealed class IntConstant : ScriptableObjectVariableBase<int> { }
}

View File

@ -3,5 +3,5 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Int/Event", fileName = "IntEvent", order = CreateAssetMenuUtils.Order.EVENT)]
public class IntEvent : GameEvent<int> { }
public sealed class IntEvent : GameEvent<int> { }
}

View File

@ -2,7 +2,6 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Int/Event x 2", fileName = "IntIntEvent", order = CreateAssetMenuUtils.Order.EVENTx2)]
public class IntIntEvent : GameEvent<int, int> { }
public sealed class IntIntEvent : GameEvent<int, int> { }
}

View File

@ -3,5 +3,5 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Int/List", fileName = "IntList", order = CreateAssetMenuUtils.Order.LIST)]
public class IntList : ScriptableObjectList<int, IntEvent> { }
public sealed class IntList : ScriptableObjectList<int, IntEvent> { }
}

View File

@ -1,4 +1,4 @@
namespace UnityAtoms
{
public class IntListener : GameEventListener<int, IntAction, IntEvent, UnityIntEvent> { }
public sealed class IntListener : GameEventListener<int, IntAction, IntEvent, UnityIntEvent> { }
}

View File

@ -3,5 +3,10 @@ using System;
namespace UnityAtoms
{
[Serializable]
public class IntReference : ScriptableObjectReference<int, IntVariable, IntEvent, IntIntEvent> { }
public sealed class IntReference : ScriptableObjectReference<
int,
IntVariable,
IntEvent,
IntIntEvent>
{ }
}

View File

@ -1,9 +1,9 @@
using UnityEngine;
using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Int/Variable", fileName = "IntVariable", order = CreateAssetMenuUtils.Order.VARIABLE)]
public class IntVariable : EquatableScriptableObjectVariable<int, IntEvent, IntIntEvent>, IWithApplyChange<int, IntEvent, IntIntEvent>
public sealed class IntVariable : EquatableScriptableObjectVariable<int, IntEvent, IntIntEvent>, IWithApplyChange<int, IntEvent, IntIntEvent>
{
public bool ApplyChange(int amount)
{

View File

@ -3,5 +3,11 @@ using UnityEngine;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Int/Set Variable", fileName = "SetIntVariableValueAction", order = CreateAssetMenuUtils.Order.SET_VARIABLE)]
public class SetIntVariableValue : SetVariableValue<int, IntVariable, IntReference, IntEvent, IntIntEvent> { }
public sealed class SetIntVariableValue : SetVariableValue<
int,
IntVariable,
IntReference,
IntEvent,
IntIntEvent>
{ }
}

View File

@ -4,5 +4,5 @@ using UnityEngine.Events;
namespace UnityAtoms
{
[Serializable]
public class UnityIntEvent : UnityEvent<int> { }
public sealed class UnityIntEvent : UnityEvent<int> { }
}

View File

@ -4,21 +4,21 @@ namespace UnityAtoms.Logger
{
public static class AtomsLogger
{
private const string logPrefix = "Unity Atoms :: ";
private const string LogPrefix = "Unity Atoms :: ";
public static void Log(string msg)
{
Debug.Log(logPrefix + msg);
Debug.Log(LogPrefix + msg);
}
public static void Warning(string msg)
{
Debug.LogWarning(logPrefix + msg);
Debug.LogWarning(LogPrefix + msg);
}
public static void Error(string msg)
{
Debug.LogError(logPrefix + msg);
Debug.LogError(LogPrefix + msg);
}
}
}

View File

@ -1,16 +1,16 @@
using System;
using System;
using UnityEngine;
namespace UnityAtoms.Mobile
{
[Serializable]
public class ConditionalTouchUserInputGameActionHelper : ConditionalGameActionHelper<TouchUserInput, TouchUserInputAction, BoolTouchUserInputFunction> { }
public sealed class ConditionalTouchUserInputGameActionHelper : ConditionalGameActionHelper<TouchUserInput, TouchUserInputAction, BoolTouchUserInputFunction> { }
[CreateAssetMenu(menuName = "Unity Atoms/Mobile/Touch User Input/Conditional", fileName = "ConditionalTouchUserInputAction", order = CreateAssetMenuUtils.Order.CONDITIONAL)]
public class ConditionalTouchUserInputAction : TouchUserInputAction
public sealed class ConditionalTouchUserInputAction : TouchUserInputAction
{
[SerializeField]
public ConditionalTouchUserInputGameActionHelper Conditional = null;
public ConditionalTouchUserInputGameActionHelper Conditional;
public override void Do(TouchUserInput t1)
{

View File

@ -1,99 +1,107 @@
using System;
using System;
using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms.Mobile
{
[Serializable]
public class DetectTap : IGameEventListener<TouchUserInput>
{
[FormerlySerializedAs("FirstTapTimer")]
[SerializeField]
private Timer FirstTapTimer = null;
[SerializeField]
private Timer SecondTapTimer = null;
[SerializeField]
private FloatReference MaxTimeBetweenTaps = null;
[SerializeField]
private FloatReference MaxDistanceBetweenTaps = null;
[SerializeField]
private FloatReference MaxMovementToCountAsTap = null;
[SerializeField]
private TouchUserInputGameEvent OnTapDetectedEvent = null;
[SerializeField]
private TouchUserInputGameEvent OnDoubleTapDetectedEvent = null;
private Timer _firstTapTimer;
private Vector2 inputPosFirstTapDown;
[FormerlySerializedAs("SecondTapTimer")]
[SerializeField]
private Timer _secondTapTimer;
private void OnEnable()
{
FirstTapTimer.Stop();
SecondTapTimer.Stop();
}
[FormerlySerializedAs("MaxTimeBetweenTaps")]
[SerializeField]
private FloatReference _maxTimeBetweenTaps;
[FormerlySerializedAs("MaxDistanceBetweenTaps")]
[SerializeField]
private FloatReference _maxDistanceBetweenTaps;
[FormerlySerializedAs("MaxMovementToCountAsTap")]
[SerializeField]
private FloatReference _maxMovementToCountAsTap;
[FormerlySerializedAs("OnTapDetectedEvent")]
[SerializeField]
private TouchUserInputGameEvent _onTapDetectedEvent;
[FormerlySerializedAs("OnDoubleTapDetectedEvent")]
[SerializeField]
private TouchUserInputGameEvent _onDoubleTapDetectedEvent;
private Vector2 _inputPosFirstTapDown;
public void OnEventRaised(TouchUserInput touchUserInput)
{
if (!IsPotentialDoubleTapInProgress())
{
FirstTapTimer.Stop();
SecondTapTimer.Stop();
_firstTapTimer.Stop();
_secondTapTimer.Stop();
}
if (touchUserInput.InputState == TouchUserInput.State.Down && CanStartDoubleTap())
{
inputPosFirstTapDown = touchUserInput.InputPos;
FirstTapTimer.Start();
_inputPosFirstTapDown = touchUserInput.InputPos;
_firstTapTimer.Start();
}
else if (touchUserInput.InputState == TouchUserInput.State.Drag && FirstTapTimer.IsStarted() && Vector2.Distance(touchUserInput.InputPos, inputPosFirstTapDown) > MaxMovementToCountAsTap.Value)
else if (touchUserInput.InputState == TouchUserInput.State.Drag && _firstTapTimer.IsStarted() && Vector2.Distance(touchUserInput.InputPos, _inputPosFirstTapDown) > _maxMovementToCountAsTap.Value)
{
FirstTapTimer.Stop();
_firstTapTimer.Stop();
}
else if (touchUserInput.InputState == TouchUserInput.State.Up && WaitingForFinishingFirstTap())
{
if (FirstTapTimer.GetElapsedTime() <= MaxTimeBetweenTaps.Value)
if (_firstTapTimer.GetElapsedTime() <= _maxTimeBetweenTaps.Value)
{
if (OnTapDetectedEvent != null)
if (_onTapDetectedEvent != null)
{
OnTapDetectedEvent.Raise(touchUserInput);
_onTapDetectedEvent.Raise(touchUserInput);
}
SecondTapTimer.Start();
_secondTapTimer.Start();
}
FirstTapTimer.Stop();
_firstTapTimer.Stop();
}
else if (touchUserInput.InputState == TouchUserInput.State.Down && WaitingForSecondTap())
{
if (Vector2.Distance(touchUserInput.InputPos, inputPosFirstTapDown) <= MaxDistanceBetweenTaps.Value && SecondTapTimer.GetElapsedTime() <= MaxTimeBetweenTaps.Value)
if (Vector2.Distance(touchUserInput.InputPos, _inputPosFirstTapDown) <= _maxDistanceBetweenTaps.Value && _secondTapTimer.GetElapsedTime() <= _maxTimeBetweenTaps.Value)
{
if (OnDoubleTapDetectedEvent != null)
if (_onDoubleTapDetectedEvent != null)
{
OnDoubleTapDetectedEvent.Raise(touchUserInput); // OPEN POINT: Should we raise event on state up or down?
_onDoubleTapDetectedEvent.Raise(touchUserInput); // OPEN POINT: Should we raise event on state up or down?
}
}
SecondTapTimer.Stop();
_secondTapTimer.Stop();
}
}
private bool CanStartDoubleTap()
{
return !SecondTapTimer.IsStarted();
return !_secondTapTimer.IsStarted();
}
private bool WaitingForFinishingFirstTap()
{
return FirstTapTimer.IsStarted();
return _firstTapTimer.IsStarted();
}
private bool WaitingForSecondTap()
{
return SecondTapTimer.IsStarted();
return _secondTapTimer.IsStarted();
}
public bool IsPotentialDoubleTapInProgress()
{
return (FirstTapTimer.IsStarted() && FirstTapTimer.GetElapsedTime() <= MaxTimeBetweenTaps.Value) || (SecondTapTimer.IsStarted() && SecondTapTimer.GetElapsedTime() <= MaxTimeBetweenTaps.Value);
return (_firstTapTimer.IsStarted() && _firstTapTimer.GetElapsedTime() <= _maxTimeBetweenTaps.Value) || (_secondTapTimer.IsStarted() && _secondTapTimer.GetElapsedTime() <= _maxTimeBetweenTaps.Value);
}
public bool InUse()
{
return FirstTapTimer != null && SecondTapTimer != null && OnDoubleTapDetectedEvent != null;
return _firstTapTimer != null && _secondTapTimer != null && _onDoubleTapDetectedEvent != null;
}
}

View File

@ -1,7 +1,7 @@
using UnityEngine;
using UnityEngine;
namespace UnityAtoms.Mobile
{
[CreateAssetMenu(menuName = "Unity Atoms/Mobile/Touch User Input/Event", fileName = "TouchUserInputEvent", order = CreateAssetMenuUtils.Order.EVENT)]
public class TouchUserInputGameEvent : GameEvent<TouchUserInput> { }
public sealed class TouchUserInputGameEvent : GameEvent<TouchUserInput> { }
}

View File

@ -1,5 +1,10 @@
namespace UnityAtoms.Mobile
namespace UnityAtoms.Mobile
{
public class TouchUserInputListener : GameEventListener<TouchUserInput, TouchUserInputAction, TouchUserInputGameEvent, UnityTouchUserInputEvent> { }
public sealed class TouchUserInputListener : GameEventListener<
TouchUserInput,
TouchUserInputAction,
TouchUserInputGameEvent,
UnityTouchUserInputEvent>
{ }
}

View File

@ -3,5 +3,5 @@ using UnityEngine;
namespace UnityAtoms.Mobile
{
[CreateAssetMenu(menuName = "Unity Atoms/Mobile/Touch User Input/Event x 2", fileName = "TouchUserInputx2Event", order = CreateAssetMenuUtils.Order.EVENTx2)]
public class TouchUserInputTouchUserInputGameEvent : GameEvent<TouchUserInput, TouchUserInput> { }
public sealed class TouchUserInputTouchUserInputGameEvent : GameEvent<TouchUserInput, TouchUserInput> { }
}

View File

@ -1,5 +1,11 @@
namespace UnityAtoms.Mobile
namespace UnityAtoms.Mobile
{
public class TouchUserInputTouchUserInputListener : GameEventListener<TouchUserInput, TouchUserInput, TouchUserInputTouchUserInputAction, TouchUserInputTouchUserInputGameEvent, UnityTouchUserInputTouchUserInputEvent> { }
public sealed class TouchUserInputTouchUserInputListener : GameEventListener<
TouchUserInput,
TouchUserInput,
TouchUserInputTouchUserInputAction,
TouchUserInputTouchUserInputGameEvent,
UnityTouchUserInputTouchUserInputEvent>
{ }
}

View File

@ -3,10 +3,13 @@ using UnityEngine;
namespace UnityAtoms.Mobile
{
[CreateAssetMenu(menuName = "Unity Atoms/Mobile/Touch User Input/Variable", fileName = "TouchUserInputVariable", order = CreateAssetMenuUtils.Order.VARIABLE)]
public class TouchUserInputVariable : ScriptableObjectVariable<TouchUserInput, TouchUserInputGameEvent, TouchUserInputTouchUserInputGameEvent>
public sealed class TouchUserInputVariable : ScriptableObjectVariable<
TouchUserInput,
TouchUserInputGameEvent,
TouchUserInputTouchUserInputGameEvent>
{
[SerializeField]
private DetectTap DetectTap = null;
private DetectTap DetectTap;
private void OnEnable()
{

View File

@ -1,11 +1,8 @@
using System;
using System;
using UnityEngine.Events;
namespace UnityAtoms.Mobile
{
[Serializable]
public class UnityTouchUserInputEvent : UnityEvent<TouchUserInput> { }
[Serializable]
public class UnityTouchUserInputTouchUserInputEvent : UnityEvent<TouchUserInput, TouchUserInput> { }
public sealed class UnityTouchUserInputEvent : UnityEvent<TouchUserInput> { }
}

View File

@ -0,0 +1,8 @@
using System;
using UnityEngine.Events;
namespace UnityAtoms.Mobile
{
[Serializable]
public sealed class UnityTouchUserInputTouchUserInputEvent : UnityEvent<TouchUserInput, TouchUserInput> { }
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4a0403191ef2d9549855169b87213829
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -5,64 +5,67 @@ namespace UnityAtoms.Mobile
/* Updates the TouchUserInputVariable on every Update tick. Meant to be placed on a OnUpdateMonoHook.
*/
[CreateAssetMenu(menuName = "Unity Atoms/Mobile/Touch User Input/Update (OnUpdateMonoHook)", fileName = "UpdateTouchUserInputVariable")]
public class UpdateTouchUserInput : VoidAction
public sealed class UpdateTouchUserInput : VoidAction
{
public TouchUserInputVariable TouchUserInputVariable;
private TouchUserInput.State inputState = TouchUserInput.State.None;
private Vector2 inputPos = Vector2.zero;
private Vector2 inputPosLastFrame = Vector2.zero;
private Vector2 inputPosLastDown = Vector2.zero;
private TouchUserInput.State _inputState = TouchUserInput.State.None;
private Vector2 _inputPos = Vector2.zero;
private Vector2 _inputPosLastFrame = Vector2.zero;
private Vector2 _inputPosLastDown = Vector2.zero;
public override void Do()
{
#if (UNITY_ANDROID || UNITY_IOS || UNITY_IPHONE) && !UNITY_EDITOR
if (Input.touchCount > 0)
{
inputPos = Input.GetTouch(0).position;
_inputPos = Input.GetTouch(0).position;
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
inputPosLastDown = inputPos;
inputState = TouchUserInput.State.Down;
_inputPosLastDown = _inputPos;
_inputState = TouchUserInput.State.Down;
}
else if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
inputState = TouchUserInput.State.Up;
_inputState = TouchUserInput.State.Up;
}
else
{
inputState = TouchUserInput.State.Drag;
_inputState = TouchUserInput.State.Drag;
}
}
else
{
inputPos = Vector2.zero;
inputState = TouchUserInput.State.None;
_inputPos = Vector2.zero;
_inputState = TouchUserInput.State.None;
}
#elif UNITY_EDITOR || UNITY_STANDALONE
inputPos = Input.mousePosition;
_inputPos = Input.mousePosition;
if (Input.GetMouseButtonDown(0))
{
inputPosLastDown = inputPos;
inputState = TouchUserInput.State.Down;
_inputPosLastDown = _inputPos;
_inputState = TouchUserInput.State.Down;
}
else if (Input.GetMouseButtonUp(0))
{
inputState = TouchUserInput.State.Up;
_inputState = TouchUserInput.State.Up;
}
else if (Input.GetMouseButton(0))
{
inputState = TouchUserInput.State.Drag;
_inputState = TouchUserInput.State.Drag;
}
else
{
inputState = TouchUserInput.State.None;
_inputState = TouchUserInput.State.None;
}
#endif
TouchUserInputVariable.SetValue(new TouchUserInput(inputState, inputPos, inputPosLastFrame, inputPosLastDown));
inputPosLastFrame = inputPos;
TouchUserInputVariable.SetValue(new TouchUserInput(_inputState, _inputPos, _inputPosLastFrame, _inputPosLastDown));
_inputPosLastFrame = _inputPos;
}
}
}

View File

@ -1,16 +1,18 @@
using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Molecules/Timer/Start Timer")]
public class StartTimer : VoidAction
public sealed class StartTimer : VoidAction
{
[FormerlySerializedAs("Timer")]
[SerializeField]
private Timer Timer = null;
private Timer _timer;
public override void Do()
{
Timer.Start();
_timer.Start();
}
}
}

View File

@ -1,16 +1,18 @@
using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Molecules/Timer/Stop Timer")]
public class StopTimer : VoidAction
public sealed class StopTimer : VoidAction
{
[FormerlySerializedAs("Timer")]
[SerializeField]
private Timer Timer = null;
private Timer _timer;
public override void Do()
{
Timer.Stop();
_timer.Stop();
}
}
}

View File

@ -1,22 +1,28 @@
using UnityEngine;
using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms
{
[CreateAssetMenu(menuName = "Unity Atoms/Molecules/Timer/Timer")]
public class Timer : ScriptableObject
{
public float TimeElapsed = 0f;
public bool Started = false;
public bool Started { get { return _started; } }
public float TimeElapsed;
[FormerlySerializedAs("Started")]
[SerializeField]
private bool _started;
public void Start()
{
Started = true;
_started = true;
}
public void Stop()
{
TimeElapsed = 0f;
Started = false;
_started = false;
}
public float GetElapsedTime()
@ -26,7 +32,7 @@ namespace UnityAtoms
public bool IsStarted()
{
return Started;
return _started;
}
}

View File

@ -1,20 +1,23 @@
using UnityEngine;
using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms
{
/* Updates the Timer. Meant to be placed on a OnUpdateMonoHook.
*/
/// <summary>
/// Updates the Timer. Meant to be placed on a OnUpdateMonoHook.
/// </summary>
[CreateAssetMenu(menuName = "Unity Atoms/Molecules/Timer/Update Timer")]
public class UpdateTimer : VoidAction
public sealed class UpdateTimer : VoidAction
{
[FormerlySerializedAs("Timer")]
[SerializeField]
private Timer Timer = null;
private Timer _timer;
public override void Do()
{
if (Timer.Started)
if (_timer.Started)
{
Timer.TimeElapsed += Time.deltaTime;
_timer.TimeElapsed += Time.deltaTime;
}
}
}

View File

@ -2,5 +2,10 @@ using UnityEngine;
namespace UnityAtoms
{
public abstract class Collider2DHook : MonoHook<Collider2DEvent, Collider2DGameObjectEvent, Collider2D, GameObjectGameObjectFunction> { }
public abstract class Collider2DHook : MonoHook<
Collider2DEvent,
Collider2DGameObjectEvent,
Collider2D,
GameObjectGameObjectFunction>
{ }
}

View File

@ -2,5 +2,10 @@ using UnityEngine;
namespace UnityAtoms
{
public abstract class ColliderHook : MonoHook<ColliderEvent, ColliderGameObjectEvent, Collider, GameObjectGameObjectFunction> { }
public abstract class ColliderHook : MonoHook<
ColliderEvent,
ColliderGameObjectEvent,
Collider,
GameObjectGameObjectFunction>
{ }
}

Some files were not shown because too many files have changed in this diff Show More