Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Reflection Tricks

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

  1. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,300
    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,377
    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,300
    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,377
    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,300
    It is in the UT5 beta, yeah