Beispiel #1
0
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        DropDownListAttribute attrib = attribute as DropDownListAttribute;

        string[] list = GetList(property, attrib);

        if (list == null || list.Length == 0 || (property.propertyType != SerializedPropertyType.String && property.propertyType != SerializedPropertyType.Integer &&
                                                 property.propertyType != SerializedPropertyType.Float))
        {
            return(base.GetPropertyHeight(property, label) + 25f);
        }
        return(base.GetPropertyHeight(property, label));
    }
Beispiel #2
0
    string[] GetList(SerializedProperty property, DropDownListAttribute attrib)
    {
        string[] list = new string[0];

        for (int i = 0; i < attrib.gameObjectTag.Length; i++)
        {
            string           gameObjectTag        = attrib.gameObjectTag[i];
            string           componentName        = attrib.componentName[i];
            string           propertyName         = attrib.propertyName[i];
            string           propertyRelativeName = attrib.propertyRelativeName[i];
            string[]         defaultKeys          = attrib.defaultKeys;
            string           prefix        = attrib.prefix[i];
            SerializedObject serializedObj = GetSerializedObject(property, gameObjectTag, componentName);
            string[]         temp          = GetList(property, serializedObj, propertyName, propertyRelativeName, defaultKeys, prefix);
            list = MergeTwoArrays(list, temp);
        }
        return(list);
    }
Beispiel #3
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property == null)
        {
            return;
        }

        label    = EditorGUI.BeginProperty(position, label, property);
        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

        var indent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;

        DropDownListAttribute attrib = attribute as DropDownListAttribute;

        string[] list = GetList(property, attrib);

        if (list == null)
        {
            EditorGUI.HelpBox(position, "Target Game Object is null, please make sure the target Game Object is active in hierarchy", MessageType.Warning);
            return;
        }

        if (list.Length == 0)
        {
            EditorGUI.HelpBox(position, "The target list is empty, cannot show value(s) on this element. Please add a value on the target list", MessageType.Warning);

            if (property.propertyType == SerializedPropertyType.String)
            {
                property.stringValue = null;
            }
            else if (property.propertyType == SerializedPropertyType.Integer)
            {
                property.intValue = ErrorKeyCode.EmptyList.GetHashCode();
            }
            else if (property.propertyType == SerializedPropertyType.Float)
            {
                property.floatValue = ErrorKeyCode.EmptyList.GetHashCode();
            }
            return;
        }

        if (property.propertyType == SerializedPropertyType.String)
        {
            string name = property.stringValue;
            DropDownList(position, list, ref name, attrib.indexValue);
            property.stringValue = name;
        }
        else if (property.propertyType == SerializedPropertyType.Integer)
        {
            string name = property.intValue.ToString();
            DropDownList(position, list, ref name, attrib.indexValue);
            name = GetDefaultKeyNumberValue(name);
            property.intValue = int.Parse(name);
        }
        else if (property.propertyType == SerializedPropertyType.Float)
        {
            string name = property.floatValue.ToString();
            DropDownList(position, list, ref name, attrib.indexValue);
            name = GetDefaultKeyNumberValue(name);
            property.floatValue = float.Parse(name);
        }
        else
        {
            EditorGUI.HelpBox(position, "DropDownList attribute only works with type string, int and float.", MessageType.Error);
        }

        EditorGUI.indentLevel = indent;

        EditorGUI.EndProperty();
    }