Ejemplo n.º 1
0
        public static void SetupSmoothedCamera()
        {
            if (!VRManager.IsVREnabled())
            {
                Main.LogWarning("[SmoothCamera] >>> Game running in non-VR mode. Skipping camera setup.");
                return;
            }

            if (GameObject.Find("SmoothCamera") != null)
            {
                Main.LogWarning("[SmoothCamera] >>> SmoothCamera already exists. Skipping camera setup.");
                return;
            }

            var veggieSys = UnityEngine.Object.FindObjectOfType <VegetationSystemPro>();

            if (Camera.main == null || veggieSys == null)
            {
                Main.Log("[SmoothCamera] >>> Delaying camera setup...");
                WorldStreamingInit.LoadingFinished += MainCamSetup;
                return;
            }

            MainCamSetup();
        }
Ejemplo n.º 2
0
 static void Postfix(ref float ___currentZoomVelocity, float ___zoomInTime, float ___zoomOutTime, float ___normalFOV, float ___zoomedFOV)
 {
     try
     {
         if (thisModEntry.Active && VRManager.IsVREnabled())
         {
             VRTK_ControllerEvents secondaryEvents = VRTK_DeviceFinder.GetControllerRightHand(false).GetComponent <VRTK_ControllerEvents>();
             Vector2 axis = secondaryEvents.GetAxis(
                 VRTK_DeviceFinder.GetHeadsetType() == SDK_BaseHeadset.HeadsetType.WindowsMixedReality
                                             ? VRTK_ControllerEvents.Vector2AxisAlias.TouchpadTwo
                                             : VRTK_ControllerEvents.Vector2AxisAlias.Touchpad
                 );
             float zoomedFactor = ___normalFOV / ___zoomedFOV;
             if (axis.y < 0.625f && XRDevice.fovZoomFactor > 1f)
             {
                 XRDevice.fovZoomFactor = Mathf.SmoothDamp(XRDevice.fovZoomFactor, 1.0f, ref ___currentZoomVelocity, ___zoomOutTime);
             }
             if (axis.y > 0.625f && XRDevice.fovZoomFactor < zoomedFactor)
             {
                 XRDevice.fovZoomFactor = Mathf.SmoothDamp(XRDevice.fovZoomFactor, zoomedFactor, ref ___currentZoomVelocity, ___zoomInTime);
             }
         }
     }
     catch (Exception e)
     {
         Debug.LogError(string.Format("Exception thrown during CameraZoom.ZoomMechanic postfix patch:\n{0}", e.Message));
         OnCriticalFailure();
     }
 }
Ejemplo n.º 3
0
 public static void ShowFloatVR(string text)
 {
     HideFloatVR();
     if (!string.IsNullOrEmpty(text))
     {
         // TODO: Check if PlayerCamera is nullable.
         Transform eyesTransform = PlayerManager.PlayerCamera?.transform;
         if (eyesTransform == null)
         {
             return;
         }
         Vector3   position = eyesTransform.position + eyesTransform.forward * 1.5f;
         Transform parent;
         if (VRManager.IsVREnabled())
         {
             parent = VRTK_DeviceFinder.PlayAreaTransform();
         }
         else
         {
             parent = (PlayerManager.Car ? PlayerManager.Car.interior : (SingletonBehaviour <WorldMover> .Exists ? SingletonBehaviour <WorldMover> .Instance.originShiftParent : null));
         }
         floatieVR = (Object.Instantiate(Resources.Load("tutorial_floatie"), position, Quaternion.identity, parent) as GameObject);
         floatieVR.GetComponent <TutorialFloatie>().UpdateTextExternally(text);
     }
 }
Ejemplo n.º 4
0
        private static void Loaded()
        {
            if (!VRManager.IsVREnabled())
            {
                return;
            }

            var belt = FindObjectOfType <VRTK_HipTracking>();

            // copy the belt to make head tracked slots
            var head = Instantiate(belt, belt.transform.parent, true);

            head.HeadOffset = 0;

            // disable all except for the center one
            for (int i = 1; i < head.transform.childCount; i++)
            {
                head.transform.GetChild(i).gameObject.SetActive(false);
            }

            head.transform.GetChild(0).localPosition = Vector3.up * 0.3f + Vector3.forward * 0.1f;

            // delete possible items in the slot, that shouldn't be there
            var drop = head.transform.GetChild(0).GetChild(0);

            for (int i = 1; i < drop.childCount; i++)
            {
                Destroy(drop.GetChild(i).gameObject);
            }

            belt.gameObject.AddComponent <BeltLoader>();            // marker to differentiate this
        }
