Ejemplo n.º 1
0
    public bool CheckHide(SerializedProperty property)
    {
        if (!string.IsNullOrEmpty(args.hideIfEmpty))
        {
            SerializedProperty p = EditorExt.GetPropertyByName(property, args.hideIfEmpty);
            if (p != null)
            {
                switch (p.propertyType)
                {
                case SerializedPropertyType.Boolean:
                    return(p.boolValue == false);

                case SerializedPropertyType.Enum:
                    return(p.enumValueIndex == 0);

                case SerializedPropertyType.Float:
                    return(Math.Abs(p.floatValue) <= float.Epsilon);

                case SerializedPropertyType.Integer:
                    return(p.intValue == 0);

                case SerializedPropertyType.ObjectReference:
                    return(p.objectReferenceValue == null);

                case SerializedPropertyType.String:
                    return(string.IsNullOrEmpty(p.stringValue));

                default:
                    LogError(string.Format("Can't ({0}) hide Property ({1}): No support for this type of property.", property.serializedObject.targetObject, property.name), property.serializedObject.targetObject);
                    break;
                }
            }
        }
        return(false);
    }
Ejemplo n.º 2
0
    public override void Draw(Rect position, SerializedProperty property, GUIContent label)
    {
        SerializedProperty prop = null;

        if (propertyPopupAttribute.sourceType == PropertyPopupAttribute.SourceType.TypeName)
        {
            Target = propertyPopupAttribute.sourcePropertyName;
        }
        else
        {
            if (propertyPopupAttribute.sourceType == PropertyPopupAttribute.SourceType.CalculatedType)
            {
                PropertyInfo pInfo = property.serializedObject.targetObject.GetType().GetProperty(propertyPopupAttribute.sourcePropertyName);
                if (pInfo != null)
                {
                    Type type = pInfo.GetValue(property.serializedObject.targetObject, null) as Type;
                    if (type != null)
                    {
                        Target = type.AssemblyQualifiedName;
                    }
                    else
                    {
                        LogError(string.Format("Can't calculate Property ({1}) in object({0}).", property.serializedObject.targetObject, label.text), property.serializedObject.targetObject);
                    }
                }
            }
            else if (!string.IsNullOrEmpty(propertyPopupAttribute.sourcePropertyName))
            {
                //SerializedObject obj = property.serializedObject;
                //prop = obj.FindProperty(propertyPopupAttribute.sourcePropertyName);
                prop = EditorExt.GetPropertyByName(property, propertyPopupAttribute.sourcePropertyName);
            }

            if (propertyPopupAttribute.sourceType == PropertyPopupAttribute.SourceType.FieldTarget)
            {
                if (!string.IsNullOrEmpty(propertyPopupAttribute.sourcePropertyName))
                {
                    if (prop != null && prop.objectReferenceValue != null)
                    {
                        Target = prop.objectReferenceValue.GetType().AssemblyQualifiedName;
                    }
                }
                else
                {
                    Target = property.serializedObject.targetObject.GetType().AssemblyQualifiedName;
                }
            }

            if (propertyPopupAttribute.sourceType == PropertyPopupAttribute.SourceType.FieldTypeName)
            {
                if (prop != null)
                {
                    Target = prop.stringValue;
                }
            }
        }

        base.Draw(position, property, label);
    }
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            var collectionList = property.FindPropertyRelative("m_SerializedCollections");

            if (collectionList.arraySize != 0)
            {
                return(GetElemHeight(collectionList, 0));
            }
            else
            {
                return(EditorExt.GetRowHeight(1));
            }
        }
