private static void AddBasicFieldToItems(BasicFieldType type, string schemaKey, string newFieldName, bool isList, object defaultValue)
        {
            List <string> itemKeys = GetItemsOfSchemaType(schemaKey);
            Dictionary <string, object> itemData;

            foreach (string itemKey in itemKeys)
            {
                if (AllItems.TryGetValue(itemKey, out itemData))
                {
                    if (isList)
                    {
                        itemData.Add(newFieldName, new List <object>());
                        itemData.Add(string.Format(GDEConstants.MetaDataFormat, GDEConstants.TypePrefix, newFieldName), type);
                        itemData.Add(string.Format(GDEConstants.MetaDataFormat, GDEConstants.IsListPrefix, newFieldName), true);
                    }
                    else
                    {
                        itemData.Add(newFieldName, defaultValue);
                        itemData.Add(string.Format(GDEConstants.MetaDataFormat, GDEConstants.TypePrefix, newFieldName), type);
                    }

                    ItemsNeedSave = true;
                }
            }
        }
        public static bool AddBasicFieldToSchema(BasicFieldType type, string schemaKey, Dictionary <string, object> schemaData, string newFieldName, out string error, bool isList = false, object defaultValue = null)
        {
            string typeKey = string.Format(GDEConstants.MetaDataFormat, GDEConstants.TypePrefix, newFieldName);

            error = "";
            bool result = IsFieldNameValid(schemaKey, newFieldName, out error);

            if (result)
            {
                if (isList)
                {
                    result = schemaData.TryAddValue(newFieldName, new List <object>());
                    schemaData.Add(typeKey, type);
                    schemaData.Add(string.Format(GDEConstants.MetaDataFormat, GDEConstants.IsListPrefix, newFieldName), true);
                }
                else
                {
                    result = schemaData.TryAddValue(newFieldName, defaultValue);
                    schemaData.Add(typeKey, type);
                }

                AddFieldToListByFieldName(newFieldName, schemaKey);
                AddBasicFieldToItems(type, schemaKey, newFieldName, isList, defaultValue);
            }

            return(result);
        }
        string Convert2DListToSheetFormat(BasicFieldType type, object value)
        {
            string result = string.Empty;

            if (GDEItemManager.IsUnityType(type))
            {
                var   pathList = new List <List <string> >();
                IList goList   = value as IList;
                foreach (var sublist in goList)
                {
                    IList list        = sublist as IList;
                    var   pathSubList = new List <string>();
                    foreach (var go in list)
                    {
                        pathSubList.Add(GDEItemManager.GetJsonRepresentation(go as UnityEngine.Object));
                    }
                    pathList.Add(pathSubList);
                }

                // Now convert the path 2d list to json
                result = Json.Serialize(pathList);
            }
            else
            {
                result = Json.Serialize(value);
            }

            return(result);
        }
Example #4
0
            private static string GetTypeName(BasicFieldType type)
            {
                switch (type)
                {
                case BasicFieldType.Int8:
                    return("int8_t");

                case BasicFieldType.UInt8:
                    return("uint8_t");

                case BasicFieldType.Int16:
                    return("int16_t");

                case BasicFieldType.UInt16:
                    return("uint16_t");

                case BasicFieldType.Int32:
                    return("int32_t");

                case BasicFieldType.UInt32:
                    return("uint32_t");

                case BasicFieldType.Float32:
                    return("float");

                case BasicFieldType.Vector2:
                    throw new NotSupportedException("Vector2 is not supported");

                case BasicFieldType.Vector3:
                    throw new NotSupportedException("Vector3 is not supported");

                case BasicFieldType.Vector4:
                    throw new NotSupportedException("Vector4 is not supported");

                case BasicFieldType.Angle:
                    return("float");

                case BasicFieldType.StringID:
                    return("StringID");

                case BasicFieldType.TagReference:
                    return("TagReference");

                case BasicFieldType.DataReference:
                    return("TagData<uint8_t>");

                case BasicFieldType.ResourceReference:
                    return("void*");

                case BasicFieldType.ShortTagReference:
                    return("int TagReference");

                default:
                    throw new ArgumentException("Unrecognized basic field type " + type);
                }
            }
            private static string GetTypeName(BasicFieldType type)
            {
                switch (type)
                {
                case BasicFieldType.Int8:
                    return("sbyte");

                case BasicFieldType.UInt8:
                    return("byte");

                case BasicFieldType.Int16:
                    return("short");

                case BasicFieldType.UInt16:
                    return("ushort");

                case BasicFieldType.Int32:
                    return("int");

                case BasicFieldType.UInt32:
                    return("uint");

                case BasicFieldType.Float32:
                    return("float");

                case BasicFieldType.Vector2:
                    return("Vector2");

                case BasicFieldType.Vector3:
                    return("Vector3");

                case BasicFieldType.Vector4:
                    return("Vector4");

                case BasicFieldType.Angle:
                    return("Angle");

                case BasicFieldType.StringId:
                    return("StringId");

                case BasicFieldType.TagReference:
                case BasicFieldType.ShortTagReference:
                    return("TagInstance");

                case BasicFieldType.DataReference:
                    return("byte[]");

                case BasicFieldType.ResourceReference:
                    return("ResourceReference");

                default:
                    throw new ArgumentException("Unrecognized basic field type " + type);
                }
            }
    protected virtual object GetDefaultValueForType(BasicFieldType type)
    {
        object defaultValue = 0;

        if (type.IsSet(BasicFieldType.Vector2))
        {
            defaultValue = new Dictionary <string, object>()
            {
                { "x", 0f },
                { "y", 0f }
            };
        }
        else if (type.IsSet(BasicFieldType.Vector3))
        {
            defaultValue = new Dictionary <string, object>()
            {
                { "x", 0f },
                { "y", 0f },
                { "z", 0f }
            };
        }
        else if (type.IsSet(BasicFieldType.Vector4))
        {
            defaultValue = new Dictionary <string, object>()
            {
                { "x", 0f },
                { "y", 0f },
                { "z", 0f },
                { "w", 0f }
            };
        }
        else if (type.IsSet(BasicFieldType.String))
        {
            defaultValue = "";
        }
        else if (type.IsSet(BasicFieldType.Color))
        {
            defaultValue = new Dictionary <string, object>()
            {
                { "r", 1f },
                { "g", 1f },
                { "b", 1f },
                { "a", 0f },
            };
        }
        else
        {
            defaultValue = 0;
        }

        return(defaultValue);
    }
        public static string GetVariableTypeFor(BasicFieldType type)
        {
            string result = type.ToString();

            if (type.Equals(BasicFieldType.Bool) ||
                type.Equals(BasicFieldType.Float) ||
                type.Equals(BasicFieldType.Int) ||
                type.Equals(BasicFieldType.String))
            {
                result = result.ToLower();
            }

            return(result);
        }
            public FieldInfo()
            {
                name       = string.Empty;
                type       = BasicFieldType.Undefined;
                customType = string.Empty;

                isList   = false;
                is2DList = false;
                isCustom = false;
                skip     = false;

                cellCol = string.Empty;
                cellRow = string.Empty;
            }
        /*private static void ReadBit(XmlReader reader)
         * {
         *  string name = "Unknown";
         *
         *  if (reader.MoveToAttribute("name"))
         *      name = reader.Value;
         *  if (!reader.MoveToAttribute("index"))
         *      throw new ArgumentException("Bit definitions must have an index." + PositionInfo(reader));
         *  int index = ParseInt(reader.Value);
         *
         *  layout.VisitBit(name, index);
         * }*/

        private void ReadOptions(XmlReader reader, string name, BasicFieldType type)
        {
            XmlReader subtree = reader.ReadSubtree();

            var enumLayout = new EnumLayout(name, type);

            subtree.ReadStartElement();
            while (subtree.ReadToNextSibling("option"))
            {
                enumLayout.Add(ReadOption(subtree));
            }

            _results.Layout.Add(new EnumTagLayoutField(name, enumLayout));
        }
        private void ReadBits(XmlReader reader, string name, BasicFieldType type)
        {
            // TODO: Bitfield support
            _results.Layout.Add(new BasicTagLayoutField(name, type));

            /*XmlReader subtree = reader.ReadSubtree();
             *
             * subtree.ReadStartElement();
             * while (subtree.ReadToNextSibling("bit"))
             *  ReadBit(subtree, layout);
             *
             * layout.LeaveBitfield();*/
            reader.Skip();
        }
        List <object> ConvertListValueToType(BasicFieldType type, List <object> values)
        {
            List <object> convertedValues = new List <object>();

            if (type.Equals(BasicFieldType.String) || type.Equals(BasicFieldType.Undefined))
            {
                values.ForEach(val => convertedValues.Add(val));
            }
            else
            {
                values.ForEach(val => convertedValues.Add(ConvertValueToType(type, val)));
            }

            return(convertedValues);
        }
        List <object> ConvertListValueToType(BasicFieldType type, List <object> values)
        {
            List <object> convertedValues = new List <object>();

            if (values.Count > 0 && !(values.Count == 1 && String.IsNullOrEmpty(values[0].ToString())))
            {
                if (type.Equals(BasicFieldType.String) || type.Equals(BasicFieldType.Undefined))
                {
                    values.ForEach(val => convertedValues.Add(val));
                }
                else
                {
                    values.ForEach(val => convertedValues.Add(ConvertValueToType(type, val)));
                }
            }

            return(convertedValues);
        }
