public override void OnExecute()
        {
            base.OnExecute();
            //GameEvents.UI_Guid_Event.OnFindSceneResult += OnGameOver;
            Vector2   center  = Vector2.right * Screen.width / 2f + Vector2.up * Screen.height / 2f;
            GUIFrame  frame   = GuidNewModule.Instance.GetFrameByResName(UIDefine.UI_GUID);
            Transform artTran = frame.FrameRootTransform.Find("guid/art");

            startLocalPos = CameraUtility.ScreenPointInLocalRectTransform(center, artTran.gameObject);
            List <SceneItemEntity> sceneItem = GameEvents.MainGameEvents.GetSceneItemEntityList.SafeInvoke(1);

            if (sceneItem.Count > 0)
            {
                entityID = sceneItem[0].EntityId;
                //Debug.Log(" item name  ===  " + sceneItem[0].EntityData.itemName + "  " + sceneItem[0].EntityPosition);
                //endLocalPos = CameraUtility.WorldPointInCanvasRectTransform(sceneItem[0].EntityPosition, artTran.gameObject);
                //endLocalPos = GuidNewTools.WordToLocalPos(artTran,sceneItem[0].EntityPosition);
                Vector2 screenPos = Camera.main.WorldToScreenPoint(sceneItem[0].EntityPosition);
                endLocalPos = CameraUtility.ScreenPointInLocalRectTransform(screenPos, artTran.gameObject);
                GameEvents.UI_Guid_Event.OnLoadEffect.SafeInvoke(20010, "UI_xinshouyindao_huadong02.prefab", startLocalPos, Vector2.one, 0f);
                GameEvents.UI_Guid_Event.OnLoadEffect.SafeInvoke(20011, "UI_xinshouyindao_huadong02_quan.prefab", endLocalPos, Vector2.one, 0f);

                m_effect = GameEvents.UI_Guid_Event.OnGetMaskEffect(20010);
                if (m_effect != null)
                {
                    GuidNewModule.Instance.PushFunction(this);
                }
                GameEvents.MainGameEvents.OnPickedSceneObject += OnPickedSceneItem;
            }
        }
Exemple #2
0
    float CalculateY()
    {
        float radius = MaxDistanceGoalObjects() + magicOffset;
        float y      = CameraUtility.CalculateOptimalDistance(GetComponent <Camera>(), radius * magicMultiplier);

        return(y);
    }
Exemple #3
0
        public override void CalcOutput(PlayerEntity player, ICameraMotorInput input, ICameraMotorState state,
                                        SubCameraMotorState subState,
                                        DummyCameraMotorOutput output,
                                        ICameraNewMotor last, int clientTime)
        {
            output.Far          = _config.Far;
            output.Near         = _config.Near;
            output.ForbidDetect = _config.ForbidDetect;

            _transitionTime = CameraUtility.GetPostureTransitionTime(_motorType, subState);
            var elapsedPercent = ElapsedPercent(clientTime, subState.ModeTime, _transitionTime);
            var realPercent    = EaseInOutQuad(0, 1, elapsedPercent);

            if (state.IsFristPersion())
            {
                //一人称和瞄准相机没有偏移
                output.Fov = Mathf.Lerp(last.FinalFov, FinalFov, realPercent);
            }
            else
            {
                if (last is AirplanePoseMotor || last is DrivePoseMotor)
                {
                    realPercent = 1;
                }

                output.ArchorOffset     = Vector3.Lerp(last.FinalArchorOffset, FinalArchorOffset, realPercent);
                output.ArchorPostOffset =
                    Vector3.Lerp(last.FinalArchorPostOffset, FinalArchorPostOffset, realPercent);
                output.Offset           = Vector3.Lerp(last.FinalOffset, FinalOffset, realPercent);
                output.ArchorEulerAngle = Vector3.Lerp(last.FinalEulerAngle, FinalEulerAngle, realPercent);
                output.Fov = Mathf.Lerp(last.FinalFov, FinalFov, realPercent);
            }
        }
    }    //OnTriggerEnter2Df

    void Update()
    {
        if (!CameraUtility.IsRendererInFrustum(grenadeCollider, cam))
        {
            Destroy(gameObject);
        }
    }
