示例#1
0
    /// <summary>
    /// 获取未连接的兵
    /// </summary>
    public static List <CanvasCore> GetUnLinkSoldiers()
    {
        List <CanvasCore> lNoLinkCore = new List <CanvasCore>();
        List <Int2>       lGold       = new List <Int2>();
        int nRoomCount = m_Room.Count;
        int nRoomCnt   = 0;

        for (nRoomCnt = 0; nRoomCnt < nRoomCount; nRoomCnt++)
        {
            RoomGrid rRoomGrid = m_Room[nRoomCnt];
            if (rRoomGrid != null && !CheckDeckRoom(rRoomGrid))
            {
                CanvasCore cavasCore = rRoomGrid.GetBuildRoom();
                if (cavasCore != null && cavasCore.m_ID == RoomGrid.EMPTYGRIDID)
                {
                    List <CanvasCore> listOther = rRoomGrid.GetOtherBuild();
                    int nCanvasCoreCount        = listOther.Count;
                    int nCanvasCoreCnt          = 0;
                    for (nCanvasCoreCnt = 0; nCanvasCoreCnt < nCanvasCoreCount; nCanvasCoreCnt++)
                    {
                        CanvasCore coreOther = listOther[nCanvasCoreCnt];
                        if (coreOther != null && coreOther.m_type == ShipBuildType.Soldier)
                        {
                            lNoLinkCore.Add(coreOther);
                        }
                    }
                }
            }
        }
        return(lNoLinkCore);
    }
示例#2
0
    /// <summary>
    /// 根据小格子获取房间的CanvasCore
    /// </summary>
    /// <param name="posMapGrid"></param>
    /// <returns></returns>
    public static CanvasCore FindCanvasCore(Int2 posMapGrid, ShipBuildType typeBuld)
    {
        RoomGrid roomGrid = FindRoomGrid(posMapGrid, XYSYS.MapGrid);

        if (roomGrid != null)
        {
            if (typeBuld == ShipBuildType.BuildRoom)
            {
                return(roomGrid.GetBuildRoom());
            }
            List <CanvasCore> roomChildList = roomGrid.GetOtherBuild();
            for (int i = 0; i < roomChildList.Count; i++)
            {
                if (roomChildList[i].m_type == typeBuld)
                {
                    return(roomChildList[i]);
                }
            }
        }
        return(null);
    }
