Ejemplo n.º 1
0
    void DetachBrick(CubeBrick _cb)
    {
        _cb.m_go.rigidbody.isKinematic = false;
        _cb.m_go.rigidbody.AddForce(0.0f, -9.8f, 0.0f);
        IntVec3 _posIdx = _cb.GetIdx();

        m_buildBrickMap.Remove(_posIdx);
        m_checkListMap.Remove(_posIdx);
    }
Ejemplo n.º 2
0
    void UpdateCheckList()
    {
        while (m_checkListMap.Count != 0)
        {
            Dictionary <IntVec3, CubeBrick> .Enumerator _enum = m_checkListMap.GetEnumerator();
            bool _b = _enum.MoveNext();
            KeyValuePair <IntVec3, CubeBrick> _it = _enum.Current;
            CubeBrick _cb = _it.Value;

            //如果为独立brick,无任何连接方向
            if (_cb.m_dirP == NoDir && _cb.m_dirN == NoDir)
            {
                IntVec3 _upIdx = _cb.GetPY();
                if (m_buildBrickMap.ContainsKey(_upIdx))
                {
                    m_checkListMap.Add(_upIdx, m_buildBrickMap[_upIdx]);
                }
                DetachBrick(_cb);
                break;
            }

            //如果为Y轴正方向
            if (_cb.m_dirP == PYAxis)
            {
                if (_cb.m_neighbour[_cb.m_dirP] != null)  //非Y轴最顶层
                {
                    m_checkListMap.Add(_cb.m_neighbour[_cb.m_dirP].GetIdx(), _cb.m_neighbour[_cb.m_dirP]);
                }
                else //为Y抽最顶层
                {
                    IntVec3 _upIdx = _cb.GetPY();
                    if (m_buildBrickMap.ContainsKey(_upIdx))
                    {
                        m_checkListMap.Add(_upIdx, m_buildBrickMap[_upIdx]);
                    }
                }

                DetachBrick(_cb);
                continue;
            }

            //如果为非Y轴队列:先检查每个brick下面是否存在支撑点,如果一个支撑点都没有,则detach改队列所有brick
            bool             _hasPillar  = false;
            List <CubeBrick> _brickGroup = new List <CubeBrick>();
            IntVec3          _downIdx    = _cb.GetNY();

            //首先检查当前brick下面是否存在支撑点
            if (m_buildBrickMap.ContainsKey(_downIdx))
            {
                _hasPillar = true;
            }
            else
            {
                _brickGroup.Add(_cb); //加入当前cubebrick
            }
            if (_hasPillar == false)
            {
                CubeBrick _cbNgb = _cb.m_neighbour[_cb.m_dirP];
                //检查正方向
                while (_cbNgb != null)
                {
                    _downIdx = _cbNgb.GetNY();
                    if (m_buildBrickMap.ContainsKey(_downIdx))
                    {
                        _hasPillar = true;
                        break;
                    }
                    else
                    {
                        _brickGroup.Add(_cbNgb);
                        _cbNgb = _cbNgb.m_neighbour[_cbNgb.m_dirP];
                    }
                }

                //检查负方向
                if (_hasPillar == false)
                {
                    _cbNgb = _cb.m_neighbour[_cb.m_dirN];
                    while (_cbNgb != null)
                    {
                        _downIdx = _cbNgb.GetNY();
                        if (m_buildBrickMap.ContainsKey(_downIdx))
                        {
                            _hasPillar = true;
                            break;
                        }
                        else
                        {
                            _brickGroup.Add(_cbNgb);
                            _cbNgb = _cbNgb.m_neighbour[_cbNgb.m_dirN];
                        }
                    }
                }
            }

            if (_hasPillar == false)
            {
                foreach (CubeBrick _brick in _brickGroup)
                {
                    m_buildBrickMap.Remove(_brick.GetIdx());
                    DetachBrick(_brick);
                    IntVec3 _upIdx = _brick.GetPY();
                    if (m_buildBrickMap.ContainsKey(_upIdx))
                    {
                        m_checkListMap.Add(_upIdx, m_buildBrickMap[_upIdx]);
                    }
                }
            }

            m_checkListMap.Remove(_cb.GetIdx());
        }
        //yield return 0;
    }
Ejemplo n.º 3
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);
                    }
                }
            }
        }
    }