Ejemplo n.º 4
0
    public static void GenIconPrefab(Sprite icon, GameObject[] templatePrefabs)
    {
        if (icon == null)
        {
            Debug.LogError("icon is null");
            return;
        }

        if (icon.name.Contains("mage"))
        {
            return;
        }


        string typeName = icon.name.Replace("_icon", "");

        for (var i = 0; i < templatePrefabs.Length; i++)
        {
            var templatePrefab = templatePrefabs[i];
            var go             = GameObject.Instantiate(templatePrefab, Localization.UIRoot.transform);
            go.name = typeName + (i + 1);
            for (int j = 0; j < i + 1; j++)
            {
                string itemName  = "bg_" + (j + 1);
                var    item_icon = go.transform.Find(itemName + "/icon").GetComponent <Image>();
                item_icon.sprite = icon;
                EditorExt.MakePixelPerfect(item_icon.rectTransform);
            }

            var prefabCom = go.GetComponent <Prefab>();
            if (prefabCom != null)
            {
                DestroyImmediate(prefabCom);
            }

            var guid = go.GetComponent <VisualDesignCafe.Editor.Prefabs.Guid>();
            if (guid != null)
            {
                DestroyImmediate(guid);
            }

            string path         = savePath + "/" + go.name + ".prefab";
            var    sourcePrefab = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject));
            if (sourcePrefab == null)
            {
                sourcePrefab = PrefabUtility.CreateEmptyPrefab(path);
            }
            PrefabUtility.ReplacePrefab(go, sourcePrefab);
            DestroyImmediate(go);
        }
    }
Ejemplo n.º 5
0
    public override void Draw(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginChangeCheck();
        EditorExt.PropertyField(position, property, label, fieldInfo);
        if (EditorGUI.EndChangeCheck())
        {
            if (IsMonoBehaviour(property))
            {
                MonoBehaviour mono = (MonoBehaviour)property.serializedObject.targetObject;

                foreach (var callbackName in observeAttribute.callbackNames)
                {
                    mono.Invoke(callbackName, 0);
                }
            }
        }
    }
Ejemplo n.º 6
0
    public override void Draw(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginChangeCheck();
        switch (property.type)
        {
        case "int":
            property.intValue = (int)getValue(position, label, property.intValue);
            break;

        case "float":
            property.floatValue = getValue(position, label, property.floatValue);
            break;

        default:
            EditorExt.PropertyField(position, property, label, fieldInfo);
            break;
        }
    }
Ejemplo n.º 7
0
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        if (CheckHide(property))
        {
            return(0f);
        }

        if (args != null && args.lines > 0)
        {
            return(EditorGUIUtility.singleLineHeight * args.lines);
        }

        return(EditorExt.PropertyHeight(property));

        /*
         * if (property.hasVisibleChildren)
         *  return EditorExt.CalculatePropertyHeight(EditorGUIUtility.singleLineHeight, property);
         * else
         *  return  EditorExt.PropertyHeight(property);//*/
    }
        public override void OnGUI(Rect area, SerializedProperty property, GUIContent label)
        {
            Rect position = EditorExt.GetInitialRectRow(area);

            var collectionList = property.FindPropertyRelative("m_SerializedCollections");

            // Make sure root always exists
            if (collectionList.arraySize == 0)
            {
                collectionList.arraySize = 1;

                var newGroupProp = collectionList.GetArrayElementAtIndex(0);
                newGroupProp.FindPropertyRelative("Weight").SetPropertyValue(1.0f);
                newGroupProp.FindPropertyRelative("Items").arraySize = 0;
                newGroupProp.FindPropertyRelative("SubcollectionIndices").arraySize = 0;
            }

            // Insert root, if it doesn't exist
            DrawCollection(ref position, collectionList, 0, label);
        }
        private float GetElemHeight(SerializedProperty collectionList, int index)
        {
            var currProp = collectionList.GetArrayElementAtIndex(index);

            if (currProp.isExpanded)
            {
                float height = EditorExt.GetRowHeight(1);

                // Items height
                {
                    height += EditorExt.GetRowHeight(1);
                    var itemsProp = currProp.FindPropertyRelative("Items");

                    for (int i = 0; i < itemsProp.arraySize; ++i)
                    {
                        var itemElemProp = itemsProp.GetArrayElementAtIndex(i);
                        var weightProp   = itemElemProp.FindPropertyRelative("Weight");
                        var itemProp     = itemElemProp.FindPropertyRelative("Item");

                        height += EditorExt.KeyValuePairHeight(weightProp, itemProp);
                    }
                }

                // Sub groups height
                {
                    var subIndicesProp = currProp.FindPropertyRelative("SubcollectionIndices");
                    for (int i = 0; i < subIndicesProp.arraySize; ++i)
                    {
                        int subIndex = subIndicesProp.GetArrayElementAtIndex(i).intValue;
                        height += GetElemHeight(collectionList, subIndex);
                    }
                }

                return(height);
            }
            else
            {
                return(EditorExt.GetRowHeight(1));
            }
        }
