Author Topic: Data binding with getters  (Read 5610 times)

vallcrist

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 49
    • View Profile
Data binding with getters
« on: May 05, 2014, 03:04:55 PM »
Why isn't it possible to Data bind to a Getter?

It would be very useful if we could, since in some cases we need to show data of one of our Singletons, and it would be easier to just write a getter instead of writing the whole "void Update() { value = Singleton.instance.value }".

Any thoughts on it?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Data binding with getters
« Reply #1 on: May 05, 2014, 11:48:21 PM »
Sure you can. I just double-checked to make sure.
  1. using UnityEngine;
  2.  
  3. public class Test : MonoBehaviour
  4. {
  5.         PropertyReference prop;
  6.  
  7.         public int testMe { get { return 123; } }
  8.         public int testMe2 { get { return 123; } set { } }
  9. }
Both testMe and testMe2 show up in inspector when I drag this object into the "Prop" field. What are you doing, exactly?

vallcrist

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 49
    • View Profile
Re: Data binding with getters
« Reply #2 on: May 07, 2014, 07:02:17 AM »
Got it, i needed to add a empty seter for it to show up. =)