Exemplo n.º 1
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);
    }
Exemplo n.º 2
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");
        }
    }