Example #1
0
    /// <summary>
    /// 点击放到一个位置
    /// </summary>
    /// <param name="args"></param>
    private void EventSetFurn2Pos(object[] args)
    {
        if (m_Selected == false)
        {
            return;
        }

        RayClickPos fp = (RayClickPos)args[0];

        //Debug.LogWarning(MapUtil.Vector3String(fp.pos) + " grid=" + MapUtil.GetMap(m_InitData.m_CurWall).Pos2Grid(fp.pos));

        //Debug.LogWarning("name=" + this.name + " wall=" + m_InitData.m_CurWall);

        if (fp.wallType == m_InitData.m_CurWall)
        {
            Place2Pos(fp.pos, false);
        }
        else
        {
            if (m_Config.setType != MapUtil.SetType.Floor &&
                fp.wallType != Enum_Wall.Floor)
            {
                SelectChange2Wall(m_InitData.m_CurWall, fp.wallType, fp.pos);
            }
        }
        UI_Ctr.Inst.ShowCtr();
    }
Example #2
0
    private void EventClick3DObj(object[] args)
    {
        if (args == null || args.Length != 1)
        {
            return;
        }

        if (MapUtil.m_SelectId == 0 ||
            MapUtil.m_SelectOK)
        {
            return;
        }

        Click3DCheck.RayClickInfo info = (Click3DCheck.RayClickInfo)args[0];
        if (MapUtil.IsWallLayer(info.col.gameObject.layer))
        {
            RayClickPos fp = new RayClickPos();
            fp.pos      = info.pos;
            fp.wallType = MapUtil.WallLayer2WallEnum(info.col.gameObject.layer);

            //JerryDrawer.Draw<DrawerElementCube>()
            //    .SetColor(Color.black)
            //    .SetLife(3f)
            //    .SetPos(fp.pos)
            //    .SetSize(Vector3.one)
            //    .SetWire(false)
            //    .SetSizeFactor(0.2f);

            JerryEventMgr.DispatchEvent(Enum_Event.SetFurn2Pos.ToString(), new object[] { fp });
        }
    }
Example #3
0
    /// <summary>
    /// 默认放一个位置
    /// </summary>
    /// <returns></returns>
    public static RayClickPos GetFirstPos(MapUtil.SetType setType)
    {
        RayClickPos ret = new RayClickPos();

        ret.pos      = Vector3.zero;
        ret.wallType = Enum_Wall.Wall;

        Vector3 pos = new Vector3(Screen.width / 2, Screen.height / 2, 0f);

        if (setType == SetType.Floor)
        {
            pos.y = Screen.height / 4;
        }

        Ray        ray = Camera.main.ScreenPointToRay(pos);
        RaycastHit hitInfo;

        if (Physics.Raycast(ray, out hitInfo, 100, JerryUtil.MakeLayerMask(JerryUtil.MakeLayerMask(false), GetWallLayerNames(setType))))
        {
            if (hitInfo.collider != null &&
                hitInfo.collider.gameObject != null)
            {
                ret.pos      = hitInfo.point;
                ret.wallType = WallLayer2WallEnum(hitInfo.collider.gameObject.layer);
            }
        }
        else
        {
            Debug.LogError("first error");
        }

        return(ret);
    }