Exemple #5
0
        public static void CalibCamera(Camera camera)
        {
            Matrix4x4 projectionMatrix = new Matrix4x4();
            float     near             = camera.nearClipPlane;
            float     far = camera.farClipPlane;

            var width   = 0f;
            var height  = 0f;
            var focalX  = 0f;
            var focalY  = 0f;
            var centerX = 0f;
            var centerY = 0f;

            var row0 = new Vector4(2 * focalX / width, 0, 1 - 2 * centerX / width, 0);
            var row1 = new Vector4(0, 2 * focalY / height, 2 * centerY / height - 1, 0);
            var row2 = new Vector4(0, 0, (far + near) / (near - far), 2 * far * near / (near - far));
            var row3 = new Vector4(0, 0, -1, 0);

            projectionMatrix.SetRow(0, row0);
            projectionMatrix.SetRow(1, row1);
            projectionMatrix.SetRow(2, row2);
            projectionMatrix.SetRow(3, row3);

            camera.fieldOfView      = CameraUtility.Focal2Fov(focalX, width);
            camera.projectionMatrix = projectionMatrix;
        }
Exemple #6
0
 void Update()
 {
     Physics2D.IgnoreLayerCollision(11, 16);
     if (!CameraUtility.IsRendererInFrustum(bulletCollider, cam))
     {
         Destroy(gameObject);
     }
 }
 /// <summary>
 /// Opens the popup with the specified DamageData.
 /// </summary>
 /// <param name="damageData">Specifies the damage location/amount.</param>
 public void Open(DamageData damageData)
 {
     if (m_Camera == null && damageData.DamageOriginator != null)
     {
         m_Camera = CameraUtility.FindCamera(damageData.DamageOriginator.Owner);
     }
     Open(damageData.Position, damageData.Amount.ToString(m_Format));
 }
Exemple #8
0
    // Manually render the camera attached to this portal
    // Called after PrePortalRender, and before PostPortalRender
    public void Render()
    {
        // Skip rendering the view from this portal if player is not looking at the linked portal
        if (!CameraUtility.VisibleFromCamera(linkedPortal.screen, playerCam))
        {
            return;
        }

        CreateViewTexture();

        var localToWorldMatrix = playerCam.transform.localToWorldMatrix;
        var renderPositions    = new Vector3[recursionLimit];
        var renderRotations    = new Quaternion[recursionLimit];

        int startIndex = 0;

        portalCam.projectionMatrix = playerCam.projectionMatrix;
        for (int i = 0; i < recursionLimit; i++)
        {
            if (i > 0)
            {
                // No need for recursive rendering if linked portal is not visible through this portal
                if (!CameraUtility.BoundsOverlap(screenMeshFilter, linkedPortal.screenMeshFilter, portalCam))
                {
                    break;
                }
            }
            localToWorldMatrix = transform.localToWorldMatrix * linkedPortal.transform.worldToLocalMatrix * localToWorldMatrix;
            int renderOrderIndex = recursionLimit - i - 1;
            renderPositions[renderOrderIndex] = localToWorldMatrix.GetColumn(3);
            renderRotations[renderOrderIndex] = localToWorldMatrix.rotation;

            portalCam.transform.SetPositionAndRotation(renderPositions[renderOrderIndex], renderRotations[renderOrderIndex]);
            startIndex = renderOrderIndex;
        }

        // Hide screen so that camera can see through portal
        screen.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly;
        linkedPortal.screen.material.SetInt("active", 0);

        for (int i = startIndex; i < recursionLimit; i++)
        {
            portalCam.transform.SetPositionAndRotation(renderPositions[i], renderRotations[i]);
            SetNearClipPlane();
            HandleClipping();
            portalCam.Render();

            if (i == startIndex)
            {
                linkedPortal.screen.material.SetInt("active", 1);
            }
        }

        // Unhide objects hidden at start of render
        screen.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
    }
        private void OnCalibrate(Sizei resolution, Matrix3x3f intrinsic, Vector5f distorsion)
        {
            var fY               = intrinsic.coeff(1, 1);
            var fovY             = CameraUtility.Focal2Fov(fY, resolution.height);
            var fX               = intrinsic.coeff(0, 0);
            var aspect           = (fY / resolution.height) / (fX / resolution.width);
            var projectionMatrix = Matrix4x4.Perspective(fovY, aspect, camera.nearClipPlane, camera.farClipPlane);

            CameraUtility.ApplyProjectionMatrix(camera, projectionMatrix);
        }