Ejemplo n.º 5
0
 private static MonoBehaviour GetGrabbableComponent(Collider col)
 {
     if (VRManager.IsVREnabled())
     {
         return(col.GetComponentInParent <Telegrabbable>());
     }
     return(col.GetComponentInParent <ItemBase>());
 }
Ejemplo n.º 6
0
        public static void StorageBase_RequestStorageSaveGameData_Postfix(StorageBase __instance, List <StorageItemData> __result)
        {
            _savingStorage = false;

            if (__instance.storageType != StorageType.World)
            {
                return;
            }

            var vr = VRManager.IsVREnabled();

            var go  = -1;
            var num = 0;

            foreach (var item in __instance.itemList)
            {
                if (StorageBase.itemTypesExcludedFromSave.Any(t => item.GetComponent(t)))
                {
                    continue;
                }

                if (vr)
                {
                    if (item.GetComponentInParent <BeltLoader>())
                    {
                        go = num;
                        break;
                    }
                }
                else
                {
                    var flashLight = item.GetComponent <FlashlightNonVR>();
                    if (!flashLight)
                    {
                        continue;
                    }
                    if (flashLight.IsHeadAttached)
                    {
                        go = num;
                        break;
                    }
                }
                num++;
            }

            if (go == -1)
            {
                return;
            }
            if (Array.IndexOf(Inventory.Instance.items, null) == -1)
            {
                return;
            }

            Log.Debug("Removing head-attached item from world");

            __result.RemoveAt(go);
        }
Ejemplo n.º 7
0
    void Start()
    {
        if (!VRManager.IsVREnabled())
        {
            Destroy(this);
            return;
        }

        _headset = VRTK_SDK_Bridge.GetHeadset();
    }
Ejemplo n.º 8
0
    void Start()
    {
        if (VRManager.IsVREnabled())
        {
            Destroy(this);
            return;
        }

        grabHandler = GetComponent <AGrabHandler>();
        grabber     = FindObjectOfType <Grabber>();
    }
Ejemplo n.º 9
0
        public static void Inventory_GetItemsArray_Postfix(ref GameObject[] __result)
        {
            if (!_savingStorage)
            {
                return;
            }

            var vr = VRManager.IsVREnabled();

            var go = default(GameObject);

            foreach (var item in StorageController.Instance.StorageWorld.itemList)
            {
                if (vr)
                {
                    if (item.GetComponentInParent <BeltLoader>())
                    {
                        go = item.gameObject;
                        break;
                    }
                }
                else
                {
                    var flashLight = item.GetComponent <FlashlightNonVR>();
                    if (!flashLight)
                    {
                        continue;
                    }
                    if (flashLight.IsHeadAttached)
                    {
                        go = flashLight.gameObject;
                        break;
                    }
                }
            }

            var empty = Array.IndexOf(__result, null);

            if (empty == -1)
            {
                return;
            }
            var copy = __result.ToArray();

            copy[empty] = go;
            __result    = copy;

            Log.Debug($"Adding head attached item to inventory {go}");
        }
Ejemplo n.º 10
0
 static void Postfix(Transform player, Camera camera)
 {
     try
     {
         // don't skip even if the mod is inactive; this setup only runs once!
         if (VRManager.IsVREnabled() && player != null && camera != null)
         {
             player.gameObject.AddComponent <CameraZoom>().cam = camera;
         }
     }
     catch (Exception e)
     {
         Debug.LogError(string.Format("Exception thrown during PlayerManager.SetPlayer postfix patch:\n{0}", e.Message));
         OnCriticalFailure();
     }
 }