示例#3
0
    void OnMouseDown()
    {
        if (PutCanvasM.CanOperate == false)
        {
            return;
        }

        RaycastHit hit;

        if (WndManager.IsHitNGUI(out hit))//当点击到UI时不做处理
        {
            return;
        }
        if (Input.touchCount >= 2)
        {
            return;
        }
        m_bMouseDown       = true;
        m_bLongTouch       = false;
        m_bTouchMoveChange = true;
        m_fMouseDownTime   = Time.time;
        m_vtotalmouseDelta = Vector2.zero;
        m_vlastFirstTouch  = GetTouchPos(0);
        m_isDrag           = false;
        if (SystemInfo.deviceType == DeviceType.Desktop)
        {
            m_v3MouseTouchDown = Input.mousePosition;
        }
        else
        {
            m_v3MouseTouchDown = Input.GetTouch(0).position;
        }

        //获取按下时画布格子
        Vector3 m_v3TouchScreenPos = new Vector3(m_v3MouseTouchDown.x, m_v3MouseTouchDown.y, -Camera.main.transform.position.z);
        Vector3 m_v3TouchWorldPos  = Camera.main.ScreenToWorldPoint(m_v3TouchScreenPos);
        Vector3 v3dLocalPos        = BattleEnvironmentM.World2LocalPos(m_v3TouchWorldPos);

        m_roomGridTouchDown = RoomMap.FindRoomGrid(v3dLocalPos);
        if (m_roomGridTouchDown == null)
        {
            return;
        }
        m_curClickType = RoomMap.PickupShipBuildType(m_roomGridTouchDown, v3dLocalPos, m_roomGridTouchDown.mPosRoomGrid.Layer);

        CanvasCore buildRoomCoreTouchDown = m_roomGridTouchDown.GetBuildRoom();

        if (TouchMove.g_bSetParaing == true)
        {
            return;
        }

        TouchMove curTouchMove = TouchMoveManager.GetCurTouchMove();

        if (null != curTouchMove)
        {
            //如果当前选中的是房间,新选中的不管是什么都不做变更
            //如果当前选中的不是房间,但是新选中的对象和当前选中的一样则也不变量。
            if (curTouchMove.IsContainsRoomGrid(m_roomGridTouchDown))
            {
                TouchMove selNewTouchMov = PutCanvasM.GetTouchMoveByRoomGrid(m_roomGridTouchDown, m_curClickType);
                if (curTouchMove.MyCore().m_type == ShipBuildType.BuildRoom ||
                    selNewTouchMov != null && selNewTouchMov == curTouchMove)
                {
                    curTouchMove.PlayEditSelectAnimationEnd();                                     //恢复上个房间内陷阱/角色 动画
                    curTouchMove.OnMouseDown();
                    m_bTouchMoveChange = false;
                }
            }
            PutCanvasM.ClearNoLinkList();
        }
        else
        {
            //判断选中物件是否在上次保存失败的物件上,如果是则直接选择
            bool bInNoLinkList = false;
            if (buildRoomCoreTouchDown != null)
            {
                TouchMove selNewTouchMov = PutCanvasM.GetTouchMoveByCore(buildRoomCoreTouchDown);
                if (null == selNewTouchMov)
                {
                    List <CanvasCore> childCores = m_roomGridTouchDown.GetOtherBuild();
                    for (int i = 0; i < childCores.Count; i++)
                    {
                        selNewTouchMov = PutCanvasM.GetTouchMoveByCore(childCores[i]);
                        break;
                    }
                }
                if (null != selNewTouchMov && PutCanvasM.NoLinkListContain(selNewTouchMov.MyCore()))
                {
                    PutCanvasM.ClearNoLinkList();
                    TouchMoveManager.SetCurTouchMove(selNewTouchMov);
                    selNewTouchMov.PlayEditSelectAnimationEnd();                     //恢复上个房间内陷阱/角色 动画
                    selNewTouchMov.OnMouseDown();
                    m_bTouchMoveChange = false;
                    bInNoLinkList      = true;
                }
            }
            if (bInNoLinkList == false)
            {
                PutCanvasM.ClearNoLinkList();
            }
        }
    }
示例#4
0
 void Update()
 {
     if (MainCameraM.s_Instance.CheckIsZooming() || MainCameraM.s_Instance.CheckCameraMove())
     {
         PutCanvasM.ShowRoomGridUI(false);
     }
     if (PutCanvasM.CanOperate == false)
     {
         return;
     }
     if (Input.touchCount >= 2)
     {
         PutCanvasM.ShowRoomGridUI(false);
         m_bTouchMoveChange  = true;
         m_roomGridTouchDown = null;
     }
     // MainCameraM.s_Instance.EnableDrag(true);
     if (m_bMouseDown)
     {
         if (!m_isDrag)
         {
             float click = mouseClickThreshold;
             click *= click;
             m_vtotalmouseDelta += m_vlastFirstTouch - GetTouchPos(0);
             m_vlastFirstTouch   = GetTouchPos(0);
             m_mag = m_vtotalmouseDelta.sqrMagnitude;
             if (m_mag > click)
             {
                 m_isDrag = true;
             }
             else
             {
                 //没有发生移动地图 或 没有发生长按  要判定
                 if (!m_isDrag && !m_bLongTouch)
                 {
                     //长按判定
                     if (!m_isDrag && m_roomGridTouchDown != null)
                     {
                         if (Time.time - m_fMouseDownTime > 0.5f)
                         {
                             m_bLongTouch = true;
                         }
                         //没有发生移动地图,但有发生长按,则更换选中房间,并将m_bTouchMoveChange=false
                         if (m_bLongTouch)
                         {
                             CanvasCore buildRoomCoreTouchDown = m_roomGridTouchDown.GetBuildRoom();
                             TouchMove  selNewTouchMov         = PutCanvasM.GetTouchMoveByCore(buildRoomCoreTouchDown);
                             TouchMove  selOldeTouchMove       = TouchMoveManager.GetCurTouchMove();
                             if (selNewTouchMov != null && selNewTouchMov != selOldeTouchMove)
                             {
                                 m_bTouchMoveChange = false;
                                 TouchMoveManager.SetCurTouchMove(selNewTouchMov);
                                 selNewTouchMov.OnMouseDown();
                             }
                         }
                     }
                 }
             }
         }
         if (m_isDrag)
         {
             //按下是选中的是原选中房间,则直接移动该房间
             //长按时会自动将最新选中房间,并将m_bTouchMoveChange设置为false
             if (!m_bTouchMoveChange)
             {
                 MainCameraM.s_Instance.EnableDrag(false);
                 TouchMove curTouchMove = TouchMoveManager.GetCurTouchMove();
                 if (null != curTouchMove)
                 {
                     PutCanvasM.ShowRoomGridUI(false);
                     //TouchMoveManager.ShowCanvas(true);
                     PutCanvasM.ShowRoomGridUI(false);
                     curTouchMove.MoveBuild();
                 }
             }
         }
     }
 }
