Ejemplo n.º 1
0
    void DestroyTargetBrick()
    {
        RaycastHit _raycastHit;
        Ray        _ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(_ray, out _raycastHit, 256))
        {
            Vector3 _hitPoint = _raycastHit.point;
            if (_raycastHit.collider.gameObject.name != "CubeBrick(Clone)")
            {
                return;
            }

            IntVec3 _cubeIdx = new IntVec3(_raycastHit.collider.gameObject.transform.position);

            if (m_buildBrickMap.ContainsKey(_cubeIdx) == true)
            {
                CubeBrick _cb = m_buildBrickMap[_cubeIdx];

                //清理targetBrick
                m_buildBrickMap.Remove(_cubeIdx);
                Object.DestroyImmediate(_cb.m_go);

                CubeBrick _cbNgb = _cb.GetBrickDirP();
                if (_cbNgb != null)
                {
                    _cbNgb.SetBrickDirN(null);
                }

                _cbNgb = _cb.GetBrickDirN();
                if (_cbNgb != null)
                {
                    _cbNgb.SetBrickDirP(null);
                }

                //无论哪种情况都需要检查上面的brick
                IntVec3 _upIdx = new IntVec3(_cubeIdx);
                _upIdx.y += 1;
                if (m_buildBrickMap.ContainsKey(_upIdx) == true)
                {
                    m_checkListMap.Add(_upIdx, m_buildBrickMap[_upIdx]);
                }

                //如果targetBrick为PY方向 或者 targetBrick无相邻对象,则通知其上面的brick
                if ((_cb.m_dirP == PYAxis) || (_cb.m_dirN == NoDir && _cb.m_dirP == NoDir))
                {
                    return;
                }

                //如果targetBrick为其它方向,则通知其相邻方向和上面的brick
                if (_cb.m_dirP != NoDir)
                {
                    _cbNgb = _cb.GetBrickDirP();
                    if (_cbNgb != null)
                    {
                        m_checkListMap.Add(_cbNgb.GetIdx(), _cbNgb);
                    }
                }

                if (_cb.m_dirN != NoDir)
                {
                    _cbNgb = _cb.GetBrickDirN();
                    if (_cbNgb != null)
                    {
                        m_checkListMap.Add(_cbNgb.GetIdx(), _cbNgb);
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    void BuildDragBrick()
    {
        if (m_bNewFirstBrick == true)
        {
            IntVec3 _pos = new IntVec3(m_firstBrick.m_go.transform.position);
            m_buildBrickMap.Add(_pos, m_firstBrick);
        }

        for (int _i = 0; _i != m_dragBrickList.Count; ++_i)
        {
            CubeBrick _cb = m_dragBrickList[_i];
            if (m_dragDir == _cb.m_dirP)
            {
                int _nextP = _i + 1;
                int _nextN = _i - 1;
                if (_nextP < m_dragBrickList.Count)
                {
                    _cb.m_neighbour[_cb.m_dirP] = m_dragBrickList[_nextP];
                }
                if (_nextN >= 0)
                {
                    _cb.m_neighbour[_cb.m_dirN] = m_dragBrickList[_nextN];
                }
            }
            else
            {
                if (m_dragDir == _cb.m_dirN)
                {
                    int _nextP = _i - 1;
                    int _nextN = _i + 1;
                    if (_nextP >= 0)
                    {
                        _cb.m_neighbour[_cb.m_dirP] = m_dragBrickList[_nextP];
                    }
                    if (_nextN < m_dragBrickList.Count)
                    {
                        _cb.m_neighbour[_cb.m_dirN] = m_dragBrickList[_nextN];
                    }
                }
            }

            IntVec3 _pos = new IntVec3(_cb.m_go.transform.position);
            m_buildBrickMap.Add(_pos, _cb);
        }

        if (m_dragBrickList.Count != 0)
        {
            CubeBrick _cb = m_dragBrickList[0];
            m_firstBrick.m_dirP = _cb.m_dirP;
            m_firstBrick.m_dirN = _cb.m_dirN;
            if (m_dragDir == _cb.m_dirP)
            {
                m_firstBrick.SetBrickDirP(m_dragBrickList[0]);
                m_dragBrickList[0].SetBrickDirN(m_firstBrick);
            }
            else
            {
                if (m_dragDir == _cb.m_dirN)
                {
                    m_firstBrick.SetBrickDirN(m_dragBrickList[0]);
                    m_dragBrickList[0].SetBrickDirP(m_firstBrick);
                }
            }
        }
        m_dragBrickList.Clear();
        m_firstBrick = null;
    }