From e18daf78d12e7df08929c089d4cbdb16818767c4 Mon Sep 17 00:00:00 2001 From: Alireza Tarahomi Date: Mon, 16 Sep 2019 20:43:29 +0430 Subject: [PATCH] Update README.md --- README.md | 97 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 87 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b431edc..2001d8a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ It is used for showing ScriptableObjects which are created in your project, in d # Usage Example 1. Clone this repository or download the latest [release package available](https://github.com/ATHellboy/ScriptableObjectDropdown/releases) (There isn't an example folder in `.unitypackage`). -2. Create `ScriptableObject` class which you want to create specified objects by that. +2. There are some options here: +* Create a `ScriptableObject` class which you want to create specified objects by that. ```cs using UnityEngine; @@ -19,11 +20,73 @@ public class Block : ScriptableObject } ``` +* Create a class that inherits another `ScriptableObject` class. + +```cs +using UnityEngine; + +[CreateAssetMenu(menuName = "Blocks/Sand")] +public class SandBlock : Block +{ + // Some fields and functions +} +``` + +* Create a abstract `ScriptableObject` class then antoher class which inherits this abstract class. + +```cs +using UnityEngine; + +public abstract class AbstarctBlock : ScriptableObject +{ + // Some fields and functions +} +``` + +```cs +using UnityEngine; + +[CreateAssetMenu(menuName = "Blocks/Water")] +public class WaterBlock : AbstarctBlock +{ + // Some fields and functions +} +``` + +* Create an interface and some `ScriptableObject` classes which inherit this interface. The interface is used for grouping. + +```cs +public interface IBlock +{ + // Some properties and functions signature +} +``` + +```cs +using UnityEngine; + +[CreateAssetMenu(menuName = "Blocks/Dirt")] +public class DirtBlock : ScriptableObject, IBlock +{ + // Some fields and functions +} +``` + +```cs +using UnityEngine; + +[CreateAssetMenu(menuName = "Blocks/Snow")] +public class SnowBlock : ScriptableObject, IBlock +{ + // Some fields and functions +} +``` + 3. Create ScriptableObjects in the project. ![](Images/Resources.PNG) -4. Use `ScriptableObjectDropdown` attribute by setting optional grouping (Default grouping is None) like this in `MonoBeahviour` or `ScriptableObject` derived classes. +4. Use `ScriptableObjectDropdown` attribute by setting type of specified `ScriptableObject` derived class and optional grouping (Default grouping is `None`) behind `ScriptableObjectReference` type variable like these in MonoBeahviour or ScriptableObject derived classes. **MonoBehavior** @@ -34,13 +97,20 @@ using UnityEngine; public class BlockManager : MonoBehaviour { // Without grouping (default is None) - [ScriptableObjectDropdown] public Block firstTargetBlock; + [ScriptableObjectDropdown(typeof(Block))] public ScriptableObjectReference targetBlock; // By grouping - [ScriptableObjectDropdown(grouping = ScriptableObjectGrouping.ByFolder)] public Block secondTargetBlock; + [ScriptableObjectDropdown(typeof(Block), grouping = ScriptableObjectGrouping.ByFolder)] + public ScriptableObjectReference targetBlockByGrouping; + // Derived class + [ScriptableObjectDropdown(typeof(SandBlock))] public ScriptableObjectReference derivedClassTargetBlock; + // Derived abstract class + [ScriptableObjectDropdown(typeof(AbstarctBlock))] public ScriptableObjectReference derivedAbstractClassTargetBlock; + // Interface + [ScriptableObjectDropdown(typeof(IBlock))] public ScriptableObjectReference interfaceTargetBlock; } ``` -![](Images/MonoBehaviourDefaultGrouping.png) +![](Images/MonoBehaviourInterface.png) ![](Images/MonoBehaviourByFolderGrouping.png) @@ -49,19 +119,26 @@ public class BlockManager : MonoBehaviour using UnityEngine; using ScriptableObjectDropdown; -[CreateAssetMenu(menuName ="Create Block Manager Settings")] +[CreateAssetMenu(menuName = "Create Block Manager Settings")] public class BlockManagerSettings : ScriptableObject { // Without grouping (default is None) - [ScriptableObjectDropdown] public Block firstTargetBlock; + [ScriptableObjectDropdown(typeof(Block))] public ScriptableObjectReference targetBlock; // By grouping - [ScriptableObjectDropdown(grouping = ScriptableObjectGrouping.ByFolderFlat)] public Block secondTargetBlock; + [ScriptableObjectDropdown(typeof(Block), grouping = ScriptableObjectGrouping.ByFolder)] + public ScriptableObjectReference targetBlockByGrouping; + // Derived class + [ScriptableObjectDropdown(typeof(SandBlock))] public ScriptableObjectReference derivedClassTargetBlock; + // Derived abstract class + [ScriptableObjectDropdown(typeof(AbstarctBlock))] public ScriptableObjectReference derivedAbstractClassTargetBlock; + // Interface + [ScriptableObjectDropdown(typeof(IBlock))] public ScriptableObjectReference interfaceTargetBlock; } ``` -![](Images/ScriptableObjectDefaultGrouping.png) +![](Images/ScriptableObjectDerivedClass.png) -![](Images/ScriptableObjectByFolderFlatGrouping.png) +![](Images/ScriptableObjectDerivedAbstractClass.png) # License MIT License