- Home /
Using save options to create saves for toggle buttons, but won't compile!
hey everybody, I read a bit about how Serialization works, and have tried every path to saving toggle states from scene to scene, (new toggles per scene, but when going back to the old scenes it deletes). I had to make a file, where it is calling the Editor. Now I can't figure out how to do this. I read it online, so dont judge to hard.
The errors are all directives errors. which include "Editor, CustomEditorAttribute, CustomEditor, SerializedProperty", saying the type or namespace (name) could not be found.
There is one error that is linked to an override method, it is for overriding the controls to save from scene to scene. It reads ECAAnimRecorderEditor.OnInspectorGUI() : no suitable method to override.
Here is the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Runtime.Serialization;
[CustomEditor(typeof(ECAAnimRecorder))]
public class ECAAnimRecorderEditor : Editor
{
private ECAAnimRecorderEditor ecaRecorder;
public SerializedProperty propAutoSave;
void OnEnable()
{
propAutoSave = serializedObject.FindProperty("file");
}
public override void OnInspectorGUI()
{
evaRecorder = ((ECAAnimRecorder)this.target);
serializedObject.Update();
EditorGUILayout.PropertyField(propAutoSave, new GUIContent("Auto Save"));
}
}
and code for button bool im trying to retrieve ( im trying to set up an array after to save and load all values at once)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using System.Runtime.Serialization;
[System.Serializable]
public class ECAAnimRecorder : MonoBehaviour
{
public AudioSource audio;
public string clip;
public AudioClip a;
public bool file;
public void OnChangeValue()
{
bool onoffSwitch = gameObject.GetComponent<Toggle>().isOn;
if (onoffSwitch)
{
AudioSource audio = gameObject.AddComponent<AudioSource>();
AudioClip a = Resources.Load(clip) as AudioClip;
audio.PlayOneShot(a);
bool file = true;
}
else
bool file = false;
}
}
If anybody understands saving toggles with serialization. Anyone at all, please help.
Answer by Trendsetter123 · Jun 15, 2019 at 04:42 PM
now I am getting an error saying "Cannot implicitly convert type "ECAAnimRecorder" to "ECAAnimRecorderEditor".. here is my updated code. it happens at (20,24), which is where ecaRecorder = ((ECAAnimRecorder)this.target);
ECAAnimRecorderEditor
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Runtime.Serialization;
using UnityEditor;
[CustomEditor(typeof(ECAAnimRecorder))]
public class ECAAnimRecorderEditor : Editor
{
private ECAAnimRecorderEditor ecaRecorder;
public SerializedProperty propAutoSave;
void OnEnable()
{
propAutoSave = serializedObject.FindProperty("file");
}
public override void OnInspectorGUI()
{
ecaRecorder = ((ECAAnimRecorder)this.target);
serializedObject.Update();
EditorGUILayout.PropertyField(propAutoSave, new GUIContent("Auto Save"));
}
}
ECAAnimRecorder
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using System.Runtime.Serialization;
[System.Serializable]
public class ECAAnimRecorder : MonoBehaviour
{
public AudioSource audio;
public string clip;
public AudioClip a;
public bool file;
public void OnChangeValue()
{
bool onoffSwitch = gameObject.GetComponent<Toggle>().isOn;
if (onoffSwitch)
{
AudioSource audio = gameObject.AddComponent<AudioSource>();
AudioClip a = Resources.Load(clip) as AudioClip;
audio.PlayOneShot(a);
file = true;
}
else
file = false;
}
}