Ejemplo n.º 10
0
    /// <summary>
    /// Gets the animator controller.
    /// </summary>
    /// <returns>
    /// The animator controller.
    /// </returns>
    /// <param name='property'>
    /// Property.
    /// </param>

    AnimatorController GetAnimatorController(SerializedProperty property)
    {
        Component component  = null;
        string    sourceName = GetSourceName();

        if (string.IsNullOrEmpty(sourceName))
        {
            component = property.serializedObject.targetObject as Component;
        }
        else
        {
            SerializedProperty source = EditorExt.GetPropertyByName(property, sourceName);
            if (source != null)
            {
                component = source.objectReferenceValue as Component;
            }
            if (component == null)
            {
                component = KingUtil.GetPropertyValue <Animator>(property.serializedObject.targetObject, sourceName);
            }
        }
        if (component == null)
        {
            LogError("Couldn't cast targetObject", property.serializedObject.targetObject);
            return(null);
        }

        Animator anim = component.GetComponent <Animator>();

        if (anim == null)
        {
            LogError("Missing Animator Component", property.serializedObject.targetObject);
            return(null);
        }

        AnimatorController animatorController = anim.runtimeAnimatorController as AnimatorController;

        return(animatorController);
    }
Ejemplo n.º 11
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            if (property.isExpanded)
            {
                float height = 0.0f;

                var elementsProp = property.FindPropertyRelative("m_Elements");
                for (int i = 0; i < elementsProp.arraySize; ++i)
                {
                    var elemProp  = elementsProp.GetArrayElementAtIndex(i);
                    var keyProp   = elemProp.FindPropertyRelative("Key");
                    var valueProp = elemProp.FindPropertyRelative("Value");

                    float maxHeight = Mathf.Max(EditorGUI.GetPropertyHeight(keyProp), EditorGUI.GetPropertyHeight(valueProp));
                    height += maxHeight;
                }

                return(height + EditorExt.GetRowHeight(3));
            }
            else
            {
                return(EditorExt.GetRowHeight());
            }
        }