Ejemplo n.º 11
0
    private void Start()
    {
        button               = buttonSpec.GetComponent <ButtonBase>();
        button.Used         += Button_Used;
        rotary               = rotarySpec.GetComponent <RotaryBase>();
        rotary.ValueChanged += Rotary_ValueChanged;
        item       = GetComponent <ItemBase>();
        item.Used += () => button.Use();

        if (VRManager.IsVREnabled())
        {
            itemScrolling = gameObject.AddComponent <ItemScrollingVR>();
        }
        else
        {
            itemScrolling = gameObject.AddComponent <ItemScrollingNonVR>();
        }
        itemScrolling.Scrolled += ItemScrolling_Scrolled;
    }
Ejemplo n.º 12
0
 public static void Initialize()
 {
     pointerTexture = new Texture2D(256, 1);
     // Note: ImageConversion.LoadImage automatically invokes Apply.
     ImageConversion.LoadImage(pointerTexture, File.ReadAllBytes(Main.mod.Path + "tutorial_UI_gradient_opaque.png"));
     // Solely based on command line args, so fine to init ASAP.
     if (VRManager.IsVREnabled())
     {
         ChangeFloatieText        = ChangeFloatieTextVR;
         HideFloatie              = HideFloatVR;
         ShowFloatie              = ShowFloatVR;
         UpdateAttentionTransform = UpdateAttentionTransformVR;
     }
     else
     {
         ChangeFloatieText        = ChangeFloatieTextNonVR;
         HideFloatie              = HideFloatNonVR;
         ShowFloatie              = ShowFloatNonVR;
         UpdateAttentionTransform = UpdateAttentionTransformNonVR;
     }
 }
Ejemplo n.º 13
0
        private void MakeButton(Transform parent, float left, float bottom, float width, float height, int page)
        {
            var container = new GameObject("link_to_" + page);

            container.transform.parent        = parent;
            container.transform.localPosition = Project(new Vector2(left + width / 2, bottom + height / 2));
            container.transform.localRotation = Quaternion.identity;
            var go = GameObject.CreatePrimitive(PrimitiveType.Cube);
            var mr = go.GetComponent <MeshRenderer>();

            mr.material.SetOverrideTag("RenderType", "TransparentCutout");
            mr.material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            mr.material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
            mr.material.SetInt("_ZWrite", 1);
            mr.material.EnableKeyword("_ALPHATEST_ON");
            mr.material.DisableKeyword("_ALPHABLEND_ON");
            mr.material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
            mr.material.renderQueue    = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
            mr.material.color          = Color.clear;
            go.transform.parent        = container.transform;
            go.transform.localPosition = Vector3.zero;
            go.transform.localRotation = Quaternion.identity;
            var size = ProjectSize(new Vector2(width, height));

            go.transform.localScale = new Vector3(size.y, 0.001f, size.x);
            var spec = go.AddComponent <Button>();

            spec.useJoints       = false;
            spec.createRigidbody = !VRManager.IsVREnabled();
            var button = go.GetComponent <ButtonBase>();

            button.add_Used(() =>
            {
                _book.FlipTo(page);
            });
        }
