├── .github └── FUNDING.yml ├── README.md ├── Scriptables ├── Custom UI.meta ├── Custom UI │ ├── EventEditor.cs │ └── EventEditor.cs.meta ├── Events.meta ├── Events │ ├── ConditionalEvent_BoolVariable.cs │ ├── ConditionalEvent_BoolVariable.cs.meta │ ├── ConditionalEvent_GameObjectState.cs │ ├── ConditionalEvent_GameObjectState.cs.meta │ ├── DelayedEvent.cs │ ├── DelayedEvent.cs.meta │ ├── EventExecutionOnMB.cs │ ├── EventExecutionOnMB.cs.meta │ ├── GameEvent.cs │ ├── GameEvent.cs.meta │ ├── GameEventListener.cs │ ├── GameEventListener.cs.meta │ ├── InstantiateObjectOnEvent.cs │ ├── NumberToNumberVariable_Comparison.cs │ ├── NumberToNumberVariable_Comparison.cs.meta │ ├── NumberVariableToNumberVariable_Comparison.cs │ └── NumberVariableToNumberVariable_Comparison.cs.meta ├── Helpers │ └── AssignTransform.cs ├── UI.meta ├── UI │ ├── UIPropertyUpdater.cs │ ├── UIPropertyUpdater.cs.meta │ ├── UpdateButtonInteractability.cs │ ├── UpdateButtonInteractability.cs.meta │ ├── UpdateImage.cs │ ├── UpdateImage.cs.meta │ ├── UpdateSlider.cs │ ├── UpdateSlider.cs.meta │ ├── UpdateText.cs │ ├── UpdateText.cs.meta │ ├── UpdateToggle.cs │ └── UpdateToggle.cs.meta ├── Variables.meta └── Variables │ ├── BoolVariable.cs │ ├── BoolVariable.cs.meta │ ├── FloatVariable.cs │ ├── FloatVariable.cs.meta │ ├── GameObjectVariable.cs │ ├── IntVariable.cs │ ├── IntVariable.cs.meta │ ├── NumberVariable.cs │ ├── NumberVariable.cs.meta │ ├── SpriteVariable.cs │ ├── SpriteVariable.cs.meta │ ├── StringVariable.cs │ ├── StringVariable.cs.meta │ ├── TransformArrayVariable.cs │ ├── TransformArrayVariable.cs.meta │ ├── TransformVariable.cs │ ├── TransformVariable.cs.meta │ ├── Vector3Variable.cs │ └── Vector3Variable.cs.meta └── Utilities ├── FindAssetsByType.cs └── FindAssetsByType.cs.meta /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: csharpaccent 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ScriptableObject-Library 2 | A collection of the most common used scriptable object cases I use through out my videos. It includes variables in data containers and scriptable object events. Plus some additional helper scripts to work with, such as True/False event stacks based on bools / gameObject states and numeric comparisons. There's also a few other utility scripts. 3 | 4 | # How to use 5 | Just include the namespace SO to access the data containers for the variables. 6 | Any UI helper script is is under SO.UI 7 | 8 | Explanation videos here: 9 | 10 | Intro video https://www.youtube.com/watch?v=R-AdCt8UyuE 11 | 12 | Conditional Event Stacks https://www.youtube.com/watch?v=vVxp3nbbh4E 13 | 14 | Updating UI Elements https://www.youtube.com/watch?v=Z1IMdmEaGRk 15 | 16 | 17 | # Patreon 18 | If you like more timer saver scripts and game development tutorials, consider supporting my cause on Patreon 19 | 20 | https://www.patreon.com/csharpaccent? 21 | 22 | # Follow me at 23 | https://sharpaccent.com/ 24 | 25 | https://twitter.com/AccentTutorials 26 | -------------------------------------------------------------------------------- /Scriptables/Custom UI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 531f86bd1747bc447bb545ecfd9d5224 3 | folderAsset: yes 4 | timeCreated: 1518781618 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Scriptables/Custom UI/EventEditor.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | namespace SO 6 | { 7 | [CustomEditor(typeof(GameEvent))] 8 | public class EventEditor : Editor 9 | { 10 | public override void OnInspectorGUI() 11 | { 12 | GUI.enabled = Application.isPlaying; 13 | GameEvent e = target as GameEvent; 14 | if (GUILayout.Button("Raise")) 15 | { 16 | e.Raise(); 17 | } 18 | } 19 | } 20 | } 21 | #endif 22 | -------------------------------------------------------------------------------- /Scriptables/Custom UI/EventEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5d9cced8e6e3cb34e92adcac3d4675f9 3 | timeCreated: 1518781627 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Events.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d55d8b591145767419fd6cefc37be067 3 | folderAsset: yes 4 | timeCreated: 1518776023 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Scriptables/Events/ConditionalEvent_BoolVariable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Events; 5 | 6 | namespace SO 7 | { 8 | public class ConditionalEvent_BoolVariable : EventExecutionOnMB 9 | { 10 | public BoolVariable targetBool; 11 | 12 | public UnityEvent IfTrue; 13 | public UnityEvent IfFalse; 14 | 15 | /// 16 | /// Use this to raise either a true or false event stack based on a bool variable 17 | /// 18 | public override void Raise() 19 | { 20 | if(targetBool == null) 21 | { 22 | Debug.Log("Bool Variable not assigned on Conditional Event " + this.gameObject.name); 23 | return; 24 | } 25 | 26 | if (targetBool.value) 27 | IfTrue.Invoke(); 28 | else 29 | IfFalse.Invoke(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Scriptables/Events/ConditionalEvent_BoolVariable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e5c1740c277785241b2a25ac4d0bf5f0 3 | timeCreated: 1518776660 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Events/ConditionalEvent_GameObjectState.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Events; 5 | 6 | namespace SO 7 | { 8 | public class ConditionalEvent_GameObjectState : EventExecutionOnMB 9 | { 10 | public GameObject targetGameObject; 11 | 12 | public UnityEvent IfTrue; 13 | public UnityEvent IfFalse; 14 | 15 | /// 16 | /// Invoke the true or false event stack based on a state of a gameObject. 17 | /// Super useful when doing categories with UI elements. 18 | /// 19 | public override void Raise() 20 | { 21 | if(targetGameObject == null) 22 | { 23 | Debug.Log("Conditional Event from GameObject state doesn't have a gameobject assigned! " + this.gameObject.name); 24 | return; 25 | } 26 | 27 | if (targetGameObject.activeInHierarchy) 28 | IfTrue.Invoke(); 29 | else 30 | IfFalse.Invoke(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Scriptables/Events/ConditionalEvent_GameObjectState.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0dafb5b48210a4d4f929927db19cf038 3 | timeCreated: 1518776813 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Events/DelayedEvent.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace SO 6 | { 7 | public class DelayedEvent : MonoBehaviour 8 | { 9 | public GameEvent targetEvent; 10 | 11 | /// 12 | /// Use this to raise an event after some time has passed 13 | /// 14 | public void Raise(float timer) 15 | { 16 | StartCoroutine(DelayedRaise(timer)); 17 | } 18 | 19 | IEnumerator DelayedRaise(float t) 20 | { 21 | yield return new WaitForSeconds(t); 22 | targetEvent.Raise(); 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Scriptables/Events/DelayedEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3503e39249fbb3147a24d8bc569a15d0 3 | timeCreated: 1518777984 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Events/EventExecutionOnMB.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace SO 6 | { 7 | public class EventExecutionOnMB : MonoBehaviour 8 | { 9 | /// 10 | /// Raise the event or comparison as soon as this gameObject is enabled 11 | /// 12 | public bool raiseOnEnable; 13 | /// 14 | /// Raise the event or comparison as soon as this gameObject is disabled 15 | /// 16 | public bool raiseOnDisable; 17 | 18 | void OnEnable() 19 | { 20 | if(raiseOnEnable) 21 | { 22 | Raise(); 23 | } 24 | } 25 | 26 | void OnDisable() 27 | { 28 | if(raiseOnDisable) 29 | { 30 | Raise(); 31 | } 32 | } 33 | 34 | public virtual void Raise() 35 | { 36 | 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Scriptables/Events/EventExecutionOnMB.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4c58441bce7290f478de895c7a78c14b 3 | timeCreated: 1518779582 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Events/GameEvent.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace SO 6 | { 7 | [CreateAssetMenu(menuName = "Game Event")] 8 | public class GameEvent : ScriptableObject 9 | { 10 | List listeners = new List(); 11 | 12 | public void Register(GameEventListener l) 13 | { 14 | listeners.Add(l); 15 | } 16 | 17 | public void UnRegister(GameEventListener l) 18 | { 19 | listeners.Remove(l); 20 | } 21 | 22 | public void Raise() 23 | { 24 | for (int i = 0; i < listeners.Count; i++) 25 | { 26 | listeners[i].Response(); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Scriptables/Events/GameEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dd5d985c973a87d47bde6f4345f7debe 3 | timeCreated: 1518776063 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Events/GameEventListener.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Events; 5 | 6 | namespace SO 7 | { 8 | public class GameEventListener : MonoBehaviour 9 | { 10 | public GameEvent gameEvent; 11 | public UnityEvent response; 12 | 13 | /// 14 | /// Override this to override the OnEnableLogic() 15 | /// 16 | public virtual void OnEnableLogic() 17 | { 18 | if (gameEvent != null) 19 | gameEvent.Register(this); 20 | } 21 | 22 | void OnEnable() 23 | { 24 | OnEnableLogic(); 25 | } 26 | 27 | /// 28 | /// Override this to override the OnDisableLogic() 29 | /// 30 | public virtual void OnDisableLogic() 31 | { 32 | if (gameEvent != null) 33 | gameEvent.UnRegister(this); 34 | } 35 | 36 | void OnDisable() 37 | { 38 | OnDisableLogic(); 39 | } 40 | 41 | public virtual void Response() 42 | { 43 | response.Invoke(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Scriptables/Events/GameEventListener.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 01a055b694402bd469a86915f1319e61 3 | timeCreated: 1518776031 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Events/InstantiateObjectOnEvent.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace SO 6 | { 7 | /// 8 | /// This script works as a game event listener (since it derives from it) 9 | /// Assign a target event and it will execute the response when it's called. 10 | /// If you don't assign an event, you can manually execute the Responce 11 | /// 12 | public class InstantiateObjectOnEvent : GameEventListener 13 | { 14 | public GameObjectVariable targetGameObject; 15 | public Transform targetSpawn; 16 | 17 | /// 18 | /// Make this true if you only want one instance of the prefab, 19 | /// Useful for visualizing gameObject that change 20 | /// 21 | public bool keepOnlyOneInstance; 22 | GameObject previousInstance; 23 | 24 | public override void Response() 25 | { 26 | if (keepOnlyOneInstance) 27 | { 28 | if (previousInstance) 29 | { 30 | Destroy(previousInstance); 31 | } 32 | } 33 | 34 | previousInstance = Instantiate(targetGameObject.value, targetSpawn.position, targetSpawn.rotation) as GameObject; 35 | 36 | response.Invoke(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Scriptables/Events/NumberToNumberVariable_Comparison.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Events; 5 | 6 | namespace SO 7 | { 8 | public class NumberToNumberVariable_Comparison : EventExecutionOnMB 9 | { 10 | public float fixedNumber; 11 | public NumberVariable targetVariable; 12 | 13 | public UnityEvent IfVariableIsLower; 14 | public UnityEvent IfVariableIsHigher; 15 | 16 | /// 17 | /// Invoke the true or false event stack based on a comparison of your targetVariable and a fixed number 18 | /// The comparison only runs when the Raise() is called, it's not monitored in Update or etc. 19 | /// 20 | public override void Raise() 21 | { 22 | if(targetVariable == null) 23 | { 24 | Debug.Log("No number variable assigned in a fixed number to numberVariable comparison! " + this.gameObject.name); 25 | return; 26 | } 27 | 28 | if(targetVariable is FloatVariable) 29 | { 30 | FloatVariable f = (FloatVariable)targetVariable; 31 | if (f.value < fixedNumber) 32 | IfVariableIsLower.Invoke(); 33 | else 34 | IfVariableIsHigher.Invoke(); 35 | } 36 | 37 | if(targetVariable is IntVariable) 38 | { 39 | IntVariable i = (IntVariable)targetVariable; 40 | int v = Mathf.RoundToInt(fixedNumber); 41 | if (i.value < v) 42 | IfVariableIsLower.Invoke(); 43 | else 44 | IfVariableIsHigher.Invoke(); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Scriptables/Events/NumberToNumberVariable_Comparison.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d6228601a85e8bc439d834bb01f2626e 3 | timeCreated: 1518777630 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Events/NumberVariableToNumberVariable_Comparison.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Events; 5 | 6 | namespace SO 7 | { 8 | public class NumberVariableToNumberVariable_Comparison : EventExecutionOnMB 9 | { 10 | public NumberVariable value1; 11 | public NumberVariable value2; 12 | 13 | public UnityEvent IfValue1IsLower; 14 | public UnityEvent IfValue1IsHigher; 15 | 16 | /// 17 | /// Raise true or false event stack based on the comparison of two number variables 18 | /// 19 | public override void Raise() 20 | { 21 | if(value1 == null || value2 == null) 22 | { 23 | Debug.Log("Number variable comparison doesn't have variables assigned! " + this.gameObject); 24 | return; 25 | } 26 | 27 | float v1 = 0; 28 | float v2 = 0; 29 | 30 | if(value1 is FloatVariable) 31 | { 32 | FloatVariable f = (FloatVariable)value1; 33 | v1 = f.value; 34 | } 35 | 36 | if(value1 is IntVariable) 37 | { 38 | IntVariable i = (IntVariable)value1; 39 | v1 = i.value; 40 | } 41 | 42 | if (value2 is FloatVariable) 43 | { 44 | FloatVariable f = (FloatVariable)value2; 45 | v2 = f.value; 46 | } 47 | 48 | if (value2 is IntVariable) 49 | { 50 | IntVariable i = (IntVariable)value2; 51 | v2 = i.value; 52 | } 53 | 54 | if(v1 < v2) 55 | { 56 | IfValue1IsLower.Invoke(); 57 | } 58 | else 59 | { 60 | IfValue1IsHigher.Invoke(); 61 | } 62 | 63 | } 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Scriptables/Events/NumberVariableToNumberVariable_Comparison.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c32de2891d1ffc746953e26dc59f42b2 3 | timeCreated: 1518776939 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Helpers/AssignTransform.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using SO; 6 | 7 | namespace SA 8 | { 9 | public class AssignTransform : MonoBehaviour 10 | { 11 | public TransformVariable transformVariable; 12 | 13 | private void OnEnable() 14 | { 15 | transformVariable.value = this.transform; 16 | Destroy(this); 17 | } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Scriptables/UI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b1f6790884756674bb7ba6f5b8646670 3 | folderAsset: yes 4 | timeCreated: 1518778302 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Scriptables/UI/UIPropertyUpdater.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | 6 | namespace SO.UI 7 | { 8 | public class UIPropertyUpdater : GameEventListener 9 | { 10 | /// 11 | /// Use this to update the UI element as soon as THIS gameObject is enabled 12 | /// 13 | public bool raiseOnEnable; 14 | /// In the off chance you need to update a UI element when disabled, just add the OnDisable() method 15 | 16 | /// 17 | /// If there's a gameEvent assigned it will automaticall call the Raise() method. 18 | /// 19 | 20 | public override void Response() 21 | { 22 | if (gameEvent != null) 23 | Raise(); 24 | } 25 | 26 | public virtual void Raise() 27 | { 28 | 29 | } 30 | 31 | public override void OnEnableLogic() 32 | { 33 | base.OnEnableLogic(); 34 | if(raiseOnEnable) 35 | { 36 | Raise(); 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Scriptables/UI/UIPropertyUpdater.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3350bc605e1985c4d9519e050e46f10e 3 | timeCreated: 1518779223 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/UI/UpdateButtonInteractability.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | using SO; 6 | 7 | namespace SO.UI 8 | { 9 | public class UpdateButtonInteractability : UIPropertyUpdater 10 | { 11 | public BoolVariable targetBool; 12 | public Button targetButton; 13 | 14 | public override void Raise() 15 | { 16 | targetButton.interactable = targetBool.value; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Scriptables/UI/UpdateButtonInteractability.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cc595db855d3a734f93b57af625c79a6 3 | timeCreated: 1518780686 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/UI/UpdateImage.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | using SO; 6 | 7 | namespace SO.UI 8 | { 9 | public class UpdateImage : UIPropertyUpdater 10 | { 11 | public SpriteVariable spriteVariable; 12 | public Image targetImage; 13 | 14 | /// 15 | /// Update the sprite of an Image UI element based on what you've set on the sprite variable 16 | /// 17 | public override void Raise() 18 | { 19 | targetImage.sprite = spriteVariable.value; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Scriptables/UI/UpdateImage.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0a78a1d51792c1a458d9ebd9f4c88829 3 | timeCreated: 1518778482 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/UI/UpdateSlider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using SO; 5 | using UnityEngine.UI; 6 | 7 | namespace SO.UI 8 | { 9 | public class UpdateSlider : UIPropertyUpdater 10 | { 11 | public NumberVariable targetVariable; 12 | public Slider targetSlider; 13 | 14 | public override void Raise() 15 | { 16 | if(targetVariable is FloatVariable) 17 | { 18 | FloatVariable f = (FloatVariable)targetVariable; 19 | targetSlider.value = f.value; 20 | return; 21 | } 22 | 23 | if(targetVariable is IntVariable) 24 | { 25 | IntVariable i = (IntVariable)targetVariable; 26 | targetSlider.value = i.value; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Scriptables/UI/UpdateSlider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 73729e954b49b8049963f260d9063f5c 3 | timeCreated: 1518780097 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/UI/UpdateText.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using SO; 5 | using UnityEngine.UI; 6 | 7 | namespace SO.UI 8 | { 9 | public class UpdateText : UIPropertyUpdater 10 | { 11 | public StringVariable targetString; 12 | public Text targetText; 13 | 14 | /// 15 | /// Use this to update a text UI element based on the target string variable 16 | /// 17 | public override void Raise() 18 | { 19 | targetText.text = targetString.value; 20 | } 21 | 22 | public void Raise(string target) 23 | { 24 | targetText.text = target; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Scriptables/UI/UpdateText.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fe18c567ed7a0194aa406239d556c83e 3 | timeCreated: 1518778312 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/UI/UpdateToggle.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | using SO; 6 | 7 | namespace SO.UI 8 | { 9 | public class UpdateToggle : UIPropertyUpdater 10 | { 11 | public BoolVariable boolVariable; 12 | public Toggle targetToggle; 13 | 14 | /// 15 | /// Use this to set the state of a toggle based on a bool variable 16 | /// 17 | public override void Raise() 18 | { 19 | targetToggle.isOn = boolVariable.value; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Scriptables/UI/UpdateToggle.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c95492e186bf434f972ed050ff95a5f 3 | timeCreated: 1518778569 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Variables.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 12743231006d639439b8b0e94125be96 3 | folderAsset: yes 4 | timeCreated: 1518775077 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Scriptables/Variables/BoolVariable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace SO 6 | { 7 | [CreateAssetMenu(menuName = "Variables/Bool")] 8 | public class BoolVariable : ScriptableObject 9 | { 10 | public bool value; 11 | 12 | public void Set(bool v) 13 | { 14 | value = v; 15 | } 16 | 17 | public void Set(BoolVariable v) 18 | { 19 | value = v.value; 20 | } 21 | 22 | public void Reverse() 23 | { 24 | value = !value; 25 | } 26 | 27 | public bool Compare(bool v) 28 | { 29 | return v == value; 30 | } 31 | 32 | public bool Compare(BoolVariable v) 33 | { 34 | return value == v.value; 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Scriptables/Variables/BoolVariable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7b70bab822f15f64f9e4f622f615213e 3 | timeCreated: 1518775154 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Variables/FloatVariable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace SO 6 | { 7 | [CreateAssetMenu(menuName = "Variables/Float")] 8 | public class FloatVariable : NumberVariable 9 | { 10 | public float value; 11 | 12 | public void Set(float v) 13 | { 14 | value = v; 15 | } 16 | 17 | public void Set(NumberVariable v) 18 | { 19 | if (v is FloatVariable) 20 | { 21 | FloatVariable f = (FloatVariable)v; 22 | value = f.value; 23 | } 24 | 25 | if (v is IntVariable) 26 | { 27 | IntVariable i = (IntVariable)v; 28 | value = i.value; 29 | } 30 | } 31 | 32 | public void Add(float v) 33 | { 34 | value += v; 35 | } 36 | 37 | public void Add(NumberVariable v) 38 | { 39 | if (v is FloatVariable) 40 | { 41 | FloatVariable f = (FloatVariable)v; 42 | value += f.value; 43 | } 44 | 45 | if (v is IntVariable) 46 | { 47 | IntVariable i = (IntVariable)v; 48 | value += i.value; 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Scriptables/Variables/FloatVariable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d933270a864652c489a8784d6e7f696f 3 | timeCreated: 1518775303 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Variables/GameObjectVariable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace SO 6 | { 7 | /// 8 | /// Similar to transform variables but this one is for keeping references to gameObjects or 9 | /// better yet, prefabs. So you don't waste memory allocating the same prefab on multiple objects. 10 | /// 11 | [CreateAssetMenu(menuName = "Variables/GameObject")] 12 | public class GameObjectVariable : ScriptableObject 13 | { 14 | public GameObject value; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Scriptables/Variables/IntVariable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace SO 6 | { 7 | [CreateAssetMenu(menuName = "Variables/Integer")] 8 | public class IntVariable : NumberVariable 9 | { 10 | public int value; 11 | 12 | public void Set(int v) 13 | { 14 | value = v; 15 | } 16 | 17 | public void Set(NumberVariable v) 18 | { 19 | if(v is FloatVariable) 20 | { 21 | FloatVariable f = (FloatVariable)v; 22 | value = Mathf.RoundToInt(f.value); 23 | } 24 | 25 | if(v is IntVariable) 26 | { 27 | IntVariable i = (IntVariable)v; 28 | value = i.value; 29 | } 30 | } 31 | 32 | public void Add(int v) 33 | { 34 | value += v; 35 | } 36 | 37 | public void Add(NumberVariable v) 38 | { 39 | if (v is FloatVariable) 40 | { 41 | FloatVariable f = (FloatVariable)v; 42 | value += Mathf.RoundToInt(f.value); 43 | } 44 | 45 | if (v is IntVariable) 46 | { 47 | IntVariable i = (IntVariable)v; 48 | value += i.value; 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Scriptables/Variables/IntVariable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e1837463d7b1e5c40940f172250ac2f9 3 | timeCreated: 1518775483 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Variables/NumberVariable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace SO 6 | { 7 | public class NumberVariable : ScriptableObject 8 | { 9 | //Base class for handling numeric variables, create subclasses if you are going to need other numeric variables such as uint etc. 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Scriptables/Variables/NumberVariable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f31d4d42c121bc345b2d75269d23d4a9 3 | timeCreated: 1518777037 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Variables/SpriteVariable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace SO 6 | { 7 | [CreateAssetMenu(menuName = "Variables/Sprite")] 8 | public class SpriteVariable : ScriptableObject 9 | { 10 | public Sprite value; 11 | 12 | public void Set(Sprite v) 13 | { 14 | value = v; 15 | } 16 | 17 | public void Set(SpriteVariable v) 18 | { 19 | value = v.value; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Scriptables/Variables/SpriteVariable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3e9fc252f7e543047a6ac060fa699b24 3 | timeCreated: 1518778419 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Variables/StringVariable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace SO 6 | { 7 | [CreateAssetMenu(menuName = "Variables/String")] 8 | public class StringVariable : ScriptableObject 9 | { 10 | public string value; 11 | 12 | public void Set(string v) 13 | { 14 | value = v; 15 | } 16 | 17 | public void Set(StringVariable v) 18 | { 19 | value = v.value; 20 | } 21 | 22 | public bool IsEmptyOrNull() 23 | { 24 | return string.IsNullOrEmpty(value); 25 | } 26 | 27 | public void Clear() 28 | { 29 | value = string.Empty; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Scriptables/Variables/StringVariable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab39a636d4f0663428eac4ac930687d7 3 | timeCreated: 1518775831 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Variables/TransformArrayVariable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace SO 6 | { 7 | [CreateAssetMenu(menuName = "Variables/Transform Array")] 8 | public class TransformArrayVariable : ScriptableObject 9 | { 10 | public Transform[] value; 11 | 12 | public int Length() 13 | { 14 | return value.Length; 15 | } 16 | 17 | public void Clear() 18 | { 19 | value = null; 20 | } 21 | 22 | public void Init(int v) 23 | { 24 | value = new Transform[v]; 25 | } 26 | 27 | public void ReplaceAt(Transform targetTransform, int pos) 28 | { 29 | if(pos < value.Length) 30 | { 31 | value[pos] = targetTransform; 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Scriptables/Variables/TransformArrayVariable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9c89e718a3d8ec049a03d3302970245a 3 | timeCreated: 1518775641 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Variables/TransformVariable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace SO 6 | { 7 | [CreateAssetMenu(menuName = "Variables/Transform")] 8 | public class TransformVariable : ScriptableObject 9 | { 10 | public Transform value; 11 | 12 | public void Set(Transform v) 13 | { 14 | value = v; 15 | } 16 | 17 | public void Set(TransformVariable v) 18 | { 19 | value = v.value; 20 | } 21 | 22 | public void Clear() 23 | { 24 | value = null; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Scriptables/Variables/TransformVariable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 034edd6a9f7307741b5b416ea4dd83d9 3 | timeCreated: 1518775577 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Scriptables/Variables/Vector3Variable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace SO 6 | { 7 | [CreateAssetMenu(menuName = "Variables/Vector3")] 8 | public class Vector3Variable : ScriptableObject 9 | { 10 | public Vector3 value; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Scriptables/Variables/Vector3Variable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b94b33feb8aa43b43870a6060b1f5374 3 | timeCreated: 1522755199 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Utilities/FindAssetsByType.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using UnityEditor; 6 | 7 | /// 8 | /// Returns all assets of the wanted type 9 | /// 10 | public static class FindAssetsByType { 11 | 12 | public static List FindAssetsOfType() where T : UnityEngine.Object 13 | { 14 | List assets = new List(); 15 | string[] guids = AssetDatabase.FindAssets(string.Format("t:{0}", typeof(T))); 16 | for (int i = 0; i < guids.Length; i++) 17 | { 18 | string assetPath = AssetDatabase.GUIDToAssetPath(guids[i]); 19 | T asset = AssetDatabase.LoadAssetAtPath(assetPath); 20 | if (asset != null) 21 | { 22 | assets.Add(asset); 23 | } 24 | } 25 | 26 | return assets; 27 | } 28 | } 29 | #endif 30 | -------------------------------------------------------------------------------- /Utilities/FindAssetsByType.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d34dc9eb6dcf50f489c17e5da41e92dd 3 | timeCreated: 1518781502 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | --------------------------------------------------------------------------------