Ejemplo n.º 12
0
 public virtual void Draw(Rect position, SerializedProperty property, GUIContent label)
 {
     //EditorGUIUtility.LookLikeControls();
     EditorExt.PropertyField(position, property, label, fieldInfo, property.hasVisibleChildren && property.isExpanded);
 }
        protected void DrawCollection(ref Rect position, SerializedProperty collectionList, int index, GUIContent label)
        {
            SerializedProperty currProp = collectionList.GetArrayElementAtIndex(index);
            var subIndicesProp          = currProp.FindPropertyRelative("SubcollectionIndices");
            var weightProp = currProp.FindPropertyRelative("Weight");
            var itemsProp  = currProp.FindPropertyRelative("Items");

            Rect foldoutRect = position;

            if (index != 0)
            {
                EditorExt.SplitColumnsPixelsFromRight(position, 20.0f, out Rect dropdown, out Rect buttonArea);
                EditorExt.SplitColumnsPercentage(dropdown, 0.5f, out Rect lhs, out Rect rhs);
                foldoutRect = lhs;

                EditorGUI.PropertyField(rhs, weightProp, GUIContent.none, true);

                if (GUI.Button(buttonArea, "-"))
                {
                    DeleteGroupAtIndex(collectionList, index);
                    return;
                }
            }

            currProp.isExpanded = EditorGUI.Foldout(foldoutRect, currProp.isExpanded, label);

            if (currProp.isExpanded)
            {
                position = EditorExt.IncrementRectIndent(position);
                position = EditorExt.IncrementRectRow(position);

                // + buttons
                {
                    EditorExt.SplitColumnsPercentage(position, 0.5f, out Rect lhs, out Rect rhs);

                    if (GUI.Button(lhs, "Add Item(" + itemsProp.arraySize + ")"))
                    {
                        itemsProp.arraySize++;
                        var newElemProp = itemsProp.GetArrayElementAtIndex(itemsProp.arraySize - 1);
                        newElemProp.FindPropertyRelative("Weight").SetPropertyValue(1.0f);
                        newElemProp.FindPropertyRelative("Item").SetPropertyValue(null);
                    }

                    if (GUI.Button(rhs, "Add Group(" + subIndicesProp.arraySize + ")"))
                    {
                        // Insert an end then swap
                        collectionList.arraySize++;
                        int collectionIndex = collectionList.arraySize - 1;
                        var newGroupProp    = collectionList.GetArrayElementAtIndex(collectionIndex);

                        newGroupProp.FindPropertyRelative("Weight").SetPropertyValue(1.0f);
                        newGroupProp.FindPropertyRelative("Items").arraySize = 0;
                        newGroupProp.FindPropertyRelative("SubcollectionIndices").arraySize = 0;

                        subIndicesProp.arraySize++;
                        subIndicesProp.GetArrayElementAtIndex(subIndicesProp.arraySize - 1).intValue = collectionIndex;
                    }
                }

                // Draw items
                for (int i = 0; i < itemsProp.arraySize; ++i)
                {
                    position = EditorExt.IncrementRectRow(position);

                    var elemProp       = itemsProp.GetArrayElementAtIndex(i);
                    var elemWeightProp = elemProp.FindPropertyRelative("Weight");
                    var elemItemProp   = elemProp.FindPropertyRelative("Item");

                    if (EditorExt.KeyValuePairField(ref position, elemWeightProp, elemItemProp, "-"))
                    {
                        elemProp.SetPropertyValue(null);
                        itemsProp.DeleteArrayElementAtIndex(i);
                        --i;
                    }
                }

                // Draw subgroups
                for (int i = 0; i < subIndicesProp.arraySize; ++i)
                {
                    int subIndex = subIndicesProp.GetArrayElementAtIndex(i).intValue;

                    position = EditorExt.IncrementRectRow(position);
                    index++;
                    DrawCollection(ref position, collectionList, subIndex, new GUIContent("Subgroup(" + i + ")"));
                }

                position = EditorExt.DecrementRectIndent(position);
            }
        }
Ejemplo n.º 14
0
 public override void Draw(Rect position, SerializedProperty property, GUIContent label)
 {
     EditorGUI.BeginDisabledGroup(true);
     EditorExt.PropertyField(position, property, label, fieldInfo);
     EditorGUI.EndDisabledGroup();
 }
