示例#1
0
        private void PaintLayer(bool isErase)
        {
            RaycastHit gHit;
            Ray        worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            LayerMask  _mask    = 1 << LayerMask.NameToLayer("EditorLevel");
            VGlobal    vg       = VGlobal.GetSetting();
            bool       isHit    = Physics.Raycast(worldRay, out gHit, vg.editDis, _mask);
            WorldPos   pos;

            if (isHit && gHit.collider.GetComponentInParent <Volume> () == volume)
            {
                gHit.point = gHit.point + new Vector3(0f, -vg.h, 0f);
                gHit.point = volume.transform.InverseTransformPoint(gHit.point);
                pos        = EditTerrain.GetBlockPos(gHit, true);

                volume.SetBlock(pos.x, pos.y, pos.z, isErase ? null : new Block());

                Chunk chunk = volume.GetChunk(pos.x, pos.y, pos.z);
                if (chunk)
                {
                    if (!dirtyChunks.ContainsKey(pos))
                    {
                        dirtyChunks.Add(pos, chunk);
                    }
                    chunk.UpdateMeshFilter();
                    SceneView.RepaintAll();
                }
            }
            EditorUtility.SetDirty(volume.vd);
        }
示例#2
0
        private void DrawLayerMarker()
        {
            RaycastHit hit;
            Ray        worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            LayerMask  _mask    = 1 << LayerMask.NameToLayer("EditorLevel");
            VGlobal    vg       = VGlobal.GetSetting();
            bool       isHit    = Physics.Raycast(worldRay, out hit, vg.editDis, _mask);

            if (isHit && hit.collider.GetComponentInParent <Volume> () == volume)
            {
                RaycastHit hitFix = hit;
                WorldPos   pos    = EditTerrain.GetBlockPos(hitFix, false);
                hitFix.point = new Vector3(pos.x * vg.w, pos.y * vg.h, pos.z * vg.d);

                Handles.RectangleCap(0, hitFix.point + new Vector3(0, vg.hh, 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);
            }
            else
            {
                volume.useBox = false;
            }
            SceneView.RepaintAll();
        }
示例#3
0
        private void DrawMarker(bool isErase)
        {
            RaycastHit hit;
            Ray        worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            LayerMask  _mask    = 1 << LayerMask.NameToLayer("Editor");
            VGlobal    vg       = VGlobal.GetSetting();
            bool       isHit    = Physics.Raycast(worldRay, out hit, vg.editDis, _mask);

            if (isHit && !isErase && hit.collider.GetComponentInParent <Volume> () == volume)
            {
                RaycastHit hitFix = hit;
                WorldPos   pos    = EditTerrain.GetBlockPos(hitFix, isErase ? false : true);
                hitFix.point = new Vector3(pos.x * vg.w, pos.y * vg.h, pos.z * vg.d);

                Handles.DrawLine(hit.point, hit.point + hit.normal);
                if (hit.collider.gameObject.tag == PathCollect.rularTag)
                {
                    hit.normal = Vector3.zero;
                }
                BoxCursorUtils.UpdateBox(volume.box, hitFix.point, hit.normal);
                SceneView.RepaintAll();
            }
            else
            {
                volume.useBox = false;
                SceneView.RepaintAll();
            }
        }
示例#4
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();
            }
        }
示例#5
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();
                }
            }
        }