diff --git a/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/Events/Event Objects/AppEvent.cs b/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/Events/Event Objects/AppEvent.cs index c702331..6052555 100644 --- a/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/Events/Event Objects/AppEvent.cs +++ b/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/Events/Event Objects/AppEvent.cs @@ -36,10 +36,20 @@ public override bool RaiseEvent ([CallerFilePath] string fileName = "", [CallerM { #if UNITY_EDITOR if (ScriptableFrameworkSettings.EditorEventLogging) + { #endif - Debug.Log (string.Format ("[EVENT] '{0}' was raised from {1}.{2}() at line {3}", name, Path.GetFileNameWithoutExtension (fileName), methodName, callerLineNumber)); + //System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame (1, false); + + + //Debug.Log (string.Format ("[EVENT] '{0}' was raised from {1}.{2} at line {3}", name, Path.GetFileNameWithoutExtension (stackFrame.GetFileName ()), stackFrame.GetMethod ().Name, stackFrame.GetFileLineNumber ())); + Debug.Log (string.Format ("[EVENT] '{0}' was raised from {1}.{2}() at line {3}", name, Path.GetFileNameWithoutExtension (fileName), methodName, callerLineNumber)); - if (listeners.Count == 0) +#if UNITY_EDITOR + } +#endif + + + if (listeners.Count == 0) { Debug.LogWarning (string.Format ("[EVENT] '{0}' was raised but has no listeners", name)); return false; diff --git a/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/Runtime Lists/RuntimeList.cs b/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/Runtime Lists/RuntimeList.cs index 1b757be..59d8530 100644 --- a/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/Runtime Lists/RuntimeList.cs +++ b/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/Runtime Lists/RuntimeList.cs @@ -17,7 +17,6 @@ public abstract class RuntimeList : RuntimeObject, IList /// /// A list of the elements in this object to be accessed externally via square bracket operator. /// - /// The internal list that actually contains the elements of this object. [Space] [SerializeField] protected List items = new List (); diff --git a/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/State Machines/StateMachine.cs b/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/State Machines/StateMachine.cs index d0026e1..14af5b8 100644 --- a/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/State Machines/StateMachine.cs +++ b/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/State Machines/StateMachine.cs @@ -22,38 +22,32 @@ public class StateMachine : StateMachineBase /// Actually runs the loop which sets the GameObjects on or off. /// /// Index of the object to be left on. - /// Whether or not the operation succeeded. - protected override bool ApplyState(int newSelectionIndex) + protected override void ApplyState(int newSelectionIndex) { selectionIndex = newSelectionIndex; for (int i = 0; i < gameObjects.Count; i++) { - if (!CheckListItemBeforeUpdate(i)) return false; + if (!CheckListItemBeforeUpdate(i)) return; gameObjects[i].SetActive(i == selectionIndex); } - - return true; } /// /// Actually runs the loop which sets all the GameObjects on or off. /// /// The new state for all GameObjects. - /// Whether or not the operation succeeded. - protected override bool ApplyState(bool stateForAll) + protected override void ApplyState (bool stateForAll) { selectionIndex = -1; for (int i = 0; i < gameObjects.Count; i++) { - if (!CheckListItemBeforeUpdate(i)) return false; + if (!CheckListItemBeforeUpdate(i)) return; gameObjects[i].SetActive(stateForAll); } - - return true; } /// @@ -61,19 +55,16 @@ protected override bool ApplyState(bool stateForAll) /// /// The index of the object to update. /// The state to provide that object with. - /// Whether or not the operation succeeded. - protected override bool ApplyState(int newSelectionIndex, bool stateAtThisObject) + protected override void ApplyState (int newSelectionIndex, bool stateAtThisObject) { selectionIndex = -1; for (int i = 0; i < gameObjects.Count; i++) { - if (!CheckListItemBeforeUpdate(i)) return false; + if (!CheckListItemBeforeUpdate(i)) return; } gameObjects[newSelectionIndex].SetActive(stateAtThisObject); - - return true; } /// @@ -82,22 +73,19 @@ protected override bool ApplyState(int newSelectionIndex, bool stateAtThisObject /// Where to start applying your state (inclusive). /// How many objects to affect. /// The state to apply within your given range. - /// Whether or not the operation succeeded. - protected override bool ApplyState(int startIndex, int length, bool stateToApply) + protected override void ApplyState (int startIndex, int length, bool stateToApply) { selectionIndex = -1; for (int i = 0; i < gameObjects.Count; i++) { - if (!CheckListItemBeforeUpdate(i)) return false; + if (!CheckListItemBeforeUpdate(i)) return; if (i >= startIndex && i < startIndex + length) gameObjects[i].SetActive (stateToApply); else gameObjects[i].SetActive (!stateToApply); } - - return true; } /// diff --git a/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/State Machines/StateMachineBase.cs b/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/State Machines/StateMachineBase.cs index 4627a9f..ee9bab4 100644 --- a/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/State Machines/StateMachineBase.cs +++ b/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/State Machines/StateMachineBase.cs @@ -28,26 +28,24 @@ public abstract class StateMachineBase : RuntimeObject /// /// Index of the state to be active. /// If true, the update for all other objects will be skipped. - /// Whether or not the operation succeeded. - public bool UpdateState (int newSelectionIndex) + public void UpdateState (int newSelectionIndex) { - if (!CheckListBeforeUpdate ()) return false; + if (!CheckListBeforeUpdate ()) return; - if (!CheckSelectionIndexBeforeUpdate (newSelectionIndex)) return false; + if (!CheckSelectionIndexBeforeUpdate (newSelectionIndex)) return; - return ApplyState (newSelectionIndex); + ApplyState (newSelectionIndex); } /// /// Applies the same state to all objects in the current list. /// /// The new state for all contained object. - /// Whether or not the operation succeeded. - public bool UpdateState (bool stateForAll) + public void UpdateState (bool stateForAll) { - if (!CheckListBeforeUpdate ()) return false; + if (!CheckListBeforeUpdate ()) return; - return ApplyState (stateForAll); + ApplyState (stateForAll); } /// @@ -55,14 +53,13 @@ public bool UpdateState (bool stateForAll) /// /// The index of the object to update. /// The state to provide that object with. - /// Whether or not the operation succeeded. - public bool UpdateState (int newSelectionIndex, bool stateAtThisObject) + public void UpdateState (int newSelectionIndex, bool stateAtThisObject) { - if (!CheckListBeforeUpdate ()) return false; + if (!CheckListBeforeUpdate ()) return; - if (!CheckSelectionIndexBeforeUpdate (newSelectionIndex)) return false; + if (!CheckSelectionIndexBeforeUpdate (newSelectionIndex)) return; - return ApplyState (newSelectionIndex, stateAtThisObject); + ApplyState (newSelectionIndex, stateAtThisObject); } /// @@ -72,12 +69,11 @@ public bool UpdateState (int newSelectionIndex, bool stateAtThisObject) /// Where to start applying your state (inclusive). /// How many objects to affect. /// The state to apply within your given range. - /// Whether or not the operation succeeded. - public bool UpdateState (int startIndex, int length, bool stateToApply) + public void UpdateState (int startIndex, int length, bool stateToApply) { - if (!CheckListBeforeUpdate ()) return false; + if (!CheckListBeforeUpdate ()) return; - return ApplyState (startIndex, length, stateToApply); + ApplyState (startIndex, length, stateToApply); } /// @@ -85,23 +81,20 @@ public bool UpdateState (int startIndex, int length, bool stateToApply) /// /// Index of the state to be active. /// If true, the update for all other objects will be skipped. - /// Whether or not the operation succeeded. - protected abstract bool ApplyState (int newSelectionIndex); + protected abstract void ApplyState (int newSelectionIndex); /// /// Actually runs the loop which sets the state of all objects in the list. /// /// State to apply for all. - /// Whether or not the operation succeeded. - protected abstract bool ApplyState (bool stateForAll); + protected abstract void ApplyState (bool stateForAll); /// /// Actually applies the new state to the selected object. /// /// The index of the object to update. /// The state to provide that object with. - /// Whether or not the operation succeeded. - protected abstract bool ApplyState (int newSelectionIndex, bool stateAtThisObject); + protected abstract void ApplyState (int newSelectionIndex, bool stateAtThisObject); /// /// Actually runs the loop which applies your given range of objects and the rest with another. @@ -109,8 +102,7 @@ public bool UpdateState (int startIndex, int length, bool stateToApply) /// Where to start applying your state (inclusive). /// How many objects to affect. /// The state to apply within your given range. - /// Whether or not the operation succeeded. - protected abstract bool ApplyState (int startIndex, int length, bool stateToApply); + protected abstract void ApplyState (int startIndex, int length, bool stateToApply); /// /// Checks if the list is null. Since the list can be a varying type, defining this as diff --git a/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/State Machines/StateMachineController.cs b/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/State Machines/StateMachineController.cs index e212b0f..dc91bb4 100644 --- a/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/State Machines/StateMachineController.cs +++ b/Scriptable Framework/Assets/Scriptable Framework/API/RuntimeObjects/State Machines/StateMachineController.cs @@ -22,38 +22,32 @@ public class StateMachineController : StateMachineBase /// Actually runs the loop which sets each object's state on or off. /// /// Index of the state to be active. - /// Whether or not the operation succeeded. - protected override bool ApplyState (int newSelectionIndex) + protected override void ApplyState (int newSelectionIndex) { selectionIndex = newSelectionIndex; for (int i = 0; i < subStateMachines.Count; i++) { - if (!CheckListItemBeforeUpdate (i)) return false; + if (!CheckListItemBeforeUpdate (i)) return; subStateMachines[i].UpdateState (i == selectionIndex); } - - return true; } /// /// Actually runs the loop which sets each object's state on or off. /// /// The new state for all objects. - /// Whether or not the operation succeeded. - protected override bool ApplyState (bool stateForAll) + protected override void ApplyState (bool stateForAll) { selectionIndex = -1; for (int i = 0; i < subStateMachines.Count; i++) { - if (!CheckListItemBeforeUpdate (i)) return false; + if (!CheckListItemBeforeUpdate (i)) return; subStateMachines[i].UpdateState (stateForAll); } - - return true; } /// @@ -61,16 +55,13 @@ protected override bool ApplyState (bool stateForAll) /// /// The index of the object to update. /// The state to provide that object with. - /// Whether or not the operation succeeded. - protected override bool ApplyState (int newSelectionIndex, bool stateAtThisObject) + protected override void ApplyState (int newSelectionIndex, bool stateAtThisObject) { selectionIndex = -1; - if (!CheckListItemBeforeUpdate (newSelectionIndex)) return false; + if (!CheckListItemBeforeUpdate (newSelectionIndex)) return; subStateMachines[newSelectionIndex].UpdateState (stateAtThisObject); - - return true; } /// @@ -79,22 +70,19 @@ protected override bool ApplyState (int newSelectionIndex, bool stateAtThisObjec /// Where to start applying your state (inclusive). /// How many objects to affect. /// The state to apply within your given range. - /// Whether or not the operation succeeded. - protected override bool ApplyState (int startIndex, int length, bool stateToApply) + protected override void ApplyState (int startIndex, int length, bool stateToApply) { selectionIndex = -1; for (int i = 0; i < subStateMachines.Count; i++) { - if (!CheckListItemBeforeUpdate (i)) return false; + if (!CheckListItemBeforeUpdate (i)) return; if (i >= startIndex && i < startIndex + length) subStateMachines[i].UpdateState (stateToApply); else subStateMachines[i].UpdateState (!stateToApply); } - - return true; } /// diff --git a/Scriptable Framework/Assets/Scriptable Framework/Tests/Editor/RuntimeData Tests/StateMachineTests/StateMachineTests.cs b/Scriptable Framework/Assets/Scriptable Framework/Tests/Editor/RuntimeData Tests/StateMachineTests/StateMachineTests.cs index 2537f4b..d58f58a 100644 --- a/Scriptable Framework/Assets/Scriptable Framework/Tests/Editor/RuntimeData Tests/StateMachineTests/StateMachineTests.cs +++ b/Scriptable Framework/Assets/Scriptable Framework/Tests/Editor/RuntimeData Tests/StateMachineTests/StateMachineTests.cs @@ -37,7 +37,8 @@ public void AddToList (int instances) [Test] public void UpdateStateSuccess () { - Assert.True (stateMachine.UpdateState (1)); + stateMachine.UpdateState (1); + Assert.True (!gameObjects[0].activeSelf && gameObjects[1].activeSelf && !gameObjects[2].activeSelf); } [Test] @@ -79,7 +80,8 @@ public void UpdateStateWithOutOfRangeIndex () [Test] public void UpdateStateWithSameIndex () { - Assert.True (stateMachine.UpdateState (0)); + stateMachine.UpdateState (0); + Assert.True (gameObjects[0].activeSelf && !gameObjects[1].activeSelf && !gameObjects[2].activeSelf); } [Test] @@ -128,7 +130,8 @@ public void AddToList (int instances) [Test] public void UpdateStateSuccess () { - Assert.True (stateMachine.UpdateState (true)); + stateMachine.UpdateState (true); + Assert.True (gameObjects[0].activeSelf && gameObjects[1].activeSelf && gameObjects[2].activeSelf); } [Test] @@ -193,7 +196,8 @@ public void AddToList (int instances) [Test] public void UpdateStateSuccess () { - Assert.True (stateMachine.UpdateState (1, true)); + stateMachine.UpdateState (1, true); + Assert.True (gameObjects[0].activeSelf && gameObjects[1].activeSelf && !gameObjects[2].activeSelf); } [Test] @@ -229,7 +233,8 @@ public void UpdateStateToggle () [Test] public void UpdateStateWithSameIndex () { - Assert.True (stateMachine.UpdateState (0, true)); + stateMachine.UpdateState (0, true); + Assert.True (gameObjects[0].activeSelf && !gameObjects[1].activeSelf && !gameObjects[2].activeSelf); } [Test] @@ -291,7 +296,8 @@ public void AddToList (int instances) [Test] public void UpdateStateSuccess () { - Assert.True (stateMachine.UpdateState (1, 2, true)); + stateMachine.UpdateState (1, 2, true); + Assert.True (!gameObjects[0].activeSelf && gameObjects[1].activeSelf && gameObjects[2].activeSelf); } [Test] diff --git a/Scriptable Framework/Assets/Scriptable Framework/package.json b/Scriptable Framework/Assets/Scriptable Framework/package.json index 2de3f93..330dabb 100644 --- a/Scriptable Framework/Assets/Scriptable Framework/package.json +++ b/Scriptable Framework/Assets/Scriptable Framework/package.json @@ -2,7 +2,7 @@ "name": "com.open.scriptable-framework", "displayName": "Scriptable Framework", "author": "Jak Hussain, Dean Giddy, Conor Galvin", - "version": "1.2.4", + "version": "1.2.5", "unity": "2018.3", "description": "A modularity framework developed to better enable Unity developers to decouple and test their code using ScriptableObject based dependencies that can be dragged and dropped into the inspector. The API and workflow makes it easy to use advanced programming patterns and SOLID principals in your projects which promotes a higher quality of code.The Scriptable Framework is the core of all future module development for Arup. See GitHub for documentation.", "keywords": [ diff --git a/docfx/articles/State Machines/usingStateMachines.md b/docfx/articles/State Machines/usingStateMachines.md index 2759ef9..e592f85 100644 --- a/docfx/articles/State Machines/usingStateMachines.md +++ b/docfx/articles/State Machines/usingStateMachines.md @@ -8,4 +8,12 @@ Because of the execution order of what goes on with Scriptable Framework behind ![Figure2](~/images/stateMachines2.png) -**NOTE**: It is much quicker to use a populator to set the references in your GameObjectList automatically rather than to write your own code for it. See the Populators manual for further details. \ No newline at end of file +**NOTE**: It is much quicker to use a populator to set the references in your GameObjectList automatically rather than to write your own code for it. See the Populators manual for further details. + +## StateMachines via UI Components + +Traditionally, a UI component like a button or a dropdown would have an instance of a MonoBehaviour dragged into them so that one of its methods could be assigned for the UI object to invoke. What most people don't know is, you can also do this with ScriptableObjects! + +![Figure3](~/images/stateMachines3.png) + +The image above shows an example of how a dropdown component has a StateMachine assigned to its object reference. By doing this, you can call the `UpdateState` method directly from the UI and not write any code at all for controlling objects in your scene. \ No newline at end of file diff --git a/docfx/images/stateMachines3.png b/docfx/images/stateMachines3.png new file mode 100644 index 0000000..1e0e4c5 Binary files /dev/null and b/docfx/images/stateMachines3.png differ diff --git a/docs/api/ScriptableFramework.AnimatorList.html b/docs/api/ScriptableFramework.AnimatorList.html new file mode 100644 index 0000000..89513f8 --- /dev/null +++ b/docs/api/ScriptableFramework.AnimatorList.html @@ -0,0 +1,788 @@ + + + + + + + + Class AnimatorList + + + + + + + + + + + + + + + + +
+
+ + + + +
+ + + +
+ + + + + + diff --git a/docs/api/ScriptableFramework.AnimatorListPopulator.html b/docs/api/ScriptableFramework.AnimatorListPopulator.html new file mode 100644 index 0000000..86b57fc --- /dev/null +++ b/docs/api/ScriptableFramework.AnimatorListPopulator.html @@ -0,0 +1,623 @@ + + + + + + + + Class AnimatorListPopulator + + + + + + + + + + + + + + + + +
+
+ + + + +
+ + + +
+ + + + + + diff --git a/docs/api/ScriptableFramework.AnimatorReference.html b/docs/api/ScriptableFramework.AnimatorReference.html new file mode 100644 index 0000000..1150afe --- /dev/null +++ b/docs/api/ScriptableFramework.AnimatorReference.html @@ -0,0 +1,600 @@ + + + + + + + + Class AnimatorReference + + + + + + + + + + + + + + + + +
+
+ + + + +
+ + + +
+ + + + + + diff --git a/docs/api/ScriptableFramework.AnimatorReferencePopulator.html b/docs/api/ScriptableFramework.AnimatorReferencePopulator.html new file mode 100644 index 0000000..015b53f --- /dev/null +++ b/docs/api/ScriptableFramework.AnimatorReferencePopulator.html @@ -0,0 +1,623 @@ + + + + + + + + Class AnimatorReferencePopulator + + + + + + + + + + + + + + + + +
+
+ + + + +
+ + + +
+ + + + + + diff --git a/docs/api/ScriptableFramework.AppEvent-1.html b/docs/api/ScriptableFramework.AppEvent-1.html index 0fcf85c..c9c183a 100644 --- a/docs/api/ScriptableFramework.AppEvent-1.html +++ b/docs/api/ScriptableFramework.AppEvent-1.html @@ -86,6 +86,18 @@ ScriptableFramework