Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: Andy22 on November 13, 2013, 06:06:59 AM
-
Hi,
did someone figure out how to extend/add your own UIHintAttribute attributes? In our case we need a bitmask field, but writing a custom property drawer per enum/action is not practically. So is there a way to extend the default UIHint system?
thx Andy
PS: For the unity Inspector we have a custom "BitMask" attribute+drawer, but seems playmaker is using a custom editor rendering system, so our attribute is not working.
-
Hi,
I am not sure you can extend attributes ( not good enough at c# to know that actually... :)
I worked on a pathfinding custom mask editor widget, I think this is what you want to implement actually.
Check this:
http://hutonggames.com/playmakerforum/index.php?topic=5280.msg25289#msg25289
it has a custom made mask editor. Tell me if that's suitable or not ok and we'll take it from there.
bye,
Jean
-
Like noted, yes u could write a CustomActionEditor per enum type, but since Unity and Playmaker already have Attributes for this kind of work, the best solution is using a Attribute.
So instead of creating a CustomActionEditor for every enum mask type, u simply set a UIHintAttribute. Unity already has EditorGUI.MaskField() to handle the actual rendering and i attached the Unity BitMask attribute we use. It would be really nice to also have a "UIHint.BitMask" type in playmaker, to accomplish the same task.
I also suspect this is quite trivial, given that u already have a special UIHint system in place.
Thx Andy
-
Hi,
How can I use your attributes? can you give a component or scene that use this? thanks.
bye,
Jean
-
Just put the drawer into a editor folder and the attribute in a normal script folder , than create a Component and use it like this.
using System;
using UnityEngine;
public class MaskExample : MonoBehaviour
{
[Flags]
public enum ExampleEvents
{
EventA = 1 << 0,
EventB = 1 << 1,
EventC = 1 << 2,
EventD = 1 << 3,
}
[BitMask(typeof(ExampleEvents))]
public ExampleEvents SendEventMask;
}
-
Hi,
Ok, thanks for the clarifications.
Bye,
Jean
-
Small source update, we reworked the attribute to use reflection, so it can be used with generics.
This way it can be used like:
public abstract class EventSenderBase<T> : BaseComponent, IEventSender
where T : struct, IConvertible // constrict to "enum"
{
[BitMask]
public T SendEventMask;
...
}
bye Andy
-
Hi,
ok, not a big deal, but be careful with the new windows platforms, reflection is not supported. Have you checked on them?
bye
Jean
-
ok, not a big deal, but be careful with the new windows platforms, reflection is not supported. Have you checked on them?
What u mean by "reflection is not supported" and what u consider "new windows platforms" ?
As far as i understand it, reflection is available on nearly all windows platforms and if not u can use the "Portable Class Library" or is there some Unity specific catch to this?
There exist some PCL "API Differences" regarding reflection, but i guess those do not apply in this case?
http://msdn.microsoft.com/en-us/library/gg597392.aspx (http://msdn.microsoft.com/en-us/library/gg597392.aspx)
Thx Andy
-
Hi,
I meant Windows 8 Phone and windows metro may give you some trouble since their implementation of the Reflection is not exhaustive.
Bye,
Jean
-
Ah oki, yes i found some differences and we target PC mainly, but thx for the info.
bye Andy
-
Just found out about a new member that makes this work without reflection.
-
Sorry to resurrect this but I grabbed your code and got the BitMaskAttribute working in editor and think it's great :)
I was wondering if there was a solution to displaying and selecting the bitmask in the playmaker editor window?