All Projects → mackysoft → Unity-SerializeReferenceExtensions

mackysoft / Unity-SerializeReferenceExtensions

Licence: MIT license
Provide popup to specify the type of the field serialized by the [SerializeReference] attribute in the inspector.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to Unity-SerializeReferenceExtensions

Java-Programs
Java Practiced Problems including concepts of OOPS, Interface, String , Collection.
Stars: ✭ 51 (-80%)
Mutual labels:  interface, polymorphism
Unity-Interface-Support
A simple implementation which allows for interface-type fields to be accepted in the Unity inspector.
Stars: ✭ 45 (-82.35%)
Mutual labels:  serialization, interface
typeclass-interface-pattern
Ideas, thoughts, and notes on a typeclass/interface based polymorphism pattern for standard C
Stars: ✭ 26 (-89.8%)
Mutual labels:  interface, polymorphism
LMS.Version
Super simple auto build version tool
Stars: ✭ 40 (-84.31%)
Mutual labels:  unity-editor
marshmallow-validators
Use 3rd-party validators (e.g. from WTForms and colander) with marshmallow
Stars: ✭ 24 (-90.59%)
Mutual labels:  serialization
jim
Immediate Mode JSON Serialization Library in C
Stars: ✭ 35 (-86.27%)
Mutual labels:  serialization
dualFace
dualFace: Two-Stage Drawing Guidance for Freehand Portrait Sketching (CVMJ)
Stars: ✭ 46 (-81.96%)
Mutual labels:  interface
sqlathanor
Serialization / De-serialization support for the SQLAlchemy Declarative ORM
Stars: ✭ 105 (-58.82%)
Mutual labels:  serialization
sassy-css
Learn UI Design, CSS, SASS by completing interesting tasks.
Stars: ✭ 16 (-93.73%)
Mutual labels:  interface
har-rs
A HTTP Archive format (HAR) serialization & deserialization library, written in Rust.
Stars: ✭ 25 (-90.2%)
Mutual labels:  serialization
Eden
edn (extensible data notation) encoder/decoder for Elixir
Stars: ✭ 32 (-87.45%)
Mutual labels:  serialization
gradle-flatbuffers-plugin
Gradle plugin for generating code from Google FlatBuffers schemas
Stars: ✭ 20 (-92.16%)
Mutual labels:  serialization
Json-to-Dart-Model
marketplace.visualstudio.com/items?itemName=hirantha.json-to-dart
Stars: ✭ 84 (-67.06%)
Mutual labels:  serialization
zkar
ZKar is a Java serialization protocol analysis tool implement in Go.
Stars: ✭ 435 (+70.59%)
Mutual labels:  serialization
surge
Simple, specialised, and efficient binary marshaling
Stars: ✭ 36 (-85.88%)
Mutual labels:  serialization
rkdb
R client for kdb+
Stars: ✭ 37 (-85.49%)
Mutual labels:  interface
urlpack
Pure JavaScript toolkit for data URLs (MessagePack, Base58 and Base62)
Stars: ✭ 51 (-80%)
Mutual labels:  serialization
jsonapi-serializable
Conveniently build and efficiently render JSON API resources.
Stars: ✭ 43 (-83.14%)
Mutual labels:  serialization
yserial
NoSQL y_serial Python module – warehouse compressed objects with SQLite
Stars: ✭ 17 (-93.33%)
Mutual labels:  serialization
scripts-manager-unity3d
📄 Gives the list of scripts in the current scene with gameobject reference.
Stars: ✭ 52 (-79.61%)
Mutual labels:  unity-editor

Unity SerializeReferenceExtensions

Build Release openupm

Inspired by this post.

The SerializeReference attribute, added in Unity 2019.3, makes it possible to serialize references to interfaces and abstract classes.

The SubclassSelector attribute allows you to easily set subclasses of those abstract classes in the Editor that are serialized by SerializeReference attribute.

SubclassSelector

Features

  • Easily set subclass by popup.
  • [New] Type finding by fuzzy finder.
  • [New] Override the type name and path by the AddTypeMenu attribute.

📥 Installation

Download any version from releases.

Releases: https://github.com/mackysoft/Unity-SerializeReferenceExtensions/releases

Install via git URL

Or, you can add this package by opening PackageManager and entering

https://github.com/mackysoft/Unity-SerializeReferenceExtensions.git?path=Assets/MackySoft/MackySoft.SerializeReferenceExtensions

from the Add package from git URL option.

Install via Open UPM

Or, you can install this package from the Open UPM registry.

More details here.

openupm add com.mackysoft.serializereference-extensions

🔰 Usage

using System;
using UnityEngine;

public class Example : MonoBehaviour {

	// The type that implements ICommand will be displayed in the popup.
	[SerializeReference, SubclassSelector]
	ICommand m_Command;

	// Collection support
	[SerializeReference, SubclassSelector]
	ICommand[] m_Commands = Array.Empty<ICommand>();

	void Start () {
		m_Command?.Execute();

		foreach (ICommand command in m_Commands) {
			command?.Execute();
		}
	}

	// Nested type support
	[Serializable]
	public class NestedCommand : ICommand {
		public void Execute () {
			Debug.Log("Execute NestedCommand");
		}
	}

}

public interface ICommand {
	void Execute ();
}

[Serializable]
public class DebugCommand : ICommand {

	[SerializeField]
	string m_Message;

	public void Execute () {
		Debug.Log(m_Message);
	}
}

[Serializable]
public class InstantiateCommand : ICommand {

	[SerializeField]
	GameObject m_Prefab;

	public void Execute () {
		UnityEngine.Object.Instantiate(m_Prefab,Vector3.zero,Quaternion.identity);
	}
}

// Menu override support
[AddTypeMenu("Example/Add Type Menu Command")]
[Serializable]
public class AddTypeMenuCommand : ICommand {
	public void Execute () {
		Debug.Log("Execute AddTypeMenuCommand");
	}
}

[Serializable]
public struct StructCommand : ICommand {
	public void Execute () {
		Debug.Log("Execute StructCommand");
	}
}

Supported Types

The SubclassSelector attribute supports types that meet the following conditions.

  • Public
  • Not abstract
  • Not generic
  • Not unity object
  • Serializable attribute is applied.

FAQ

If the type is renamed, the reference is lost.

It is a limitation of SerializeReference of Unity.

When serializing a SerializeReference reference, the type name, namespace, and assembly name are used, so if any of these are changed, the reference cannot be resolved during deserialization.

To solve this problem, UnityEngine.Scripting.APIUpdating.MovedFromAttribute can be used.

Also, this thread will be helpful.

References

Help & Contribute

I welcome feature requests and bug reports in issues and pull requests.

If you feel that my works are worthwhile, I would greatly appreciate it if you could sponsor me.

GitHub Sponsors: https://github.com/sponsors/mackysoft

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].