Ejemplo n.º 15
0
        public override void OnGUI(Rect area, SerializedProperty property, GUIContent label)
        {
            Rect position = EditorExt.GetInitialRectRow(area);

            property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label);

            if (property.isExpanded)
            {
                position = EditorExt.IncrementRectIndent(position);
                var elementsProp = property.FindPropertyRelative("m_Elements");

                // Draw temp KVP for + buttong
                {
                    position = EditorExt.IncrementRectRow(position);

                    Rect keyArea, buttonArea;
                    EditorExt.SplitColumnsPixelsFromRight(position, 20.0f, out keyArea, out buttonArea);

                    var tempProp  = property.FindPropertyRelative("m_TemporaryKVP");
                    var keyProp   = tempProp.FindPropertyRelative("Key");
                    var valueProp = tempProp.FindPropertyRelative("Value");

                    // Draw KVP
                    {
                        float origLabelWidth = EditorGUIUtility.labelWidth;

                        keyArea.height = EditorGUI.GetPropertyHeight(keyProp);

                        EditorGUI.PropertyField(keyArea, keyProp, new GUIContent("New Key"), true);

                        float maxHeight = keyArea.height;

                        if (maxHeight > position.height)
                        {
                            float delta = maxHeight - position.height;
                            position.y += delta;
                        }
                    }

                    if (GUI.Button(buttonArea, "+"))
                    {
                        // Just change append temporary flag rather than mess around with serialzation stuff above
                        var dirtyFlagProp = property.FindPropertyRelative("m_AppendTemporary");
                        dirtyFlagProp.boolValue = true;

                        //elementsProp.arraySize++;
                        //var newProp = elementsProp.GetArrayElementAtIndex(elementsProp.arraySize - 1);
                        //var newKeyProp = newProp.FindPropertyRelative("Key");
                        //var newValueProp = newProp.FindPropertyRelative("Value");
                        //newKeyProp.SetPropertyValue(null);
                        //newValueProp.SetPropertyValue(null);
                        //
                        //keyProp.SetPropertyValue(null);
                        //valueProp.SetPropertyValue(null);
                    }
                }

                for (int i = 0; i < elementsProp.arraySize; ++i)
                {
                    position = EditorExt.IncrementRectRow(position);

                    Rect kvpArea, buttonArea;
                    EditorExt.SplitColumnsPixelsFromRight(position, 20.0f, out kvpArea, out buttonArea);

                    var elemProp  = elementsProp.GetArrayElementAtIndex(i);
                    var keyProp   = elemProp.FindPropertyRelative("Key");
                    var valueProp = elemProp.FindPropertyRelative("Value");

                    // Draw KVP
                    {
                        Rect lhs, rhs;
                        EditorExt.SplitColumnsPercentage(kvpArea, 0.3f, out lhs, out rhs);

                        float origLabelWidth = EditorGUIUtility.labelWidth;

                        lhs.height = EditorGUI.GetPropertyHeight(keyProp);
                        rhs.height = EditorGUI.GetPropertyHeight(valueProp);

                        EditorGUIUtility.labelWidth = 0.001f;
                        EditorGUI.PropertyField(lhs, keyProp, new GUIContent("Key"), true);

                        if (EditorGUI.GetPropertyHeight(valueProp) <= EditorExt.GetRowHeight())
                        {
                            EditorGUIUtility.labelWidth = 0.001f;
                        }
                        else
                        {
                            EditorGUIUtility.labelWidth = origLabelWidth * 0.6f;
                        }
                        EditorGUI.PropertyField(rhs, valueProp, new GUIContent("Value"), true);

                        EditorGUIUtility.labelWidth = origLabelWidth;

                        float maxHeight = Mathf.Max(lhs.height, rhs.height);

                        if (maxHeight > position.height)
                        {
                            float delta = maxHeight - position.height;
                            position.y += delta;
                        }
                    }

                    if (GUI.Button(buttonArea, "-"))
                    {
                        elemProp.SetPropertyValue(null);
                        elementsProp.DeleteArrayElementAtIndex(i);
                        --i;
                    }
                }

                position = EditorExt.IncrementRectRow(position);
                if (GUI.Button(position, "Clear All"))
                {
                    elementsProp.ClearArray();
                }
            }
        }