Ejemplo n.º 14
0
        static void OnUpdate(UnityModManager.ModEntry mod, float delta)
        {
            timer += delta;
            if (!floatLoaded)
            {
                floatLoaded = Floaties.Initialize();
            }
            else if (!listenersSetup)
            {
                // eyesTransform = PlayerManager.PlayerCamera.transform;
                if (VRManager.IsVREnabled())
                {
                    VRTK_InteractGrab lGrab = VRTK_DeviceFinder.GetControllerLeftHand(true)?.transform.GetComponentInChildren <VRTK_InteractGrab>();
                    VRTK_InteractGrab rGrab = VRTK_DeviceFinder.GetControllerRightHand(true)?.transform.GetComponentInChildren <VRTK_InteractGrab>();
                    if (lGrab == null || rGrab == null)
                    {
                        return;
                    }
                    lGrab.ControllerGrabInteractableObject        += OnItemGrabbedLeftVR;
                    lGrab.ControllerStartUngrabInteractableObject += OnItemUngrabbedLeftVR;
                    rGrab.ControllerGrabInteractableObject        += OnItemGrabbedRightVR;
                    rGrab.ControllerStartUngrabInteractableObject += OnItemUngrabbedRightVR;
                }
                else
                {
                    Grabber grab = PlayerManager.PlayerTransform.GetComponentInChildren <Grabber>();
                    grab.Grabbed  += OnItemGrabbedRightNonVR;
                    grab.Released += OnItemUngrabbedRightNonVR;
                    SingletonBehaviour <Inventory> .Instance.ItemAddedToInventory += OnItemAddedToInventory;
                }

                mod.Logger.Log(string.Format("Listeners have been set up, total time elapsed: {0:0.00} seconds.", timer));
                listenersSetup = true;
            }
            else
            {
                if (showing)
                {
                    if (holdingRight == null || !showFloat)
                    {
                        Floaties.HideFloatie();
                        showing = false;
                    }
                    else
                    {
                        if (timer > POINTER_INTERVAL)
                        {
                            counter++;
                            timer %= POINTER_INTERVAL;
                            // Calculate tracks that cars are on.
                            holdingRight.UpdateJobCars();
                            holdingRight.UpdateJobPrivilege();
                            Floaties.ChangeFloatieText(holdingRight.GetFloatieText(counter));
                            Floaties.UpdateAttentionTransform(holdingRight.GetPointerAt(counter));
                        }
                    }
                }
                else if (!showing && holdingRight != null && showFloat)
                {
                    // TODO: Read job information and process text accordingly.
                    Floaties.ShowFloatie(holdingRight.GetFloatieText(counter));
                    Floaties.UpdateAttentionTransform(holdingRight.GetPointerAt(counter));
                    showing = true;
                    timer   = 0;
                }
            }
        }
Ejemplo n.º 15
0
        public static bool Initialize()
        {
            if (pointerTexture == null)
            {
                pointerTexture = new Texture2D(256, 1);
                // Note: ImageConversion.LoadImage automatically invokes Apply.
                ImageConversion.LoadImage(pointerTexture, File.ReadAllBytes(Main.mod.Path + "tutorial_UI_gradient_opaque.png"));
            }

            if (VRManager.IsVREnabled())
            {
                ChangeFloatieText        = ChangeFloatieTextVR;
                HideFloatie              = HideFloatVR;
                ShowFloatie              = ShowFloatVR;
                UpdateAttentionTransform = UpdateAttentionTransformVR;
            }
            else if (LoadingScreenManager.IsLoading || !WorldStreamingInit.IsLoaded ||
                     !SingletonBehaviour <InventoryStartingItems> .Instance.itemsLoaded)
            {
                return(false);
            }
            else
            {
                GameObject g = GameObject.Find("[NonVRFloatie]");
                if (g == null)
                {
                    SceneManager.LoadScene("non_vr_ui_floatie", LoadSceneMode.Additive);
                    g = GameObject.Find("[NonVRFloatie]");
                }

                if (g == null)
                {
                    return(false);
                }
                g = GameObject.Instantiate(g); // The tutorial sequence destroys non VR floaties, so make our own.

                Image i = g.GetComponentInChildren <Image>(true);
                if (i == null)
                {
                    return(false);
                }
                floatieNonVR = i.gameObject;
                Main.mod.Logger.Log("Found the non VR float.");

                floatieNonVRText = floatieNonVR.GetComponentInChildren <TextMeshProUGUI>(true);
                if (floatieNonVRText == null)
                {
                    return(false);
                }
                Main.mod.Logger.Log("Found the non VR text.");

                floatieNonVRLine = floatieNonVR.GetComponentInChildren <TutorialLineNonVR>(true);
                if (floatieNonVRLine == null)
                {
                    return(false);
                }
                Main.mod.Logger.Log("Found the non VR line.");

                ChangeFloatieText        = ChangeFloatieTextNonVR;
                HideFloatie              = HideFloatNonVR;
                ShowFloatie              = ShowFloatNonVR;
                UpdateAttentionTransform = UpdateAttentionTransformNonVR;
            }

            Main.mod.Logger.Log("Floaties have been set up.");
            return(true);
        }