예제 #1
0
        private void DrawGridMarker()
        {
            if (_pieceSelected == null)
            {
                return;
            }
            bool       isNotLayer = (currentEditMode != EditMode.ObjectLayer);
            RaycastHit hit;
            Ray        worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            LayerMask  _mask    = isNotLayer ? 1 << LayerMask.NameToLayer("Editor") : 1 << LayerMask.NameToLayer("EditorLevel");
            VGlobal    vg       = VGlobal.GetSetting();
            bool       isHit    = Physics.Raycast(worldRay, out hit, (int)vg.editDis, _mask);

            if (isHit && hit.collider.GetComponentInParent <Volume> () == volume)
            {
                if (hit.normal.y <= 0)
                {
                    return;
                }

                RaycastHit hitFix = hit;
                WorldPos   pos    = EditTerrain.GetBlockPos(hitFix, isNotLayer);
                hitFix.point = new Vector3(pos.x * vg.w, pos.y * vg.h, pos.z * vg.d);

                WorldPos gPos = EditTerrain.GetGridPos(hit.point);
                gPos.y = isNotLayer ? 0 : (int)vg.h;

                float gx = pos.x * vg.w + gPos.x + ((pos.x < 0) ? 1 : -1);
                float gy = pos.y * vg.h + gPos.y - vg.hh;
                float gz = pos.z * vg.d + gPos.z + ((pos.z < 0) ? 1 : -1);

                LevelPiece.PivotType pivot = _pieceSelected.pivot;
                if (CheckPlaceable((int)gPos.x, (int)gPos.z, pivot))
                {
                    Handles.color = Color.red;
                    Handles.RectangleCap(0, new Vector3(gx, gy, gz), Quaternion.Euler(90, 0, 0), 0.5f);
                    Handles.color = Color.white;
                }

                Handles.color    = Color.white;
                Handles.lighting = true;
                Handles.RectangleCap(0, hitFix.point - new Vector3(0, vg.hh - gPos.y, 0), Quaternion.Euler(90, 0, 0), vg.hw);
                Handles.DrawLine(hit.point, hitFix.point);

                volume.useBox = true;
                BoxCursorUtils.UpdateBox(volume.box, hitFix.point, Vector3.zero);
                SceneView.RepaintAll();
            }
            else
            {
                volume.useBox = false;
                SceneView.RepaintAll();
            }
        }
예제 #2
0
        private void PaintPieces(bool isErase)
        {
            if (_pieceSelected == null)
            {
                return;
            }

            bool canPlace = false;

            RaycastHit gHit;
            Ray        worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            LayerMask  _mask    = (currentEditMode == EditMode.Object) ? 1 << LayerMask.NameToLayer("Editor") : 1 << LayerMask.NameToLayer("EditorLevel");
            VGlobal    vg       = VGlobal.GetSetting();
            bool       isHit    = Physics.Raycast(worldRay, out gHit, vg.editDis, _mask);

            if (isHit && gHit.collider.GetComponentInParent <Volume> () == volume)
            {
                if (gHit.normal.y <= 0)
                {
                    return;
                }

                gHit.point = volume.transform.InverseTransformPoint(gHit.point);
                WorldPos bPos = EditTerrain.GetBlockPos(gHit, (currentEditMode == EditMode.Object));
                WorldPos gPos = EditTerrain.GetGridPos(gHit.point);
                gPos.y = 0;
                int gx = gPos.x;
                int gz = gPos.z;

                if (CheckPlaceable(gx, gz, _pieceSelected.pivot))
                {
                    canPlace = true;
                }

                if (canPlace)
                {
                    volume.PlacePiece(bPos, gPos, isErase ? null : _pieceSelected);
                    Chunk chunk = volume.GetChunk(bPos.x, bPos.y, bPos.z);
                    chunk.UpdateMeshFilter();
                    chunk.UpdateMeshCollider();
                    EditorUtility.SetDirty(volume.vd);
                    SceneView.RepaintAll();
                }
            }
        }