示例#5
0
    /// <summary>
    /// 检测该位置是否适合放置,新建摆放对象和显示可放不可放状态时使用
    /// </summary>
    public static bool CheckCanPut(CanvasCore Core, Int2 posMapGrid)
    {
        if (Core == null)
        {
            return(false);
        }
        ShipPlan P = ShipPlanDC.GetCurShipPlan();

        if (P == null)
        {
            return(false);
        }
        ShipPutInfo Info = P.GetShipBuildInfo(Core);

        if (Info == null)
        {
            return(false);
        }

        RoomGrid grid = RoomMap.FindRoomGrid(posMapGrid, XYSYS.MapGrid);

        if (grid != null)
        {
            bool result = BattleEnvironmentM.BuildInShape(grid.mPosRoomGrid);
            if (!result)
            {
                return(false);
            }
        }


        if (Core.m_type == ShipBuildType.BuildRoom)
        {
            List <Int2> AddList = Core.GetMovetoRoomGridPos(posMapGrid);
            if (Core.IsDeckRoom == false)
            {
                List <Int2> oldList = Core.GetPutRoomGridPos();
                if (Core.IsNewCreate)
                {
                    oldList.Clear();//新建连接房间没位置
                }
                //连接房判定是否可放
                bool bLinkOK = RoomMap.CheckLinkToGoldRoom(oldList, AddList, Core.IsNewCreate);
                if (bLinkOK)
                {
                    List <RoomGrid> listRoomGrid       = RoomMap.GetPutRoomGrid(Core);
                    List <RoomGrid> listMovetoRoomGrid = RoomMap.GetMovetoRoomGrid(Core, posMapGrid);
                    if (listRoomGrid.Count != listMovetoRoomGrid.Count)
                    {
                        return(false);
                    }
                    int nMoveToCount = listMovetoRoomGrid.Count;
                    int nMoveCnt     = 0;
                    for (nMoveCnt = 0; nMoveCnt < nMoveToCount; nMoveCnt++)
                    {
                        RoomGrid   roomGrid  = listMovetoRoomGrid[nMoveCnt];
                        CanvasCore buildCore = roomGrid.GetBuildRoom();
                        //所放的地方有其它的连接房或甲板房则不能临时放
                        if (buildCore.m_ID != RoomGrid.EMPTYGRIDID && buildCore.m_ID != Core.m_ID && buildCore.m_type == ShipBuildType.BuildRoom)
                        {
                            return(false);
                        }
                    }
                    return(bLinkOK);
                }
            }
            else
            {
                //甲板房放置判定
                return(RoomMap.CheckCanPutDeckBuild(Core.m_ID, AddList));
            }
        }
        else if (Core.m_type == ShipBuildType.BuildStair)
        {
            //楼梯需保证在活动范围内移动。
            Int2 Area = RoomMap.GetStairActiveArea(Info.cyMapGrid, Info.cxMapGrid);
            if (posMapGrid.Unit < Area.Layer || posMapGrid.Unit > Area.Unit)
            {
                return(false);
            }
            if (posMapGrid.Layer != Info.cyMapGrid)
            {
                return(false);
            }
            RoomMap.RemoveMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            RoomMap.AddMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            return(true);
        }
        else if (Core.m_type == ShipBuildType.Soldier)
        {
            //原占有先移除
            if (!Core.IsNewCreate)
            {
                RoomMap.RemoveMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            }
            //new
            bool ret = RoomMap.CheckMapPosition(RoomMap.GetMovetoRoomGridPosition(Core, posMapGrid));
            //原占有复原
            if (!Core.IsNewCreate)
            {
                RoomMap.AddMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            }
            return(ret);
        }
        return(false);
    }
