Esempio n. 1
0
        /// <summary>
        /// 将表示三维向量的字符串解析为Vector3
        /// </summary>
        /// <param name="str">表示三维向量的字符串</param>
        /// <param name="value">解析后的Vector3</param>
        /// <returns>是否成功解析</returns>
        public static bool ParseVector3(string str, out Vector3 value)
        {
            if (string.IsNullOrEmpty(str))
            {
                value = Vector3.zero;
                return(false);
            }
            string[] splits = TypeParser.trimBracket(str).Split(',');
            if (splits.Length != 3)
            {
                value = Vector3.zero;
                return(false);
            }
            float x, y, z;

            if (float.TryParse(splits[0], out x) && float.TryParse(splits[1], out y) && float.TryParse(splits[2], out z))
            {
                value = new Vector3(x, y, z);
                return(true);
            }
            value = Vector3.zero;
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// 将表示矩形(x,y,width,height)的字符串解析为Rect
        /// </summary>
        /// <param name="str">表示矩形的字符串</param>
        /// <param name="value">解析后的Rect</param>
        /// <returns>是否成功解析</returns>
        public static bool ParseRect(string str, out Rect value)
        {
            if (string.IsNullOrEmpty(str))
            {
                value = new Rect();
                return(false);
            }
            string[] splits = TypeParser.trimBracket(str).Split(',');
            if (splits.Length != 4)
            {
                value = new Rect();
                return(false);
            }
            float x, y, w, h;

            if (float.TryParse(splits[0], out x) && float.TryParse(splits[1], out y) &&
                float.TryParse(splits[2], out w) && float.TryParse(splits[3], out h))
            {
                value = new Rect(x, y, w, h);
                return(true);
            }
            value = new Rect();
            return(false);
        }