Author Topic: Can you add editor classes support to EventDelegates?  (Read 2861 times)

vexe

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 153
    • View Profile
Can you add editor classes support to EventDelegates?
« on: February 26, 2014, 11:39:20 AM »
I have a RenameNotifer MonoBehaviour attached to some of my gameObjects, whenever there's a change in their name, it notifies a method in their editors. However, I had to make a slight adjustment for the delegate to be executed:

  1.                         if (Application.isPlaying) {
  2.                                 call();
  3.                         }
  4.                         else if (call.Target != null) {
  5.                                 System.Type type = call.Target.GetType();
  6.                                 object[] objs = type.GetCustomAttributes(typeof(ExecuteInEditMode), true);
  7.                                 if (objs != null && objs.Length > 0
  8.                                         || type.IsSubclassOf(typeof(UnityEditor.Editor)))
  9.                                         call();
  10.                         }
  11.  

Can you add this to NGUI's code?

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can you add editor classes support to EventDelegates?
« Reply #1 on: February 26, 2014, 02:24:42 PM »
UnityEditor is not available at run-time. This code won't compile. What is it you're trying to do? You shouldn't register any delegates at edit time.

vexe

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 153
    • View Profile
Re: Can you add editor classes support to EventDelegates?
« Reply #2 on: February 27, 2014, 04:14:14 AM »
As I mentioned before, there's a certain method in my editor that I want to execute when there's a rename on a certain GameObject (which has RenameNotifier attached to it - if there's a rename, it executes onRename which is a List<eventdelegate>)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can you add editor classes support to EventDelegates?
« Reply #3 on: February 27, 2014, 05:25:51 PM »
Durr. That entire section is in an #if UNITY_EDITOR check. My bad. Yes, your code makes perfect sense now, thanks.

vexe

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 153
    • View Profile
Re: Can you add editor classes support to EventDelegates?
« Reply #4 on: February 27, 2014, 05:57:02 PM »
yeah well I tried doing what I was doing, it seems that this is not the only place one has to make changes to, to be able to notify editors. since I'm interested in notifying my editor (which is a non-MB) - the "Target" of the delegate will be null, since you're only targeting MBs. I've also had issues with the delegate not serializing, probably related to the fact that the target is null or something, haven't looked into it in depth, but yea... more stuff needs to be editor in order to fully support that. I would love to see it happen though :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can you add editor classes support to EventDelegates?
« Reply #5 on: February 27, 2014, 06:17:55 PM »
Yea... might be easier to just use regular delegates.