Example #13
0
    private bool AddBasicField(BasicFieldType type, string schemaKey, Dictionary <string, object> schemaData, string newFieldName, bool isList)
    {
        bool   result       = true;
        object defaultValue = GetDefaultValueForType(type);
        string error;

        if (GDEItemManager.AddBasicFieldToSchema(type, schemaKey, schemaData, newFieldName, out error, isList, defaultValue))
        {
            SetNeedToSave(true);
        }
        else
        {
            EditorUtility.DisplayDialog(GDEStrings.ErrorCreatingField, error, GDEStrings.OkLbl);
            result = false;
        }

        return(result);
    }
 /// <summary>
 /// Creates a named enum layout.
 /// </summary>
 /// <param name="name">The name of the layout.</param>
 /// <param name="underlyingType">The underlying type of the enum. Must be an integer type.</param>
 public EnumLayout(string name, BasicFieldType underlyingType)
 {
     switch (underlyingType)
     {
         case BasicFieldType.UInt8:
         case BasicFieldType.Int8:
         case BasicFieldType.UInt16:
         case BasicFieldType.Int16:
         case BasicFieldType.UInt32:
         case BasicFieldType.Int32:
         case BasicFieldType.StringId:
             break;
         default:
             throw new ArgumentException("The underlying type of an enum must be an integer type.");
     }
     Name = name;
     UnderlyingType = underlyingType;
     Values = _values.AsReadOnly();
 }
        BasicFieldType ParseFieldType(string fieldKey, Dictionary <string, object> schemaData, out string customType)
        {
            BasicFieldType result = BasicFieldType.Undefined;

            customType = string.Empty;

            try
            {
                string typeKey = string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey);
                customType = schemaData[typeKey].ToString();

                result = (BasicFieldType)Enum.Parse(typeof(BasicFieldType), customType, true);
            }
            catch
            {
                result = BasicFieldType.Undefined;
            }

            return(result);
        }
Example #16
0
        /// <summary>
        /// Creates a named enum layout.
        /// </summary>
        /// <param name="name">The name of the layout.</param>
        /// <param name="underlyingType">The underlying type of the enum. Must be an integer type.</param>
        public EnumLayout(string name, BasicFieldType underlyingType)
        {
            switch (underlyingType)
            {
            case BasicFieldType.UInt8:
            case BasicFieldType.Int8:
            case BasicFieldType.UInt16:
            case BasicFieldType.Int16:
            case BasicFieldType.UInt32:
            case BasicFieldType.Int32:
            case BasicFieldType.StringID:
                break;

            default:
                throw new ArgumentException("The underlying type of an enum must be an integer type.");
            }
            Name           = name;
            UnderlyingType = underlyingType;
            Values         = _values.AsReadOnly();
        }
        private void ReadBits(XmlReader reader, string name, BasicFieldType type)
        {
            // TODO: Bitfield support
            _results.Layout.Add(new BasicTagLayoutField(name, type));

            /*XmlReader subtree = reader.ReadSubtree();

            subtree.ReadStartElement();
            while (subtree.ReadToNextSibling("bit"))
                ReadBit(subtree, layout);

            layout.LeaveBitfield();*/
            reader.Skip();
        }
