Giter VIP home page Giter VIP logo

scriptableobjectdropdown's Introduction

ScriptableObjectDropdown

ScriptableObjectDropdown is an attribute for the Unity Inspector. It is used for showing ScriptableObjects which are created in your project, in dropdown menu and select between them in Inspector.

Usage Example

  1. Clone this repository or download the latest release package available (There isn't an example folder in .unitypackage).

  2. There are some options here:

  • Create a ScriptableObject class which you want to create specified objects by that.
using UnityEngine;

[CreateAssetMenu(menuName = "Create Block")]
public class Block : ScriptableObject
{
    // Some fields
}
  • Create a class that inherits another ScriptableObject class.
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.
using UnityEngine;

public abstract class AbstarctBlock : ScriptableObject
{
    // Some fields and functions
}
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.
public interface IBlock
{
    // Some properties and functions signature
}
using UnityEngine;

[CreateAssetMenu(menuName = "Blocks/Dirt")]
public class DirtBlock : ScriptableObject, IBlock
{
    // Some fields and functions
}
using UnityEngine;

[CreateAssetMenu(menuName = "Blocks/Snow")]
public class SnowBlock : ScriptableObject, IBlock
{
    // Some fields and functions
}
  1. Create ScriptableObjects in the project.

  1. 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

using ScriptableObjectDropdown;
using UnityEngine;

public class BlockManager : MonoBehaviour
{
    // Without grouping (default is None)
    [ScriptableObjectDropdown(typeof(Block))] public ScriptableObjectReference targetBlock;
    // By grouping
    [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;
}

ScriptableObject

using UnityEngine;
using ScriptableObjectDropdown;

[CreateAssetMenu(menuName = "Create Block Manager Settings")]
public class BlockManagerSettings : ScriptableObject
{
    // Without grouping (default is None)
    [ScriptableObjectDropdown(typeof(Block))] public ScriptableObjectReference targetBlock;
    // By grouping
    [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;
}

License

MIT License

Copyright (c) 2019 Alireza Tarahomi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

scriptableobjectdropdown's People

Contributors

athellboy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

scriptableobjectdropdown's Issues

2020.1.14f1

image

Is it supposed to work for Unity 2020?

This is what I get.

Is it possible to avoid using the Resources folder?

From Unity Manual https://docs.unity3d.com/Manual/BestPracticeUnderstandingPerformanceInUnity6.html

The Resources folder is a common source of many problems in Unity projects. Improper use of the Resources folder can bloat the size of a project’s build, lead to uncontrollable excessive memory utilization, and significantly increase application startup times.

Is it possible to avoid the need to put the objects in the Resources folder to get this functionality?

Removing requirement of ScriptableObjectReference

Nice work on the tool, thanks for making it available.

If there's no need for interface support is it possible to entirely remove ScriptableObjectReference?

In practice it is very inconvenient to actually use ScriptableObjectReference in place of real types where you want a dropdown. It would be much better if fields simply needed the Attribute with the Type in order to become a dropdown of that type pointing to the asset.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.