예제 #1
0
        private void ControlRange(int index, Ranges.IItem config)
        {
            Vector3 offset = Vector3.zero;
            Vector3 size   = Vector3.zero;

            switch (config)
            {
            case Ranges.RectItem v:
                offset = (Vector2)v.offset;
                size   = (Vector2)v.size;
                break;

            case Ranges.CircleItem v:
                offset = (Vector2)v.offset;
                size   = new Vector3(v.radius, 0, 0);
                break;

            case Ranges.BoxItem v:
                offset = v.offset;
                size   = v.size;
                break;

            case Ranges.SphereItem v:
                offset = v.offset;
                size   = new Vector2(v.radius, 0);
                break;

            default:
                return;
            }

            //draw handle =========================================

            float handleSize = HandleUtility.GetHandleSize(offset);

            switch (Tools.current)
            {
            case Tool.View:
                break;

            case Tool.Move:
                offset = (Vector3)Handles.DoPositionHandle(offset, Quaternion.identity);
                break;

            case Tool.Scale:
                size = (Vector3)Handles.DoScaleHandle(size, offset, Quaternion.identity, handleSize);
                break;

            case Tool.Transform:
                UnityEngine.Vector3 _offset = offset;
                UnityEngine.Vector3 _size   = size;
                Handles.TransformHandle(ref _offset, UnityEngine.Quaternion.identity, ref _size);
                offset = (Vector3)_offset;
                size   = (Vector3)_size;
                break;

            case Tool.Rect:

                switch (config)
                {
                case Ranges.RectItem v:
                {
                    boxHandle.axes   = PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Y;
                    boxHandle.center = offset;
                    boxHandle.size   = size;
                    boxHandle.DrawHandle();
                    offset = (Vector3)boxHandle.center;
                    size   = (Vector3)boxHandle.size;
                    break;
                }

                case Ranges.CircleItem v:
                {
                    sphereHandle.axes   = PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Y;
                    sphereHandle.center = offset;
                    sphereHandle.radius = size.x;
                    sphereHandle.DrawHandle();
                    offset = (Vector3)sphereHandle.center;
                    size.x = (Single)sphereHandle.radius;
                    break;
                }

                case Ranges.BoxItem v:
                {
                    boxHandle.axes   = PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Y | PrimitiveBoundsHandle.Axes.Z;
                    boxHandle.center = offset;
                    boxHandle.size   = size;
                    boxHandle.DrawHandle();
                    offset = (Vector3)boxHandle.center;
                    size   = (Vector3)boxHandle.size;
                    break;
                }

                case Ranges.SphereItem v:
                {
                    sphereHandle.axes   = PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Y | PrimitiveBoundsHandle.Axes.Z;
                    sphereHandle.center = offset;
                    sphereHandle.radius = size.x;
                    sphereHandle.DrawHandle();
                    offset = (Vector3)sphereHandle.center;
                    size.x = (Single)sphereHandle.radius;
                    break;
                }
                }

                break;
            }

            //===============================================

            Func <Vector3> getOffset = () => new Vector3(FixFloat(offset.x), FixFloat(offset.y), FixFloat(offset.z));
            Func <Vector3> getSize   = () => new Vector3(FixFloat(size.x), FixFloat(size.y), FixFloat(size.z));
            Func <Single>  getRadius = () => FixFloat(size.magnitude);

            switch (config)
            {
            case Ranges.RectItem v:
                v.offset = getOffset();
                v.size   = getSize();
                break;

            case Ranges.CircleItem v:
                v.offset = getOffset();
                v.radius = getRadius();
                break;

            case Ranges.BoxItem v:
                v.offset = getOffset();
                v.size   = getSize();
                break;

            case Ranges.SphereItem v:
                v.offset = getOffset();
                v.radius = getRadius();
                break;
            }
        }
예제 #2
0
 public RangeConfig(RangeConfig config)
 {
     this.value = config.value.Clone();
 }