Example #18
0
    void Draw2DListField(string schemaKey, string itemKey, string fieldKey, Dictionary <string, object> itemData)
    {
        try
        {
            string foldoutKey = string.Format(GDMConstants.MetaDataFormat, itemKey, fieldKey);
            object defaultResizeValue;

            string fieldType;
            itemData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out fieldType);

            BasicFieldType fieldTypeEnum = BasicFieldType.Undefined;
            if (Enum.IsDefined(typeof(BasicFieldType), fieldType))
            {
                fieldTypeEnum = (BasicFieldType)Enum.Parse(typeof(BasicFieldType), fieldType);
                fieldType     = GDEItemManager.GetVariableTypeFor(fieldTypeEnum);
            }

            content.text = string.Format("List<List<{0}>>", fieldType);
            bool isOpen = DrawFoldout(content.text, foldoutKey, string.Empty, string.Empty, null);

            drawHelper.CurrentLinePosition = Math.Max(drawHelper.CurrentLinePosition, GDEConstants.MinLabelWidth + GDEConstants.Indent + 4);
            content.text = fieldKey.HighlightSubstring(filterText, highlightColor);
            drawHelper.TryGetCachedSize(schemaKey + fieldKey + GDEConstants.LblSuffix, content, labelStyle, out size);

            size.x = Math.Max(size.x, GDEConstants.MinLabelWidth);
            EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), fieldKey.HighlightSubstring(filterText, highlightColor), labelStyle);
            drawHelper.CurrentLinePosition += (size.x + 2);

            object temp = null;
            IList  list = null;

            if (itemData.TryGetValue(fieldKey, out temp))
            {
                list = temp as IList;
            }

            content.text = GDEConstants.SizeLbl;
            drawHelper.TryGetCachedSize(GDEConstants.SizeSizeLblKey, content, EditorStyles.label, out size);
            EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content);
            drawHelper.CurrentLinePosition += (size.x + 2);

            int    newListCount;
            string listCountKey = string.Format(GDMConstants.MetaDataFormat, itemKey, fieldKey);
            if (newListCountDict.ContainsKey(listCountKey))
            {
                newListCount = newListCountDict[listCountKey];
            }
            else
            {
                newListCount = list.Count;
                newListCountDict.Add(listCountKey, newListCount);
            }

            size.x       = 40;
            newListCount = EditorGUI.IntField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, drawHelper.StandardHeight()), newListCount);
            drawHelper.CurrentLinePosition += (size.x + 4);

            content.text = GDEConstants.ResizeBtn;
            drawHelper.TryGetCachedSize(GDEConstants.SizeResizeBtnKey, content, GUI.skin.button, out size);
            newListCountDict[listCountKey] = newListCount;
            if (list != null && newListCount != list.Count && GUI.Button(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content))
            {
                if (GDEItemManager.IsUnityType(fieldTypeEnum))
                {
                    defaultResizeValue = Activator.CreateInstance(list.GetType().GetGenericArguments()[0]);
                }
                else
                {
                    defaultResizeValue = new List <object>();
                }

                ResizeList(list, newListCount, defaultResizeValue);
                newListCountDict[listCountKey]  = newListCount;
                drawHelper.CurrentLinePosition += (size.x + 2);
            }

            drawHelper.NewLine();

            if (isOpen)
            {
                defaultResizeValue = GDEItemManager.GetDefaultValueForType(fieldTypeEnum);
                for (int index = 0; index < list.Count; index++)
                {
                    IList subList = list[index] as IList;

                    drawHelper.CurrentLinePosition += GDEConstants.Indent * 2;
                    content.text = string.Format("[{0}]:    List<{1}>", index, fieldType);

                    isOpen = DrawFoldout(content.text, foldoutKey + "_" + index, string.Empty, string.Empty, null);
                    drawHelper.CurrentLinePosition += 4;

                    // Draw resize
                    content.text = GDEConstants.SizeLbl;
                    drawHelper.TryGetCachedSize(GDEConstants.SizeSizeLblKey, content, EditorStyles.label, out size);
                    EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content);
                    drawHelper.CurrentLinePosition += (size.x + 2);

                    listCountKey = string.Format(GDMConstants.MetaDataFormat, schemaKey, fieldKey) + "_" + index;
                    if (newListCountDict.ContainsKey(listCountKey))
                    {
                        newListCount = newListCountDict[listCountKey];
                    }
                    else
                    {
                        newListCount = subList.Count;
                        newListCountDict.Add(listCountKey, newListCount);
                    }

                    size.x       = 40;
                    newListCount = EditorGUI.IntField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, drawHelper.StandardHeight()), newListCount);
                    drawHelper.CurrentLinePosition += (size.x + 2);

                    newListCountDict[listCountKey] = newListCount;

                    content.text = GDEConstants.ResizeBtn;
                    drawHelper.TryGetCachedSize(GDEConstants.SizeResizeBtnKey, content, GUI.skin.button, out size);
                    if (newListCount != subList.Count)
                    {
                        if (GUI.Button(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content))
                        {
                            ResizeList(subList, newListCount, defaultResizeValue);
                        }
                        drawHelper.CurrentLinePosition += (size.x + 2);
                    }

                    drawHelper.NewLine();

                    if (isOpen)
                    {
                        for (int x = 0; x < subList.Count; x++)
                        {
                            drawHelper.CurrentLinePosition += GDEConstants.Indent * 3;
                            content.text = string.Format("[{0}][{1}]:", index, x);

                            switch (fieldTypeEnum)
                            {
                            case BasicFieldType.Bool:
                            {
                                DrawListBool(content, x, Convert.ToBoolean(subList[x]), subList);
                                drawHelper.NewLine();
                                break;
                            }

                            case BasicFieldType.Int:
                            {
                                DrawListInt(content, x, Convert.ToInt32(subList[x]), subList);
                                drawHelper.NewLine();
                                break;
                            }

                            case BasicFieldType.Float:
                            {
                                DrawListFloat(content, x, Convert.ToSingle(subList[x]), subList);
                                drawHelper.NewLine();
                                break;
                            }

                            case BasicFieldType.String:
                            {
                                DrawListString(content, x, subList[x] as string, subList);
                                drawHelper.NewLine();
                                break;
                            }

                            case BasicFieldType.Vector2:
                            {
                                DrawListVector2(content, x, subList[x] as Dictionary <string, object>, subList);
                                drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
                                break;
                            }

                            case BasicFieldType.Vector3:
                            {
                                DrawListVector3(content, x, subList[x] as Dictionary <string, object>, subList);
                                drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
                                break;
                            }

                            case BasicFieldType.Vector4:
                            {
                                DrawListVector4(content, x, subList[x] as Dictionary <string, object>, subList);
                                drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
                                break;
                            }

                            case BasicFieldType.Color:
                            {
                                DrawListColor(content, x, subList[x] as Dictionary <string, object>, subList);
                                drawHelper.NewLine();
                                break;
                            }

                            case BasicFieldType.GameObject:
                            {
                                DrawListObject <GameObject>(foldoutKey + index + "_" + x, content, x, subList[x] as GameObject, subList);
                                drawHelper.NewLine();
                                break;
                            }

                            case BasicFieldType.Texture2D:
                            {
                                DrawListObject <Texture2D>(foldoutKey + index + "_" + x, content, x, subList[x] as Texture2D, subList);
                                drawHelper.NewLine();
                                break;
                            }

                            case BasicFieldType.Material:
                            {
                                DrawListObject <Material>(foldoutKey + index + "_" + x, content, x, subList[x] as Material, subList);
                                drawHelper.NewLine();
                                break;
                            }

                            case BasicFieldType.AudioClip:
                            {
                                DrawListAudio(foldoutKey + index + "_" + x, content, x, subList[x] as AudioClip, subList);
                                drawHelper.NewLine();
                                break;
                            }

                            default:
                            {
                                List <string> itemKeys = GetPossibleCustomValues(schemaKey, fieldType);
                                DrawListCustom(content, x, subList[x] as string, subList, true, itemKeys);
                                drawHelper.NewLine();
                                break;
                            }
                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }
    }
 public BasicTagLayoutField(string name, BasicFieldType type)
     : base(name)
 {
     Type = type;
 }
Example #20
0
    void DrawSingleField(string schemaKey, string itemKey, string fieldKey, Dictionary <string, object> itemData)
    {
        string fieldPreviewKey = schemaKey + "_" + itemKey + "_" + fieldKey;
        string fieldType;

        itemData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out fieldType);

        BasicFieldType fieldTypeEnum = BasicFieldType.Undefined;

        if (Enum.IsDefined(typeof(BasicFieldType), fieldType))
        {
            fieldTypeEnum = (BasicFieldType)Enum.Parse(typeof(BasicFieldType), fieldType);
            fieldType     = GDEItemManager.GetVariableTypeFor(fieldTypeEnum);
        }

        content.text = fieldType;
        drawHelper.TryGetCachedSize(schemaKey + fieldKey + GDEConstants.TypeSuffix, content, labelStyle, out size);
        size.x = Math.Max(size.x, GDEConstants.MinLabelWidth);

        GUI.Label(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle);
        drawHelper.CurrentLinePosition += (size.x + 2);

        content.text = fieldKey.HighlightSubstring(filterText, highlightColor);
        drawHelper.TryGetCachedSize(schemaKey + fieldKey + GDEConstants.LblSuffix, content, labelStyle, out size);
        size.x = Math.Max(size.x, GDEConstants.MinLabelWidth);

        GUI.Label(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content, labelStyle);
        drawHelper.CurrentLinePosition += (size.x + 2);

        switch (fieldTypeEnum)
        {
        case BasicFieldType.Bool:
        {
            DrawBool(fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        case BasicFieldType.Int:
        {
            DrawInt(fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        case BasicFieldType.Float:
        {
            DrawFloat(fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        case BasicFieldType.String:
        {
            DrawString(fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        case BasicFieldType.Vector2:
        {
            DrawVector2(fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
            break;
        }

        case BasicFieldType.Vector3:
        {
            DrawVector3(fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
            break;
        }

        case BasicFieldType.Vector4:
        {
            DrawVector4(fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
            break;
        }

        case BasicFieldType.Color:
        {
            DrawColor(fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        case BasicFieldType.GameObject:
        {
            DrawObject <GameObject>(fieldPreviewKey, fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        case BasicFieldType.Texture2D:
        {
            DrawObject <Texture2D>(fieldPreviewKey, fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        case BasicFieldType.Material:
        {
            DrawObject <Material>(fieldPreviewKey, fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        case BasicFieldType.AudioClip:
        {
            DrawAudio(fieldPreviewKey, fieldKey, itemData, GDEConstants.ValueLbl);
            drawHelper.NewLine();
            break;
        }

        default:
        {
            List <string> itemKeys = GetPossibleCustomValues(schemaKey, fieldType);
            DrawCustom(fieldKey, itemData, true, itemKeys);
            drawHelper.NewLine();
            break;
        }
        }
    }
Example #21
0
    void DrawListField(string schemaKey, string itemKey, string fieldKey, Dictionary <string, object> itemData)
    {
        try
        {
            string foldoutKey = string.Format(GDMConstants.MetaDataFormat, itemKey, fieldKey);
            bool   newFoldoutState;
            bool   currentFoldoutState = listFieldFoldoutState.Contains(foldoutKey);
            object defaultResizeValue  = null;

            string fieldType;
            itemData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out fieldType);

            BasicFieldType fieldTypeEnum = BasicFieldType.Undefined;
            if (Enum.IsDefined(typeof(BasicFieldType), fieldType))
            {
                fieldTypeEnum      = (BasicFieldType)Enum.Parse(typeof(BasicFieldType), fieldType);
                fieldType          = GDEItemManager.GetVariableTypeFor(fieldTypeEnum);
                defaultResizeValue = GDEItemManager.GetDefaultValueForType(fieldTypeEnum);
            }

            content.text = string.Format("List<{0}>", fieldType);
            drawHelper.TryGetCachedSize(schemaKey + fieldKey + GDEConstants.TypeSuffix, content, EditorStyles.foldout, out size);
            size.x          = Math.Max(size.x, GDEConstants.MinLabelWidth);
            newFoldoutState = EditorGUI.Foldout(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), currentFoldoutState, content);
            drawHelper.CurrentLinePosition += (size.x + 2);

            content.text = fieldKey.HighlightSubstring(filterText, highlightColor);
            drawHelper.TryGetCachedSize(schemaKey + fieldKey + GDEConstants.LblSuffix, content, labelStyle, out size);
            size.x = Math.Max(size.x, GDEConstants.MinLabelWidth);
            GUI.Label(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), fieldKey.HighlightSubstring(filterText, highlightColor), labelStyle);
            drawHelper.CurrentLinePosition += (size.x + 2);

            if (newFoldoutState != currentFoldoutState)
            {
                if (newFoldoutState)
                {
                    listFieldFoldoutState.Add(foldoutKey);
                }
                else
                {
                    listFieldFoldoutState.Remove(foldoutKey);
                }
            }

            object temp = null;
            IList  list = null;

            if (itemData.TryGetValue(fieldKey, out temp))
            {
                list = temp as IList;
            }

            content.text = GDEConstants.SizeLbl;
            drawHelper.TryGetCachedSize(GDEConstants.SizeSizeLblKey, content, EditorStyles.label, out size);
            EditorGUI.LabelField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content);
            drawHelper.CurrentLinePosition += (size.x + 2);

            int    newListCount;
            string listCountKey = string.Format(GDMConstants.MetaDataFormat, itemKey, fieldKey);
            if (newListCountDict.ContainsKey(listCountKey))
            {
                newListCount = newListCountDict[listCountKey];
            }
            else
            {
                newListCount = list.Count;
                newListCountDict.Add(listCountKey, newListCount);
            }

            size.x       = 40;
            newListCount = EditorGUI.IntField(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, drawHelper.StandardHeight()), newListCount);
            drawHelper.CurrentLinePosition += (size.x + 4);

            content.text = GDEConstants.ResizeBtn;
            drawHelper.TryGetCachedSize(GDEConstants.SizeResizeBtnKey, content, GUI.skin.button, out size);
            newListCountDict[listCountKey] = newListCount;
            if (newListCount != list.Count && GUI.Button(new Rect(drawHelper.CurrentLinePosition, drawHelper.TopOfLine(), size.x, size.y), content))
            {
                ResizeList(list, newListCount, defaultResizeValue);
                newListCountDict[listCountKey]  = newListCount;
                drawHelper.CurrentLinePosition += (size.x + 2);
            }

            drawHelper.NewLine();

            if (newFoldoutState)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    drawHelper.CurrentLinePosition += GDEConstants.Indent * 2;
                    content.text = string.Format("[{0}]:", i);

                    switch (fieldTypeEnum)
                    {
                    case BasicFieldType.Bool:
                    {
                        DrawListBool(content, i, Convert.ToBoolean(list[i]), list);
                        drawHelper.NewLine();
                        break;
                    }

                    case BasicFieldType.Int:
                    {
                        DrawListInt(content, i, Convert.ToInt32(list[i]), list);
                        drawHelper.NewLine();
                        break;
                    }

                    case BasicFieldType.Float:
                    {
                        DrawListFloat(content, i, Convert.ToSingle(list[i]), list);
                        drawHelper.NewLine();
                        break;
                    }

                    case BasicFieldType.String:
                    {
                        DrawListString(content, i, list[i] as string, list);
                        drawHelper.NewLine();
                        break;
                    }

                    case BasicFieldType.Vector2:
                    {
                        DrawListVector2(content, i, list[i] as Dictionary <string, object>, list);
                        drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
                        break;
                    }

                    case BasicFieldType.Vector3:
                    {
                        DrawListVector3(content, i, list[i] as Dictionary <string, object>, list);
                        drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
                        break;
                    }

                    case BasicFieldType.Vector4:
                    {
                        DrawListVector4(content, i, list[i] as Dictionary <string, object>, list);
                        drawHelper.NewLine(GDEConstants.VectorFieldBuffer + 1);
                        break;
                    }

                    case BasicFieldType.Color:
                    {
                        DrawListColor(content, i, list[i] as Dictionary <string, object>, list);
                        drawHelper.NewLine();
                        break;
                    }

                    case BasicFieldType.GameObject:
                    {
                        DrawListObject <GameObject>(foldoutKey + i, content, i, list[i] as GameObject, list);
                        drawHelper.NewLine();
                        break;
                    }

                    case BasicFieldType.Texture2D:
                    {
                        DrawListObject <Texture2D>(foldoutKey + i, content, i, list[i] as Texture2D, list);
                        drawHelper.NewLine();
                        break;
                    }

                    case BasicFieldType.Material:
                    {
                        DrawListObject <Material>(foldoutKey + i, content, i, list[i] as Material, list);
                        drawHelper.NewLine();
                        break;
                    }

                    case BasicFieldType.AudioClip:
                    {
                        DrawListAudio(foldoutKey + i, content, i, list[i] as AudioClip, list);
                        drawHelper.NewLine();
                        break;
                    }

                    default:
                    {
                        List <string> itemKeys = GetPossibleCustomValues(schemaKey, fieldType);
                        DrawListCustom(content, i, list[i] as string, list, true, itemKeys);
                        drawHelper.NewLine();
                        break;
                    }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }
    }
 private static BasicTagLayoutField MakeField(uint offset, BasicFieldType type)
 {
     return new BasicTagLayoutField(MakeName(offset), type);
 }
    private bool AddBasicField(BasicFieldType type, string schemaKey, Dictionary<string, object> schemaData, string newFieldName, bool isList, bool is2DList)
    {
        bool result = true;
        object defaultValue = GDEItemManager.GetDefaultValueForType(type);
        string error;

        if (GDEItemManager.AddBasicFieldToSchema(type, schemaKey, schemaData, newFieldName, out error, isList, is2DList, defaultValue))
        {
            SetNeedToSave(true);
            HighlightNew(newFieldName);
        }
        else
        {
            EditorUtility.DisplayDialog(GDEConstants.ErrorCreatingField, error, GDEConstants.OkLbl);
            result = false;
        }

        return result;
    }
        void DrawListField(string schemaKey, string itemKey, string fieldKey, Dictionary <string, object> itemData)
        {
            try
            {
                string foldoutKey = string.Format(GDMConstants.MetaDataFormat, itemKey, fieldKey);
                bool   newFoldoutState;
                bool   currentFoldoutState = listFieldFoldoutState.Contains(foldoutKey);
                object defaultResizeValue  = null;

                string fieldType;
                itemData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out fieldType);

                BasicFieldType fieldTypeEnum = BasicFieldType.Undefined;
                if (Enum.IsDefined(typeof(BasicFieldType), fieldType))
                {
                    fieldTypeEnum = (BasicFieldType)Enum.Parse(typeof(BasicFieldType), fieldType);
                    if (!fieldTypeEnum.Equals(BasicFieldType.Vector2) &&
                        !fieldTypeEnum.Equals(BasicFieldType.Vector3) &&
                        !fieldTypeEnum.Equals(BasicFieldType.Vector4) &&
                        !fieldTypeEnum.Equals(BasicFieldType.Color))
                    {
                        fieldType = fieldType.ToLower();
                    }

                    defaultResizeValue = GDEItemManager.GetDefaultValueForType(fieldTypeEnum);
                }

                GUIContent content = new GUIContent(string.Format("List<{0}>", fieldType));
                float      width   = Math.Max(EditorStyles.foldout.CalcSize(content).x, GDEConstants.MinLabelWidth);
                newFoldoutState      = EditorGUI.Foldout(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), currentFoldoutState, string.Format("List<{0}>", fieldType));
                currentLinePosition += (width + 2);

                content.text = fieldKey.HighlightSubstring(filterText, highlightColor);
                width        = Math.Max(labelStyle.CalcSize(content).x, GDEConstants.MinLabelWidth);
                GUI.Label(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), fieldKey.HighlightSubstring(filterText, highlightColor), labelStyle);
                currentLinePosition += (width + 2);

                if (newFoldoutState != currentFoldoutState)
                {
                    if (newFoldoutState)
                    {
                        listFieldFoldoutState.Add(foldoutKey);
                    }
                    else
                    {
                        listFieldFoldoutState.Remove(foldoutKey);
                    }
                }

                object        temp = null;
                List <object> list = null;

                if (itemData.TryGetValue(fieldKey, out temp))
                {
                    list = temp as List <object>;
                }

                content.text = GDEConstants.SizeLbl;
                width        = GUI.skin.label.CalcSize(content).x;
                GUI.Label(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), content);
                currentLinePosition += (width + 2);

                int    newListCount;
                string listCountKey = string.Format(GDMConstants.MetaDataFormat, itemKey, fieldKey);
                if (newListCountDict.ContainsKey(listCountKey))
                {
                    newListCount = newListCountDict[listCountKey];
                }
                else
                {
                    newListCount = list.Count;
                    newListCountDict.Add(listCountKey, newListCount);
                }

                width                = 40;
                newListCount         = EditorGUI.IntField(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), newListCount);
                currentLinePosition += (width + 4);

                content.text = GDEConstants.ResizeBtn;
                width        = GUI.skin.button.CalcSize(content).x;
                newListCountDict[listCountKey] = newListCount;
                if (newListCount != list.Count && GUI.Button(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), content))
                {
                    ResizeList(list, newListCount, defaultResizeValue);
                    newListCountDict[listCountKey] = newListCount;
                    currentLinePosition           += (width + 2);
                }

                NewLine();

                if (newFoldoutState)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        currentLinePosition += GDEConstants.Indent * 2;

                        switch (fieldTypeEnum)
                        {
                        case BasicFieldType.Bool:
                        {
                            DrawListBool(i, Convert.ToBoolean(list[i]), list);
                            NewLine();
                            break;
                        }

                        case BasicFieldType.Int:
                        {
                            DrawListInt(i, Convert.ToInt32(list[i]), list);
                            NewLine();
                            break;
                        }

                        case BasicFieldType.Float:
                        {
                            DrawListFloat(i, Convert.ToSingle(list[i]), list);
                            NewLine();
                            break;
                        }

                        case BasicFieldType.String:
                        {
                            DrawListString(i, list[i] as string, list);
                            NewLine();
                            break;
                        }

                        case BasicFieldType.Vector2:
                        {
                            DrawListVector2(i, list[i] as Dictionary <string, object>, list);
                            NewLine(GDEConstants.VectorFieldBuffer + 1);
                            break;
                        }

                        case BasicFieldType.Vector3:
                        {
                            DrawListVector3(i, list[i] as Dictionary <string, object>, list);
                            NewLine(GDEConstants.VectorFieldBuffer + 1);
                            break;
                        }

                        case BasicFieldType.Vector4:
                        {
                            DrawListVector4(i, list[i] as Dictionary <string, object>, list);
                            NewLine(GDEConstants.VectorFieldBuffer + 1);
                            break;
                        }

                        case BasicFieldType.Color:
                        {
                            DrawListColor(i, list[i] as Dictionary <string, object>, list);
                            NewLine();
                            break;
                        }

                        default:
                        {
                            List <string> itemKeys = GetPossibleCustomValues(schemaKey, fieldType);
                            DrawListCustom(i, list[i] as string, list, true, itemKeys);
                            NewLine();
                            break;
                        }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogError(ex);
            }
        }
Example #25
0
    void DrawSingleField(string schemaKey, string fieldKey, Dictionary <string, object> schemaData)
    {
        string fieldType;

        schemaData.TryGetString(string.Format(GDEConstants.MetaDataFormat, GDEConstants.TypePrefix, fieldKey), out fieldType);

        BasicFieldType fieldTypeEnum = BasicFieldType.Undefined;

        if (Enum.IsDefined(typeof(BasicFieldType), fieldType))
        {
            fieldTypeEnum = (BasicFieldType)Enum.Parse(typeof(BasicFieldType), fieldType);
            if (!fieldTypeEnum.Equals(BasicFieldType.Vector2) &&
                !fieldTypeEnum.Equals(BasicFieldType.Vector3) &&
                !fieldTypeEnum.Equals(BasicFieldType.Vector4) &&
                !fieldTypeEnum.Equals(BasicFieldType.Color))
            {
                fieldType = fieldType.ToLower();
            }
        }

        float width = 120;

        EditorGUI.LabelField(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), fieldType);
        currentLinePosition += (width + 2);

        string editFieldKey = string.Format(GDEConstants.MetaDataFormat, schemaKey, fieldKey);

        DrawEditableLabel(fieldKey, editFieldKey, RenameSchemaField, schemaData);

        switch (fieldTypeEnum)
        {
        case BasicFieldType.Bool:
            DrawBool(fieldKey, schemaData, GDEStrings.DefaultValueLbl);
            break;

        case BasicFieldType.Int:
            DrawInt(fieldKey, schemaData, GDEStrings.DefaultValueLbl);
            break;

        case BasicFieldType.Float:
            DrawFloat(fieldKey, schemaData, GDEStrings.DefaultValueLbl);
            break;

        case BasicFieldType.String:
            DrawString(fieldKey, schemaData, GDEStrings.DefaultValueLbl);
            break;

        case BasicFieldType.Vector2:
            DrawVector2(fieldKey, schemaData, GDEStrings.DefaultValuesLbl);
            break;

        case BasicFieldType.Vector3:
            DrawVector3(fieldKey, schemaData, GDEStrings.DefaultValuesLbl);
            break;

        case BasicFieldType.Vector4:
            DrawVector4(fieldKey, schemaData, GDEStrings.DefaultValuesLbl);
            break;

        case BasicFieldType.Color:
            DrawColor(fieldKey, schemaData, GDEStrings.DefaultValuesLbl);
            break;

        default:
            DrawCustom(fieldKey, schemaData, false);
            break;
        }

        GUIContent content = new GUIContent(GDEStrings.DeleteBtn);

        width = GUI.skin.button.CalcSize(content).x;
        if (fieldTypeEnum.Equals(BasicFieldType.Vector2) ||
            fieldTypeEnum.Equals(BasicFieldType.Vector3) ||
            fieldTypeEnum.Equals(BasicFieldType.Vector4))
        {
            if (GUI.Button(new Rect(currentLinePosition, VerticalMiddleOfLine(), width, StandardHeight()), content))
            {
                deletedFields.Add(fieldKey);
            }

            NewLine(GDEConstants.VectorFieldBuffer + 1);
        }
        else
        {
            if (GUI.Button(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), content))
            {
                deletedFields.Add(fieldKey);
            }

            NewLine();
        }
    }
Example #26
0
        private static void AddBasicFieldToItems(BasicFieldType type, string schemaKey, string newFieldName, bool isList, object defaultValue)
        {
            List<string> itemKeys = GetItemsOfSchemaType(schemaKey);
            Dictionary<string, object> itemData;

            foreach(string itemKey in itemKeys)
            {
                if (AllItems.TryGetValue(itemKey, out itemData))
                {
                    if (isList)
                    {
                        itemData.Add(newFieldName, new List<object>());
                        itemData.Add(string.Format(GDEConstants.MetaDataFormat, GDEConstants.TypePrefix, newFieldName), type);
                        itemData.Add(string.Format(GDEConstants.MetaDataFormat, GDEConstants.IsListPrefix, newFieldName), true);
                    }
                    else
                    {
                        itemData.Add(newFieldName, defaultValue);
                        itemData.Add(string.Format(GDEConstants.MetaDataFormat, GDEConstants.TypePrefix, newFieldName), type);
                    }

                    ItemsNeedSave = true;
                }
            }
        }
Example #27
0
 private static BasicTagLayoutField MakeField(uint offset, BasicFieldType type)
 {
     return(new BasicTagLayoutField(MakeName(offset), type));
 }
        string ConvertListToSheetFormat(BasicFieldType type, object value)
        {
            string result  = string.Empty;
            bool   isFirst = true;

            switch (type)
            {
            case BasicFieldType.Color:
            {
                List <object> dict = value as List <object>;
                dict.ForEach(x => {
                        Dictionary <string, object> entry = x as Dictionary <string, object>;
                        if (!isFirst)
                        {
                            result += ",";
                        }
                        else
                        {
                            isFirst = false;
                        }

                        result += "(";
                        result += (Convert.ToSingle(entry["r"]) * 255f).ToString() + ",";
                        result += (Convert.ToSingle(entry["g"]) * 255f).ToString() + ",";
                        result += (Convert.ToSingle(entry["b"]) * 255f).ToString() + ",";
                        result += Convert.ToSingle(entry["a"]).ToString();
                        result += ")";
                    });

                break;
            }

            case BasicFieldType.Vector2:
            {
                List <object> dict = value as List <object>;
                dict.ForEach(x => {
                        Dictionary <string, object> entry = x as Dictionary <string, object>;

                        if (!isFirst)
                        {
                            result += ",";
                        }
                        else
                        {
                            isFirst = false;
                        }

                        result += "(";
                        result += (Convert.ToSingle(entry["x"])).ToString() + ",";
                        result += (Convert.ToSingle(entry["y"])).ToString();
                        result += ")";
                    });
                break;
            }

            case BasicFieldType.Vector3:
            {
                List <object> dict = value as List <object>;
                dict.ForEach(x => {
                        Dictionary <string, object> entry = x as Dictionary <string, object>;

                        if (!isFirst)
                        {
                            result += ",";
                        }
                        else
                        {
                            isFirst = false;
                        }

                        result += "(";
                        result += (Convert.ToSingle(entry["x"])).ToString() + ",";
                        result += (Convert.ToSingle(entry["y"])).ToString() + ",";
                        result += (Convert.ToSingle(entry["z"])).ToString();
                        result += ")";
                    });
                break;
            }

            case BasicFieldType.Vector4:
            {
                List <object> dict = value as List <object>;
                dict.ForEach(x => {
                        Dictionary <string, object> entry = x as Dictionary <string, object>;

                        if (!isFirst)
                        {
                            result += ",";
                        }
                        else
                        {
                            isFirst = false;
                        }

                        result += "(";
                        result += (Convert.ToSingle(entry["x"])).ToString() + ",";
                        result += (Convert.ToSingle(entry["y"])).ToString() + ",";
                        result += (Convert.ToSingle(entry["z"])).ToString() + ",";
                        result += (Convert.ToSingle(entry["w"])).ToString();
                        result += ")";
                    });
                break;
            }

            case BasicFieldType.GameObject:
            case BasicFieldType.Texture2D:
            case BasicFieldType.Material:
            case BasicFieldType.AudioClip:
            {
                IList list = value as IList;
                foreach (UnityEngine.Object entry in list)
                {
                    if (!isFirst)
                    {
                        result += ",";
                    }
                    else
                    {
                        isFirst = false;
                    }

                    result += "\"";
                    result += GDEItemManager.GetJsonRepresentation(entry);
                    result += "\"";
                }
                break;
            }

            case BasicFieldType.String:
            case BasicFieldType.Undefined:
            {
                IList list = value as IList;
                foreach (var entry in list)
                {
                    if (!isFirst)
                    {
                        result += ",";
                    }
                    else
                    {
                        isFirst = false;
                    }

                    result += "\"";
                    if (entry != null)
                    {
                        result += entry.ToString();
                    }
                    result += "\"";
                }
                break;
            }

            default:
            {
                IList list = value as IList;
                foreach (var entry in list)
                {
                    if (!isFirst)
                    {
                        result += ",";
                    }
                    else
                    {
                        isFirst = false;
                    }

                    if (entry != null)
                    {
                        result += entry.ToString();
                    }
                }
                break;
            }
            }

            return(result);
        }
 private static string GetTypeName(BasicFieldType type)
 {
     switch (type)
     {
         case BasicFieldType.Int8:
             return "int8_t";
         case BasicFieldType.UInt8:
             return "uint8_t";
         case BasicFieldType.Int16:
             return "int16_t";
         case BasicFieldType.UInt16:
             return "uint16_t";
         case BasicFieldType.Int32:
             return "int32_t";
         case BasicFieldType.UInt32:
             return "uint32_t";
         case BasicFieldType.Float32:
             return "float";
         case BasicFieldType.Vector2:
             throw new NotSupportedException("Vector2 is not supported");
         case BasicFieldType.Vector3:
             throw new NotSupportedException("Vector3 is not supported");
         case BasicFieldType.Vector4:
             throw new NotSupportedException("Vector4 is not supported");
         case BasicFieldType.Angle:
             return "float";
         case BasicFieldType.StringId:
             return "int32_t";
         case BasicFieldType.TagReference:
             return "TagReference";
         case BasicFieldType.DataReference:
             return "DataReference<uint8_t>";
         case BasicFieldType.ResourceReference:
             return "void*";
         default:
             throw new ArgumentException("Unrecognized basic field type " + type);
     }
 }
        object ConvertValueToType(BasicFieldType type, object value)
        {
            object convertedValue = 0;

            switch (type)
            {
            case BasicFieldType.Bool:
            {
                string b = value.ToString().Trim();
                if (b.ToString().Equals("0"))
                {
                    convertedValue = false;
                }
                else if (b.ToString().Equals("1"))
                {
                    convertedValue = true;
                }
                else
                {
                    convertedValue = Convert.ToBoolean(b);
                }

                break;
            }

            case BasicFieldType.Int:
            {
                convertedValue = Convert.ToInt32(value);
                break;
            }

            case BasicFieldType.Float:
            {
                convertedValue = Convert.ToSingle(value);
                break;
            }

            case BasicFieldType.String:
            {
                convertedValue = value.ToString();
                break;
            }

            case BasicFieldType.Color:
            {
                List <object> colorValues             = value as List <object>;
                Dictionary <string, object> colorDict = new Dictionary <string, object>();
                colorDict.TryAddOrUpdateValue("r", Convert.ToSingle(colorValues[0]) / 255f);
                colorDict.TryAddOrUpdateValue("g", Convert.ToSingle(colorValues[1]) / 255f);
                colorDict.TryAddOrUpdateValue("b", Convert.ToSingle(colorValues[2]) / 255f);
                colorDict.TryAddOrUpdateValue("a", Convert.ToSingle(colorValues[3]));

                convertedValue = colorDict;

                break;
            }

            case BasicFieldType.Vector2:
            {
                List <object> vectValues             = value as List <object>;
                Dictionary <string, object> vectDict = new Dictionary <string, object>();
                vectDict.TryAddOrUpdateValue("x", Convert.ToSingle(vectValues[0]));
                vectDict.TryAddOrUpdateValue("y", Convert.ToSingle(vectValues[1]));

                convertedValue = vectDict;

                break;
            }

            case BasicFieldType.Vector3:
            {
                List <object> vectValues             = value as List <object>;
                Dictionary <string, object> vectDict = new Dictionary <string, object>();
                vectDict.TryAddOrUpdateValue("x", Convert.ToSingle(vectValues[0]));
                vectDict.TryAddOrUpdateValue("y", Convert.ToSingle(vectValues[1]));
                vectDict.TryAddOrUpdateValue("z", Convert.ToSingle(vectValues[2]));

                convertedValue = vectDict;

                break;
            }

            case BasicFieldType.Vector4:
            {
                List <object> vectValues             = value as List <object>;
                Dictionary <string, object> vectDict = new Dictionary <string, object>();
                vectDict.TryAddOrUpdateValue("x", Convert.ToSingle(vectValues[0]));
                vectDict.TryAddOrUpdateValue("y", Convert.ToSingle(vectValues[1]));
                vectDict.TryAddOrUpdateValue("z", Convert.ToSingle(vectValues[2]));
                vectDict.TryAddOrUpdateValue("w", Convert.ToSingle(vectValues[3]));

                convertedValue = vectDict;

                break;
            }

            case BasicFieldType.GameObject:
            {
                convertedValue = GDEItemManager.GetTypeFromJson <GameObject>(value.ToString());
                break;
            }

            case BasicFieldType.Texture2D:
            {
                convertedValue = GDEItemManager.GetTypeFromJson <Texture2D>(value.ToString());
                break;
            }

            case BasicFieldType.Material:
            {
                convertedValue = GDEItemManager.GetTypeFromJson <Material>(value.ToString());
                break;
            }

            case BasicFieldType.AudioClip:
            {
                convertedValue = GDEItemManager.GetTypeFromJson <AudioClip>(value.ToString());
                break;
            }

            case BasicFieldType.Undefined:
            {
                if (value != null)
                {
                    convertedValue = value.ToString();
                }
                break;
            }
            }

            return(convertedValue);
        }
        /*private static void ReadBit(XmlReader reader)
        {
            string name = "Unknown";

            if (reader.MoveToAttribute("name"))
                name = reader.Value;
            if (!reader.MoveToAttribute("index"))
                throw new ArgumentException("Bit definitions must have an index." + PositionInfo(reader));
            int index = ParseInt(reader.Value);

            layout.VisitBit(name, index);
        }*/

        private void ReadOptions(XmlReader reader, string name, BasicFieldType type)
        {
            XmlReader subtree = reader.ReadSubtree();

            var enumLayout = new EnumLayout(name, type);
            subtree.ReadStartElement();
            while (subtree.ReadToNextSibling("option"))
                enumLayout.Add(ReadOption(subtree));

            _results.Layout.Add(new EnumTagLayoutField(name, enumLayout));
        }
Example #32
0
    void DrawListField(string schemaKey, Dictionary <string, object> schemaData, string fieldKey)
    {
        try
        {
            string foldoutKey = string.Format(GDEConstants.MetaDataFormat, schemaKey, fieldKey);
            bool   newFoldoutState;
            bool   currentFoldoutState = listFieldFoldoutState.Contains(foldoutKey);
            object defaultResizeValue  = null;

            string fieldType;
            schemaData.TryGetString(string.Format(GDEConstants.MetaDataFormat, GDEConstants.TypePrefix, fieldKey), out fieldType);

            BasicFieldType fieldTypeEnum = BasicFieldType.Undefined;
            if (Enum.IsDefined(typeof(BasicFieldType), fieldType))
            {
                fieldTypeEnum = (BasicFieldType)Enum.Parse(typeof(BasicFieldType), fieldType);
                if (!fieldTypeEnum.Equals(BasicFieldType.Vector2) &&
                    !fieldTypeEnum.Equals(BasicFieldType.Vector3) &&
                    !fieldTypeEnum.Equals(BasicFieldType.Vector4) &&
                    !fieldTypeEnum.Equals(BasicFieldType.Color))
                {
                    fieldType = fieldType.ToLower();
                }

                defaultResizeValue = GetDefaultValueForType(fieldTypeEnum);
            }

            float width = 120;
            newFoldoutState      = EditorGUI.Foldout(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), currentFoldoutState, string.Format("List<{0}>", fieldType), true);
            currentLinePosition += (width + 2);

            DrawEditableLabel(fieldKey, string.Format(GDEConstants.MetaDataFormat, schemaKey, fieldKey), RenameSchemaField, schemaData);

            if (newFoldoutState != currentFoldoutState)
            {
                if (newFoldoutState)
                {
                    listFieldFoldoutState.Add(foldoutKey);
                }
                else
                {
                    listFieldFoldoutState.Remove(foldoutKey);
                }
            }

            object        temp = null;
            List <object> list = null;

            if (schemaData.TryGetValue(fieldKey, out temp))
            {
                list = temp as List <object>;
            }

            GUIContent content = new GUIContent(GDEStrings.DefaultSizeLbl);
            width = GUI.skin.label.CalcSize(content).x;
            EditorGUI.LabelField(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), content);
            currentLinePosition += (width + 2);

            int    newListCount;
            string listCountKey = string.Format(GDEConstants.MetaDataFormat, schemaKey, fieldKey);
            if (newListCountDict.ContainsKey(listCountKey))
            {
                newListCount = newListCountDict[listCountKey];
            }
            else
            {
                newListCount = list.Count;
                newListCountDict.Add(listCountKey, newListCount);
            }

            width                = 40;
            newListCount         = EditorGUI.IntField(new Rect(currentLinePosition, TopOfLine(), width, TextBoxHeight()), newListCount);
            currentLinePosition += (width + 2);

            newListCountDict[listCountKey] = newListCount;

            content.text = GDEStrings.ResizeBtn;
            width        = GUI.skin.button.CalcSize(content).x;
            if (newListCount != list.Count)
            {
                if (GUI.Button(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), content))
                {
                    ResizeList(list, newListCount, defaultResizeValue);
                }
                currentLinePosition += (width + 2);
            }

            content.text = GDEStrings.DeleteBtn;
            width        = GUI.skin.button.CalcSize(content).x;
            if (GUI.Button(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), content))
            {
                deletedFields.Add(fieldKey);
            }

            NewLine();

            if (newFoldoutState)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    currentLinePosition += GDEConstants.Indent * 2;

                    switch (fieldTypeEnum)
                    {
                    case BasicFieldType.Bool:
                    {
                        DrawListBool(i, Convert.ToBoolean(list[i]), list);
                        NewLine();
                        break;
                    }

                    case BasicFieldType.Int:
                    {
                        DrawListInt(i, Convert.ToInt32(list[i]), list);
                        NewLine();
                        break;
                    }

                    case BasicFieldType.Float:
                    {
                        DrawListFloat(i, Convert.ToSingle(list[i]), list);
                        NewLine();
                        break;
                    }

                    case BasicFieldType.String:
                    {
                        DrawListString(i, list[i] as string, list);
                        NewLine();
                        break;
                    }

                    case BasicFieldType.Vector2:
                    {
                        DrawListVector2(i, list[i] as Dictionary <string, object>, list);
                        NewLine(GDEConstants.VectorFieldBuffer + 1);
                        break;
                    }

                    case BasicFieldType.Vector3:
                    {
                        DrawListVector3(i, list[i] as Dictionary <string, object>, list);
                        NewLine(GDEConstants.VectorFieldBuffer + 1);
                        break;
                    }

                    case BasicFieldType.Vector4:
                    {
                        DrawListVector4(i, list[i] as Dictionary <string, object>, list);
                        NewLine(GDEConstants.VectorFieldBuffer + 1);
                        break;
                    }

                    case BasicFieldType.Color:
                    {
                        DrawListColor(i, list[i] as Dictionary <string, object>, list);
                        NewLine();
                        break;
                    }

                    default:
                    {
                        DrawListCustom(i, list[i] as string, list, false);
                        NewLine();
                        break;
                    }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
        }
    }
Example #33
0
 public BasicTagLayoutField(string name, BasicFieldType type)
     : base(name)
 {
     Type = type;
 }
Example #34
0
        public static bool AddBasicFieldToSchema(BasicFieldType type, string schemaKey, Dictionary<string, object> schemaData, string newFieldName, out string error, bool isList = false, object defaultValue = null)
        {
            string typeKey = string.Format(GDEConstants.MetaDataFormat, GDEConstants.TypePrefix, newFieldName);
            error = "";
            bool result = IsFieldNameValid(schemaKey, newFieldName, out error);

            if (result)
            {
                if (isList)
                {
                    result = schemaData.TryAddValue(newFieldName, new List<object>());
                    schemaData.Add(typeKey, type);
                    schemaData.Add(string.Format(GDEConstants.MetaDataFormat, GDEConstants.IsListPrefix, newFieldName), true);
                }
                else
                {
                    result = schemaData.TryAddValue(newFieldName, defaultValue);
                    schemaData.Add(typeKey, type);
                }

                AddFieldToListByFieldName(newFieldName, schemaKey);
                AddBasicFieldToItems(type, schemaKey, newFieldName, isList, defaultValue);
            }

            return result;
        }
    protected virtual object GetDefaultValueForType(BasicFieldType type)
    {
        object defaultValue = 0;
        if (type.IsSet(BasicFieldType.Vector2))
        {
            defaultValue = new Dictionary<string, object>()
            {
                {"x", 0f},
                {"y", 0f}
            };
        }
        else if (type.IsSet(BasicFieldType.Vector3))
        {
            defaultValue = new Dictionary<string, object>()
            {
                {"x", 0f},
                {"y", 0f},
                {"z", 0f}
            };
        }
        else if (type.IsSet(BasicFieldType.Vector4))
        {
            defaultValue = new Dictionary<string, object>()
            {
                {"x", 0f},
                {"y", 0f},
                {"z", 0f},
                {"w", 0f}
            };
        }
        else if (type.IsSet(BasicFieldType.String))
        {
            defaultValue = "";
        }
        else if (type.IsSet(BasicFieldType.Color))
        {
            defaultValue = new Dictionary<string, object>()
            {
                {"r", 1f},
                {"g", 1f},
                {"b", 1f},
                {"a", 0f},
            };
        }
        else
            defaultValue = 0;

        return defaultValue;
    }
 private static string GetTypeName(BasicFieldType type)
 {
     switch (type)
     {
         case BasicFieldType.Int8:
             return "sbyte";
         case BasicFieldType.UInt8:
             return "byte";
         case BasicFieldType.Int16:
             return "short";
         case BasicFieldType.UInt16:
             return "ushort";
         case BasicFieldType.Int32:
             return "int";
         case BasicFieldType.UInt32:
             return "uint";
         case BasicFieldType.Float32:
             return "float";
         case BasicFieldType.Vector2:
             return "Vector2";
         case BasicFieldType.Vector3:
             return "Vector3";
         case BasicFieldType.Vector4:
             return "Vector4";
         case BasicFieldType.Angle:
             return "Angle";
         case BasicFieldType.StringID:
             return "StringID";
         case BasicFieldType.TagReference:
         case BasicFieldType.ShortTagReference:
             return "TagInstance";
         case BasicFieldType.DataReference:
             return "byte[]";
         case BasicFieldType.ResourceReference:
             return "ResourceReference";
         default:
             throw new ArgumentException("Unrecognized basic field type " + type);
     }
 }
        object ConvertToSheetFormat(BasicFieldType type, object value)
        {
            object result;

            switch (type)
            {
            case BasicFieldType.Color:
            {
                Dictionary <string, object> dict = value as Dictionary <string, object>;
                result  = (Convert.ToSingle(dict["r"]) * 255f).ToString() + ",";
                result += (Convert.ToSingle(dict["g"]) * 255f).ToString() + ",";
                result += (Convert.ToSingle(dict["b"]) * 255f).ToString() + ",";
                result += Convert.ToSingle(dict["a"]).ToString();
                break;
            }

            case BasicFieldType.Vector2:
            {
                Dictionary <string, object> dict = value as Dictionary <string, object>;
                result  = (Convert.ToSingle(dict["x"])).ToString() + ",";
                result += (Convert.ToSingle(dict["y"])).ToString();
                break;
            }

            case BasicFieldType.Vector3:
            {
                Dictionary <string, object> dict = value as Dictionary <string, object>;
                result  = (Convert.ToSingle(dict["x"])).ToString() + ",";
                result += (Convert.ToSingle(dict["y"])).ToString() + ",";
                result += (Convert.ToSingle(dict["z"])).ToString();
                break;
            }

            case BasicFieldType.Vector4:
            {
                Dictionary <string, object> dict = value as Dictionary <string, object>;
                result  = (Convert.ToSingle(dict["x"])).ToString() + ",";
                result += (Convert.ToSingle(dict["y"])).ToString() + ",";
                result += (Convert.ToSingle(dict["z"])).ToString() + ",";
                result += (Convert.ToSingle(dict["w"])).ToString();
                break;
            }

            case BasicFieldType.GameObject:
            case BasicFieldType.Texture2D:
            case BasicFieldType.Material:
            case BasicFieldType.AudioClip:
            {
                result = GDEItemManager.GetJsonRepresentation(value as UnityEngine.Object);
                break;
            }

            default:
            {
                result = value;
                break;
            }
            }

            return(result);
        }
        void DrawSingleField(string schemaKey, string fieldKey, Dictionary <string, object> itemData)
        {
            string fieldType;

            itemData.TryGetString(string.Format(GDMConstants.MetaDataFormat, GDMConstants.TypePrefix, fieldKey), out fieldType);

            BasicFieldType fieldTypeEnum = BasicFieldType.Undefined;

            if (Enum.IsDefined(typeof(BasicFieldType), fieldType))
            {
                fieldTypeEnum = (BasicFieldType)Enum.Parse(typeof(BasicFieldType), fieldType);
                if (!fieldTypeEnum.Equals(BasicFieldType.Vector2) &&
                    !fieldTypeEnum.Equals(BasicFieldType.Vector3) &&
                    !fieldTypeEnum.Equals(BasicFieldType.Vector4) &&
                    !fieldTypeEnum.Equals(BasicFieldType.Color))
                {
                    fieldType = fieldType.ToLower();
                }
            }

            GUIContent content = new GUIContent(fieldType);
            float      width   = Math.Max(labelStyle.CalcSize(content).x, GDEConstants.MinLabelWidth);

            GUI.Label(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), content, labelStyle);
            currentLinePosition += (width + 2);

            content.text = fieldKey.HighlightSubstring(filterText, highlightColor);
            width        = Math.Max(labelStyle.CalcSize(content).x, GDEConstants.MinLabelWidth);

            GUI.Label(new Rect(currentLinePosition, TopOfLine(), width, StandardHeight()), content, labelStyle);
            currentLinePosition += (width + 2);

            switch (fieldTypeEnum)
            {
            case BasicFieldType.Bool:
            {
                DrawBool(fieldKey, itemData, GDEConstants.ValueLbl);
                NewLine();
                break;
            }

            case BasicFieldType.Int:
            {
                DrawInt(fieldKey, itemData, GDEConstants.ValueLbl);
                NewLine();
                break;
            }

            case BasicFieldType.Float:
            {
                DrawFloat(fieldKey, itemData, GDEConstants.ValueLbl);
                NewLine();
                break;
            }

            case BasicFieldType.String:
            {
                DrawString(fieldKey, itemData, GDEConstants.ValueLbl);
                NewLine();
                break;
            }

            case BasicFieldType.Vector2:
            {
                DrawVector2(fieldKey, itemData, GDEConstants.ValuesLbl);
                NewLine(GDEConstants.VectorFieldBuffer + 1);
                break;
            }

            case BasicFieldType.Vector3:
            {
                DrawVector3(fieldKey, itemData, GDEConstants.ValuesLbl);
                NewLine(GDEConstants.VectorFieldBuffer + 1);
                break;
            }

            case BasicFieldType.Vector4:
            {
                DrawVector4(fieldKey, itemData, GDEConstants.ValuesLbl);
                NewLine(GDEConstants.VectorFieldBuffer + 1);
                break;
            }

            case BasicFieldType.Color:
            {
                DrawColor(fieldKey, itemData, GDEConstants.ValuesLbl);
                NewLine();
                break;
            }

            default:
            {
                List <string> itemKeys = GetPossibleCustomValues(schemaKey, fieldType);
                DrawCustom(fieldKey, itemData, true, itemKeys);
                NewLine();
                break;
            }
            }
        }