예제 #1
0
        public override void Render(Camera camera)
        {
            var sgLookAndFeel = _sceneGizmo.LookAndFeel;
            RTSceneGizmoCamera sceneGizmoCamera = _sceneGizmo.SceneGizmoCamera;

            _cap.Render(camera);

            if (_axisDesc.IsPositive)
            {
                GizmoLabelMaterial labelMaterial = GizmoLabelMaterial.Get;
                labelMaterial.SetZWriteEnabled(false);
                labelMaterial.SetZTestLessEqual();
                labelMaterial.SetColor(ColorEx.KeepAllButAlpha(sgLookAndFeel.AxesLabelTint, _color.Value.a));
                labelMaterial.SetTexture(_labelTexture);
                labelMaterial.SetPass(0);

                Vector3 gizmoAxis  = _sceneGizmo.Gizmo.Transform.GetAxis3D(_axisDesc);
                Vector3 labelScale = Vector3Ex.FromValue(sgLookAndFeel.GetAxesLabelWorldSize(sceneGizmoCamera.Camera, _cap.Position));
                Vector3 labelPos   = _cap.Position + gizmoAxis * (labelScale.x * 0.5f);

                Vector2 labelScreenPos   = sceneGizmoCamera.Camera.WorldToScreenPoint(labelPos);
                Vector2 midAxisScreenPos = sceneGizmoCamera.Camera.WorldToScreenPoint(_sceneGizmo.SceneGizmoCamera.LookAtPoint);
                Vector2 labelScreenDir   = (labelScreenPos - midAxisScreenPos).normalized;

                float absDotCamLook = Mathf.Abs(Vector3Ex.AbsDot(sceneGizmoCamera.Look, gizmoAxis));
                labelScreenPos = labelScreenPos + Vector2.Scale(labelScreenDir, Vector2Ex.FromValue(SceneGizmoLookAndFeel.AxisLabelScreenSize)) * absDotCamLook;
                labelPos       = sceneGizmoCamera.Camera.ScreenToWorldPoint(new Vector3(labelScreenPos.x, labelScreenPos.y, (labelPos - sceneGizmoCamera.WorldPosition).magnitude));

                Quaternion labelRotation     = Quaternion.LookRotation(sceneGizmoCamera.Look, sceneGizmoCamera.Up);
                Matrix4x4  labelTransformMtx = Matrix4x4.TRS(labelPos, labelRotation, labelScale);

                Graphics.DrawMeshNow(MeshPool.Get.UnitQuadXY, labelTransformMtx);
            }
        }
        public void SetAxisColor(int axisIndex, Color color)
        {
            GetSglSliderLookAndFeel(axisIndex, AxisSign.Positive).Color = color;
            GetSglSliderLookAndFeel(axisIndex, AxisSign.Positive).CapLookAndFeel.Color = color;
            GetSglSliderLookAndFeel(axisIndex, AxisSign.Negative).Color = color;
            GetSglSliderLookAndFeel(axisIndex, AxisSign.Negative).CapLookAndFeel.Color = color;

            GizmoPlaneSlider3DLookAndFeel dblLookAndFeel = null;

            if (axisIndex == 0)
            {
                dblLookAndFeel = GetDblSliderLookAndFeel(PlaneId.YZ);
                _scaleGuideLookAndFeel.XAxisColor = color;
            }
            else
            if (axisIndex == 1)
            {
                dblLookAndFeel = GetDblSliderLookAndFeel(PlaneId.ZX);
                _scaleGuideLookAndFeel.YAxisColor = color;
            }
            else
            if (axisIndex == 2)
            {
                dblLookAndFeel = GetDblSliderLookAndFeel(PlaneId.XY);
                _scaleGuideLookAndFeel.ZAxisColor = color;
            }

            dblLookAndFeel.Color       = ColorEx.KeepAllButAlpha(color, dblLookAndFeel.Color.a);
            dblLookAndFeel.BorderColor = color;
        }
