NaughtyAttributes icon indicating copy to clipboard operation
NaughtyAttributes copied to clipboard

TypeDropdown Attribute

Open apilola opened this issue 1 year ago • 6 comments

I've written this attribute using the SerializedReference API. It should work with pretty much any Non UnityEngine.Object derived type. Here is an example of it in action. I would submit a pull request for it, but it requires the project to be upgraded to 2021.2.

I could use a preprocessor directive to hide it, after I make my pull request. What are your thoughts?

TypeDropdown

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnimalTest : MonoBehaviour
{
    [SerializeReference, TypeDropdown(typeof(Animal))] Animal MyPet;
}

[System.Serializable]
public class Animal
{
    public string nickname = "Silly Billy";
}


public class Dog : Animal
{
    public string Breed = "Golden Retriever";
}

public class Cat : Animal
{
    public int lives = 9;
}

apilola avatar Apr 17 '23 19:04 apilola

Quck Note: When switching between types, the property will automatically try to copy any fields from the original object to the destination object.

apilola avatar Apr 20 '23 14:04 apilola

I am really interested in this !

antiNT2 avatar Apr 25 '23 01:04 antiNT2

What do you think? Should I submit a pull request with a preprocessor directive hiding it from older versions of unity?

apilola avatar Apr 25 '23 01:04 apilola

Hey! What's the progress on this?

Vatredox avatar Aug 14 '23 04:08 Vatredox

I am about to merge a lot of pull requests next weekend, so I will include it :)

dbrizov avatar Aug 15 '23 13:08 dbrizov

Formerly Created a PR here: https://github.com/dbrizov/NaughtyAttributes/pull/368

apilola avatar Aug 15 '23 16:08 apilola