예제 #1
0
        /// <summary>
        /// 在源字符串中寻找 begin 开头, end位置的字符串,用给定函数进行处理以后,
        /// 并将该字符串替换成处理以后的字符串;
        /// 为避免死循环,从处理后字符串继续寻找和下一次处理
        /// </summary>
        /// <param name="source">源字符串</param>
        /// <param name="begin">待处理的开头标记字符串</param>
        /// <param name="end">待处理的结尾标记字符串, 如果本参数为 null,表示从 beginstr 开始,直到结尾字符串全部进行处理;
        ///                      如果 endstr 为 "" , 则只处理 begin 字符串;
        /// </param>
        /// <param name="aHandle">对字符串进行处理的函数,返回处理结果字符串</param>
        /// <returns></returns>
        public static string Handle(this string source, string begin, string end, HandleString aHandle)
        {
            int beginIndex = source.IndexOf(begin);  //<n></n> 没有传入,替换成 null

            if (beginIndex < 0)
            {
                return(source);
            }
            if (beginIndex >= 0 && end == null)
            {
                return(source.Substring(0, beginIndex) + aHandle(source.Substring(beginIndex)));
            }
            int beginLen = begin.Length;
            int endLen   = end.Length;

            while (beginIndex >= 0)
            {
                int endIndex = beginIndex + beginLen;
                if (endLen != 0)
                {
                    endIndex = source.IndexOf(end, beginIndex + beginLen);
                }
                if (endIndex < 0)
                {
                    break;
                }
                string beginEndString = source.Substring(beginIndex, endIndex - beginIndex + endLen); //替换字符串
                string handeledString = aHandle(beginEndString);                                      //
                source = source.Substring(0, beginIndex) + handeledString + source.Substring(endIndex + endLen);
                //为避免死循环,因为处理不一定是替换,也可能是追加字符串,而 begin 仍然存在于原有的字符串中
                beginIndex = source.IndexOf(begin, beginIndex + handeledString.Length);
            }
            return(source);
        }
예제 #2
0
    static public MapObject create(string aFileName, string aName, string id = "")
    {
        if (!mObjectDatas.ContainsKey(aFileName))
        {
            mObjectDatas[aFileName] = new Arg(MyJson.deserializeResourse(MapObjectCreater.kDirPath + "/" + aFileName));
        }
        Arg       tObjectData = mObjectDatas[aFileName].get <Arg>(aName);
        MapObject tMapObject  = MyBehaviour.create <MapObject>();

        tMapObject.name = (id == "") ? aName : aFileName;
        //sprite
        if (tObjectData.ContainsKey("sprite"))
        {
            //画像があるフォルダのパス
            string tPath = HandleString.cutOff(aFileName, "/");
            tPath = (tPath == "") ? MapObjectCreater.kDirPath : MapObjectCreater.kDirPath + "/" + tPath;
            Arg tData = tObjectData.get <Arg>("sprite");
            //pivotYが設定されていないなら0に設定
            if (!tData.ContainsKey("pivotY"))
            {
                tData.set("pivotY", 0f);
            }
            //スプライトセット
            ChildSprite.addSpriteObject(tMapObject.gameObject, tData, tPath);
        }
        //zIndex
        if (tObjectData.ContainsKey("zIndex"))
        {
            tMapObject.zIndex = tObjectData.get <float>("zIndex");
        }
        //マップ属性
        if (tObjectData.ContainsKey("attribute"))
        {
            tMapObject.gameObject.AddComponent <MapAttributeBehaviour>().setAttribute(tObjectData.get <string>("attribute"));
        }
        //collider設定
        if (tObjectData.ContainsKey("collider"))
        {
            Arg tColliderData = tObjectData.get <Arg>("collider");
            ColliderInstaller.addCollider(tMapObject.gameObject, tObjectData.get <Arg>("collider"));
        }
        //category
        if (tObjectData.ContainsKey("category"))
        {
        }
        return(tMapObject);
    }
예제 #3
0
 public void TestCleanup()
 {
     mHandleString = null;
 }
예제 #4
0
 public void TestInit()
 {
     mHandleString = new HandleString();
 }