示例#6
0
    /// <summary>
    /// 确认房间是否可置换
    /// </summary>
    public static bool CheckExchange(CanvasCore coreSrc, CanvasCore coreExchange)
    {
        if (coreSrc == null || coreExchange == null)
        {
            return(false);
        }
        if (coreSrc.m_ID == coreExchange.m_ID)
        {
            return(false);
        }
        if (coreSrc.m_type == ShipBuildType.BuildStair)
        {
            return(false);
        }
        if (coreSrc.m_type != coreExchange.m_type)
        {
            return(false);
        }
        if (coreSrc.Data == null || coreExchange.Data == null)
        {
            return(false);
        }
        if (coreSrc.m_type == ShipBuildType.Soldier)
        {
            return(true);
        }
        if (coreSrc.Data.m_DeckRoom != coreExchange.Data.m_DeckRoom)
        {
            return(false);
        }
        TouchMove tmSrc      = PutCanvasM.GetTouchMoveByCore(coreSrc);
        TouchMove tmExchange = PutCanvasM.GetTouchMoveByCore(coreExchange);

        if (tmSrc == null || tmExchange == null)
        {
            return(false);
        }
        if (tmSrc.m_orgPosMapGrid.Layer + tmExchange.MyCore().GetSize().Layer - 1 >= RoomMap.DeckRoomTopLayer)
        {
            return(false);
        }

        List <RoomGrid> listRoomGridSrc       = RoomMap.GetPutRoomGrid(coreSrc);
        List <RoomGrid> listMovetoRoomGridSrc = RoomMap.GetMovetoRoomGrid(coreSrc, tmSrc.m_posMapGrid);

        if (listRoomGridSrc.Count != listMovetoRoomGridSrc.Count)
        {
            return(false);
        }
        List <RoomGrid> listRoomGridExchange     = RoomMap.GetPutRoomGrid(coreExchange);
        List <RoomGrid> listMoveRoomGridExchange = RoomMap.GetMovetoRoomGrid(coreExchange, tmSrc.m_orgPosMapGrid);

        if (listRoomGridExchange.Count != listMoveRoomGridExchange.Count)
        {
            return(false);
        }

        int nMoveToCount = listMovetoRoomGridSrc.Count;
        int nMoveCnt     = 0;

        for (nMoveCnt = 0; nMoveCnt < nMoveToCount; nMoveCnt++)
        {
            RoomGrid roomGrid = listMovetoRoomGridSrc[nMoveCnt];
            if (listMoveRoomGridExchange.Contains(roomGrid))
            {
                return(false);
            }
            CanvasCore buildCore = roomGrid.GetBuildRoom();
            if (buildCore.m_ID != RoomGrid.EMPTYGRIDID && buildCore.m_ID != coreSrc.m_ID && buildCore.m_ID != coreExchange.m_ID)
            {
                return(false);
            }
            if (buildCore.m_ID == RoomGrid.EMPTYGRIDID)
            {
                List <CanvasCore> childrenCore = roomGrid.GetOtherBuild();
                foreach (CanvasCore childCore in childrenCore)
                {
                    if (childCore.m_type == ShipBuildType.Soldier)
                    {
                        return(false);
                    }
                }
            }
        }
        nMoveToCount = listMoveRoomGridExchange.Count;
        for (nMoveCnt = 0; nMoveCnt < nMoveToCount; nMoveCnt++)
        {
            RoomGrid roomGrid = listMoveRoomGridExchange[nMoveCnt];
            if (listMovetoRoomGridSrc.Contains(roomGrid))
            {
                return(false);
            }
            CanvasCore buildCore = roomGrid.GetBuildRoom();
            if (buildCore.m_ID != RoomGrid.EMPTYGRIDID && buildCore.m_ID != coreExchange.m_ID && buildCore.m_ID != coreSrc.m_ID)
            {
                return(false);
            }
        }

        return(true);//ShipPutInfo.CheckExchangeRoom(core1.Data ,core2.Data);
    }