Example #4
0
    /// <summary>
    /// 选中
    /// </summary>
    private void SelectSelf(bool isNew = false)
    {
        if (MapUtil.m_SelectId != 0 &&
            !MapUtil.m_SelectOK)
        {
            if (MapUtil.m_SelectNew)
            {
                JerryEventMgr.DispatchEvent(Enum_Event.SetFurn2Package.ToString(), new object[] { MapUtil.m_SelectId });
            }
            else
            {
                JerryEventMgr.DispatchEvent(Enum_Event.CancelSetFurn.ToString(), new object[] { MapUtil.m_SelectId });
            }
        }

        if (isNew)
        {
            RayClickPos fp = MapUtil.GetFirstPos(m_Config.setType);
            //Debug.LogWarning(fp.pos + " x " + fp.wallType + " " + m_Config.setType);
            SelectChange2Wall(Enum_Wall.Wall, fp.wallType, fp.pos);
        }
        else if (m_InitData.m_CurWall != Enum_Wall.None)
        {
            //先浮起来,再记录,保持回退时一致性
            this.transform.position = MapUtil.GetMap(m_InitData.m_CurWall).AdjustFurn2Wall(m_Config.size, true, this.transform.position);

            m_InitData.m_LastPos  = this.transform.position;
            m_InitData.m_LastWall = m_InitData.m_CurWall;

            MapUtil.GetMap(m_InitData.m_CurWall).CleanOne(this.transform.position, m_Config.size);
        }

        //Debug.LogWarning("xxx " + m_InitData.isNew + " " + m_InitData.m_CurWall);

        MapUtil.m_SelectId   = m_Id;
        MapUtil.m_SelectOK   = false;
        MapUtil.m_SelectNew  = isNew;
        MapUtil.m_SelectFurn = this;

        this.gameObject.layer = LayerMask.NameToLayer(Enum_Layer.ActiveFurniture.ToString());
        m_Selected            = true;
        m_InitData.isSeted    = false;

        bool canSet = MapUtil.GetMap(m_InitData.m_CurWall).JudgeSet(this.transform.position, m_Config.size);

        //GridMgr.Inst.ShowGrid(m_Config.setType, m_Config.size.y);
        MeshDraw.Inst.ShowGrid(m_Config.setType, m_Config.size.y);

        SetOutLineVisible(true);
        SetOutLineColor(canSet ? Color.green : Color.red);
        FurnitureShadow.Inst.SetSize(m_Config.size.ToVector3(), m_InitData.m_CurWall);
        FurnitureShadow.Inst.SetVisible(true);
        FurnitureShadow.Inst.SetPosColor(MapUtil.GetMap(m_InitData.m_CurWall).Adjust2Wall(this.transform.position), canSet ? Color.green : Color.red);
        UI_Ctr.Inst.ShowCtr();
    }
Example #5
0
    private IEnumerator IE_DoDrag()
    {
        Camera camera = Camera.main;

        if (camera == null)
        {
            yield break;
        }

        CalOffset();

        while (m_InDraging)
        {
            if (Util.Vector3Equal(JerryUtil.GetClickPos() - m_Offset, m_LastDragingPos, 2) &&
                !JudgePosOutScreen())   //移动屏幕的时候,相对位置永远不变,这样物体不会更随
            {
                yield return(new WaitForEndOfFrame());

                yield return(new WaitForEndOfFrame());//等两帧,减小频率

                continue;
            }

            m_LastDragingPos = JerryUtil.GetClickPos() - m_Offset;
            m_Ray            = Camera.main.ScreenPointToRay(m_LastDragingPos);

            if (Physics.Raycast(m_Ray, out m_HitInfo, 100,
                                JerryUtil.MakeLayerMask(JerryUtil.MakeLayerMask(false),
                                                        MapUtil.GetWallLayerNames(m_Config.setType))))
            {
                if (m_HitInfo.collider != null &&
                    m_HitInfo.collider.gameObject != null)
                {
                    RayClickPos fp = new RayClickPos();
                    fp.pos      = m_HitInfo.point;
                    fp.wallType = MapUtil.WallLayer2WallEnum(m_HitInfo.collider.gameObject.layer);

                    //Debug.LogWarning(fp.wallType + " xxx " + m_InitData.m_CurWall);

                    if (fp.wallType != m_InitData.m_CurWall ||
                        !Util.Vector3Equal(fp.pos, m_LastPos))
                    {
                        m_LastPos = fp.pos;

                        if (fp.wallType == m_InitData.m_CurWall)
                        {
                            UI_Ctr.Inst.HideCtr();
                            //Debug.LogWarning("bbbb================ " + MapUtil.Vector3String(fp.pos));
                            if (Place2Pos(fp.pos, true))
                            {
                                CalOffset();
                                //yield break;
                            }
                        }
                        else
                        {
                            if (fp.wallType != Enum_Wall.Floor &&
                                m_Config.setType != MapUtil.SetType.Floor)
                            {
                                //Debug.LogWarning("aaaa================");
                                UI_Ctr.Inst.HideCtr();
                                SelectChange2Wall(m_InitData.m_CurWall, fp.wallType, fp.pos);
                                //yield return new WaitForEndOfFrame();
                                CalOffset();
                                //yield break;
                            }
                        }
                    }
                }
            }

            yield return(new WaitForEndOfFrame());

            yield return(new WaitForEndOfFrame());//等两帧,减小频率
        }

        if (m_Selected)
        {
            UI_Ctr.Inst.ShowCtr();
            //Debug.LogWarning("Click ShowCtr");
        }
    }