示例#1
0
        protected virtual void OnSceneGUI()
        {
            Light t = target as Light;

            Color temp = Handles.color;

            if (t.enabled)
            {
                Handles.color = kGizmoLight;
            }
            else
            {
                Handles.color = kGizmoDisabledLight;
            }

            float thisRange = t.range;

            switch (t.type)
            {
            case LightType.Directional:
                Vector3 lightPos = t.transform.position;
                float   lightSize;
                using (new Handles.DrawingScope(Matrix4x4.identity))        //be sure no matrix affect the size computation
                {
                    lightSize = HandleUtility.GetHandleSize(lightPos);
                }
                float radius = lightSize * 0.2f;
                using (new Handles.DrawingScope(Matrix4x4.TRS(lightPos, t.transform.rotation, Vector3.one)))
                {
                    Handles.DrawWireDisc(Vector3.zero, Vector3.forward, radius);
                    foreach (Vector3 normalizedPos in directionalLightHandlesRayPositions)
                    {
                        Vector3 pos = normalizedPos * radius;
                        Handles.DrawLine(pos, pos + new Vector3(0, 0, lightSize));
                    }
                }
                break;

            case LightType.Point:
                thisRange = Handles.RadiusHandle(Quaternion.identity, t.transform.position, thisRange);
                if (GUI.changed)
                {
                    Undo.RecordObject(t, "Adjust Point Light");
                    t.range = thisRange;
                }
                break;

            case LightType.Spot:
                Transform tr            = t.transform;
                Vector3   circleCenter  = tr.position;
                Vector3   arrivalCenter = circleCenter + tr.forward * t.range;
                float     lightDisc     = t.range * Mathf.Tan(Mathf.Deg2Rad * t.spotAngle / 2.0f);
                Handles.DrawLine(circleCenter, arrivalCenter + tr.up * lightDisc);
                Handles.DrawLine(circleCenter, arrivalCenter - tr.up * lightDisc);
                Handles.DrawLine(circleCenter, arrivalCenter + tr.right * lightDisc);
                Handles.DrawLine(circleCenter, arrivalCenter - tr.right * lightDisc);
                Handles.DrawWireDisc(arrivalCenter, tr.forward, lightDisc);
                Handles.color = GetLightHandleColor(Handles.color);
                Vector2 angleAndRange = new Vector2(t.spotAngle, t.range);
                angleAndRange = Handles.ConeHandle(t.transform.rotation, t.transform.position, angleAndRange, 1.0f, 1.0f, true);
                if (GUI.changed)
                {
                    Undo.RecordObject(t, "Adjust Spot Light");
                    t.spotAngle = angleAndRange.x;
                    t.range     = Mathf.Max(angleAndRange.y, 0.01F);
                }
                break;

            case LightType.Rectangle:
                EditorGUI.BeginChangeCheck();
                Vector2 size = Handles.DoRectHandles(t.transform.rotation, t.transform.position, t.areaSize, false);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(t, "Adjust Rect Light");
                    t.areaSize = size;
                }
                // Draw the area light's normal only if it will not overlap with the current tool
                if (!((Tools.current == Tool.Move || Tools.current == Tool.Scale) && Tools.pivotRotation == PivotRotation.Local))
                {
                    Handles.DrawLine(t.transform.position, t.transform.position + t.transform.forward);
                }
                break;

            case LightType.Disc:
                m_BoundsHandle.radius         = t.areaSize.x;
                m_BoundsHandle.axes           = IMGUI.Controls.PrimitiveBoundsHandle.Axes.X | IMGUI.Controls.PrimitiveBoundsHandle.Axes.Y;
                m_BoundsHandle.center         = Vector3.zero;
                m_BoundsHandle.wireframeColor = Handles.color;
                m_BoundsHandle.handleColor    = GetLightHandleColor(Handles.color);
                Matrix4x4 mat = new Matrix4x4();
                mat.SetTRS(t.transform.position, t.transform.rotation, new Vector3(1, 1, 1));
                EditorGUI.BeginChangeCheck();
                using (new Handles.DrawingScope(Color.white, mat))
                    m_BoundsHandle.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(t, "Adjust Disc Light");
                    t.areaSize = new Vector2(m_BoundsHandle.radius, t.areaSize.y);
                }
                break;
            }
            Handles.color = temp;
        }
        internal static Quaternion DoRotationHandle(RotationHandleIds ids, Quaternion rotation, Vector3 position, RotationHandleParam param)
        {
            var evt        = Event.current;
            var camForward = Handles.inverseMatrix.MultiplyVector(Camera.current != null ? Camera.current.transform.forward : Vector3.forward);

            var size     = HandleUtility.GetHandleSize(position);
            var temp     = color;
            var isStatic = (!Tools.s_Hidden && EditorApplication.isPlaying && GameObjectUtility.ContainsStatic(Selection.gameObjects));

            var isHot = ids.Has(GUIUtility.hotControl);

            // Draw freerotation first to give it the lowest priority
            if (!isStatic &&
                param.ShouldShow(RotationHandleParam.Handle.XYZ) &&
                (isHot && ids.xyz == GUIUtility.hotControl || !isHot))
            {
                color    = centerColor;
                rotation = UnityEditorInternal.FreeRotate.Do(ids.xyz, rotation, position, size * param.xyzSize, param.displayXYZCircle);
            }

            var radiusOfAxesHandles = -1f;

            for (var i = 0; i < 3; ++i)
            {
                if (!param.ShouldShow(i))
                {
                    continue;
                }

                var axisColor = GetColorByAxis(i);
                color = isStatic ? Color.Lerp(axisColor, staticColor, staticBlend) : axisColor;
                color = ToActiveColorSpace(color);
                var axisDir = GetAxisVector(i);

                var radius = size * param.axisSize[i];
                radiusOfAxesHandles = Mathf.Max(radius, radiusOfAxesHandles);

                rotation = UnityEditorInternal.Disc.Do(ids[i], rotation, position, rotation * axisDir, radius, true, EditorSnapSettings.rotate, param.enableRayDrag, true, k_RotationPieColor);
            }

            if (radiusOfAxesHandles > 0 && evt.type == EventType.Repaint)
            {
                Handles.color = new Color(0, 0, 0, 0.2f);
                Handles.DrawWireDisc(position, camForward, radiusOfAxesHandles);
            }

            if (isHot && evt.type == EventType.Repaint)
            {
                color = ToActiveColorSpace(s_DisabledHandleColor);
                Handles.DrawWireDisc(position, camForward, size * param.axisSize[0]);
            }

            if (!isStatic &&
                param.ShouldShow(RotationHandleParam.Handle.CameraAxis) &&
                (isHot && ids.cameraAxis == GUIUtility.hotControl || !isHot))
            {
                color    = ToActiveColorSpace(centerColor);
                rotation = UnityEditorInternal.Disc.Do(ids.cameraAxis, rotation, position, camForward, size * param.cameraAxisSize, false, 0, param.enableRayDrag, true, k_RotationPieColor);
            }

            color = temp;
            return(rotation);
        }