예제 #3
0
        public UniversalGizmoLookAndFeel2D()
        {
            for (int axisIndex = 0; axisIndex < _mvSglSliderLookAndFeel.Length; ++axisIndex)
            {
                _mvSglSliderLookAndFeel[axisIndex] = new GizmoLineSlider2DLookAndFeel();
            }

            SetMvAxisColor(0, RTSystemValues.XAxisColor);
            SetMvAxisColor(1, RTSystemValues.YAxisColor);
            SetMvAxisBorderColor(0, RTSystemValues.XAxisColor);
            SetMvAxisBorderColor(1, RTSystemValues.YAxisColor);
            SetMvSliderHoveredFillColor(RTSystemValues.HoveredAxisColor);
            SetMvSliderHoveredBorderColor(RTSystemValues.HoveredAxisColor);
            SetMvSliderCapType(GizmoCap2DType.Arrow);
            SetMvSliderCapFillMode(GizmoFillMode2D.Filled);

            SetMvSliderFillMode(GizmoFillMode2D.Filled);
            SetMvSliderVisible(0, AxisSign.Positive, true);
            SetMvSliderVisible(1, AxisSign.Positive, true);
            SetMvSliderCapVisible(0, AxisSign.Positive, true);
            SetMvSliderCapVisible(1, AxisSign.Positive, true);

            SetMvDblSliderFillMode(GizmoFillMode2D.Border);
            SetMvDblSliderColor(ColorEx.KeepAllButAlpha(Color.white, RTSystemValues.AxisAlpha));
            SetMvDblSliderBorderColor(Color.white);
            SetMvDblSliderHoveredColor(ColorEx.KeepAllButAlpha(RTSystemValues.HoveredAxisColor, RTSystemValues.AxisAlpha));
            SetMvDblSliderHoveredBorderColor(RTSystemValues.HoveredAxisColor);
        }
 public void SetDblSliderFillAlpha(float alpha)
 {
     alpha = Mathf.Clamp(alpha, 0.0f, 1.0f);
     foreach (GizmoPlaneSlider3DLookAndFeel lookAndFeel in _dblSlidersLookAndFeel)
     {
         lookAndFeel.Color        = ColorEx.KeepAllButAlpha(lookAndFeel.Color, alpha);
         lookAndFeel.HoveredColor = ColorEx.KeepAllButAlpha(lookAndFeel.HoveredColor, alpha);
     }
 }