Exemple #10
0
 public void SetHintSceneEntity(SceneItemEntity hintEntity, bool needHint)
 {
     this.m_needHint            = needHint;
     this.m_hintSceneItemEntity = hintEntity;
     EntityOnCanvasPosition     = CameraUtility.WorldPointInCanvasRectTransform(hintEntity.CenterPosition, LogicHandler.Canvas.gameObject);
     this.m_hintEffect.Position = EntityOnCanvasPosition;
     if (needHint)
     {
         this.m_hintSceneItemEntity.EntityObject.ChangeEntityMatToHint();
     }
 }
        public override void OnExecute()
        {
            base.OnExecute();
            GameEvents.MainGameEvents.OnGameOver += OnGameOver;
            TimeModule.Instance.SetTimeout(() => {
                List <SceneItemEntity> sceneItem = GameEvents.MainGameEvents.GetSceneItemEntityList.SafeInvoke(1);
                if (sceneItem != null && sceneItem.Count > 0)
                {
                    Vector3 entityPos = sceneItem[0].EntityPosition;
                    GUIFrame frame    = GuidNewModule.Instance.GetFrameByResName(UIDefine.UI_GUID);
                    entityPos         = CameraUtility.WorldPointInCanvasRectTransform(entityPos, frame.LogicHandler.Canvas.gameObject);
                    Vector2[] corn    = new Vector2[4];
                    float w           = 10f;
                    float h           = 10f;
                    if (sceneItem[0].EntityData.itemID == 11197)
                    {
                        w            = 20f;
                        h            = 50f;
                        entityPos.y += 40f;
                    }
                    corn[0] = new Vector2(entityPos.x - w, entityPos.y - h);
                    corn[1] = new Vector2(entityPos.x - w, entityPos.y + h);
                    corn[2] = new Vector2(entityPos.x + w, entityPos.y + h);
                    corn[3] = new Vector2(entityPos.x + w, entityPos.y - h);
                    if (!isComplete)
                    {
                        GameEvents.UI_Guid_Event.OnShowMask.SafeInvoke(new List <Vector2[]> {
                            corn
                        }, new List <MaskEmptyType> {
                            MaskEmptyType.Rect
                        }, MaskAnimType.ToInner, "aa", false);
                        GUIFrame guidFrame = GuidNewModule.Instance.GetFrameByResName(UIDefine.UI_GUID);
                        if (guidFrame != null)
                        {
                            Vector2[] emptyPos = GuidNewTools.GetEmptyPos(corn, guidFrame.FrameRootTransform);
                            emptyPos[0]       += Vector2.left * 20f;
                            emptyPos[0]       += Vector2.up * 30f;
                            //Vector2 center = new Vector2((emptyPos[2].x + cornPos[0].x) / 2f, (cornPos[1].y + cornPos[0].y) / 2f);
                            GameEvents.UI_Guid_Event.OnLoadEffect.SafeInvoke(20000, "UI_xinshouyindao_shou.prefab", emptyPos[0], Vector2.one, 0);
                        }

                        GameEvents.UI_Guid_Event.OnMaskClick += OnMaskClick;
                    }
                    else
                    {
                        OnDestory();
                    }

                    return;
                }
                OnDestory();
            }, 1f);
            //GameEvents.MainGameEvents.RequestHintSceneItemList.SafeInvoke(5);
        }
Exemple #12
0
    public bool Judge(Camera _viewCamera, int limit)
    {
        Vector3 viewCamerPos = _viewCamera.cameraToWorldMatrix.GetColumn(3);
        float   distance     = Vector3.Distance(viewCamerPos, transform.position);

        if (!CameraUtility.VisibleFromCamera(screen, _viewCamera) || limit < 0 || distance > hideDistance || linkedPortal.enabled == false || this.enabled == false || !linkedPortal.gameObject.activeInHierarchy || !gameObject.activeInHierarchy)
        {
            return(false);
        }
        return(true);
    }
Exemple #13
0
    public void Render()
    {
        if (!CameraUtility.VisibleFromCamera(other.screen, playerCam))
        {
            return;
        }

        CreateRenderTexture();

        var localToWorldMatrix = playerCam.transform.localToWorldMatrix;
        var renderPositions    = new Vector3[recursionLimit];
        var renderRotations    = new Quaternion[recursionLimit];

        int startIndex = 0;

        portalCam.projectionMatrix = playerCam.projectionMatrix;

        for (int i = 0; i < recursionLimit; i++)
        {
            if (i > 0 && !CameraUtility.BoundsOverlap(screenMeshFilter, other.screenMeshFilter, portalCam))
            {
                break;
            }

            localToWorldMatrix = transform.localToWorldMatrix * other.transform.worldToLocalMatrix * localToWorldMatrix;
            int renderOrderIndex = recursionLimit - i - 1;
            renderPositions[renderOrderIndex] = localToWorldMatrix.GetColumn(3);
            renderRotations[renderOrderIndex] = localToWorldMatrix.rotation;

            portalCam.transform.SetPositionAndRotation(renderPositions[renderOrderIndex], renderRotations[renderOrderIndex]);
            startIndex = renderOrderIndex;
        }

        // Hides Screen from rendering pass
        screen.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly;
        other.screen.material.SetInt("displayMask", 0);

        for (int i = startIndex; i < recursionLimit; i++)
        {
            portalCam.transform.SetPositionAndRotation(renderPositions[i], renderRotations[i]);
            SetNearClipPlane();
            HandleClipping();

            portalCam.Render();

            if (i == startIndex)
            {
                other.screen.material.SetInt("displayMask", 1);
            }
        }

        screen.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
    }
Exemple #14
0
    // manually renderportal camera
    public void Render()
    {
        CreateViewTexture();
        //allow for portal recursion
        var localToWorldMatrix = playerCam.transform.localToWorldMatrix;
        var renderPositions    = new Vector3[recursionLimit];
        var renderRotations    = new Quaternion[recursionLimit];

        Debug.Log("Portal view rendered");
        int startIndex = 0;

        portalCam.projectionMatrix = playerCam.projectionMatrix;
        for (int i = 0; i < recursionLimit; i++)
        {
            if (i > 0)
            {
                //dont render recursion if linked portal isnt visble
                if (!CameraUtility.BoundsOverlap(screenMeshFilter, linkedPortal.screenMeshFilter, portalCam))
                {
                    Debug.Log("Portal not visible");
                    break;
                }
            }
            localToWorldMatrix = transform.localToWorldMatrix * linkedPortal.transform.worldToLocalMatrix * localToWorldMatrix;
            int renderOrderIndex = recursionLimit - i - 1;
            renderPositions[renderOrderIndex] = localToWorldMatrix.GetColumn(3);
            renderRotations[renderOrderIndex] = localToWorldMatrix.rotation;

            portalCam.transform.SetPositionAndRotation(renderPositions[renderOrderIndex], renderRotations[renderOrderIndex]);
            startIndex = renderOrderIndex;
        }

        // hide portal screen so that camera can see through portal
        screen.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly;
        linkedPortal.screen.material.SetInt("displayMask", 0);
        //limit amount of recursions
        for (int i = startIndex; i < recursionLimit; i++)
        {
            portalCam.transform.SetPositionAndRotation(renderPositions[i], renderRotations[i]);
            SetNearClipPlane();
            HandleClipping();
            portalCam.Render();

            if (i == startIndex)
            {
                linkedPortal.screen.material.SetInt("displayMask", 1);
            }
        }

        // show hidden objects at render
        screen.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
    }
Exemple #15
0
        void FitCamera()
        {
            var     cellMin = puzzleManager.tilemapNavigation.Min;
            var     cellmax = puzzleManager.tilemapNavigation.Max;
            Vector2 min     = (Vector2)puzzleManager.tilemapNavigation.CellToWorld(cellMin);
            Vector2 max     = puzzleManager.tilemapNavigation.CellToWorld(cellmax);

            min = min - Vector2.one;
            max = max + Vector2.one;
            Rect w = new Rect();

            w.min = min;
            w.max = max;
            CameraUtility.SetCameraToRect(w);
        }
