Tanoda
GraphicCallbackInfo.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System;
10using UnityEngine;
11
13
14 public static class GraphicExtensions {
15
16 public static GraphicCallbackInfo.GraphicInfo OnAwake(this LeapGraphic graphic) {
17 return graphic.GetComponent<GraphicCallbackInfo>().awakeInfo;
18 }
19
20 public static GraphicCallbackInfo.GraphicInfo OnEnable(this LeapGraphic graphic) {
21 return graphic.GetComponent<GraphicCallbackInfo>().enableInfo;
22 }
23
24 public static GraphicCallbackInfo.GraphicInfo OnStart(this LeapGraphic graphic) {
25 return graphic.GetComponent<GraphicCallbackInfo>().startInfo;
26 }
27 }
28
29 public class GraphicCallbackInfo : MonoBehaviour {
30
32
33 private void Awake() {
34 awakeInfo = new GraphicInfo(gameObject);
35 }
36
37 private void OnEnable() {
38 enableInfo = new GraphicInfo(gameObject);
39 }
40
41 private void Start() {
42 startInfo = new GraphicInfo(gameObject);
43 }
44
45 public struct GraphicInfo {
46 public readonly bool hasFired;
47
48 private bool _wasAttached;
49 private LeapGraphicGroup _attachedGroup;
50
51 public bool hasNotFired {
52 get {
53 return !hasFired;
54 }
55 }
56
57 public bool wasAttached {
58 get {
59 if (!hasFired) throw new Exception("Event has not fired yet.");
60 return _wasAttached;
61 }
62 }
63
65 get {
66 if (!hasFired) throw new Exception("Event has not fired yet.");
67 return _attachedGroup;
68 }
69 }
70
71 public GraphicInfo(GameObject obj) {
72 var graphic = obj.GetComponent<LeapGraphic>();
73 hasFired = true;
74 _wasAttached = graphic.isAttachedToGroup;
75 _attachedGroup = graphic.attachedGroup;
76 }
77 }
78 }
79}