Inheritance: JsonConverter
        public void TypeConverterConvertToString()
        {
            Vector2Converter vconv = new Vector2Converter();
            Vector2          v2    = new Vector2(100, 99);

            string s = (string)vconv.ConvertTo(v2, typeof(string));

            Assert.AreEqual("{100, 99}", s);
        }
        public void TypeConverterConvertFromString()
        {
            Vector2Converter vconv = new Vector2Converter();
            Vector2          v2    = new Vector2(100, 99);

            Vector2 s = (Vector2)vconv.ConvertFrom("{100, 99}");

            Assert.AreEqual(v2.X, s.X);
            Assert.AreEqual(v2.Y, s.Y);
        }
示例#3
0
        public static bool HasVector2(this XmlElement xml, string attribute, out Vector2 value)
        {
            value = Vector2.zero;
            if (!xml.HasAttribute(attribute))
            {
                return(false);
            }

            return(Vector2Converter.Convert(xml.Attributes[attribute], ref value));
        }
示例#4
0
        public override void Execute()
        {
            GameConstants.Directories.Root = Application.dataPath + @"/../";

            var overlayCanvas = GameObject.Find("OverlayCanvas");

            injectionBinder.Bind <GameObject>().ToValue(overlayCanvas).ToName(GameContextKeys.OverlayCanvas);
            var worldSpaceCanvas = GameObject.Find("WorldSpaceCanvas");

            injectionBinder.Bind <GameObject>().ToValue(worldSpaceCanvas).ToName(GameContextKeys.WorldSpaceCanvas);

            var floatConverter   = new FloatConverter();
            var stringConverter  = new StringConverter();
            var vector2Converter = new Vector2Converter();

            LoadDispatcher.Dispatch();
        }
        public void TypeConverterCanConvertToString()
        {
            Vector2Converter vconv = new Vector2Converter();

            Assert.IsTrue(vconv.CanConvertTo(typeof(string)));
        }
        public void TypeConverterCanConvertToInstanceDescriptor()
        {
            Vector2Converter vconv = new Vector2Converter();

            Assert.IsTrue(vconv.CanConvertTo(typeof(InstanceDescriptor)));
        }
        public void TypeConverterCannotConvertFromInt()
        {
            Vector2Converter vconv = new Vector2Converter();

            Assert.IsFalse(vconv.CanConvertFrom(typeof(InstanceDescriptor)));
        }
示例#8
0
        public override object Convert(object value, Type type, IFormatProvider formatProvider)
        {
            if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                if (value == null)
                {
                    return(null);
                }

                Type underlyingType = type.GetGenericArguments()[0];
                return(Convert(value, underlyingType, formatProvider));
            }


            if (type == YogaValueType)
            {
                var res = YogaValueConverter.NormalizeYogaValue(value);
                if (res.HasValue)
                {
                    return(res.Value);
                }
            }

            if (value == null)
            {
                if (TypeConverter.TypeIsNullable(type))
                {
                    return(null);
                }
                throw new NotSupportedException($"Unable to convert null to '{type.FullName}'");
            }

            if (type == ColorType)
            {
                if (value is Color v)
                {
                    return(v);
                }
                var res = ColorConverter.FromJsValue(JsValue.FromObject(engine, value));
                if (res.HasValue)
                {
                    return(res.Value);
                }
            }
            else if (type == Vector2Type)
            {
                if (value is Vector2 v)
                {
                    return(v);
                }
                var res = Vector2Converter.FromJsValue(JsValue.FromObject(engine, value));
                if (res.HasValue)
                {
                    return(res.Value);
                }
            }
            else if (type == Vector4Type)
            {
                if (value is Vector4 v)
                {
                    return(v);
                }
                var res = Vector4Converter.FromJsValue(JsValue.FromObject(engine, value));
                if (res.HasValue)
                {
                    return(res.Value);
                }
            }
            else if (type.IsEnum && value is string s)
            {
                return(Enum.Parse(type, s, true));
            }

            return(base.Convert(value, type, formatProvider));
        }