Пример #1
0
    void Update()
    {
        if (GameConfig.IsInVCE)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.O))
        {
            Gen = true;
        }

        if (Gen)
        {
            if (m_Cursor != null)
            {
                Destroy(m_Cursor.gameObject);
            }
            m_Cursor = BIsoCursor.CreateIsoCursor(GameConfig.GetUserDataPath() + BSSaveIsoBrush.s_IsoPath + File_Name + BSSaveIsoBrush.s_Ext);
            m_Rot    = 0;
            Gen      = false;
        }

        if (m_Cursor == null)
        {
            return;
        }

        if (BSInput.s_Cancel)
        {
            Cancel();
            if (onCancelClick != null)
            {
                onCancelClick();
            }
            return;
        }

        if (m_Cursor != null)
        {
            m_Cursor.gameObject.SetActive(true);
        }

        if (m_Cursor.ISO.m_HeadInfo.Mode == EBSVoxelType.Block)
        {
            if (BSMath.RayCastDrawTarget(BSInput.s_PickRay, BuildingMan.Blocks, out m_Target, BSMath.MC_ISO_VALUE, true, BuildingMan.Datas))
            {
                m_Cursor.gameObject.SetActive(true);

                Vector3 offset = Vector3.zero;
                offset.x = (m_Cursor.ISO.m_HeadInfo.xSize) / 2 * BSBlock45Data.s_Scale;
                offset.z = (m_Cursor.ISO.m_HeadInfo.zSize) / 2 * BSBlock45Data.s_Scale;


                if (Input.GetKeyDown(KeyCode.T))
                {
                    m_Rot = ++m_Rot > 3 ? 0 : m_Rot;
                }


                m_Cursor.SetOriginOffset(-offset);
                m_Cursor.transform.rotation = Quaternion.Euler(0, 90 * m_Rot, 0);

                // Adjust Offset
                FocusAjust();

                m_Cursor.transform.position = m_Target.cursor + m_FocusOffset * BSBlock45Data.s_Scale;

                if (Input.GetMouseButtonDown(0))
                {
                    if (BSInput.s_MouseOnUI)
                    {
                        return;
                    }

                    if (m_Cursor.gizmoTrigger.RayCast)
                    {
                        return;
                    }

                    // For History
                    m_OldVoxel.Clear();
                    m_NewVoxel.Clear();
                    m_Indexes.Clear();
                    m_VoxelMap.Clear();

                    m_Cursor.OutputVoxels(Vector3.zero, OnOutputBlocks);

                    // Extra Extendable
                    FindExtraExtendableVoxels(dataSource, m_NewVoxel, m_OldVoxel, m_Indexes, m_VoxelMap);

                    // For History
                    BSAction      action = new BSAction();
                    BSVoxelModify modify = new BSVoxelModify(m_Indexes.ToArray(), m_OldVoxel.ToArray(), m_NewVoxel.ToArray(), BuildingMan.Blocks, EBSBrushMode.Add);
                    if (!modify.IsNull())
                    {
                        action.AddModify(modify);
                    }

                    if (action.Do())
                    {
                        BSHistory.AddAction(action);
                        if (onBrushDo != null)
                        {
                            onBrushDo();
                        }
                    }
                }
            }
            else
            {
                m_Cursor.gameObject.SetActive(false);
            }
        }
        else if (m_Cursor.ISO.m_HeadInfo.Mode == EBSVoxelType.Block)
        {
            if (BSMath.RayCastDrawTarget(BSInput.s_PickRay, BuildingMan.Voxels, out m_Target, 1, true, BuildingMan.Datas))
            {
                m_Cursor.gameObject.SetActive(false);
                Debug.Log("Draw building Iso dont support the voxel");
                return;
            }
            else
            {
                m_Cursor.gameObject.SetActive(false);
            }
        }
    }