Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ATHellboy committed Sep 16, 2019
2 parents 83aa11a + e18daf7 commit 894f4c8
Showing 1 changed file with 87 additions and 10 deletions.
97 changes: 87 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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**

Expand All @@ -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)

Expand All @@ -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
Expand Down

0 comments on commit 894f4c8

Please sign in to comment.