Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. //
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. // Licensed under the MIT License. See LICENSE in the project root for license information.
  4. //
  5. using HUX.Buttons;
  6. using UnityEngine;
  7.  
  8. namespace HUX.Interaction
  9. {
  10. /// <summary>
  11. /// This script assists in using a bounding box to target objects
  12. /// Bounding boxes and manipulation toolbars can both be used without this script
  13. /// But this makes it easier to use a single bounding box to target multiple objects
  14. /// as well as to specify per-target display options and operations
  15. /// </summary>
  16. [RequireComponent (typeof (CompoundButton))]
  17. public class BoundingBoxTarget : MonoBehaviour {
  18.  
  19. /// <summary>
  20. /// Tags to use when selected / deselected
  21. /// This should be set to something the FocusManager will ignore
  22. /// Otherwise the colliders from this object may occlude bounding box
  23. /// </summary>
  24. public FilterTag TagOnSelected;
  25. public FilterTag TagOnDeselected;
  26.  
  27. /// <summary>
  28. /// Which operations will be permitted when the bounding box targets this object
  29. /// </summary>
  30. [HideInInspector]
  31. public BoundingBoxManipulate.OperationEnum PermittedOperations = BoundingBoxManipulate.OperationEnum.Drag | BoundingBoxManipulate.OperationEnum.ScaleUniform | BoundingBoxManipulate.OperationEnum.RotateY;
  32.  
  33. /// <summary>
  34. /// Whether to show the manipulation display when the bounding box targets this object
  35. /// </summary>
  36. [HideInInspector]
  37. public bool ShowAppBar = true;
  38.  
  39. /// <summary>
  40. /// Bounding box to use. If this is not set, the first bounding box in the scene will be used.
  41. /// </summary>
  42. private BoundingBoxManipulate boundingBox;
  43.  
  44. /// <summary>
  45. /// Manipulation toolbar to use. If this is not set, the first toolbar in the scene will be uesd.
  46. /// </summary>
  47. private AppBar toolbar;
  48.  
  49. private void Start()
  50. {
  51. // 以下、4行を追記
  52. TagOnSelected = new FilterTag();
  53. TagOnSelected.Tag = "hidden";
  54. TagOnDeselected = new FilterTag();
  55. TagOnDeselected.Tag = FilterTag.DefaultTag;
  56.  
  57. Button button = GetComponent<Button>();
  58. button.FilterTag = TagOnDeselected;
  59. }
  60.  
  61. public void OnTargetSelected()
  62. {
  63. //Debug.Log("Selecting target" + name);
  64. GetComponent<Button>().FilterTag = TagOnSelected;
  65. }
  66.  
  67. public void OnTargetDeselected ()
  68. {
  69. //Debug.Log("Deselecting target " + name);
  70. GetComponent<Button>().FilterTag = TagOnDeselected;
  71. }
  72.  
  73. public void Tapped()
  74. {
  75.  
  76. // Return if there isn't a Manipulation Manager
  77. if (ManipulationManager.Instance == null)
  78. {
  79. Debug.LogError("No manipulation manager for " + name);
  80. return;
  81. }
  82.  
  83. // Try to find our bounding box
  84. if (boundingBox == null)
  85. {
  86. boundingBox = ManipulationManager.Instance.ActiveBoundingBox;
  87. }
  88.  
  89. // Try to find our toolbar
  90. if (toolbar == null)
  91. {
  92. toolbar = ManipulationManager.Instance.ActiveAppBar;
  93. }
  94.  
  95. // If we've already got a bounding box and it's pointing to us, do nothing
  96. if (boundingBox != null && boundingBox.Target == this.gameObject)
  97. return;
  98.  
  99. // Set the bounding box's target and permitted operations
  100. boundingBox.PermittedOperations = PermittedOperations;
  101. boundingBox.Target = gameObject;
  102.  
  103. if (ShowAppBar)
  104. {
  105. // Show it and set its bounding box object
  106. toolbar.BoundingBox = boundingBox;
  107. toolbar.Reset();
  108. } else if (toolbar != null)
  109. {
  110. // Set its bounding box to null to hide it
  111. toolbar.BoundingBox = null;
  112. // Set to accept input immediately
  113. boundingBox.AcceptInput = true;
  114. }
  115. }
  116.  
  117. private void OnDestroy ()
  118. {
  119. if (boundingBox != null && boundingBox.Target == this)
  120. boundingBox.Target = null;
  121. }
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement