// Apply Head Bobbing Effect on User Camera //private void ApplyHeadBobbing() //{ // UserCam.transform.localPosition = new Vector3(BobbingForce.x * Mathf.Sin(headBobbingTimer * BobbingSpeed.x), // BobbingForce.y * Mathf.Cos(headBobbingTimer * BobbingSpeed.y), 0f); //} /// <summary> /// On selection, rotate the current hand the other way around (if Left). /// </summary> /// <param name="hand">Current item hand</param> protected override void ConstructOver(VRHand.Hand hand) { if (hand == VRHand.Hand.LEFT) { Vector3 oScale = GetComponentInChildren <MeshRenderer>().transform.localScale, oRotate = GetComponentInChildren <MeshRenderer>().transform.localRotation.eulerAngles; GetComponentInChildren <MeshRenderer>().transform.localScale = new Vector3(oScale.x, oScale.y, -oScale.z); GetComponentInChildren <MeshRenderer>().transform.localRotation = Quaternion.Euler(new Vector3(-oRotate.x, oRotate.y, oRotate.z)); } }
/// <summary> /// Called on Item selection, allow current item to be modified accordingly. /// </summary> /// <param name="target">Script for targetted hand object</param> /// <param name="hand">Specific Hand for Input (Right or Left)</param> public void onCreation(VRHandController target, VRHand.Hand hand) { currentInput = MGR_VRControls.get.hand(hand); //transform.localPosition = Vector3.zero; GetComponentInChildren <MeshRenderer>().sharedMaterial = target.handMaterial; target.ChangeTo(gameObject); ConstructOver(hand); }
/// <summary> /// Allow for object selection of a new Item. /// </summary> /// <param name="go">Item object prefab</param> /// <param name="target">Script for targetted hand object</param> /// <param name="hand">Specific Hand for Input (Right or Left)</param> public static void Select(GameObject go, VRHandController target, VRHand.Hand hand) { if (go == null) { return; } if (target.GetComponentInChildren <InventoryItem>() != null) { Destroy(target.GetComponentInChildren <InventoryItem>().gameObject); } GameObject obj = Instantiate(go, target.transform); obj.GetComponent <InventoryItem>().onCreation(target, hand); }
/// <summary> /// Cycle item by changing its color. /// Select item when the inventory is desactivated. /// </summary> /// <param name="hand">Current hand to cycle with</param> private void CycleItem(VRHand.Hand hand) { if (generatorInstance.inventory.Count == 0) { return; } switch (hand) { case VRHand.Hand.RIGHT: generatorInstance.invContent[RightHandIndex][0].transform.GetChild(0).GetComponent <Image>().color = Color.white; generatorInstance.invContent[RightHandIndex][0].transform.GetChild(0).GetComponent <Image>().sprite = generatorInstance.emptyImage; RightHandIndex++; if (RightHandIndex % tInvSize == LeftHandIndex) { RightHandIndex++; } RightHandIndex %= tInvSize; generatorInstance.invContent[RightHandIndex][0].transform.GetChild(0).GetComponent <Image>().color = MGR_VRControls.get.RightHand.handColor; generatorInstance.invContent[RightHandIndex][0].transform.GetChild(0).GetComponent <Image>().sprite = generatorInstance.holdingImage; break; case VRHand.Hand.LEFT: generatorInstance.invContent[LeftHandIndex][0].transform.GetChild(0).GetComponent <Image>().color = Color.white; generatorInstance.invContent[LeftHandIndex][0].transform.GetChild(0).GetComponent <Image>().sprite = generatorInstance.emptyImage; LeftHandIndex++; if (LeftHandIndex % tInvSize == RightHandIndex) { LeftHandIndex++; } LeftHandIndex %= tInvSize; generatorInstance.invContent[LeftHandIndex][0].transform.GetChild(0).GetComponent <Image>().color = MGR_VRControls.get.LeftHand.handColor; generatorInstance.invContent[LeftHandIndex][0].transform.GetChild(0).GetComponent <Image>().sprite = generatorInstance.holdingImage; break; default: return; } }
/// <summary> /// Start Function, initialize propreties and select first Button (having no purpose). /// </summary> void Start() { MenuHand = VRHand.oppositeOf(MGR_VRControls.mainHand); SwitchButton = (MenuHand == VRHand.Hand.RIGHT) ? VRButton.Code.B : VRButton.Code.Y; transform.SetParent(MenuHand == VRHand.Hand.RIGHT ? MGR_VRControls.get.RightHand.transform : MGR_VRControls.get.LeftHand.transform); transform.localPosition = new Vector3(0, .25f, 0); Actions = GetComponentsInChildren <Button>(); foreach (Button btn in Actions) { btn.image.color = UnselectedColor; } LoadButton(0); SavedPlayerPosition = VRUserController.main.transform.position; setActivaton(false); }
/// <summary> /// Start Function, initialize propreties, and inputs, and make first selection. /// </summary> void Start() { generatorInstance = GetComponentInChildren <InventoryGenerator>(); InventoryHand = MGR_VRControls.mainHand; SwitchButton = (InventoryHand == VRHand.Hand.RIGHT) ? VRButton.Code.B : VRButton.Code.Y; transform.SetParent(InventoryHand == VRHand.Hand.RIGHT ? MGR_VRControls.get.RightHand.transform : MGR_VRControls.get.LeftHand.transform); transform.localPosition = new Vector3(0, .25f, 0); generatorInstance.gameObject.SetActive(CurrentInventoryState); tInvSize = generatorInstance.invContent.Count; // First Select switch (MGR_VRControls.mainHand) { case VRHand.Hand.LEFT: LeftHandIndex = 0; RightHandIndex = 1; break; case VRHand.Hand.RIGHT: RightHandIndex = 0; LeftHandIndex = 1; break; default: break; } ComputeSelection(MGR_VRControls.get.RightHand, MGR_VRControls.get.LeftHand); generatorInstance.holdOn(0, MGR_VRControls.get.primary.handColor); generatorInstance.holdOn(1, MGR_VRControls.get.secondary.handColor); MGR_VRControls.get.primary.LateStart(); MGR_VRControls.get.secondary.LateStart(); }
/// <summary> /// Abstract function for Item selection handling (called on selection). /// </summary> /// <param name="hand">Specific Hand for Input (Right or Left)</param> protected abstract void ConstructOver(VRHand.Hand hand);
/// <summary> /// Access a specific hand scene object. /// </summary> /// <param name="_hand">Specific hand to access from</param> /// <returns>Hand scene object</returns> public VRHandController handObject(VRHand.Hand _hand) { return(_hand == VRHand.Hand.RIGHT ? RightHand : LeftHand); }
/// <summary> /// Access on a specific hand input data. /// </summary> /// <param name="_hand">Specific hand to access from</param> /// <returns>Hand input data</returns> public VRHand.Controls.HandInput hand(VRHand.Hand _hand) { return(mainInput.content[(int)_hand]); }
/// <summary> /// Set the main input Controls depending on the main hand. /// </summary> /// <param name="mainHand">Specific main hand</param> public void set(VRHand.Hand mainHand) { mainInput = VRHand.constructOver(mainHand); }
/// <summary> /// Empty overwritten method. /// </summary> /// <param name="hand">Current item's hand</param> protected override void ConstructOver(VRHand.Hand hand) { }
/// <summary> /// Default constructor. /// Take the row data of any current settings. /// </summary> /// <param name="hand">Main hand for the current user</param> /// <param name="size">Size of the player in game</param> public SettingData(VRHand.Hand hand, float size) { MainHand = hand; UserSize = size; }