Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Reflection Tricks

Discussion in 'Scripting' started by Hikiko66, Oct 31, 2014.

  1. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,304
    So, I was having trouble with digging into arrays with reflection, but I solved it

    Code (csharp):
    1.  
    2.     public AudioMixer AudMix;
    3.  
    4.     void Start () {
    5.  
    6.         Array value = (Array)AudMix.GetType().GetProperty("exposedParameters").GetValue(AudMix, null);
    7.  
    8.         for(int i = 0; i< value.Length; i++)
    9.         {
    10.             var o = value.GetValue(i);
    11.             string Name = (string)o.GetType().GetField("name").GetValue(o);
    12.         }
    13. }
    14.  
     
    Last edited: Oct 31, 2014
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,514
    What type is AudioMixer?

    What type is the array in AudioMixer? Is it too an internal/private type?

    If not, why not cast the array that your retrieve out of 'AudMix' with reflection as its appropriate type so you don't need to use reflection to get the name.
     
  3. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,304
    UnityEditor.Audio.ExposedParameter

    Unfortunately it is not an exposed type, so I had to dig deeper.
     
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,514
    I still don't know what type that is.

    There is no UnityEditor.Audio namespace.

    There is no AudioMixer type that I know of.

    Is this in some newer version of unity, like a beta or something?
     
  5. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,304
    It is in the UT5 beta, yeah