Exemple #1
0
        public object GetValue()
        {
            switch (type)
            {
            case XMonoVariableType.Bool:
                return(XMonoVariableUtility.ToBool(valData));

            case XMonoVariableType.Float:
                return(XMonoVariableUtility.ToSingle(valData));

            case XMonoVariableType.Int:
                return(XMonoVariableUtility.ToInt32(valData));

            case XMonoVariableType.String:
                return(valData);

            case XMonoVariableType.Color:
                return(XMonoVariableUtility.ToColor(valData));

            case XMonoVariableType.Vector2:
                return(XMonoVariableUtility.ToVector2(valData));

            case XMonoVariableType.Vector3:
                return(XMonoVariableUtility.ToVector3(valData));

            case XMonoVariableType.Vector4:
                return(XMonoVariableUtility.ToVector4(valData));

            case XMonoVariableType.GameObject:
                return(objData);

            case XMonoVariableType.Component:
                return(objData);

            default:
                throw new System.NotSupportedException();
            }
        }
        static bool _Inject <T>(T obj, FieldInfo fieldInfo, XMonoVariable value)
        {
            switch (value.type)
            {
            case XMonoVariableType.GameObject:
            case XMonoVariableType.Component:
                var objType = value.objData.GetType();
                if (fieldInfo.FieldType == objType || objType.IsSubclassOf(fieldInfo.FieldType))
                {
                    fieldInfo.SetValue(obj, value.objData);
                    return(true);
                }

                break;

            case XMonoVariableType.Bool:
                if (fieldInfo.FieldType == typeof(bool))
                {
                    fieldInfo.SetValue(obj, XMonoVariableUtility.ToBool(value.valData));
                    return(true);
                }

                break;

            case XMonoVariableType.Float:
                if (fieldInfo.FieldType == typeof(float))
                {
                    fieldInfo.SetValue(obj, XMonoVariableUtility.ToSingle(value.valData));
                    return(true);
                }

                break;

            case XMonoVariableType.Int:
                if (fieldInfo.FieldType == typeof(int))
                {
                    fieldInfo.SetValue(obj, XMonoVariableUtility.ToInt32(value.valData));
                    return(true);
                }

                break;

            case XMonoVariableType.String:
                if (fieldInfo.FieldType == typeof(string))
                {
                    fieldInfo.SetValue(obj, value.valData);
                    return(true);
                }

                break;

            case XMonoVariableType.Color:
                if (fieldInfo.FieldType == typeof(Color))
                {
                    fieldInfo.SetValue(obj, XMonoVariableUtility.ToColor(value.valData));
                    return(true);
                }

                break;

            case XMonoVariableType.Vector2:
                if (fieldInfo.FieldType == typeof(Vector2))
                {
                    fieldInfo.SetValue(obj, XMonoVariableUtility.ToVector2(value.valData));
                    return(true);
                }

                break;

            case XMonoVariableType.Vector3:
                if (fieldInfo.FieldType == typeof(Vector3))
                {
                    fieldInfo.SetValue(obj, XMonoVariableUtility.ToVector3(value.valData));
                    return(true);
                }

                break;

            case XMonoVariableType.Vector4:
                if (fieldInfo.FieldType == typeof(Vector4))
                {
                    fieldInfo.SetValue(obj, XMonoVariableUtility.ToVector4(value.valData));
                    return(true);
                }

                break;
            }

            return(false);
        }