Jump to content

Question for Developers


DKnight
 Share

Recommended Posts

I am having an issue tring to find a solution. So i figure i will ask here.

I have 2 classes.

The first class is a manager class which inherits from MonoBehaviour. The second is inheriting from ScriptableObject. I have created two custom editor scripts for each of these class. The custom script for the manager class seems to be working proper. I can Load/Save accounts to the disk. And the function that to add an account seems to work. I am using a scriptable object for other reasons instead of an class object.

 

The issue that I am having, i cant seem to figure out how, that when you select an element in the list that the selected object is expanded below the list using it's custom editor.

example:

image.png.a8400d7297a38efb833e1ec3186136e8.png

 

Account Manager : Editor script

    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();

        if (GUILayout.Button(new GUIContent("Clear", "Clear"), EditorStyles.miniButton, GUILayout.Width(85)))
        {
            AccountsManager.Singleton.ClearData();
        }

        if (GUILayout.Button(new GUIContent("Save", "Save"), EditorStyles.miniButton, GUILayout.Width(85)))
        {
            AccountsManager.Singleton.SaveData();
        }

        if (GUILayout.Button(new GUIContent("Load", "Load"), EditorStyles.miniButton, GUILayout.Width(85)))
        {
            AccountsManager.Singleton.LoadData();
        }

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.PropertyField(_accounts, true);

        SerializedProperty property = _accounts.GetArrayElementAtIndex(0);
        if (property != null )
        {
            Account account = property.objectReferenceValue as Account;

            _accounts.isExpanded = 
                EditorGUILayout.InspectorTitlebar(true, account);


        }

        serializedObject.ApplyModifiedProperties();
    }

Account :  Editor script

    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button(new GUIContent("Clear", "Clear")))
        {
            //AccountsManager.Singleton.ClearData();
        }

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.PropertyField(username, true );
        EditorGUILayout.PropertyField(playername, true);
        EditorGUILayout.PropertyField(email, true);

        serializedObject.ApplyModifiedProperties();
    }

 

Any suggestion or ideas would be very helpful.  Even an example would be helpful. 

DKnight

 

Link to comment
Share on other sites

 Share

  • Tell a friend

    Love Canopy - Procedural Worlds? Tell a friend!
  • Need help?

    We work with some of the biggest brands in global gaming, automotive, technology, and government to create environments, games, simulations, and product launches for desktop, mobile, and VR.

    Our unique expertise and technology enable us to deliver solutions that look and run better at a fraction of the time and cost of a typical project.

    Check out some of our non-NDA work in the Gallery, and then Contact Us to accelerate your next project!

×
×
  • Create New...