Hi,
I’m working on a scriptable animation system which stores all the animation data in scriptable object so the same animation can be used without duplicating game objects or anything I use modifier scripts which are connected to the scriptable object script but the problem is I want to add these modifiers using a menu like in add component menu using custom attribute as well how can I do that I just want to find the type and I can do the rest I guess
- You have class (for example MyAnimations) that inherits from ScriptableObject.
- In that class you had stored Animations (probably some List or Dictionary).
- Now you can drag and drop that asset to other scripts (for example Player).
- In Player you for sure added reference to MyAnimations.
- You can add in MyAnimations enumeration (for example ID) with list of stored Animations and in Player you need to set value MyAnimations.ID animationID (in inspector will show select list).
Rest is send enum value to some method that return proper Animation (in Awake or Start method of Player class).
Yes but that’s how to use MyAnimation basically MyAnimation is a scriptable object which inherits from Scriptable Object and in MyAnimation I added a list of MyAnimationModifier this is a class which every modifier can inherit from them when I create any new modifier I just write new MyAnimationModifier(); so each animation asset contains animation data and modifiers with modifiers data as well but I currently add modifiers using editor buttons which is not good for extendability
Finding all types with a specific Attribute will require Reflection, but is very doable:
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); // Find ALL assemblies in current domain
for (int i = 0; i < assemblies.Length; i++)
{
var types = assemblies[i].GetTypes().Where(t => t.IsDefined(typeof(SerializableAttribute))); // Filter Types with Serializable-Attribute
}
From here you’ll need to find all assets with those Types on it.
Thank you so much this is what I was looking for ![]()
But I see that you looped through every single assembly how slow this could get?
Very slow. But in the editor, outside of playmode, that shouldn’t really matter.
If this is an editor only feature, I would recommend the much faster TypeCache class: Unity - Scripting API: TypeCache