Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }