Ejemplo n.º 1
0
        protected override void OnToolGUI(UnityEngine.Event e)
        {
            if (!m_toolController.IsInsideUI && e.type == UnityEngine.EventType.MouseDown)
            {
                if (e.button == 0)
                {
                    m_mouseLeftDown = true;
                    m_endPosition   = m_mousePosition;
                }
                else if (e.button == 1)
                {
                    //begin mod
                    if (m_mode == TerrainTool.Mode.Shift || m_mode == TerrainTool.Mode.Soften || isDitch)
                    {
                        //end mod
                        m_mouseRightDown = true;
                    }
                    else if (m_mode == TerrainTool.Mode.Level || m_mode == TerrainTool.Mode.Slope)
                    {
                        m_startPosition = m_mousePosition;
                    }
                }
            }
            else if (e.type == UnityEngine.EventType.MouseUp)
            {
                if (e.button == 0)
                {
                    m_mouseLeftDown = false;
                    if (!m_mouseRightDown)
                    {
                        m_strokeEnded = true;
                    }
                }
                else if (e.button == 1)
                {
                    m_mouseRightDown = false;
                    if (!m_mouseLeftDown)
                    {
                        m_strokeEnded = true;
                    }
                }
            }
            if (m_UndoKey == null)
            {
                m_UndoKey = (SavedInputKey)typeof(TerrainTool).GetField("m_UndoKey", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(this);
            }

            if (!m_UndoKey.IsPressed(e) || m_undoRequest || (m_mouseLeftDown || m_mouseRightDown) || !IsUndoAvailable())
            {
                return;
            }
            Undo();
        }
Ejemplo n.º 2
0
 private Level HandleShortcut(Event e, SavedInputKey shortcut, Message message)
 {
     if (shortcut.IsPressed(e))
     {
         Send(message);
         return(null);
     }
     else
     {
         return(this);
     }
 }
Ejemplo n.º 3
0
        private void HandleElevation(Event e)
        {
            var current = Event.current;

            if (current == null || !current.isKey || current.keyCode == KeyCode.None || UIView.HasModalInput() ||
                UIView.HasInputFocus())
            {
                return;
            }

            if (_buildElevationUp.IsPressed(e))
            {
                ChangeElevation(true);
            }
            if (_buildElevationDown.IsPressed(e))
            {
                ChangeElevation(false);
            }
        }
Ejemplo n.º 4
0
        void Update()
        {
            if (onUpdate != null)
            {
                onUpdate();
            }

            if (!initPositions)
            {
                mainCameraPosition    = gameObject.transform.position;
                mainCameraOrientation = gameObject.transform.rotation;
                rotationY             = -instance.transform.localEulerAngles.x;
                initPositions         = true;
            }

            if (!checkedForHideUI)
            {
                var gameObjects = FindObjectsOfType <GameObject>();
                foreach (var go in gameObjects)
                {
                    var tmp = go.GetComponent("HideUI");
                    if (tmp != null)
                    {
                        hideUIComponent = tmp;
                        break;
                    }
                }

                checkedForHideUI = true;
            }

            if (cityWalkthroughMode)
            {
                cityWalkthroughNextChangeTimer -= Time.deltaTime;
                if (cityWalkthroughNextChangeTimer <= 0.0f || !(citizenCamera.following || vehicleCamera.following))
                {
                    cityWalkthroughNextChangeTimer = Random.Range(5.0f, 10.0f);
                    bool vehicleOrCitizen = Random.Range(0, 3) == 0;
                    if (!vehicleOrCitizen)
                    {
                        if (citizenCamera.following)
                        {
                            citizenCamera.StopFollowing();
                        }

                        var vehicle = GetRandomVehicle();
                        if (vehicle != 0)
                        {
                            vehicleCamera.SetFollowInstance(vehicle);
                        }
                    }
                    else
                    {
                        if (vehicleCamera.following)
                        {
                            vehicleCamera.StopFollowing();
                        }

                        var citizen = GetRandomCitizenInstance();
                        if (citizen != 0)
                        {
                            citizenCamera.SetFollowInstance(citizen);
                        }
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                if (cityWalkthroughMode)
                {
                    cityWalkthroughMode = false;
                    if (vehicleCamera.following)
                    {
                        vehicleCamera.StopFollowing();
                    }
                    if (citizenCamera.following)
                    {
                        citizenCamera.StopFollowing();
                    }

                    if (hideUIComponent != null && config.integrateHideUI)
                    {
                        hideUIComponent.SendMessage("Show");
                    }
                }
                else if (vehicleCamera.following)
                {
                    vehicleCamera.StopFollowing();

                    if (hideUIComponent != null && config.integrateHideUI)
                    {
                        hideUIComponent.SendMessage("Show");
                    }
                }
                else if (citizenCamera.following)
                {
                    citizenCamera.StopFollowing();

                    if (hideUIComponent != null && config.integrateHideUI)
                    {
                        hideUIComponent.SendMessage("Show");
                    }
                }
                else if (fpsModeEnabled)
                {
                    if (config.animateTransitions && fpsModeEnabled)
                    {
                        inModeTransition = true;
                        transitionT      = 0.0f;

                        if ((gameObject.transform.position - mainCameraPosition).magnitude <= 1.0f)
                        {
                            transitionT           = 1.0f;
                            mainCameraOrientation = gameObject.transform.rotation;
                        }

                        transitionStartPosition    = gameObject.transform.position;
                        transitionStartOrientation = gameObject.transform.rotation;

                        transitionTargetPosition    = mainCameraPosition;
                        transitionTargetOrientation = mainCameraOrientation;
                    }

                    SetMode(!fpsModeEnabled);
                }
            }

            if (Input.GetKeyDown(config.toggleFPSCameraHotkey))
            {
                if (cityWalkthroughMode)
                {
                    cityWalkthroughMode = false;
                    if (vehicleCamera.following)
                    {
                        vehicleCamera.StopFollowing();
                    }
                    if (citizenCamera.following)
                    {
                        citizenCamera.StopFollowing();
                    }

                    if (hideUIComponent != null && config.integrateHideUI)
                    {
                        hideUIComponent.SendMessage("Show");
                    }
                }
                else if (vehicleCamera.following)
                {
                    vehicleCamera.StopFollowing();
                }
                else if (citizenCamera.following)
                {
                    citizenCamera.StopFollowing();
                }
                else
                {
                    if (config.animateTransitions && fpsModeEnabled)
                    {
                        inModeTransition = true;
                        transitionT      = 0.0f;

                        if ((gameObject.transform.position - mainCameraPosition).magnitude <= 1.0f)
                        {
                            transitionT           = 1.0f;
                            mainCameraOrientation = gameObject.transform.rotation;
                        }

                        transitionStartPosition    = gameObject.transform.position;
                        transitionStartOrientation = gameObject.transform.rotation;

                        transitionTargetPosition    = mainCameraPosition;
                        transitionTargetOrientation = mainCameraOrientation;
                    }

                    SetMode(!fpsModeEnabled);
                }
            }

            if (config.animateTransitions && inModeTransition)
            {
                transitionT += Time.deltaTime * config.animationSpeed;

                gameObject.transform.position = Vector3.Slerp(transitionStartPosition, transitionTargetPosition, transitionT);
                gameObject.transform.rotation = Quaternion.Slerp(transitionStartOrientation, transitionTargetOrientation, transitionT);

                if (transitionT >= 1.0f)
                {
                    inModeTransition = false;

                    if (!fpsModeEnabled)
                    {
                        instance.controller.enabled = true;
                    }
                }
            }
            else if (fpsModeEnabled)
            {
                var   pos      = gameObject.transform.position;
                float terrainY = terrainManager.SampleDetailHeight(gameObject.transform.position);
                float waterY   = terrainManager.WaterLevel(new Vector2(gameObject.transform.position.x, gameObject.transform.position.z));
                terrainY = Mathf.Max(terrainY, waterY);

                if (config.snapToGround)
                {
                    Segment3 ray = new Segment3(gameObject.transform.position + new Vector3(0f, 1.5f, 0f), gameObject.transform.position + new Vector3(0f, -1000f, 0f));

                    Vector3 hitPos;
                    ushort  nodeIndex;
                    ushort  segmentIndex;
                    Vector3 hitPos2;

                    if (netManager.RayCast(ray, 0f, ItemClass.Service.Road, ItemClass.Service.PublicTransport, ItemClass.SubService.None, ItemClass.SubService.None, ItemClass.Layer.Default, ItemClass.Layer.None, NetNode.Flags.None, NetSegment.Flags.None, out hitPos, out nodeIndex, out segmentIndex)
                        | netManager.RayCast(ray, 0f, ItemClass.Service.Beautification, ItemClass.Service.Water, ItemClass.SubService.None, ItemClass.SubService.None, ItemClass.Layer.Default, ItemClass.Layer.None, NetNode.Flags.None, NetSegment.Flags.None, out hitPos2, out nodeIndex, out segmentIndex))
                    {
                        terrainY = Mathf.Max(terrainY, Mathf.Max(hitPos.y, hitPos2.y));
                    }

                    gameObject.transform.position = Vector3.Lerp(gameObject.transform.position, new Vector3(pos.x, terrainY + config.groundOffset, pos.z), 0.9f);
                }

                float speedFactor = 1.0f;
                if (config.limitSpeedGround)
                {
                    speedFactor *= Mathf.Sqrt(terrainY);
                    speedFactor  = Mathf.Clamp(speedFactor, 1.0f, 256.0f);
                }

                if (Input.GetKey(config.goFasterHotKey))
                {
                    speedFactor *= 10.0f;
                }

                if (cameraMoveForward.IsPressed())
                {
                    gameObject.transform.position += gameObject.transform.forward * config.cameraMoveSpeed * speedFactor * Time.deltaTime;
                }
                else if (cameraMoveBackward.IsPressed())
                {
                    gameObject.transform.position -= gameObject.transform.forward * config.cameraMoveSpeed * speedFactor * Time.deltaTime;
                }

                if (cameraMoveLeft.IsPressed())
                {
                    gameObject.transform.position -= gameObject.transform.right * config.cameraMoveSpeed * speedFactor * Time.deltaTime;
                }
                else if (cameraMoveRight.IsPressed())
                {
                    gameObject.transform.position += gameObject.transform.right * config.cameraMoveSpeed * speedFactor * Time.deltaTime;
                }

                if (cameraZoomAway.IsPressed())
                {
                    gameObject.transform.position -= gameObject.transform.up * config.cameraMoveSpeed * speedFactor * Time.deltaTime;
                }
                else if (cameraZoomCloser.IsPressed())
                {
                    gameObject.transform.position += gameObject.transform.up * config.cameraMoveSpeed * speedFactor * Time.deltaTime;
                }

                if (Input.GetKey(config.showCodeFPSMouseHotkey))
                {
                    Cursor.visible = true;
                }
                else
                {
                    float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * config.cameraRotationSensitivity;
                    rotationY += Input.GetAxis("Mouse Y") * config.cameraRotationSensitivity * (config.invertYAxis ? -1.0f : 1.0f);
                    transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
                    Cursor.visible             = false;
                }

                if (config.preventClipGround)
                {
                    if (transform.position.y < terrainY + config.groundOffset)
                    {
                        transform.position = new Vector3(transform.position.x, terrainY + config.groundOffset, transform.position.z);
                    }
                }

                camera.fieldOfView   = config.fieldOfView;
                camera.nearClipPlane = 1.0f;
            }
            else
            {
                mainCameraPosition    = gameObject.transform.position;
                mainCameraOrientation = gameObject.transform.rotation;
            }
        }
Ejemplo n.º 5
0
        static bool Prefix(
            CameraController __instance,
            float multiplier,

            ref Vector3 ___m_velocity,
            ref Vector2 ___m_angleVelocity,
            ref float ___m_zoomVelocity,

            SavedInputKey ___m_cameraMoveLeft,
            SavedInputKey ___m_cameraMoveRight,
            SavedInputKey ___m_cameraMoveForward,
            SavedInputKey ___m_cameraMoveBackward,

            SavedInputKey ___m_cameraRotateLeft,
            SavedInputKey ___m_cameraRotateRight,
            SavedInputKey ___m_cameraRotateUp,
            SavedInputKey ___m_cameraRotateDown,

            SavedInputKey ___m_cameraZoomAway,
            SavedInputKey ___m_cameraZoomCloser
            )
        {
            if (App.Instance.IsDive)
            {
                return(false);
            }

            var delta        = Vector3.zero;
            var analogAction = SteamController.GetAnalogAction(SteamController.AnalogInput.CameraScroll);

            if (analogAction.sqrMagnitude > 0.0001f)
            {
                delta.x = analogAction.x;
                delta.z = analogAction.y;
                __instance.ClearTarget();
            }

            if (___m_cameraMoveLeft.IsPressed())
            {
                delta.x -= 1f;
                __instance.ClearTarget();
            }
            if (___m_cameraMoveRight.IsPressed())
            {
                delta.x += 1f;
                __instance.ClearTarget();
            }
            if (___m_cameraMoveForward.IsPressed())
            {
                delta.z += 1f;
                __instance.ClearTarget();
            }
            if (___m_cameraMoveBackward.IsPressed())
            {
                delta.z -= 1f;
                __instance.ClearTarget();
            }

            if (__instance.m_analogController)
            {
                float num  = UnityEngine.Input.GetAxis("Horizontal") * __instance.m_GamepadMotionZoomScalar.x;
                float num2 = UnityEngine.Input.GetAxis("Vertical") * __instance.m_GamepadMotionZoomScalar.z;
                if (num != 0f)
                {
                    delta.x = num;
                }
                if (num2 != 0f)
                {
                    delta.z = num2;
                }
            }
            ___m_velocity += delta * multiplier * Time.deltaTime;

            var rotDelta = Vector2.zero;

            if (!__instance.m_freeCamera)
            {
                if (___m_cameraRotateLeft.IsPressed())
                {
                    rotDelta.x += 200f;
                }
                if (___m_cameraRotateRight.IsPressed())
                {
                    rotDelta.x -= 200f;
                }
                if (___m_cameraRotateUp.IsPressed())
                {
                    rotDelta.y += 200f;
                }
                if (___m_cameraRotateDown.IsPressed())
                {
                    rotDelta.y -= 200f;
                }
            }
            ___m_angleVelocity += rotDelta * multiplier * Time.deltaTime;
            float num3 = 0f;

            if (___m_cameraZoomCloser.IsPressed() || SteamController.GetDigitalAction(SteamController.DigitalInput.ZoomIn))
            {
                num3 -= 50f;
            }
            if (___m_cameraZoomAway.IsPressed() || SteamController.GetDigitalAction(SteamController.DigitalInput.ZoomOut))
            {
                num3 += 50f;
            }
            ___m_zoomVelocity += num3 * multiplier * Time.deltaTime;
            return(false);
        }
Ejemplo n.º 6
0
        void UpdateCameras()
        {
            if (vehicleCamera != null && vehicleCamera.following && config.allowUserOffsetInVehicleCitizenMode)
            {
                if (cameraMoveForward.IsPressed())
                {
                    vehicleCamera.userOffset += gameObject.transform.forward * config.cameraMoveSpeed * 0.25f * Time.deltaTime;
                }
                else if (cameraMoveBackward.IsPressed())
                {
                    vehicleCamera.userOffset -= gameObject.transform.forward * config.cameraMoveSpeed * 0.25f * Time.deltaTime;
                }

                if (cameraMoveLeft.IsPressed())
                {
                    vehicleCamera.userOffset -= gameObject.transform.right * config.cameraMoveSpeed * 0.25f * Time.deltaTime;
                }
                else if (cameraMoveRight.IsPressed())
                {
                    vehicleCamera.userOffset += gameObject.transform.right * config.cameraMoveSpeed * 0.25f * Time.deltaTime;
                }

                if (cameraZoomAway.IsPressed())
                {
                    vehicleCamera.userOffset -= gameObject.transform.up * config.cameraMoveSpeed * 0.25f * Time.deltaTime;
                }
                else if (cameraZoomCloser.IsPressed())
                {
                    vehicleCamera.userOffset += gameObject.transform.up * config.cameraMoveSpeed * 0.25f * Time.deltaTime;
                }
            }

            if (citizenCamera != null && citizenCamera.following && config.allowUserOffsetInVehicleCitizenMode)
            {
                if (cameraMoveForward.IsPressed())
                {
                    citizenCamera.userOffset += gameObject.transform.forward * config.cameraMoveSpeed * 0.25f * Time.deltaTime;
                }
                else if (cameraMoveBackward.IsPressed())
                {
                    citizenCamera.userOffset -= gameObject.transform.forward * config.cameraMoveSpeed * 0.25f * Time.deltaTime;
                }

                if (cameraMoveLeft.IsPressed())
                {
                    citizenCamera.userOffset -= gameObject.transform.right * config.cameraMoveSpeed * 0.25f * Time.deltaTime;
                }
                else if (cameraMoveRight.IsPressed())
                {
                    citizenCamera.userOffset += gameObject.transform.right * config.cameraMoveSpeed * 0.25f * Time.deltaTime;
                }

                if (cameraZoomAway.IsPressed())
                {
                    citizenCamera.userOffset -= gameObject.transform.up * config.cameraMoveSpeed * 0.25f * Time.deltaTime;
                }
                else if (cameraZoomCloser.IsPressed())
                {
                    citizenCamera.userOffset += gameObject.transform.up * config.cameraMoveSpeed * 0.25f * Time.deltaTime;
                }
            }
        }