コード例 #1
0
        public void init(IceFishingHole iceFishingHole)
        {
            "AutoCook.init".logDbg();
            if (iceFishingHole)
            {
                this.iceFishingHole = iceFishingHole;
                fire           = iceFishingHole.transform.parent.GetComponentInChildren <Fire>();
                gearPlacePoint = iceFishingHole.transform.parent.GetComponentInChildren <GearPlacePoint>();
            }

            if (!iceFishingHole || !fire || !gearPlacePoint)
            {
                $"AutoCook.init: something went wrong (iceFishingHole: '{iceFishingHole}, fire: '{fire}', gearPlacePoint: '{gearPlacePoint}'')".logError();
                Destroy(this);
            }
        }
コード例 #2
0
        private static void Postfix(PlayerManager __instance, ref MeshLocationCategory __result)
        {
            if (__instance == null)
            {
                return;
            }

            GameObject gameObject = __instance.GetObjectToPlace();

            if (!PlacingAnywhere.isPlacing)
            {
                PlacingAnywhere.isPlacing    = true;
                PlacingAnywhere.lastRotation = gameObject.transform.eulerAngles;
            }

            if (gameObject == null)
            {
                return;
            }

            vp_FPSCamera cam        = GameManager.GetVpFPSPlayer().FPSCamera;
            RaycastHit   raycastHit = PlacingAnywhere.DoRayCast(cam.transform.position, cam.transform.forward, true);

            GearPlacePoint gearPlacePoint = null;

            if (raycastHit.collider != null)
            {
                gearPlacePoint = __instance.GetGearPlacePoint(raycastHit.collider.gameObject, raycastHit.point);
            }

            if (gearPlacePoint == null)
            {
                gameObject.transform.eulerAngles = PlacingAnywhere.lastRotation;
            }

            //Z Rotation - G/H
            if (KeyboardUtilities.InputManager.GetKey(Settings.options.rotateZRight) && Time.time > PlacingAnywhere.nextRotate)
            {
                PlacingAnywhere.nextRotate = Time.time + PlacingAnywhere.rotateRate;

                if (KeyboardUtilities.InputManager.GetKey(KeyCode.LeftShift))
                {
                    gameObject.transform.Rotate(Vector3.right, PlacingAnywhere.rotateAngle / 4f, Space.Self);
                }
                else
                {
                    gameObject.transform.Rotate(Vector3.right, PlacingAnywhere.rotateAngle, Space.Self);
                }
            }
            else if (KeyboardUtilities.InputManager.GetKey(Settings.options.rotateZLeft) && Time.time > PlacingAnywhere.nextRotate)
            {
                PlacingAnywhere.nextRotate = Time.time + PlacingAnywhere.rotateRate;

                if (KeyboardUtilities.InputManager.GetKey(KeyCode.LeftShift))
                {
                    gameObject.transform.Rotate(Vector3.right, -(PlacingAnywhere.rotateAngle / 4f), Space.Self);
                }
                else
                {
                    gameObject.transform.Rotate(Vector3.right, -PlacingAnywhere.rotateAngle, Space.Self);
                }
            }

            //Y Rotation - Q/E - Handled by vanilla

            //X Rotation - T/Y
            if (KeyboardUtilities.InputManager.GetKey(Settings.options.rotateXRight) && Time.time > PlacingAnywhere.nextRotate)
            {
                PlacingAnywhere.nextRotate = Time.time + PlacingAnywhere.rotateRate;

                if (KeyboardUtilities.InputManager.GetKey(KeyCode.LeftShift))
                {
                    gameObject.transform.Rotate(Vector3.forward, PlacingAnywhere.rotateAngle / 4f, Space.Self);
                }
                else
                {
                    gameObject.transform.Rotate(Vector3.forward, PlacingAnywhere.rotateAngle, Space.Self);
                }
            }
            else if (KeyboardUtilities.InputManager.GetKey(Settings.options.rotateXLeft) && Time.time > PlacingAnywhere.nextRotate)
            {
                PlacingAnywhere.nextRotate = Time.time + PlacingAnywhere.rotateRate;

                if (KeyboardUtilities.InputManager.GetKey(KeyCode.LeftShift))
                {
                    gameObject.transform.Rotate(Vector3.forward, -(PlacingAnywhere.rotateAngle / 4f), Space.Self);
                }
                else
                {
                    gameObject.transform.Rotate(Vector3.forward, -PlacingAnywhere.rotateAngle, Space.Self);
                }
            }

            //Y Position - B/N
            if (KeyboardUtilities.InputManager.GetKey(Settings.options.moveUp) && Time.time > PlacingAnywhere.nextRotate)
            {
                PlacingAnywhere.nextRotate = Time.time + PlacingAnywhere.rotateRate;

                if (KeyboardUtilities.InputManager.GetKey(KeyCode.LeftShift))
                {
                    PlacingAnywhere.positionYOffset += (PlacingAnywhere.positionOffset / 4f);
                }
                else
                {
                    PlacingAnywhere.positionYOffset += PlacingAnywhere.positionOffset;
                }
            }
            else if (KeyboardUtilities.InputManager.GetKey(Settings.options.moveDown) && Time.time > PlacingAnywhere.nextRotate)
            {
                PlacingAnywhere.nextRotate = Time.time + PlacingAnywhere.rotateRate;

                if (KeyboardUtilities.InputManager.GetKey(KeyCode.LeftShift))
                {
                    PlacingAnywhere.positionYOffset -= (PlacingAnywhere.positionOffset / 4f);
                }
                else
                {
                    PlacingAnywhere.positionYOffset -= PlacingAnywhere.positionOffset;
                }
            }

            if (KeyboardUtilities.InputManager.GetKeyDown(Settings.options.resetRotation))
            {
                float diff = Vector3.Dot(Vector3.up, raycastHit.normal);
                if (diff > 0.05f)
                {
                    Quaternion lhs = Quaternion.FromToRotation(Vector3.up, raycastHit.normal);
                    gameObject.transform.rotation = Quaternion.Euler(0f, gameObject.transform.rotation.eulerAngles.y, 0f);
                    gameObject.transform.rotation = lhs * gameObject.transform.rotation;
                    gameObject.transform.rotation = Quaternion.Euler(gameObject.transform.rotation.eulerAngles.x, gameObject.transform.rotation.eulerAngles.y, gameObject.transform.rotation.eulerAngles.z);
                }
            }

            //Conform to surface
            if (KeyboardUtilities.InputManager.GetKeyDown(Settings.options.conformToggleKey))
            {
                if (PlacingAnywhere.conformToggle)
                {
                    PlacingAnywhere.conformToggle = false;
                    HUDMessage.AddMessage("Conform to surface: off");
                    PlacingAnywhere.RemoveItemsFromPhysicalCollisionMask();
                }
                else
                {
                    PlacingAnywhere.conformToggle   = true;
                    PlacingAnywhere.positionYOffset = 0;
                    HUDMessage.AddMessage("Conform to surface: on");
                    PlacingAnywhere.AddItemsToPhysicalCollisionMask();
                }
            }

            //Snap to object below
            if (KeyboardUtilities.InputManager.GetKeyDown(Settings.options.snapKey))
            {
                if (PlacingAnywhere.snapToggle)
                {
                    PlacingAnywhere.snapToggle = false;
                    HUDMessage.AddMessage("Snap to objects: off");
                }
                else
                {
                    PlacingAnywhere.snapToggle = true;
                    HUDMessage.AddMessage("Snap to objects: on");
                }
            }

            Vector2   cameraMovementMouse = InputManager.GetCameraMovementMouse(__instance);
            Transform transform           = GameManager.GetMainCamera().transform;

            if (KeyboardUtilities.InputManager.GetKey(KeyCode.LeftAlt))
            {
                //Stop camera movement
                cam.MouseSensitivity = 0f;

                float angleForward = cameraMovementMouse.x * 1f;
                float angleRight   = cameraMovementMouse.y * 1f;

                if (KeyboardUtilities.InputManager.GetKey(KeyCode.LeftShift))
                {
                    angleForward *= 0.25f;
                    angleRight   *= 0.25f;
                }


                if (Mathf.Abs(angleForward) > Mathf.Abs(angleRight))
                {
                    gameObject.transform.Rotate(Vector3.forward, -angleForward, Space.World);
                }
                else
                {
                    gameObject.transform.Rotate(Vector3.right, -angleRight, Space.World);
                }
            }
            else
            {
                //Restore camera movement
                if (PlacingAnywhere.mouseSensivity > 0)
                {
                    cam.MouseSensitivity = PlacingAnywhere.mouseSensivity;
                }
            }

            gameObject.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y + PlacingAnywhere.positionYOffset, gameObject.transform.position.z);

            if (PlacingAnywhere.snapToggle && gearPlacePoint == null)
            {
                if (raycastHit.collider != null)
                {
                    GameObject goHit = raycastHit.collider.gameObject;

                    if (goHit.GetComponent <GearItem>() != null)
                    {
                        gameObject.transform.rotation = goHit.transform.rotation;
                        gameObject.transform.position = new Vector3(goHit.transform.position.x, gameObject.transform.position.y, goHit.transform.position.z);
                    }
                }
            }

            if (PlacingAnywhere.snapToggle && gearPlacePoint == null)
            {
                PlacingAnywhere.SnapToPositionBelow(gameObject);
                PlacingAnywhere.SnapToRotationBelow(gameObject);
            }

            PlacingAnywhere.lastRotation = gameObject.transform.eulerAngles;

            __result = MeshLocationCategory.Valid;
        }