Exemple #16
0
        private void CalcuWhenObserveFreeMove(PlayerEntity playerEntity, FreeMoveEntity observedFreeMove)
        {
            var camera  = playerEntity.cameraFinalOutputNew;
            var calsOut = playerEntity.cameraStateOutputNew;

            camera.EulerAngle = calsOut.ArchorEulerAngle + calsOut.EulerAngle;

            var   rotation       = Quaternion.Euler(camera.EulerAngle);
            var   archorPos      = observedFreeMove.position.Value + observeOffset;
            float actualDistance = CameraUtility.ScatterCast(archorPos, rotation, observeDistance,
                                                             _samplePoints, _collisionLayers);

            var finalPostOffset = -rotation.Forward() * actualDistance;

            camera.Position = archorPos + finalPostOffset;
        }
        public void Generate(PlayerEntity player, IUserCmd usercmd, ICameraMotorState state, bool lockView)
        {
            var speedRatio = CameraUtility.GetGunSightSpeed(player, state);

            DeltaYaw   = usercmd.DeltaYaw * speedRatio;
            DeltaPitch = usercmd.DeltaPitch * speedRatio;
            if (usercmd.FilteredInput != null)
            {
                IsCameraFree         = usercmd.FilteredInput.IsInput(EPlayerInput.IsCameraFree);
                FilteredChangeCamera = lockView ? false : usercmd.FilteredInput.IsInput(EPlayerInput.ChangeCamera);
                FilteredCameraFocus  = usercmd.FilteredInput.IsInput(EPlayerInput.IsCameraFocus);
            }
            FrameInterval        = usercmd.FrameInterval;
            ChangeCamera         = lockView ? false :usercmd.ChangeCamera;
            IsCameraFocus        = usercmd.IsCameraFocus;
            IsCmdRun             = usercmd.IsRun;
            IsCmdMoveVertical    = usercmd.MoveVertical > 0;
            InterruptCameraFocus = usercmd.IsUseAction || usercmd.IsTabDown;

            if (player.hasStateInterface)
            {
                CurrentPostureState = player.stateInterface.State.GetCurrentPostureState();
                NextPostureState    = player.stateInterface.State.GetNextPostureState();
                LeanState           = player.stateInterface.State.GetNextLeanState();
                ActionState         = player.stateInterface.State.GetActionState();
                ActionKeepState     = player.stateInterface.State.GetActionKeepState();
            }
            else if (player.hasThirdPersonAppearance)
            {
                CurrentPostureState = (PostureInConfig)player.thirdPersonAppearance.PostureValue;
                NextPostureState    = (PostureInConfig)player.thirdPersonAppearance.NextPostureValue;
                ActionState         = (ActionInConfig)player.thirdPersonAppearance.ActionValue;
            }

            IsAirPlane          = player.gamePlay.GameState == GameState.AirPlane;
            IsDriveCar          = player.IsOnVehicle();
            IsDead              = player.gamePlay.IsLifeState(EPlayerLifeState.Dead);
            CanWeaponGunSight   = player.WeaponController().HeldWeaponAgent.CanWeaponSight;
            ArchorPitch         = YawPitchUtility.Normalize(player.cameraArchor.ArchorEulerAngle.x);
            ArchorYaw           = YawPitchUtility.Normalize(player.cameraArchor.ArchorEulerAngle.y);
            IsParachuteAttached = player.hasPlayerSkyMove && player.playerSkyMove.IsParachuteAttached;
            LastViewByOrder     = player.gamePlay.LastViewModeByCmd;
            RoleId              = player.playerInfo.RoleModelId;
            LockViewByRoom      = lockView;
            ModelLoaded         = player.hasFirstPersonModel && player.hasThirdPersonModel;
            IsVariant           = JudgeVariant(player);
        }
        public void SetHintEntityComponentList(List <HintEffectComponent> effectComponents)
        {
            //排序
            this.m_HintEffectComponentList = effectComponents.OrderBy(component => component.EntityOnCanvasPosition.x).ToList();
            if (this.m_HintEffectComponentList.Count > 0)
            {
                this.m_hintEntityCanvasPosition = new List <Vector2>(this.m_HintEffectComponentList.Count);

                for (int i = 0; i < this.m_HintEffectComponentList.Count; ++i)
                {
                    //world pos to canvas pos
                    Vector2 hintEntityInCanvasSpace = CameraUtility.WorldPointToCanvasLocalPosition(this.m_HintEffectComponentList[i].Entity.EntityPosition, LogicHandler.Canvas);
                    this.m_hintEntityCanvasPosition.Add(hintEntityInCanvasSpace);
                }
            }
            this.nextDetectEntityIndex = 0;
        }
Exemple #19
0
    private void Update()
    {
        if (Player.Position.y > topPos.y)
        {
            if (sectorPassed == false)
            {
                sectorPassed = true;
                GameManager.instance.Level++;
            }

            if (CameraUtility.CheckInCameraSpace(topPos) == false &&
                CameraUtility.CheckInCameraSpace(bottomPos) == false)
            {
                gameObject.SetActive(false);
                GameManager.instance.ResetQuadrant();
            }
        }
    }
Exemple #20
0
    protected override IEnumerator movementPattern()
    {
        while (true)
        {
            Vector3 forward = transform.up;
            transform.position += (forward * Speed * Time.deltaTime);
            Vector3 pos = transform.position;

            if (CameraUtility.ClampPositionToCamera(ref pos))
            {
                Vector3 LookDir = Vector3.Reflect(transform.up, Vector3.right);

                transform.up = LookDir;
            }

            yield return(null);
        }
    }
