Exemple #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();
            }
        }
Exemple #2
0
        private bool CheckPlaceable(int x, int z, LevelPiece.PivotType pType)
        {
            if (pType == LevelPiece.PivotType.Grid)
            {
                return(true);
            }
            else if (pType == LevelPiece.PivotType.Center && (x * z) == 1)
            {
                return(true);
            }
            else if (pType == LevelPiece.PivotType.Vertex && (x + z) % 2 == 0 && x * z != 1)
            {
                return(true);
            }
            else if (pType == LevelPiece.PivotType.Edge && (Mathf.Abs(x) + Mathf.Abs(z)) % 2 == 1)
            {
                return(true);
            }

            return(false);
        }