public virtual IComponent_InteractiveObject PickInteractiveObject(Component_GameMode gameMode, UIControl playScreen, Viewport viewport)
        {
            IComponent_InteractiveObject result = null;

            PickInteractiveObjectEvent?.Invoke(this, gameMode, playScreen, viewport, ref result);

            return(result);
        }
Esempio n. 2
0
        public virtual IComponent_InteractiveObject PickInteractiveObject(UIControl playScreen, Viewport viewport)
        {
            IComponent_InteractiveObject result = null;

            PickInteractiveObjectEvent?.Invoke(this, playScreen, viewport, ref result);

            if (!FreeCamera)
            {
                //pick for 3D
                if (Scene.Mode.Value == Component_Scene.ModeEnum._3D)
                {
                    if (UseBuiltInCamera.Value == BuiltInCameraEnum.FirstPerson || UseBuiltInCamera.Value == BuiltInCameraEnum.ThirdPerson)
                    {
                        Ray ray;
                        {
                            double rayDistance = UseBuiltInCamera.Value == BuiltInCameraEnum.FirstPerson ? 2.5 : 10;
                            //scaling
                            {
                                var obj = ObjectControlledByPlayer.Value as Component_ObjectInSpace;
                                if (obj != null)
                                {
                                    rayDistance *= obj.TransformV.Scale.MaxComponent();
                                }
                            }

                            ray           = viewport.CameraSettings.GetRayByScreenCoordinates(new Vector2(0.5, 0.5));
                            ray.Direction = ray.Direction.GetNormalize() * rayDistance;
                        }

                        var getObjectsItem = new Component_Scene.GetObjectsInSpaceItem(Component_Scene.GetObjectsInSpaceItem.CastTypeEnum.All, null, true, ray);
                        Scene.GetObjectsInSpace(getObjectsItem);

                        foreach (var item in getObjectsItem.Result)
                        {
                            var obj = item.Object.FindThisOrParent <IComponent_InteractiveObject>();
                            if (obj != null)
                            {
                                if (GetInteractiveObjectInfo(playScreen, obj).AllowInteract)
                                {
                                    result = obj;
                                }
                            }
                        }
                    }
                }

                //pick for 2D
                if (Scene.Mode.Value == Component_Scene.ModeEnum._2D)
                {
                    if (UseBuiltInCamera.Value == BuiltInCameraEnum.None || UseBuiltInCamera.Value == BuiltInCameraEnum.ThirdPerson)
                    {
                        var character = ObjectControlledByPlayer.Value as Component_Character2D;
                        if (character != null)
                        {
                            double maxDistance = 2.0;
                            //scaling
                            {
                                var obj = ObjectControlledByPlayer.Value as Component_ObjectInSpace;
                                if (obj != null)
                                {
                                    maxDistance *= obj.TransformV.Scale.MaxComponent();
                                }
                            }

                            var bounds = new Bounds(character.TransformV.Position);
                            bounds.Expand(new Vector3(maxDistance, maxDistance, 10000));

                            var getObjectsItem = new Component_Scene.GetObjectsInSpaceItem(Component_Scene.GetObjectsInSpaceItem.CastTypeEnum.All, null, true, bounds);
                            Scene.GetObjectsInSpace(getObjectsItem);

                            foreach (var item in getObjectsItem.Result)
                            {
                                var obj = item.Object.FindThisOrParent <IComponent_InteractiveObject>();
                                if (obj != null)
                                {
                                    var objectInSpace = obj as Component_ObjectInSpace;
                                    if (objectInSpace != null)
                                    {
                                        var distance = (objectInSpace.TransformV.Position - character.TransformV.Position).Length();
                                        if (distance <= maxDistance)
                                        {
                                            if (GetInteractiveObjectInfo(playScreen, obj).AllowInteract)
                                            {
                                                result = obj;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //Component_CameraManagement
            var m = GetCurrentCameraManagement();

            if (m != null)
            {
                result = m.PickInteractiveObject(this, playScreen, viewport);
            }

            return(result);
        }