private CreatureStateHud.TUIElement GetElementForTouch(TouchData touchData, CreatureState creatureState, UnityEngine.Vector2 currentPosition) { for (int index = 0; index < _weaponUIDataArray.Count; ++index) { WeaponUIData weaponUIData = _weaponUIDataArray[index]; if ((false == weaponUIData.clickedOn) && (weaponUIData.rect.Contains(touchData.start))) { CreatureStateHud.THandPose pose = CreatureStateHud.THandPose.Swing; var distance = (currentPosition - touchData.start).magnitude; var position = currentPosition; if (distance < weaponUIData.rect.width * 0.5f) { pose = CreatureStateHud.THandPose.Shoot; position = new UnityEngine.Vector2(UnityEngine.Screen.width * 0.5f, UnityEngine.Screen.height * 0.5f) + (currentPosition - touchData.start); } creatureState.creatureStateHud.handPoseArray.Add(new CreatureStateHud.HandPoseData() { handPose = pose, position = position }); weaponUIData.clickedOn = true; _weaponUIDataArray[index] = weaponUIData; return(CreatureStateHud.TUIElement.None); } } //dont start a move/ hand action if click was on foreach (CreatureStateHud.UIElementData uiElementData in creatureState.creatureStateHud.uiElementDataArray) { //uiElementData.r var rect = CreatureHud2D.UIPositionToRect(uiElementData.position); if (rect.Contains(touchData.start)) { return(CreatureStateHud.TUIElement.None); } } CreatureStateHud.TUIElement uiElement = CreatureStateHud.TUIElement.None; if (touchData.start.x < (UnityEngine.Screen.width * 0.25f)) { uiElement = CreatureStateHud.TUIElement.Movement; } else if ((UnityEngine.Screen.width * 0.75f) < touchData.start.x) { uiElement = CreatureStateHud.TUIElement.View; } else { uiElement = CreatureStateHud.TUIElement.None; creatureState.creatureStateHud.handPoseArray.Add(new CreatureStateHud.HandPoseData() { handPose = CreatureStateHud.THandPose.Empty, position = currentPosition }); } return(uiElement); }
private void DealEndTouch(CreatureState creatureState, TouchData touchData, CreatureStateHud.TUIElement uiElement) { //do we have jump input if ((crouchTime < touchData.duration) || (CreatureStateHud.TUIElement.Movement != uiElement)) { return; } var normalisedRatio = ((touchData.duration / crouchTime) * 2.0f) - 1.0f; //normalise -1 ... 1 var temp = normalisedRatio * normalisedRatio; creatureState.creatureStateInput.jump = 1.0f - temp; }
private void AddMoveView(CreatureState creatureState, TouchData touchData, UnityEngine.Vector2 currentPosition, CreatureStateHud.TUIElement uiElement) { var offset = (currentPosition - touchData.start) / 100.0f; var length = offset.magnitude; if (UnityEngine.Mathf.Approximately(0.0f, length)) { return; } var normal = offset / length; var inputLength = UnityEngine.Mathf.Min(length, 1.0f) * 0.25f; switch (uiElement) { default: break; case CreatureStateHud.TUIElement.Movement: creatureState.creatureStateInput.inputMove += (normal * inputLength); break; case CreatureStateHud.TUIElement.View: creatureState.creatureStateInput.inputView += new UnityEngine.Vector2( normal.x * UnityEngine.Mathf.Min(length * 2.0f, 1.0f), normal.y * length * 2.0f ); break; } }
private void DealCrouch(CreatureState creatureState, TouchData touchData, UnityEngine.Vector2 currentPosition, CreatureStateHud.TUIElement uiElement) { //do we have crouch input if (CreatureStateHud.TUIElement.Movement != uiElement) { return; } var length = (touchData.start - currentPosition).magnitude; if (80.0f < length) { return; } length /= 80.0f; length *= length; var factor = 1.0f - length; //var crouch = UnityEngine.Mathf.Min(1.0f, touchData.duration / crouchTime); creatureState.creatureStateInput.crouch += factor; // (crouch * factor); }