playMaker

Author Topic: Bitmask field and custom UIHintAttribute?  (Read 5174 times)

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Bitmask field and custom UIHintAttribute?
« 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.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Bitmask field and custom UIHintAttribute?
« Reply #1 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

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: Bitmask field and custom UIHintAttribute?
« Reply #2 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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Bitmask field and custom UIHintAttribute?
« Reply #3 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

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: Bitmask field and custom UIHintAttribute?
« Reply #4 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;
}
« Last Edit: November 14, 2013, 06:33:38 AM by Andy22 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Bitmask field and custom UIHintAttribute?
« Reply #5 on: November 14, 2013, 06:20:42 AM »
Hi,

 Ok, thanks for the clarifications.

 Bye,

 Jean

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: Bitmask field and custom UIHintAttribute?
« Reply #6 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

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Bitmask field and custom UIHintAttribute?
« Reply #7 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

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: Bitmask field and custom UIHintAttribute?
« Reply #8 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

Thx Andy
« Last Edit: November 28, 2013, 07:00:11 AM by Andy22 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Bitmask field and custom UIHintAttribute?
« Reply #9 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

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: Bitmask field and custom UIHintAttribute?
« Reply #10 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

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: Bitmask field and custom UIHintAttribute?
« Reply #11 on: December 03, 2013, 08:39:00 AM »
Just found out about a new member that makes this work without reflection.

jakeslack27

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Bitmask field and custom UIHintAttribute?
« Reply #12 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?