Exemple #21
0
        public void Generate(Contexts contexts, PlayerEntity player, IUserCmd usercmd, float archorYaw, float archorPitch, ICameraMotorState state)
        {
            var speedRatio = CameraUtility.GetGunSightSpeed(player, state);

            DeltaYaw   = usercmd.DeltaYaw * speedRatio;
            DeltaPitch = usercmd.DeltaPitch * speedRatio;
            if (usercmd.FilteredInput != null)
            {
                IsCameraFree         = usercmd.FilteredInput.IsInput(EPlayerInput.IsCameraFree);
                FilteredChangeCamera = usercmd.FilteredInput.IsInput(EPlayerInput.ChangeCamera);
                FilteredCameraFocus  = usercmd.FilteredInput.IsInput(EPlayerInput.IsCameraFocus);
            }
            var controller = player.WeaponController();

            FrameInterval = usercmd.FrameInterval;
            ChangeCamera  = usercmd.ChangeCamera;

            IsCameraFocus = usercmd.IsCameraFocus;

            IsCmdRun            = usercmd.IsRun;
            IsCmdMoveVertical   = usercmd.MoveVertical > 0;
            CurrentPostureState = player.stateInterface.State.GetCurrentPostureState();
            NextPostureState    = player.stateInterface.State.GetNextPostureState();
            LeanState           = player.stateInterface.State.GetNextLeanState();
            IsAirPlane          = player.gamePlay.GameState == GameState.AirPlane;
            ActionState         = player.stateInterface.State.GetActionState();
            ActionKeepState     = player.stateInterface.State.GetActionKeepState();
            IsDriveCar          = player.IsOnVehicle();
            IsDead              = player.gamePlay.IsLifeState(EPlayerLifeState.Dead);
            CanWeaponGunSight   = controller.HeldWeaponAgent.CanWeaponSight;
            ArchorPitch         = YawPitchUtility.Normalize(archorPitch);
            ArchorYaw           = YawPitchUtility.Normalize(archorYaw);
            IsParachuteAttached = player.hasPlayerSkyMove && player.playerSkyMove.IsParachuteAttached;
            if (player.gamePlay.CameraEntityId == 0)
            {
                IsObservingFreemove = false;
            }
            else
            {
                IsObservingFreemove = null != contexts.freeMove.GetEntityWithEntityKey(new EntityKey(player.gamePlay.CameraEntityId, (short)EEntityType.FreeMove));
            }
            InterruptCameraFocus = usercmd.IsUseAction || usercmd.IsTabDown;
            LastViewByOrder      = player.gamePlay.LastViewModeByCmd;
        }
Exemple #22
0
        public void IsCameraOverStep(ref CameraDirection direction_0, ref CameraDirection direction_1, ref Vector3 rotateValue)
        {
            //x > 0  up  y<0 right
            direction_0   = CameraDirection.None;
            direction_1   = CameraDirection.None;
            targetDummy_0 = GetRotateX(rotateValue.x);
            targetDummy_1 = GetRotateY(rotateValue.y);
            if (CameraUtility.IsBoundsInCameraView(targetDummy_1))
            {
                direction_0   = rotateValue.y > 0 ? CameraDirection.Right : CameraDirection.Left;
                rotateValue.y = 0;
            }

            if (CameraUtility.IsBoundsInCameraView(targetDummy_0))
            {
                direction_1   = rotateValue.x > 0 ? CameraDirection.Down : CameraDirection.Up;
                rotateValue.x = 0;
            }
        }
Exemple #23
0
    private void Update()
    {
        if (InputManager.JoystickIsActive == false)
        {
            Time.timeScale = .1f;
        }
        else
        {
            Time.timeScale = 1f;
        }

        Vector3 newPos = Vector3.zero;

        newPos.x = (InputManager.GetAxis(Joystick.Keys.xAxis) * moveSpeed);
        newPos.y = (InputManager.GetAxis(Joystick.Keys.yAxis) * moveSpeed);
        newPos  += transform.position;
        CameraUtility.ClampPositionToCamera(ref newPos);
        transform.position = newPos;
    }