예제 #5
0
        public void Render_SystemCall()
        {
            var iconMaterial = MaterialPool.Get.TintedTexture;
            var iconMesh     = MeshPool.Get.UnitQuadXY;

            Camera     renderCam    = Camera.current;
            Transform  camTransform = renderCam.transform;
            Vector3    camPos       = camTransform.position;
            Quaternion camRotation  = camTransform.rotation;

            if (LookAndFeel.DrawParticleSystemIcons && LookAndFeel.ParticleSystemIcon != null)
            {
                iconMaterial.SetTexture("_MainTex", LookAndFeel.ParticleSystemIcon);
                iconMaterial.SetColor(ColorEx.KeepAllButAlpha(Color.white, LookAndFeel.ParticleSystemIconAlpha));
                iconMaterial.SetZTestAlways();
                iconMaterial.SetPass(0);

                Vector3 scale = new Vector3(Settings.NonMeshObjectSize, Settings.NonMeshObjectSize, 1.0f);
                foreach (var particleSystem in _particleSystems)
                {
                    if (particleSystem != null && particleSystem.gameObject.activeInHierarchy)
                    {
                        Transform  objectTransform = particleSystem.gameObject.transform;
                        Vector3    position        = objectTransform.position;
                        Quaternion rotation        = camTransform.rotation;

                        Matrix4x4 transformMatrix = Matrix4x4.TRS(position, rotation, scale);
                        Graphics.DrawMeshNow(iconMesh, transformMatrix);
                    }
                }
            }

            if (LookAndFeel.DrawLightIcons && LookAndFeel.LightIcon != null)
            {
                iconMaterial.SetTexture("_MainTex", LookAndFeel.LightIcon);
                iconMaterial.SetZTestAlways();

                Vector3 scale = new Vector3(Settings.NonMeshObjectSize, Settings.NonMeshObjectSize, 1.0f);
                foreach (var light in _lights)
                {
                    if (light != null && light.enabled && light.gameObject.activeInHierarchy)
                    {
                        Transform  objectTransform = light.gameObject.transform;
                        Vector3    position        = objectTransform.position;
                        Quaternion rotation        = camTransform.rotation;

                        Matrix4x4 transformMatrix = Matrix4x4.TRS(position, rotation, scale);

                        iconMaterial.SetColor(ColorEx.KeepAllButAlpha(light.color, LookAndFeel.LightIconAlpha));
                        iconMaterial.SetPass(0);
                        Graphics.DrawMeshNow(iconMesh, transformMatrix);
                    }
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Can be used to draw the tree in the scene for debugging purposes.
        /// </summary>
        public void DebugDraw()
        {
            // Setup the rendering material
            Material material = MaterialPool.Get.GizmoSolidHandle;

            material.SetInt("_IsLit", 0);
            material.SetColor(ColorEx.KeepAllButAlpha(Color.green, 0.3f));
            material.SetPass(0);

            // Draw the entire tree
            _root.DebugDraw();
        }
        public void OnGUI()
        {
            var    sgLookAndFeel = _sceneGizmo.LookAndFeel;
            Camera gizmoCamera   = _sceneGizmo.SceneGizmoCamera.Camera;

            if (sgLookAndFeel.IsCamPrjSwitchLabelVisible)
            {
                if (_sceneGizmo.SceneGizmoCamera.SceneCamera != RTFocusCamera.Get.TargetCamera ||
                    !RTFocusCamera.Get.IsDoingProjectionSwitch)
                {
                    Texture2D labelTexture = gizmoCamera.orthographic ? sgLookAndFeel.CamOrthoModeLabelTexture : sgLookAndFeel.CamPerspModeLabelTexture;
                    GUIEx.PushColor(sgLookAndFeel.CamPrjSwitchLabelTint);

                    Rect drawRect = RectEx.FromTexture2D(labelTexture).PlaceBelowCenterHrz(gizmoCamera.pixelRect).InvertScreenY();
                    drawRect.center = new Vector2(drawRect.center.x, Screen.height - 1 - _labelQuad.Center.y);

                    GUI.DrawTexture(drawRect, labelTexture);
                    GUIEx.PopColor();
                }
                else
                {
                    Texture2D destLabelTexture   = sgLookAndFeel.CamOrthoModeLabelTexture;
                    Texture2D sourceLabelTexture = sgLookAndFeel.CamPerspModeLabelTexture;
                    if (RTFocusCamera.Get.PrjSwitchTransitionType == CameraPrjSwitchTransition.Type.ToPerspective)
                    {
                        destLabelTexture   = sgLookAndFeel.CamPerspModeLabelTexture;
                        sourceLabelTexture = sgLookAndFeel.CamOrthoModeLabelTexture;
                    }

                    AnimationCurve srcAnimCurve  = AnimationCurve.EaseInOut(0.0f, sgLookAndFeel.CamPrjSwitchLabelTint.a, 1.0f, 0.0f);
                    AnimationCurve destAnimCurve = AnimationCurve.EaseInOut(0.0f, 0.0f, 1.0f, sgLookAndFeel.CamPrjSwitchLabelTint.a);

                    float destAlpha = destAnimCurve.Evaluate(RTFocusCamera.Get.PrjSwitchProgress);
                    float srcAlpha  = srcAnimCurve.Evaluate(RTFocusCamera.Get.PrjSwitchProgress);

                    GUIEx.PushColor(ColorEx.KeepAllButAlpha(sgLookAndFeel.CamPrjSwitchLabelTint, srcAlpha));
                    Rect drawRect = RectEx.FromTexture2D(sourceLabelTexture).PlaceBelowCenterHrz(gizmoCamera.pixelRect).InvertScreenY();
                    drawRect.center = new Vector2(drawRect.center.x, Screen.height - 1 - _labelQuad.Center.y);
                    GUI.DrawTexture(drawRect, sourceLabelTexture);
                    GUIEx.PopColor();

                    GUIEx.PushColor(ColorEx.KeepAllButAlpha(sgLookAndFeel.CamPrjSwitchLabelTint, destAlpha));
                    drawRect        = RectEx.FromTexture2D(destLabelTexture).PlaceBelowCenterHrz(gizmoCamera.pixelRect).InvertScreenY();
                    drawRect.center = new Vector2(drawRect.center.x, Screen.height - 1 - _labelQuad.Center.y);
                    GUI.DrawTexture(drawRect, destLabelTexture);
                    GUIEx.PopColor();
                }
            }
        }
        public void SetHoveredColor(Color hoveredColor)
        {
            foreach (GizmoLineSlider3DLookAndFeel lookAndFeel in _sglSlidersLookAndFeel)
            {
                lookAndFeel.HoveredColor = hoveredColor;
                lookAndFeel.CapLookAndFeel.HoveredColor = hoveredColor;
            }

            foreach (GizmoPlaneSlider3DLookAndFeel lookAndFeel in _dblSlidersLookAndFeel)
            {
                lookAndFeel.HoveredBorderColor = hoveredColor;
                lookAndFeel.HoveredColor       = ColorEx.KeepAllButAlpha(hoveredColor, lookAndFeel.Color.a);
            }

            _midCapLookAndFeel.HoveredColor = hoveredColor;
        }
예제 #9
0
        private void UpdateColor()
        {
            var   sgLookAndFeel    = _sceneGizmo.LookAndFeel;
            Color lookAndFeelColor = sgLookAndFeel.GetAxisCapColor(_axisDesc.Index, _axisDesc.Sign);

            if (_cap.IsHovered)
            {
                lookAndFeelColor = sgLookAndFeel.HoveredColor;
            }
            ColorTransition.State ctState = _colorTransition.TransitionState;

            Vector3 axis      = _sceneGizmo.Gizmo.Transform.GetAxis3D(_axisDesc);
            float   alignment = Vector3Ex.AbsDot(axis, _sceneGizmo.SceneGizmoCamera.Look);

            if (alignment > SceneGizmoLookAndFeel.AxisCamAlignFadeOutThreshold)
            {
                if (ctState != ColorTransition.State.CompleteFadeOut &&
                    ctState != ColorTransition.State.FadingOut)
                {
                    _colorTransition.DurationInSeconds = SceneGizmoLookAndFeel.AxisCamAlignFadeOutDuration;
                    _colorTransition.FadeOutColor      = ColorEx.KeepAllButAlpha(lookAndFeelColor, SceneGizmoLookAndFeel.AxisCamAlignFadeOutAlpha);
                    _colorTransition.BeginFadeOut(true);
                }
            }
            else
            {
                if (ctState != ColorTransition.State.FadingIn &&
                    ctState != ColorTransition.State.CompleteFadeIn &&
                    ctState != ColorTransition.State.Ready)
                {
                    _colorTransition.DurationInSeconds = SceneGizmoLookAndFeel.AxisCamAlignFadeOutDuration;
                    _colorTransition.FadeInColor       = lookAndFeelColor;
                    _colorTransition.BeginFadeIn(true);
                }
                else
                {
                    _color.Value = lookAndFeelColor;
                }
            }

            _colorTransition.Update(Time.deltaTime);
            _cap.OverrideColor.IsActive = true;
            _cap.OverrideColor.Color    = _color.Value;
        }
예제 #10
0
        public BoxGizmoLookAndFeel3D()
        {
            for (int tickIndex = 0; tickIndex < _tickLookAndFeel.Length; ++tickIndex)
            {
                _tickLookAndFeel[tickIndex] = new GizmoCap2DLookAndFeel();
            }

            SetAxisTickColor(0, RTSystemValues.XAxisColor);
            SetAxisTickColor(1, RTSystemValues.YAxisColor);
            SetAxisTickColor(2, RTSystemValues.ZAxisColor);
            SetTickHoveredColor(RTSystemValues.HoveredAxisColor);
            SetTickBorderColor(ColorEx.KeepAllButAlpha(Color.black, 0.0f));
            SetTickHoveredBorderColor(ColorEx.KeepAllButAlpha(Color.black, 0.0f));

            SetTickQuadWidth(10.0f);
            SetTickQuadHeight(10.0f);
            SetTickCircleRadius(6.0f);
            SetTickType(GizmoCap2DType.Quad);
        }
예제 #11
0
        public void Render_SystemCall()
        {
            var iconMaterial = MaterialPool.Get.TintedTexture;
            var iconMesh     = MeshPool.Get.UnitQuadXY;

            Camera renderCam = Camera.current;

            if (IsIconRenderIgnoreCamera(renderCam))
            {
                return;
            }

            Transform  renderCamTransform = renderCam.transform;
            Vector3    renderCamPos       = renderCamTransform.position;
            Quaternion renderCamRotation  = renderCamTransform.rotation;

            if (LookAndFeel.DrawCameraIcons && LookAndFeel.CameraIcon != null)
            {
                iconMaterial.SetTexture("_MainTex", LookAndFeel.CameraIcon);
                iconMaterial.SetColor(ColorEx.KeepAllButAlpha(Color.white, LookAndFeel.CameraIconAlpha));
                iconMaterial.SetZTestAlways();
                iconMaterial.SetPass(0);

                Camera targetFocusCamera = RTFocusCamera.Get.TargetCamera;

                Vector3 scale = new Vector3(Settings.NonMeshObjectSize, Settings.NonMeshObjectSize, 1.0f);
                for (int cameraIndex = 0; cameraIndex < _cameras.Count; ++cameraIndex)
                {
                    Camera camera = _cameras[cameraIndex];
                    if (camera != null && camera.gameObject.activeInHierarchy && !ReferenceEquals(targetFocusCamera, camera))
                    {
                        if (CanRenderCameraIcon != null)
                        {
                            CanRenderCameraIcon(camera, _yesNoAnswer);
                            if (_yesNoAnswer.HasNo)
                            {
                                continue;
                            }
                        }

                        Transform  objectTransform = camera.gameObject.transform;
                        Vector3    position        = objectTransform.position;
                        Quaternion rotation        = renderCamTransform.rotation;

                        Matrix4x4 transformMatrix = Matrix4x4.TRS(position, rotation, scale);
                        Graphics.DrawMeshNow(iconMesh, transformMatrix);
                    }
                }
            }

            if (LookAndFeel.DrawParticleSystemIcons && LookAndFeel.ParticleSystemIcon != null)
            {
                iconMaterial.SetTexture("_MainTex", LookAndFeel.ParticleSystemIcon);
                iconMaterial.SetColor(ColorEx.KeepAllButAlpha(Color.white, LookAndFeel.ParticleSystemIconAlpha));
                iconMaterial.SetZTestAlways();
                iconMaterial.SetPass(0);

                Vector3 scale = new Vector3(Settings.NonMeshObjectSize, Settings.NonMeshObjectSize, 1.0f);
                for (int psIndex = 0; psIndex < _particleSystems.Count; ++psIndex)
                {
                    var particleSystem = _particleSystems[psIndex];
                    if (particleSystem != null && particleSystem.gameObject.activeInHierarchy)
                    {
                        Transform  objectTransform = particleSystem.gameObject.transform;
                        Vector3    position        = objectTransform.position;
                        Quaternion rotation        = renderCamTransform.rotation;

                        Matrix4x4 transformMatrix = Matrix4x4.TRS(position, rotation, scale);
                        Graphics.DrawMeshNow(iconMesh, transformMatrix);
                    }
                }
            }

            if (LookAndFeel.DrawLightIcons && LookAndFeel.LightIcon != null)
            {
                iconMaterial.SetTexture("_MainTex", LookAndFeel.LightIcon);
                iconMaterial.SetZTestAlways();

                Vector3 scale = new Vector3(Settings.NonMeshObjectSize, Settings.NonMeshObjectSize, 1.0f);
                for (int lightIndex = 0; lightIndex < _lights.Count; ++lightIndex)
                {
                    Light light = _lights[lightIndex];
                    if (light != null && light.enabled && light.gameObject.activeInHierarchy)
                    {
                        Transform  objectTransform = light.gameObject.transform;
                        Vector3    position        = objectTransform.position;
                        Quaternion rotation        = renderCamTransform.rotation;

                        Matrix4x4 transformMatrix = Matrix4x4.TRS(position, rotation, scale);

                        iconMaterial.SetColor(ColorEx.KeepAllButAlpha(light.color, LookAndFeel.LightIconAlpha));
                        iconMaterial.SetPass(0);
                        Graphics.DrawMeshNow(iconMesh, transformMatrix);
                    }
                }
            }
        }