Ejemplo n.º 16
0
    public override void Draw(Rect position, SerializedProperty property, GUIContent label)
    {
        string errorMsg = "";

        if (string.IsNullOrEmpty(propertyValueAttribute.sourceTypeName))
        {
            errorMsg = "Not specified object type as the source.";
        }
        else if (string.IsNullOrEmpty(propertyValueAttribute.sourcePropertyName))
        {
            errorMsg = "There is not setting the name property of the object as a source.";
        }
        else
        {
            //object obj = property.serializedObject.targetObject;
            SerializedProperty prop     = EditorExt.GetPropertyByName(property, propertyValueAttribute.sourceTypeName);
            string             typeName = prop == null ? null: prop.stringValue;

            if (string.IsNullOrEmpty(typeName) || KingUtil.GetType(typeName) == null)
            {
                errorMsg = "Failed to determine the type of object.";
            }
            else
            {
                Type typeObj                    = KingUtil.GetType(typeName);
                SerializedProperty prp          = EditorExt.GetPropertyByName(property, propertyValueAttribute.sourcePropertyName);
                string             propertyName = prp == null ? null : prp.stringValue; //GetPropertyValue(obj, propertyValueAttribute.sourcePropertyName);

                if (string.IsNullOrEmpty(propertyName))
                {
                    errorMsg = "Failed  to determine the property as the source.";
                }
                else
                {
                    Type typeProperty = null;

                    propertyName = KingUtil.GetOnlyName(propertyName);
                    FieldInfo field = typeObj.GetField(propertyName);
                    if (field != null)
                    {
                        typeProperty = field.FieldType;
                    }
                    else
                    {
                        PropertyInfo pInfo = typeObj.GetProperty(propertyName);
                        if (pInfo != null)
                        {
                            typeProperty = pInfo.PropertyType;
                        }
                    }

                    if (typeProperty == null)
                    {
                        LogError("Failed to determine the type property of the source.");
                        return;
                    }
                    else
                    {
                        try
                        {
                            //if (lastTypeProperty != null && lastTypeProperty != typeProperty)
                            //    property.stringValue = "";

                            if (typeProperty == typeof(int))
                            {
                                if (string.IsNullOrEmpty(property.stringValue))
                                {
                                    property.stringValue = "0";
                                }
                                int i = Convert.ToInt32(property.stringValue);
                                i = EditorGUI.IntField(position, label, i);
                                property.stringValue = Prop2Str(i);
                            }
                            else
                            if (typeProperty == typeof(float))
                            {
                                if (string.IsNullOrEmpty(property.stringValue))
                                {
                                    property.stringValue = 0f.ToString();
                                }
                                float f = Convert.ToSingle(property.stringValue);
                                f = EditorGUI.FloatField(position, label, f);
                                property.stringValue = Prop2Str(f);
                            }
                            else
                            if (typeProperty == typeof(string))
                            {
                                property.stringValue = EditorGUI.TextField(position, label, property.stringValue);
                            }
                            else
                            if (typeProperty == typeof(bool))
                            {
                                if (string.IsNullOrEmpty(property.stringValue))
                                {
                                    property.stringValue = bool.FalseString;
                                }

                                bool b = Convert.ToBoolean(property.stringValue);
                                b = EditorGUI.Toggle(position, label, b);
                                property.stringValue = Prop2Str(b);
                            }
                            else if (typeProperty.IsEnum)
                            {
                                if (string.IsNullOrEmpty(property.stringValue))
                                {
                                    property.stringValue = Enum.GetValues(typeProperty).GetValue(0).ToString();
                                }

                                int e = (int)Enum.Parse(typeProperty, property.stringValue);

                                object o = EditorGUI.EnumPopup(position, label, Enum.ToObject(typeProperty, e) as Enum);
                                e = (int)o;
                                property.stringValue = Prop2Str(Enum.Parse(typeProperty, e.ToString()));
                            }
                            else
                            {
                                errorMsg = "No support.";
                            }
                        }
                        catch (Exception)
                        {
                            property.stringValue = "";
                        }

                        //lastTypeProperty = typeProperty;
                    }
                }
            }
        }

        if (!string.IsNullOrEmpty(errorMsg))
        {
            Rect  rect     = EditorGUI.PrefixLabel(position, label);
            Color oldColor = GUI.color;
            GUI.color = Color.grey;
            EditorGUI.LabelField(rect, errorMsg);
            GUI.color = oldColor;
        }
    }