Search Unity

Access namespace from Editor

Discussion in 'Scripting' started by CDF, Apr 4, 2014.

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Hi, is it possible for an Editor script which shares the same namespace as its target Component to access an internal variable in that Component?

    doesn't seem to work.

    Code (csharp):
    1.  
    2. namespace MyNameSpace {
    3.  
    4.     public class Test {
    5.    
    6.         internal float hello;
    7.     }
    8. }
    9.  
    10. namespace MyNameSpace {
    11.  
    12.     [CustomEditor (typeof(Test))]
    13.     public class TestEditor : Editor {
    14.    
    15.         void OnEnable() {
    16.            
    17.             Test test = target as Test;
    18.            
    19.             float hello = test.hello; //cannot find variable "hello"
    20.         }
    21.     }
    22. }
    23.  
     
  2. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
    Did you tried to write:
    Code (csharp):
    1.  
    2. [CustomEditor (typeof(MyNameSpace.Test))]
    3.  
     
  3. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Same Namespace, but different Assembly. I doubt it will work.

    You can always get that field by reflection. Nothing is hidden to reflection. :p
     
  4. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
  5. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Ah Reflection, my old friend.

    Thanks.
     
  6. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    My best friend. :p