Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. 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:
    636
    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:
    129
  4. PsyKaw

    PsyKaw

    Joined:
    Aug 16, 2012
    Posts:
    88
  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