Exemple #24
0
    private void Start()
    {
        Bounds         bounds         = CameraUtility.GetCameraBounds(Camera.main);
        float          min_separation = BoidPrefab.GetComponent <Agent>().separationRadius * 2;
        int            max_attempts   = 40;
        int            boids_spawned  = 0;
        List <Vector2> placedSoFar    = new List <Vector2>();

        for (int i = 0; i < NumBoids; i++)
        {
            int current_attempts = 0;

            bool  foundSpot = false;
            float initial_x = 0;
            float initial_y = 0;
            while (!foundSpot && current_attempts < max_attempts)
            {
                initial_x = Random.Range(bounds.min.x, bounds.max.x);
                initial_y = Random.Range(bounds.min.y, bounds.max.y);
                Vector2 current = new Vector2(initial_x, initial_y);
                foundSpot = true;
                foreach (Vector2 toCheck in placedSoFar)
                {
                    if (Vector2.Distance(toCheck, current) < min_separation)
                    {
                        foundSpot = false;
                        break;
                    }
                }
                current_attempts++;
            }
            if (foundSpot)
            {
                Quaternion intial_rotation = Quaternion.Euler(0, 0, Random.Range(0.0f, 360.0f));
                GameObject go = Instantiate(BoidPrefab, new Vector3(initial_x, initial_y, 0), intial_rotation);
                placedSoFar.Add(new Vector2(initial_x, initial_y));
                boids_spawned++;
            }
        }
        Debug.Log("Boids spawned " + boids_spawned);
    }
 void Update()
 {
     gameManager.updateHealth(currentHealth);
     if (damage)
     {
         spriteRender.color = screenFadeColor;
     }
     else
     {
         spriteRender.color = Color.Lerp(spriteRender.color, Color.white, screenFadeSpeed * Time.deltaTime);
     }
     damage = false;
     if (isDead)
     {
         fader.FadeToDark();
         Physics2D.IgnoreLayerCollision(PLAYER_LAYER_MASK, ENEMY_LAYER_MASK, true);
         playerTransform.position = Vector2.Lerp(playerTransform.position,
                                                 new Vector2(playerTransform.position.x, playerTransform.position.y - 100f), 0.01f * Time.deltaTime);
         playerRdb2.isKinematic = true;
         if (!CameraUtility.IsRendererInFrustum(boxCollider, cam))
         {
             isDestroyed = true;
             Destroy(gameObject);
         }
     }
     if (!isDead)
     {
         if (temp1 != null && !level1Manager.goNextRound)
         {
             fader.FadeToClear();
         }
         if (temp2 != null && !level2Manager.goNextRound)
         {
             fader.FadeToClear();
         }
         if (temp3 != null && !level3Manager.goNextRound)
         {
             fader.FadeToClear();
         }
     }
 }
Exemple #26
0
	Vector3 WorldToMinimapUiPosition(Vector3 pos)
	{
		var cameraPosition = new Vector3(minimapCamera.transform.position.x, 0, minimapCamera.transform.position.z);
		var iconPosition = new Vector3(pos.x, 0, pos.z);
		var delta = iconPosition - cameraPosition;

		delta.y = delta.z;
		delta.z = 0.0f;

		var rotatedDelta = minimapRotation.TransformDirection(delta);
		var deltaFactor = CameraUtility.CalculateFactor(minimapCamera) * worldToTexelFactor;
		rotatedDelta *= deltaFactor;

		var radius = rotatedDelta.magnitude;
		if (radius > minimapBorderRadius)
		{
			rotatedDelta.Normalize();
			rotatedDelta *= minimapBorderRadius;
		}
		return rotatedDelta;
	}
Exemple #27
0
        private bool IsBoundsInCameraView(ref Vector3 rotateValue)
        {
            Bounds bound0 = default(Bounds);
            Bounds bound1 = default(Bounds);

            if (Mathf.Abs(rotateValue.x) < Mathf.Abs(rotateValue.y) && (Mathf.Atan(Mathf.Abs(rotateValue.x / rotateValue.y))) * Mathf.Rad2Deg <= 10f)
            {
                bound1        = GetRotateY(rotateValue.y);
                rotateValue.x = 0f;

                return(CameraUtility.IsBoundsInCameraView(bound0, bound1));
            }
            else if (Mathf.Abs(rotateValue.y) < Mathf.Abs(rotateValue.x) && Mathf.Atan(Mathf.Abs(rotateValue.y / rotateValue.x)) * Mathf.Rad2Deg <= 10f)
            {
                bound0        = GetRotateX(rotateValue.x);
                rotateValue.y = 0f;
                return(CameraUtility.IsBoundsInCameraView(bound0, bound1));
            }
            bound0 = GetRotateX(rotateValue.x);
            bound1 = GetRotateY(rotateValue.y);
            return(CameraUtility.IsBoundsInCameraView(bound0, bound1));
        }
Exemple #28
0
    void OnValidate()
    {
        if (UnityEditor.EditorApplication.isPlaying == true)
        {
            return;
        }
        // 슬라이스를 다시 계산한다.
        CalcuateSliceHeights();
        // 상자 크기를 바꾼다.
        var gridBox = GameObject.Find("GridBox");

        gridBox.transform.localScale = m_SpaceSize;
        // 카메라를 조정한다.
        var normalCamera = GameObject.Find("NormalCamera");

        CameraUtility.Refresh(normalCamera, m_SpaceSize);
        var simulateCamera = GameObject.Find("SimulateCamera");

        CameraUtility.Refresh(simulateCamera, m_SpaceSize);
        // 슬라이스 그리드의 높이를 조절한다.
        var sliceGridViewer = GameObject.Find("SliceGridViewer").GetComponent <SliceGridViewer>();

        sliceGridViewer.Refresh(m_SliceHeights, m_SpaceSize);
    }
