Example #1
0
    private List <WaterShore> GenerateWaterShoreList(List <WaterShoreSegment> waterShoreSegmentList)
    {
        List <WaterShore> waterShoreList = new List <WaterShore> ();

        //先把零散的线段第一次刷选,处理成一一系列的WaterInfo
        for (int i = 0; i < waterShoreSegmentList.Count; ++i)
        {
            WaterShoreSegment waterShoreSegment = waterShoreSegmentList [i];
            bool hasFind = false;
            for (int j = 0; j < waterShoreList.Count; ++j)
            {
                WaterShore waterShore = waterShoreList [j];
                if (waterShore.JoinWaterShoreSegment(waterShoreSegment))
                {
                    hasFind = true;
                    break;
                }
            }
            if (!hasFind)
            {
                WaterShore waterInfo = new WaterShore(waterHeight);
                waterInfo.JoinWaterShoreSegment(waterShoreSegment);
                waterShoreList.Add(waterInfo);
            }
        }

        bool hasJoinSuccess = false;

        for (int i = 0; i < waterShoreList.Count; ++i)
        {
            //之所以j从0开始,因为A连接B失败,但是B连接A有可能成功,可以优化连接函数
            for (int j = 0; j < waterShoreList.Count; ++j)
            {
                if (i == j)
                {
                    continue;
                }
                WaterShore waterShoreA = waterShoreList [i];
                WaterShore waterShoreB = waterShoreList [j];

                //可以为每一个WaterInfo设定唯一表示,并且拼接WaterLine后ID改变,在这里缓存拼接失败的ID对
                if (waterShoreA.JoinWaterShore(waterShoreB))
                {
                    hasJoinSuccess = true;
                    waterShoreList.RemoveAt(j);
                    break;
                }
            }

            //成功拼接后,waterInfos中的某一个数据已经无效,从新开始
            if (hasJoinSuccess)
            {
                i = -1;
                hasJoinSuccess = false;
            }
        }
        Debug.Log("waterInfos.cout:  " + waterShoreList.Count);

        for (int i = 0; i < waterShoreList.Count; ++i)
        {
            waterShoreList [i].CheckError();
        }
        return(waterShoreList);
    }