CubismLookTarget.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * Copyright(c) Live2D Inc. All rights reserved.
  3. *
  4. * Use of this source code is governed by the Live2D Open Software license
  5. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
  6. */
  7. using Live2D.Cubism.Framework.LookAt;
  8. using UnityEngine;
  9. namespace Live2D.Cubism.Samples.OriginalWorkflow.Demo
  10. {
  11. public class CubismLookTarget : MonoBehaviour, ICubismLookTarget
  12. {
  13. /// <summary>
  14. /// Get mouse coordinates while dragging.
  15. /// </summary>
  16. /// <returns>Mouse coordinates.</returns>
  17. public Vector3 GetPosition()
  18. {
  19. if (!Input.GetMouseButton(0))
  20. {
  21. return Vector3.zero;
  22. }
  23. var targetPosition = Input.mousePosition;
  24. targetPosition = (Camera.main.ScreenToViewportPoint(targetPosition) * 2) - Vector3.one;
  25. return targetPosition;
  26. }
  27. /// <summary>
  28. /// Gets whether the target is active.
  29. /// </summary>
  30. /// <returns><see langword="true"/> if the target is active; <see langword="false"/> otherwise.</returns>
  31. public bool IsActive()
  32. {
  33. return true;
  34. }
  35. }
  36. }