コード例 #1
0
        private void DrawScreenGUI(EditableTileVolume lattice)
        {
            Handles.BeginGUI();
            GUILayout.BeginArea(new Rect(5, 5, 120, 160));
            GUILayout.BeginVertical();

            if (GUILayout.Button(editToggle ? "edit mode" : "view mode"))
            {
                editToggle = !editToggle;
            }

            if (GUILayout.Button(viewMenuOpen ? "<<<" : "view menu >>>", GUILayout.Height(20)))
            {
                viewMenuOpen = !viewMenuOpen;
            }

            if (viewMenuOpen)
            {
                if (GUILayout.Button("reset grid"))
                {
                    needsRepaint = true;
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndArea();
            Handles.EndGUI();
        }
コード例 #2
0
        private void CalcHitList(Ray ray, EditableTileVolume volume)
        {
            hitList.Clear();

            var volTrans = volume.transform;

            ray.origin = volTrans.InverseTransformPoint(ray.origin);
            var dir = volTrans.InverseTransformDirection(ray.direction).normalized;

            ray.direction = dir;

            rayStart = ray.origin;
            rayEnd   = ray.origin + ray.direction * 100f;

            Vector3 cellSize = Vector3.one;
            Vector3 halfSize = new Vector3(volume.DataXSize * cellSize.x * 0.5f, volume.DataYSize * cellSize.y * 0.5f, volume.DataZSize * cellSize.z * 0.5f);

            GridRayIntersection intersect = new GridRayIntersection(halfSize, new Vector3Int(volume.DataXSize, volume.DataYSize, volume.DataZSize), cellSize, ray);

            if (intersect.DidHit)
            {
                hitList.Add(intersect.CurrentTraverseCell);
                for (int i = 0; i < 10; ++i)
                {
                    hitList.Add(intersect.NextCell());
                }
            }
        }
コード例 #3
0
        private void DrawHitList(List <Vector3Int> coords, EditableTileVolume volume)
        {
            Vector3 cellSize = Vector3.one;

            Vector3 offset = new Vector3(volume.DataXSize * -0.5f * cellSize.x + 0.5f * cellSize.x,
                                         volume.DataYSize * -0.5f + 0.5f * cellSize.y,
                                         volume.DataZSize * -0.5f + 0.5f * cellSize.z);
            Vector3 prev = Vector3.zero;

            foreach (var c in coords)
            {
                var position = new Vector3(c.x + offset.x, c.y + offset.y, c.z + offset.z);
                Handles.color = Color.red;
                Handles.DrawWireCube(position, Vector3.one);
                Handles.color = Color.magenta;
                Handles.CubeHandleCap(0, position, Quaternion.identity, 0.5f, EventType.Used);

                Handles.color = Color.white;

                if (prev != Vector3.zero)
                {
                    Handles.DrawLine(prev, position);
                }
                prev = position;
            }

            Handles.color = Color.yellow;
            Handles.DrawDottedLine(rayStart, rayEnd, 0.2f);
        }
コード例 #4
0
        private void Draw(EditableTileVolume volume)
        {
            Camera    cam   = SceneView.lastActiveSceneView.camera;
            Transform trans = volume.transform;

            using (var scope = new Handles.DrawingScope(trans.localToWorldMatrix))
            {
                var camPos  = trans.InverseTransformPoint(cam.transform.position);
                var camLook = trans.InverseTransformDirection(cam.transform.forward);
                DrawBgGrid(volume, camPos, camLook, Vector3.one);

                DrawHitList(hitList, volume);
            }

            needsRepaint = false;
        }
コード例 #5
0
        private void DrawBgGrid(EditableTileVolume volume, Vector3 camPos, Vector3 camLook, Vector3 cellSize)
        {
            var halfSize = new Vector3(volume.DataXSize, volume.DataYSize, volume.DataZSize);

            halfSize.x *= cellSize.x;
            halfSize.y *= cellSize.y;
            halfSize.z *= cellSize.z;
            halfSize   *= 0.5f;

            var pos = (camLook.y < 0) ? Down * halfSize.y : Up * halfSize.y;

            DrawGrid(pos, Forward, Right, volume.DataZSize, volume.DataXSize, cellSize.z, cellSize.x);

            pos = (camLook.x > 0) ? Right * halfSize.x : Left * halfSize.x;
            DrawGrid(pos, Up, Forward, volume.DataYSize, volume.DataZSize, cellSize.y, cellSize.z);

            pos = (camLook.z > 0) ? Forward * halfSize.z : Backward * halfSize.z;
            DrawGrid(pos, Up, Right, volume.DataYSize, volume.DataXSize, cellSize.y, cellSize.x);
        }