16 private enum VanishType
22 private enum AppearType
35 private Vector3 defaultDimensions =
new Vector3(0.182f, 0.028f, 1.0f);
38 private bool showBackground =
true;
41 private bool showOutline =
false;
44 private bool showConnector =
true;
47 private AppearType appearType = AppearType.AppearOnFocusEnter;
50 private VanishType vanishType = VanishType.VanishOnFocusExit;
57 private float appearDelay = 0.0f;
61 private float vanishDelay = 2.0f;
65 private float lifetime = 1.0f;
68 private GameObject toolTipPrefab = null;
83 private Vector3 manualPivotDirection = Vector3.up;
86 private Vector3 manualPivotLocalPosition = Vector3.up;
91 private float pivotDistance = 0.25f;
95 private string ToolTipText =
"New Tooltip";
98 private Transform Anchor = null;
100 private float focusEnterTime = 0f;
102 private float focusExitTime = 0f;
104 private float tappedTime = 0f;
106 private bool hasFocus;
116 focusEnterTime = Time.unscaledTime;
118 if (toolTip == null || !toolTip.gameObject.activeSelf)
122 case AppearType.AppearOnFocusEnter:
134 focusExitTime = Time.unscaledTime;
140 tappedTime = Time.unscaledTime;
141 if (toolTip == null || !toolTip.gameObject.activeSelf)
143 if( appearType == AppearType.AppearOnTap)
156 private void ShowToolTip()
158 StartCoroutine(UpdateTooltip(focusEnterTime, tappedTime));
161 private IEnumerator UpdateTooltip(
float focusEnterTimeOnStart,
float tappedTimeOnStart)
165 GameObject toolTipGo = GameObject.Instantiate(toolTipPrefab) as GameObject;
166 toolTip = toolTipGo.GetComponent<
ToolTip>();
167 toolTip.gameObject.SetActive(
false);
171 toolTip.transform.position = transform.position;
172 toolTip.transform.parent = transform;
176 if( appearType == AppearType.AppearOnFocusEnter)
179 yield
return new WaitForSeconds(appearDelay);
188 toolTip.gameObject.SetActive(
true);
190 connector.
Target = (Anchor != null) ? Anchor.gameObject : gameObject;
200 toolTip.
PivotPosition = transform.TransformPoint(manualPivotLocalPosition);
203 while (toolTip.gameObject.activeSelf)
207 if (appearType == AppearType.AppearOnTap)
209 if (Time.unscaledTime - tappedTime >= lifetime)
211 toolTip.gameObject.SetActive(
false);
215 else if (appearType == AppearType.AppearOnFocusEnter)
217 if (Time.unscaledTime - focusEnterTime >= lifetime)
219 toolTip.gameObject.SetActive(
false);
228 case VanishType.VanishOnFocusExit:
231 case VanishType.VanishOnTap:
232 if (tappedTime != tappedTimeOnStart)
234 toolTip.gameObject.SetActive(
false);
241 if (Time.time - focusExitTime > vanishDelay)
243 toolTip.gameObject.SetActive(
false);
254 private void OnDrawGizmos()
256 if (Application.isPlaying)
259 if (gameObject ==
UnityEditor.Selection.activeGameObject)
261 Gizmos.color = Color.cyan;
262 Transform relativeTo = null;
263 switch (pivotDirectionOrient) {
265 relativeTo = Camera.main.transform;
269 relativeTo = (Anchor != null) ? Anchor.transform : transform;
273 Vector3 targetPosition = (Anchor != null) ? Anchor.transform.position : transform.position;
276 manualPivotDirection,
277 relativeTo) * pivotDistance;
278 Gizmos.DrawLine(targetPosition, toolTipPosition);
279 Gizmos.DrawWireCube(toolTipPosition, Vector3.one * 0.05f);
281 Vector3 targetPosition = (Anchor != null) ? Anchor.transform.position : transform.position;
282 Vector3 toolTipPosition = transform.TransformPoint (manualPivotLocalPosition);
283 Gizmos.DrawLine(targetPosition, toolTipPosition);
284 Gizmos.DrawWireCube(toolTipPosition, Vector3.one * 0.05f);