示例#7
0
    /// <summary>
    /// 检测是否可临时放置(只要空白空间够就可以)
    /// </summary>
    public static bool CheckCanTempPut(CanvasCore Core, Int2 posMapGrid)
    {
        if (Core == null)
        {
            return(false);
        }
        ShipPlan P = ShipPlanDC.GetCurShipPlan();

        if (P == null)
        {
            return(false);
        }
        ShipPutInfo Info = P.GetShipBuildInfo(Core);

        if (Info == null)
        {
            return(false);
        }

        //是否在设计图方案区域内.
        RoomGrid grid = RoomMap.FindRoomGrid(posMapGrid, XYSYS.MapGrid);

        if (grid != null)
        {
            bool result = BattleEnvironmentM.BuildInShape(grid.mPosRoomGrid);
            if (!result)
            {
                return(false);
            }
        }


        if (Core.m_type == ShipBuildType.BuildRoom)
        {
            List <RoomGrid> listRoomGrid       = RoomMap.GetPutRoomGrid(Core);
            List <RoomGrid> listMovetoRoomGrid = RoomMap.GetMovetoRoomGrid(Core, posMapGrid);
            if (listRoomGrid.Count != listMovetoRoomGrid.Count)
            {
                return(false);
            }
            int nMoveToCount = listMovetoRoomGrid.Count;
            int nMoveCnt     = 0;
            for (nMoveCnt = 0; nMoveCnt < nMoveToCount; nMoveCnt++)
            {
                RoomGrid   roomGrid  = listMovetoRoomGrid[nMoveCnt];
                CanvasCore buildCore = roomGrid.GetBuildRoom();
                //所放的地方有其它的连接房或甲板房则不能临时放
                if (buildCore.m_ID != RoomGrid.EMPTYGRIDID && buildCore.m_ID != Core.m_ID && buildCore.m_type == ShipBuildType.BuildRoom)
                {
                    return(false);
                }
                //普通房间(非甲板房)不能放在有炮弹兵甲板上
                if (buildCore.m_ID == RoomGrid.EMPTYGRIDID)
                {
                    List <CanvasCore> childrenCore = roomGrid.GetOtherBuild();
                    foreach (CanvasCore childCore in childrenCore)
                    {
                        if (childCore.m_type == ShipBuildType.Soldier)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
        else if (Core.m_type == ShipBuildType.BuildStair)
        {
            //楼梯需保证在活动范围内移动。
            Int2 Area = RoomMap.GetStairActiveArea(Info.cyMapGrid, Info.cxMapGrid);
            if (posMapGrid.Unit < Area.Layer || posMapGrid.Unit > Area.Unit)
            {
                return(false);
            }
            if (posMapGrid.Layer != Info.cyMapGrid)
            {
                return(false);
            }
            RoomMap.RemoveMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            RoomMap.AddMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            return(true);
        }
        else if (Core.m_type == ShipBuildType.Soldier)
        {
            //原占有先移除
            if (!Core.IsNewCreate)
            {
                RoomMap.RemoveMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            }
            //new
            bool ret = RoomMap.CheckMapPosition(RoomMap.GetMovetoRoomGridPosition(Core, posMapGrid));
            //原占有复原
            if (!Core.IsNewCreate)
            {
                RoomMap.AddMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            }
            if (!ret)
            {
                List <RoomGrid> lRoomGrid = RoomMap.GetMovetoRoomGrid(Core, posMapGrid);
                if (null != lRoomGrid && null != lRoomGrid[0])
                {
                    //所在位置是连接房则上面已经判定不能放就是不能临时放
                    if (lRoomGrid[0].GetBuildRoom().m_ID == RoomGrid.EMPTYGRIDID)
                    {
                        ret = true;
                    }
                }
            }
            return(ret);
        }
        return(false);
    }