Hi,
I’ve been working on a little ‘audio mixer’ editor window. (So I can control multiple audio sources in one place. I’ve recently managed to figure out the serialisation, so the settings can be adjusted in play mode)
The problem is that when I close down unity and open it again, the list elements are all gone. The screenshots shot a bit better what I mean. (The list is a list of ‘Track’ elements, a custom class)
When I re-open unity, the game objects are all there in the hierarchy, with the settings left as they were.
When I get the new errors, I have to use a line like this to reset it…
void OnFocus(){
audiosources.Clear ();
}
It seems like the elements are there, but all the information for each object is gone from my ‘track’ objects, inside my list of track elements - 'audiosources’ . Really not sure where to be looking to solve this: is it a serialisation issue? or a completely different issue I should look into
Thanks for reading, I know it’s quite lengthy
Here’s my scripts anyway: (I’ve removed some gui layout lines for ease of read )
Track.cs:
usingUnityEngine;
usingSystem.Collections;
usingUnityEditor;
[System.Serializable]
public class Track {
[SerializeField]
publicstring_name;
[SerializeField]
publicfloat_volume;
[SerializeField]
publicfloat_pan;
[SerializeField]
publicGameObject_gameobject;
[SerializeField]
publicAudioClip_audioclip;
public Track()
{
_name = "Default Name";
_volume = 1;
_pan = 0;
_gameobject = GameObject.Instantiate (Resources.Load ("Track"), Vector3.zero, Quaternion.identity)asGameObject;
_gameobject.transform.parent = GameObject.FindGameObjectWithTag ("AudioManager").transform;
}
public void OnGUI()
{
//Volume
GUILayout.Label ("Volume:", EditorStyles.boldLabel);
_volume = GUILayout.HorizontalSlider(_volume, 0, 1);
_gameobject.audio.volume = _volume;
//Pan
GUILayout.Label ("Pan:", EditorStyles.boldLabel);
_pan = GUILayout.HorizontalSlider(_pan, -1, 1);
_gameobject.audio.pan = _pan;
//AudioClip
GUILayout.Label ("AudioClip:", EditorStyles.boldLabel);
_audioclip = EditorGUILayout.ObjectField(_audioclip, typeof(AudioClip), true) asAudioClip;
_gameobject.audio.clip = _audioclip;
//Name
GUILayout.Label ("Name:", EditorStyles.boldLabel);
if(_name != null){
_name = GUILayout.TextArea(_name);
}
_gameobject.name = _name;
}
}
Mixer.cs:
usingUnityEngine;
usingSystem.Collections;
usingUnityEditor;
usingSystem.Collections.Generic;
[System.Serializable]
public class Mixer : EditorWindow {
[SerializeField]
public List<Track> audiosources;
AudioSource[] inscene;
[MenuItem("Audio/Mixer")]
static void Init()
{
Mixerwindow = (Mixer)Mixer.GetWindow <Mixer> ();
window.title = "Mixer";
}
voidOnEnable ()
{
hideFlags = HideFlags.HideAndDontSave;
}
public void OnGUI()
{
if (audiosources != null ) {
GUILayout.Label ("AS:" + audiosources.Count);
}
if(GUILayout.Button ("New"))
{
audiosources.Add(newTrack());
}
for (inti = 0; i < audiosources.Count; i++) {
audiosources [i].OnGUI ();
if(GUILayout.Button ("Delete"))
{
stringtemp = audiosources[i]._name;
audiosources.Remove(audiosources[i]);
DestroyImmediate(GameObject.Find(temp));
}
}
}
voidUpdate()
{
Repaint ();
}
}