#Scripted Editor

1 messages · Page 1 of 1 (latest)

rough bison
#

using UnityEditor.Rendering;
using UnityEngine;

[CreateAssetMenu(fileName = "New ItemData", menuName = "ItemData")]
public class MaterialType : ScriptableObject
{
public string itemName;
public string itemDescription;
public int itemID;
public bool hasTiers;
public string[] tierNames;
public bool[] tiers;

public MaterialType()
{
    tierNames = new string[] { "Tier 1", "Tier 2", "Tier 3" };
    tiers = new bool[] { false, false, false };
}   

}

#

using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(MaterialType))]
public class MaterialTypeEditor : Editor
{
SerializedProperty hasOptionsProperty;
SerializedProperty optionLabelsProperty;
SerializedProperty optionsProperty;

private void OnEnable()
{
    hasOptionsProperty = serializedObject.FindProperty("hasTiers");
    optionLabelsProperty = serializedObject.FindProperty("tierNames");
    optionsProperty = serializedObject.FindProperty("tiers");
}

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

    EditorGUILayout.PropertyField(hasOptionsProperty);

    if (hasOptionsProperty.boolValue)
    {
        // Display the options array as a list of named toggle fields
        EditorGUI.indentLevel++;
        for (int i = 0; i < optionsProperty.arraySize; i++)
        {
            EditorGUILayout.PropertyField(optionsProperty.GetArrayElementAtIndex(i), new GUIContent(optionLabelsProperty.GetArrayElementAtIndex(i).stringValue));
        }
        EditorGUI.indentLevel--;
    }

    serializedObject.ApplyModifiedProperties();
}

}

#

so the only properties displaying is my bool array, and my string array works too but im only using that to define the name of the bools, and the other one that is displaying is the hasTier bool

#

i cant get the itemName String, the itemdescription, itemID to show

olive mango
#

Also post the code in code tags or a paste site

rough bison
#

ok

olive mango
#

So get rid of this part:cs public MaterialType() { tierNames = new string[] { "Tier 1", "Tier 2", "Tier 3" }; tiers = new bool[] { false, false, false }; }
You can do it in Awake I think, or just directly in the field initializer

#

public string[] tierNames = new string[] { "Tier 1", "Tier 2", "Tier 3" }; etc.

rough bison
#

oh ok

#

I fixed it had to do some stuff but it works now