コード例 #1
0
        protected virtual void RenderObjectInteraction(UIControl playScreen, CanvasRenderer renderer)
        {
            if (!FreeCamera && ObjectInteractionContext != null)
            {
                bool render = false;
                if (Scene.Mode.Value == Component_Scene.ModeEnum._3D)
                {
                    if (UseBuiltInCamera.Value == BuiltInCameraEnum.FirstPerson || UseBuiltInCamera.Value == BuiltInCameraEnum.ThirdPerson)
                    {
                        render = true;
                    }
                }
                if (Scene.Mode.Value == Component_Scene.ModeEnum._2D)
                {
                    if (UseBuiltInCamera.Value == BuiltInCameraEnum.None || UseBuiltInCamera.Value == BuiltInCameraEnum.ThirdPerson)
                    {
                        render = true;
                    }
                }
                var m = GetCurrentCameraManagement();
                if (m != null)
                {
                    render = m.IsNeedRenderObjectInteraction(this, playScreen, renderer);
                }

                if (render)
                {
                    var obj = ObjectInteractionContext.Obj as Component_ObjectInSpace;
                    if (obj != null)
                    {
                        var info = GetInteractiveObjectInfo(playScreen, ObjectInteractionContext.Obj);

                        if (info.AllowInteract && info.DisplaySelectionRectangle)
                        {
                            //calculate screen rectangle
                            var rectangle = Rectangle.Cleared;
                            foreach (var point in obj.SpaceBounds.CalculatedBoundingBox.ToPoints())
                            {
                                if (renderer.ViewportForScreenCanvasRenderer.CameraSettings.ProjectToScreenCoordinates(point, out var screenPosition))
                                {
                                    rectangle.Add(screenPosition);
                                }
                            }

                            if (!rectangle.IsCleared())
                            {
                                //expand rectangle
                                {
                                    var multiplier = 1.3;
                                    var center     = rectangle.GetCenter();
                                    var size       = rectangle.GetSize();
                                    rectangle = new Rectangle(center);
                                    rectangle.Expand(size / 2 * multiplier);
                                }

                                var color = new ColorValue(1, 1, 0, 0.5);

                                //add rectangle
                                var thickness = new Vector2(0.004, 0.004 * renderer.AspectRatio);
                                var inner     = rectangle;
                                inner.Expand(-thickness);
                                renderer.AddThickRectangle(rectangle, inner, color);

                                //add text
                                renderer.AddTextLines(info.SelectionTextInfo, new Vector2(rectangle.GetCenter().X, rectangle.Bottom), EHorizontalAlignment.Center, EVerticalAlignment.Top, 0, color);
                            }
                        }
                    }
                }
            }
        }