Пример #1
0
            public static void OnConvertToJSONElement(object obj, JSONElement node)
            {
                Gradient gradient = (Gradient)obj;

                if (gradient != null)
                {
                    JSONElement colorKeysJSONElement = JSONUtils.CreateJSONElement(node.OwnerDocument, JSONConverter.kJSONArrayTag);
                    for (int i = 0; i < gradient.colorKeys.Length; i++)
                    {
                        JSONElement colorKeyJSONElement = JSONUtils.CreateJSONElement(node.OwnerDocument, "ColorKey");
                        JSONConverter.AppendFieldObject(colorKeyJSONElement, gradient.colorKeys[i].color, "color");
                        JSONConverter.AppendFieldObject(colorKeyJSONElement, gradient.colorKeys[i].time, "time");
                        JSONUtils.SafeAppendChild(colorKeysJSONElement, colorKeyJSONElement);
                    }
                    JSONUtils.AddAttribute(node.OwnerDocument, colorKeysJSONElement, JSONConverter.kJSONFieldIdAttributeTag, "colorKeys");
                    JSONUtils.SafeAppendChild(node, colorKeysJSONElement);


                    JSONElement alphasKeyJSONElement = JSONUtils.CreateJSONElement(node.OwnerDocument, JSONConverter.kJSONArrayTag);
                    for (int i = 0; i < gradient.alphaKeys.Length; i++)
                    {
                        JSONElement alphaKeyJSONElement = JSONUtils.CreateJSONElement(node.OwnerDocument, "AlphaKey");
                        JSONConverter.AppendFieldObject(alphaKeyJSONElement, gradient.alphaKeys[i].alpha, "alpha");
                        JSONConverter.AppendFieldObject(alphaKeyJSONElement, gradient.alphaKeys[i].time, "time");
                        JSONUtils.SafeAppendChild(alphasKeyJSONElement, alphaKeyJSONElement);
                    }
                    JSONUtils.AddAttribute(node.OwnerDocument, alphasKeyJSONElement, JSONConverter.kJSONFieldIdAttributeTag, "alphaKeys");
                    JSONUtils.SafeAppendChild(node, alphasKeyJSONElement);
                }
            }
            public static void OnConvertToJSONElement(object obj, JSONElement node)
            {
                IDictionary dictionary = (IDictionary)obj;

                Type[] dictionaryTypes = SystemUtils.GetGenericImplementationTypes(typeof(Dictionary <,>), obj.GetType());

                if (dictionaryTypes != null)
                {
                    //Find keys
                    string[] keys = new string[dictionary.Keys.Count];
                    int      i    = 0;
                    foreach (object key in dictionary.Keys)
                    {
                        keys[i++] = Convert.ToString(key);
                    }

                    //Append all child nodes
                    i = 0;
                    foreach (object value in dictionary.Values)
                    {
                        JSONElement arrayItemJSONElement = JSONConverter.ToJSONElement(value, node.OwnerDocument);
                        JSONUtils.AddAttribute(node.OwnerDocument, arrayItemJSONElement, "key", keys[i++]);
                        JSONUtils.SafeAppendChild(node, arrayItemJSONElement);
                    }
                }
            }
Пример #3
0
            public static void OnConvertToJSONElement(object obj, JSONElement node)
            {
                AnimationCurve curve = (AnimationCurve)obj;

                if (curve != null)
                {
                    JSONElement keyframesJSONElement = JSONUtils.CreateJSONElement(node.OwnerDocument, JSONConverter.kJSONArrayTag);
                    for (int i = 0; i < curve.length; i++)
                    {
                        Keyframe    keyFrame            = curve[i];
                        JSONElement keyFrameJSONElement = JSONUtils.CreateJSONElement(node.OwnerDocument, "KeyFrame");
                        JSONConverter.AppendFieldObject(keyFrameJSONElement, keyFrame.inTangent, "inTangent");
                        JSONConverter.AppendFieldObject(keyFrameJSONElement, keyFrame.outTangent, "outTangent");
                        JSONConverter.AppendFieldObject(keyFrameJSONElement, keyFrame.tangentMode, "tangentMode");
                        JSONConverter.AppendFieldObject(keyFrameJSONElement, keyFrame.time, "time");
                        JSONConverter.AppendFieldObject(keyFrameJSONElement, keyFrame.value, "value");
                        JSONUtils.SafeAppendChild(keyframesJSONElement, keyFrameJSONElement);
                    }
                    JSONUtils.AddAttribute(node.OwnerDocument, keyframesJSONElement, JSONConverter.kJSONFieldIdAttributeTag, "keyFrames");
                    JSONUtils.SafeAppendChild(node, keyframesJSONElement);
                }
            }