Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Replicate AudioSource Inspector

Discussion in 'Extensions & OnGUI' started by chlorosoft, Jun 22, 2018.

  1. chlorosoft

    chlorosoft

    Joined:
    Oct 24, 2017
    Posts:
    4
    Hello,

    We are a videogame development studio and also we are developing assets for Asset store.

    We are currently developing a tool to manage the audio. This tool has a settings window, in this windows the developar can configure all audioclip settings (the same settings that you can find in a AudioSource).
    We want to implement the 3D sound settings that are in the AudioSoruce also in the window.

    We have tried:
    - Make an AnimationCurve with multiple curves but we have not found anything.
    - Get the unity editor class of the AudioSource but this uses a lot of internal classes and properties.

    Would there be any way to draw the AudioSource inspector as Unity does in our custom inspector or other solution?

    Thanks
     
  2. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    625
    The Odin inspector asset has something called inline inspectors where you can just add on to the audio inspector...
     
  3. BinaryCats

    BinaryCats

    Joined:
    Feb 8, 2016
    Posts:
    111
  4. PsyKaw

    PsyKaw

    Joined:
    Aug 16, 2012
    Posts:
    83
  5. chlorosoft

    chlorosoft

    Joined:
    Oct 24, 2017
    Posts:
    4
    First I use Editor.CreateEditor to get the AudioSource editor and then I access the Audio3DGUI method that is responsible for drawing the part of the 3D audio. This was achieved thanks to the reflection in the code part:

    Code (CSharp):
    1.  
    2.  
    3.                tmpEditor.serializedObject.Update();
    4.  
    5.                MethodInfo methodAudio = tmpEditor.GetType().GetMethod(
    6.                    "Audio3DGUI", BindingFlags.NonPublic | BindingFlags.Instance
    7.                );
    8.  
    9.                methodAudio.Invoke(tmpEditor, null);
    10.  
    11.                tmpEditor.serializedObject.ApplyModifiedProperties();
    At this moment I have another problem. To apply the curves in AudioSource I use the SetCustomCurve and GetCustomCurve methods (from AudioSoruce class) with the animation curves that I saved in an external class.
    Sometimes during this stage some animations curves are lost and I get an error of missing keys of the animation curve of the final AudiosSource.

    My Unity version is 5.4.2f2.

    Thank you
     
    Last edited: Jul 2, 2018