Apologize for if I use the thread incorrectly.
I followed Microsoft tutorial to create a project that I can modify according to my requirement. But the problem is when I press the “rotate button”, I can rotate the focused object correctly, however, when I stop and release the tap gesture, the state will be changed back to ‘translate’ state, which means if I want to rotate again, I will need to press the rotate button once more.
I have tried so many ways to achieve this, the current most hopeful manner is :
I added two tasks in my ButtonAction script, and when I click a button, the recognizer will be changed to specific state. Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//using UnityEngine.XR.WSA.Input;
namespace Academy.HoloToolkit.Unity
{
public class ButtonAction : MonoBehaviour
{
public Button AssignYourButton;
// Use this for initialization
void Start()
{
//Button btn = AssignYourButton.GetComponent<Button>();
AssignYourButton.GetComponent<Button>().onClick.AddListener(TaskOnClickTranslate);
AssignYourButton.GetComponent<Button>().onClick.AddListener(TaskOnClickRotate);
//btn.onClick.AddListener(TaskOnClickRotate);
//btn.onClick.AddListener(TaskOnClickReset);
}
// Update is called once per frame
void Update()
{
//Button btn = AssignYourButton.GetComponent<Button>();
if (AssignYourButton.GetComponent<Button>().name == "Translate")
{
TaskOnClickTranslate();
}
else if (AssignYourButton.GetComponent<Button>().name == "Rotate")
{
TaskOnClickRotate();
}
//else if(btn.name == "Reset")
//{
// TaskOnClickReset();
//}
}
void TaskOnClickTranslate()
{
//GameObject astro=GameObject.Find
Debug.Log("You have clicked the button for translation!");
GestureManager.Instance.Transition(GestureManager.Instance.ManipulationRecognizer);
print("Translate");
}
void TaskOnClickRotate()
{
Debug.Log("You have clicked the button for rotation!");
GestureManager.Instance.Transition(GestureManager.Instance.NavigationRecognizer);
print("Rotate");
}
}
}
And in the GestureManger script, there is nothing special: two recognizer initialized in Awake function, and no action in the Update function.
Here is also nothing new in GestureAction script:
private void Start()
{
}
void Update()
{
}
private void PerformRotation()
{
if (GestureManager.Instance.IsNavigating
&&
(!ExpandModel.Instance.IsModelExpanded ||
(ExpandModel.Instance.IsModelExpanded && HandsManager.Instance.FocusedGameObject == gameObject))
)
{
/* TODO: DEVELOPER CODING EXERCISE 2.c */
// 2.c: Calculate rotationFactor based on GestureManager's NavigationPosition.X and multiply by RotationSensitivity.
// This will help control the amount of rotation.
rotationFactorX = GestureManager.Instance.NavigationPosition.x * RotationSensitivity;
rotationFactorY = GestureManager.Instance.NavigationPosition.y * RotationSensitivity;
// 2.c: transform.Rotate along the Y axis using rotationFactor.
transform.Rotate(new Vector3(-1 * rotationFactorY, -1 * rotationFactorX, 0));
}
}
void PerformManipulationStart(Vector3 position)
{
manipulationPreviousPosition = position;
}
void PerformManipulationUpdate(Vector3 position)
{
if (GestureManager.Instance.IsManipulating)
{
//GestureManager.Instance.Transition(GestureManager.Instance.ManipulationRecognizer);
/* TODO: DEVELOPER CODING EXERCISE 4.a */
Vector3 moveVector = Vector3.zero;
// 4.a: Calculate the moveVector as position - manipulationPreviousPosition.
moveVector = position - manipulationPreviousPosition;
// 4.a: Update the manipulationPreviousPosition with the current position.
manipulationPreviousPosition = position;
// 4.a: Increment this transform's position by the moveVector.
transform.position += moveVector;
}
}