コード例 #1
0
        protected override void EmitSetPropertyValidator(CodeStatementCollection stmts, CodeTypeDeclaration type,
                                                         CodeSnippetExpression storage, CodeTypeReference interfaceType, bool changed, string name)
        {
            FloatCompression[] ac = Decorator.PropertyType.Compression;

            for (int i = 0; i < ac.Length; ++i)
            {
                FloatCompression c = ac[i];

                if (c.Enabled)
                {
                    char axis = (char)(120 + i);

#if DEBUG
                    stmts.If("value.{2} < {0}f || value.{2} > {1}f".Expr(c.MinValue, c.MaxValue, axis),
                             ifBody =>
                    {
                        ifBody.Expr(
                            "Ascension.Networking.NetLog.Warn(\"Axis '{3}' of property '{0}' is being set to a value larger than the compression settings, it will be clamped to [{1}f, {2}f]\")",
                            Decorator.Definition.Name, c.MinValue.ToStringSigned(), c.MaxValue.ToStringSigned(),
                            axis);
                    });
#endif

                    stmts.Expr("value.{2} = UnityEngine.Mathf.Clamp(value.{2}, {0}, {1})", c.MinValue, c.MaxValue, axis);
                }
            }
        }
コード例 #2
0
        public CodeExpression CreateFloatCompressionExpression(FloatCompression c, bool enabled)
        {
            if (c == null)
            {
                c = FloatCompression.Default();
            }

            if (enabled)
            {
                if (c.Enabled)
                {
                    return("Ascension.Networking.PropertyFloatCompressionSettings.Create({0}, {1}f, {2}f, {3}f)".Expr(c.BitsRequired,
                                                                                                                      c.Shift, c.Pack, c.Read));
                }
                return("Ascension.Networking.PropertyFloatCompressionSettings.Create()".Expr());
            }
            return("default(Ascension.Networking.PropertyFloatCompressionSettings)".Expr());
        }
コード例 #3
0
        public void EmitQuaternionSettings(CodeExpression expr, CodeStatementCollection statements,
                                           FloatCompression[] axes, FloatCompression quaternion, AxisSelections selection, bool strictCompare)
        {
            if (selection != AxisSelections.Disabled)
            {
                if (axes == null || quaternion == null || selection == AxisSelections.XYZ)
                {
                    statements.Call(expr, "Settings_Quaternion", CreateFloatCompressionExpression(quaternion, true),
                                    strictCompare.Literal());
                }
                else
                {
                    List <CodeExpression> exprs = CreateAxisCompressionExpression(axes, selection);
                    exprs.Add(strictCompare.Literal());

                    statements.Call(expr, "Settings_QuaternionEuler", exprs.ToArray());
                }
            }
        }
コード例 #4
0
        protected override void EmitSetPropertyValidator(CodeStatementCollection stmts, CodeTypeDeclaration type,
                                                         CodeSnippetExpression storage, CodeTypeReference interfaceType, bool changed, string name)
        {
            FloatCompression c = Decorator.PropertyType.Compression;

            if (c != null && c.Enabled && c.BitsRequired < 32)
            {
#if DEBUG
                stmts.If("value < {0}f || value > {1}f".Expr(c.MinValue, c.MaxValue),
                         ifBody =>
                {
                    ifBody.Expr(
                        "Ascension.Networking.NetLog.Warn(\"Property '{0}' is being set to a value larger than the compression settings, it will be clamped to [{1}f, {2}f]\")",
                        Decorator.Definition.Name, c.MinValue.ToStringSigned(), c.MaxValue.ToStringSigned());
                });
#endif

                stmts.Expr("value = UnityEngine.Mathf.Clamp(value, {0}f, {1}f)", c.MinValue, c.MaxValue);
            }
        }
コード例 #5
0
 public void EmitFloatSettings(CodeExpression expr, CodeStatementCollection statements, FloatCompression c)
 {
     statements.Call(expr, "Settings_Float", CreateFloatCompressionExpression(c, true));
 }