Exemple #29
0
        private void CalcuFreeMovePos(FreeMoveEntity observedFreeMove, CameraFinalOutputNewComponent camera)
        {
            if (observedFreeMove == null || !observedFreeMove.hasPosition)
            {
                return;
            }

            var archorPos = observedFreeMove.position.Value +
                            (observedFreeMove.hasFreeMoveController ? Vector3.zero : observeOffset);
            var rotation = Quaternion.Euler(camera.EulerAngle);

            if (observedFreeMove.hasFreeMoveController && observedFreeMove.freeMoveController.ControllType ==
                (byte)EFreeMoveControllType.FixFocusPos)
            {
                camera.Position = archorPos;
            }
            else
            {
                float actualDistance = CameraUtility.ScatterCast(archorPos, rotation, observeDistance,
                                                                 _samplePoints, _collisionLayers);
                var finalPostOffset = -rotation.Forward() * actualDistance;
                camera.Position = archorPos + finalPostOffset;
            }
        }
Exemple #30
0
        public bool Render(
            Camera playerCamera,
            Matrix4x4 playerProjectionMatrix, Matrix4x4 playerTransformMatrix,
            Camera portalCamera,
            Matrix4x4 portalMatrix, Bounds portalBounds,
            Matrix4x4 linkedPortalMatrix, Bounds linkedPortalBounds,
            float3 portalPosition, float3 portalForward,
            Entity portal, ref RenderMesh renderMesh, float distanceToCamera)    //, Material linkedPortalMaterial)
        {
            // Skip rendering the view from this portal if player is not looking at the linked portal
            //Debug.LogError(linkedPortalBounds);
            if (distanceToCamera > 2 && !CameraUtility.VisibleFromCamera(linkedPortalBounds, playerCamera))
            {
                return(false);
            }
            Matrix4x4 localToWorldMatrix = playerTransformMatrix;//playerCamera.transform.localToWorldMatrix;
            var       renderPositions    = new float3[recursionLimit];
            var       renderRotations    = new quaternion[recursionLimit];
            int       startIndex         = 0;

            portalCamera.projectionMatrix = playerProjectionMatrix; //playerCamera.projectionMatrix;
            Matrix4x4 linkedPortalWorldToLocalMatrix = math.inverse(linkedPortalMatrix);

            for (int i = 0; i < recursionLimit; i++)
            {
                if (i > 0)
                {
                    // No need for recursive rendering if linked portal is not visible through this portal
                    if (!CameraUtility.BoundsOverlap(portalMatrix, portalBounds, linkedPortalMatrix, linkedPortalBounds, portalCamera))
                    {
                        break;
                    }
                }
                localToWorldMatrix = portalMatrix * linkedPortalWorldToLocalMatrix * localToWorldMatrix;
                int renderOrderIndex = recursionLimit - i - 1;
                renderPositions[renderOrderIndex] = ((Vector3)localToWorldMatrix.GetColumn(3));
                if (float.IsNaN(renderPositions[renderOrderIndex].x))
                {
                    //Debug.LogError("NAN in portal system.");
                    return(false);
                }
                renderRotations[renderOrderIndex] = localToWorldMatrix.rotation;
                startIndex = renderOrderIndex;
            }
            // Hide portal mesh so that camera can see through portal
            var preMesh = renderMesh.mesh;

            renderMesh.mesh = null;
            World.EntityManager.SetSharedComponentData(portal, renderMesh);
            //linkedPortalMaterial.SetInt ("displayMask", 0);
            for (int i = startIndex; i < recursionLimit; i++)
            {
                portalCamera.transform.SetPositionAndRotation(renderPositions[i], renderRotations[i]);
                //var preFarClipPlane = playerCamera.farClipPlane;
                //playerCamera.farClipPlane = portalCamera.farClipPlane;
                //SetNearClipPlane(playerCamera, portalCamera, portalPosition, portalForward);
                SetNearClipPlane(playerCamera, portalCamera, portalPosition, portalForward);
                portalCamera.Render();
                //playerCamera.farClipPlane = preFarClipPlane;
            }
            renderMesh.mesh = preMesh;
            World.EntityManager.SetSharedComponentData(portal, renderMesh);
            return(true);
        }
 /// <summary>
 /// Function to initialize user control.
 /// </summary>
 private void InitializeUserControl()
 {
     this.cameraUtility = new CameraUtility();
     int videoHorizontalResolution = PhotoSettings.Instance.VideoHorizontalResolution;
     int videoVerticalResolution = PhotoSettings.Instance.VideoVerticalResolution;
     this.cameraUtility.StartVideo(this.videoPanel.Child.Handle, this.videoRegion, videoHorizontalResolution, videoVerticalResolution);
     this.cameraStatus = CameraStatus.Status;
 }