- Home /
Question by
Valoon129 · May 03, 2019 at 05:01 PM ·
scripting problemserializationcustom-inspectorserializedproperty
Access serialized values from an outside script,Custom Editor Values access on Play
Hello I am trying to make a script using a custom inspector and I think I don't understand the serialization part of all of it. This is the first time I do this so I am a beginner.
Main class is this :
[System.Serializable]
public class LanguageManager : MonoBehaviour {
private static LanguageManager instance = null;
public static LanguageManager Instance
{
get
{
if (instance == null)
{
instance = new LanguageManager();
}
return instance;
}
}
[System.Serializable]
public class LanguageMainClass
{
public string language;
public Sprite flag;
public string path;
public bool isDefault;
public bool isSelected;
}
[SerializeField]
public List<LanguageMainClass> listOfLanguages;
[SerializeField]
private AudioLanguageScriptableObject languageObject;
public AudioLanguageScriptableObject LanguageObject
{
get
{
return languageObject;
}
set
{
languageObject = value;
}
}
Editor is this :
[ExecuteInEditMode]
[CustomEditor(typeof(LanguageManager))]
public class LanguageManagerEditor : Editor {
ReorderableList languageListReorderable;
SerializedProperty languageObject;
private string pathToUse;
void OnEnable()
{
languageListReorderable = new ReorderableList(serializedObject.FindProperty("listOfLanguages"));
languageObject = serializedObject.FindProperty("languageObject");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
GUILayout.Label("Create an object to store all your voice clips for each language", EditorStyles.boldLabel);
if (GUILayout.Button("Create a Scriptable Object"))
{
LanguageManager.Instance.CreateMyScriptableObject();
}
GUILayout.Label("Languages List :", EditorStyles.boldLabel);
languageListReorderable.DoLayoutList();
languageListReorderable.GetItem(0).FindPropertyRelative("isDefault").boolValue = true;
for (int i = 1; i < languageListReorderable.Length; i++)
{
languageListReorderable.GetItem(i).FindPropertyRelative("isDefault").boolValue = false;
}
for (int i = 1; i < languageListReorderable.Length; i++)
{
if (languageListReorderable.GetItem(i).FindPropertyRelative("isSelected").boolValue)
pathToUse = languageListReorderable.GetItem(i).FindPropertyRelative("path").stringValue;
else
pathToUse = languageListReorderable.GetItem(0).FindPropertyRelative("path").stringValue;
}
languageObject.objectReferenceValue = Resources.Load<AudioLanguageScriptableObject>(pathToUse);
GUILayout.Label("Currently using :", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(languageObject);
EditorUtility.SetDirty(this);
serializedObject.ApplyModifiedProperties();
}
}
The thing is working very well but I can't access any of it from outside, everything returns null no matter what I try.
Thank you for your help.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612200644im_/https://answers.unity.com/themes/thub/images/avi.jpg)