Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Andy22 on November 13, 2013, 06:06:59 AM

Title: Bitmask field and custom UIHintAttribute?
Post 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.
Title: Re: Bitmask field and custom UIHintAttribute?
Post by: jeanfabre on November 14, 2013, 12:56:22 AM
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
Title: Re: Bitmask field and custom UIHintAttribute?
Post by: Andy22 on November 14, 2013, 03:59:05 AM
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
Title: Re: Bitmask field and custom UIHintAttribute?
Post by: jeanfabre on November 14, 2013, 05:56:41 AM
Hi,

 How can I use your attributes? can you give a component or scene that use this? thanks.

bye,

 Jean
Title: Re: Bitmask field and custom UIHintAttribute?
Post by: Andy22 on November 14, 2013, 06:15:53 AM
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.

Code: [Select]
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;
}
Title: Re: Bitmask field and custom UIHintAttribute?
Post by: jeanfabre on November 14, 2013, 06:20:42 AM
Hi,

 Ok, thanks for the clarifications.

 Bye,

 Jean
Title: Re: Bitmask field and custom UIHintAttribute?
Post by: Andy22 on November 26, 2013, 09:32:09 AM
Small source update, we reworked the attribute to use reflection, so it can be used with generics.

This way it can be used like:

Code: [Select]
public abstract class EventSenderBase<T> : BaseComponent, IEventSender
where T : struct, IConvertible // constrict to "enum"
{
[BitMask]
public T SendEventMask;
...
}


bye Andy
Title: Re: Bitmask field and custom UIHintAttribute?
Post by: jeanfabre on November 28, 2013, 02:51:21 AM
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
Title: Re: Bitmask field and custom UIHintAttribute?
Post by: Andy22 on November 28, 2013, 06:31:00 AM
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
Title: Re: Bitmask field and custom UIHintAttribute?
Post by: jeanfabre on November 28, 2013, 07:18:49 AM
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
Title: Re: Bitmask field and custom UIHintAttribute?
Post by: Andy22 on November 28, 2013, 09:46:45 AM
Ah oki, yes i found some differences and we target PC mainly, but thx for the info.

bye Andy
Title: Re: Bitmask field and custom UIHintAttribute?
Post by: Andy22 on December 03, 2013, 08:39:00 AM
Just found out about a new member that makes this work without reflection.
Title: Re: Bitmask field and custom UIHintAttribute?
Post by: jakeslack27 on March 15, 2015, 04:46:59 PM
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?