Skip to content

Commit 894f4c8

Browse files
committed
2 parents 83aa11a + e18daf7 commit 894f4c8

1 file changed

Lines changed: 87 additions & 10 deletions

File tree

README.md

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ It is used for showing ScriptableObjects which are created in your project, in d
77
# Usage Example
88
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`).
99

10-
2. Create `ScriptableObject` class which you want to create specified objects by that.
10+
2. There are some options here:
11+
* Create a `ScriptableObject` class which you want to create specified objects by that.
1112

1213
```cs
1314
using UnityEngine;
@@ -19,11 +20,73 @@ public class Block : ScriptableObject
1920
}
2021
```
2122

23+
* Create a class that inherits another `ScriptableObject` class.
24+
25+
```cs
26+
using UnityEngine;
27+
28+
[CreateAssetMenu(menuName = "Blocks/Sand")]
29+
public class SandBlock : Block
30+
{
31+
// Some fields and functions
32+
}
33+
```
34+
35+
* Create a abstract `ScriptableObject` class then antoher class which inherits this abstract class.
36+
37+
```cs
38+
using UnityEngine;
39+
40+
public abstract class AbstarctBlock : ScriptableObject
41+
{
42+
// Some fields and functions
43+
}
44+
```
45+
46+
```cs
47+
using UnityEngine;
48+
49+
[CreateAssetMenu(menuName = "Blocks/Water")]
50+
public class WaterBlock : AbstarctBlock
51+
{
52+
// Some fields and functions
53+
}
54+
```
55+
56+
* Create an interface and some `ScriptableObject` classes which inherit this interface. The interface is used for grouping.
57+
58+
```cs
59+
public interface IBlock
60+
{
61+
// Some properties and functions signature
62+
}
63+
```
64+
65+
```cs
66+
using UnityEngine;
67+
68+
[CreateAssetMenu(menuName = "Blocks/Dirt")]
69+
public class DirtBlock : ScriptableObject, IBlock
70+
{
71+
// Some fields and functions
72+
}
73+
```
74+
75+
```cs
76+
using UnityEngine;
77+
78+
[CreateAssetMenu(menuName = "Blocks/Snow")]
79+
public class SnowBlock : ScriptableObject, IBlock
80+
{
81+
// Some fields and functions
82+
}
83+
```
84+
2285
3. Create ScriptableObjects in the project.
2386

2487
![](Images/Resources.PNG)
2588

26-
4. Use `ScriptableObjectDropdown` attribute by setting optional grouping (Default grouping is None) like this in `MonoBeahviour` or `ScriptableObject` derived classes.
89+
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.
2790

2891
**MonoBehavior**
2992

@@ -34,13 +97,20 @@ using UnityEngine;
3497
public class BlockManager : MonoBehaviour
3598
{
3699
// Without grouping (default is None)
37-
[ScriptableObjectDropdown] public Block firstTargetBlock;
100+
[ScriptableObjectDropdown(typeof(Block))] public ScriptableObjectReference targetBlock;
38101
// By grouping
39-
[ScriptableObjectDropdown(grouping = ScriptableObjectGrouping.ByFolder)] public Block secondTargetBlock;
102+
[ScriptableObjectDropdown(typeof(Block), grouping = ScriptableObjectGrouping.ByFolder)]
103+
public ScriptableObjectReference targetBlockByGrouping;
104+
// Derived class
105+
[ScriptableObjectDropdown(typeof(SandBlock))] public ScriptableObjectReference derivedClassTargetBlock;
106+
// Derived abstract class
107+
[ScriptableObjectDropdown(typeof(AbstarctBlock))] public ScriptableObjectReference derivedAbstractClassTargetBlock;
108+
// Interface
109+
[ScriptableObjectDropdown(typeof(IBlock))] public ScriptableObjectReference interfaceTargetBlock;
40110
}
41111
```
42112

43-
![](Images/MonoBehaviourDefaultGrouping.png)
113+
![](Images/MonoBehaviourInterface.png)
44114

45115
![](Images/MonoBehaviourByFolderGrouping.png)
46116

@@ -49,19 +119,26 @@ public class BlockManager : MonoBehaviour
49119
using UnityEngine;
50120
using ScriptableObjectDropdown;
51121

52-
[CreateAssetMenu(menuName ="Create Block Manager Settings")]
122+
[CreateAssetMenu(menuName = "Create Block Manager Settings")]
53123
public class BlockManagerSettings : ScriptableObject
54124
{
55125
// Without grouping (default is None)
56-
[ScriptableObjectDropdown] public Block firstTargetBlock;
126+
[ScriptableObjectDropdown(typeof(Block))] public ScriptableObjectReference targetBlock;
57127
// By grouping
58-
[ScriptableObjectDropdown(grouping = ScriptableObjectGrouping.ByFolderFlat)] public Block secondTargetBlock;
128+
[ScriptableObjectDropdown(typeof(Block), grouping = ScriptableObjectGrouping.ByFolder)]
129+
public ScriptableObjectReference targetBlockByGrouping;
130+
// Derived class
131+
[ScriptableObjectDropdown(typeof(SandBlock))] public ScriptableObjectReference derivedClassTargetBlock;
132+
// Derived abstract class
133+
[ScriptableObjectDropdown(typeof(AbstarctBlock))] public ScriptableObjectReference derivedAbstractClassTargetBlock;
134+
// Interface
135+
[ScriptableObjectDropdown(typeof(IBlock))] public ScriptableObjectReference interfaceTargetBlock;
59136
}
60137
```
61138

62-
![](Images/ScriptableObjectDefaultGrouping.png)
139+
![](Images/ScriptableObjectDerivedClass.png)
63140

64-
![](Images/ScriptableObjectByFolderFlatGrouping.png)
141+
![](Images/ScriptableObjectDerivedAbstractClass.png)
65142

66143
# License
67144
MIT License

0 commit comments

Comments
 (0)