Exemple #1
0
        // ====================================================

        public static void Fail(string condition, object o, params object[] ctx)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("ASSERT! ");
            sb.Append(FLog.GetStamp());
            sb.Append(FLog.Bracketize(condition));
            sb.Append(FLog.Bracketize(o));
            foreach (object co in ctx)
            {
                sb.Append(FLog.Bracketize(co));
            }
            FLog.LogError(sb.ToString());
#if RAISE_EXCEPTIONS
            throw new FAssertException(sb.ToString());
#endif
        }
Exemple #2
0
        // Convert a JSON object to a vector.
        // The object can be either of two forms:
        //     { "x": 0, "y": 0, "z": 0 }
        //     [ 0, 0, 0 ]
        // In the object form, all three fields are optional.
        // In the array form, you can have two or three fields.
        public static Vector3 jtov(object j, Vector3 defaultValue)
        {
            Vector3 rv = defaultValue;

            if (j is List <object> )
            {
                List <object> jl = j as List <object>;
                if (jl.Count > 0)
                {
                    rv.x = System.Convert.ToSingle(jl[0]);
                }
                if (jl.Count > 1)
                {
                    rv.y = System.Convert.ToSingle(jl[1]);
                }
                if (jl.Count > 2)
                {
                    rv.z = System.Convert.ToSingle(jl[2]);
                }
            }
            else if (j is Dictionary <string, object> )
            {
                Dictionary <string, object> jd = j as Dictionary <string, object>;
                if (jd.ContainsKey("x"))
                {
                    rv.x = System.Convert.ToSingle(jd["x"]);
                }
                if (jd.ContainsKey("y"))
                {
                    rv.y = System.Convert.ToSingle(jd["y"]);
                }
                if (jd.ContainsKey("z"))
                {
                    rv.z = System.Convert.ToSingle(jd["z"]);
                }
            }
            else
            {
                FLog.LogError("invalid JSON vector object [" + j.ToString() + "]");
            }
            return(rv);
        }