10using System.Collections.Generic;
20 [DisallowMultipleComponent]
21 public abstract partial class LeapGraphic : MonoBehaviour,
ISpaceComponent, ISerializationCallbackReceiver {
23 #region INSPECTOR FIELDS
46 private bool _willBeAttached =
false;
48 private bool _willBeDetached =
false;
52 private bool _isRepresentationDirty =
true;
66 return _isRepresentationDirty;
69 _isRepresentationDirty = value;
80 if (!Application.isPlaying) {
84 return _isRepresentationDirty;
175 return _willBeAttached;
186 return _willBeDetached;
209 if (attachedGroup ==
null) {
221 return _featureData.Query().OfType<T>().FirstOrDefault();
229 Assert.IsFalse(_willBeAttached);
230 Assert.IsNull(_groupToBeAttachedTo);
232 _willBeAttached =
true;
233 _groupToBeAttachedTo = toBeAttachedTo;
241 Assert.IsTrue(_willBeAttached);
242 Assert.IsNotNull(_groupToBeAttachedTo);
244 _willBeAttached =
false;
245 _groupToBeAttachedTo =
null;
253 Assert.IsFalse(_willBeDetached);
255 _willBeDetached =
true;
263 Assert.IsTrue(_willBeDetached);
265 _willBeDetached =
false;
274 editor.OnAttachedToGroup(group,
anchor);
277 _willBeAttached =
false;
278 _groupToBeAttachedTo =
null;
304 _willBeDetached =
false;
325 foreach (var dataObj
in data) {
331 #region UNITY CALLBACKS
333 var rectTransform = GetComponent<RectTransform>();
334 if (rectTransform !=
null &&
335 Mathf.Abs(rectTransform.sizeDelta.x - 100) < Mathf.Epsilon &&
336 Mathf.Abs(rectTransform.sizeDelta.y - 100) < Mathf.Epsilon) {
337 rectTransform.sizeDelta = Vector3.one * 0.1f;
340 var parentRenderer = GetComponentInParent<LeapGraphicRenderer>();
341 if (parentRenderer !=
null) {
342 parentRenderer.TryAddGraphic(
this);
360 preferredGroup.TryAddGraphic(
this);
376 editor.OnDrawGizmos();
382 #region PRIVATE IMPLEMENTATION
386 editor =
new EditorApi(
this);
389 protected LeapGraphic(EditorApi editor) {
390 this.editor = editor;
402 private void patchReferences() {
411 private T getFeatureDataOrThrow<T>() where T : LeapFeatureData {
412 var data =
_featureData.Query().OfType<T>().FirstOrDefault();
414 throw new Exception(
"There is not a feature data object of type " + typeof(T).Name +
" attached to this graphic.");
424 CustomFloatChannelData,
425 CustomVectorChannelData,
426 CustomColorChannelData,
427 CustomMatrixChannelData> { }
List< LeapGraphic > graphics
Returns the list of graphics attached to this group. This getter returns a regular mutable list for s...
bool TryRemoveGraphic(LeapGraphic graphic)
Tries to remove the given graphic from this group. This can safely be called during runtime or edit t...
LeapGraphicRenderer renderer
Gets the renderer this group is attached to.
bool isAttachedToGroup
Returns whether or not this graphic is attached to any group. Can still return false at runtime even ...
IList< LeapFeatureData > featureData
Returns a list of feature data attached to this graphic. If this graphic is attached to a group,...
virtual void OnValidate()
bool TryDetach()
This method tries to detach this graphic from whatever group it is currently attached to....
virtual void OnAfterDeserialize()
bool isRepresentationDirty
An internal flag that returns true if the visual representation of this graphic needs to be updated....
virtual void NotifyWillBeAttached(LeapGraphicGroup toBeAttachedTo)
Called by the system to notify that this graphic will be attached within the next frame....
void OnUpdateAnchor(LeapSpaceAnchor anchor)
Called by graphic groups when a renderer's attached space changes.
bool willbeDetached
Returns whether or not this graphic will be detached from a group within the next frame....
LeapSpaceAnchor anchor
Returns the space anchor for this graphic. This will be null if the graphic is not currently part of ...
FeatureDataList _featureData
T GetFeatureData< T >()
Gets a single feature data object of a given type T. This will return null if there is no feature dat...
SerializableType _preferredRendererType
string _favoriteGroupName
virtual void CancelWillBeDetached()
Called by the system to notify that a previous notification that this graphic would be detached has b...
virtual void OnDrawGizmos()
LeapGraphicGroup attachedGroup
Returns the group this graphic is attached to.
virtual void OnBeforeSerialize()
virtual void CancelWillBeAttached()
Called by the system to notify that a previous notification that this graphic would be attached has b...
virtual void OnAttachedToGroup(LeapGraphicGroup group, LeapSpaceAnchor anchor)
Called by the system when this graphic is attached to a group. This method is invoked both at runtime...
string favoriteGroupName
Gets or sets the name of the group that this graphic likes to be attached to. Whenever a graphic is e...
bool isRepresentationDirtyOrEditTime
A simple utility getter that returns true if isRepresentationDirty is true, OR it is currently edit t...
virtual void OnDetachedFromGroup()
Called by the system when this graphic is detached from a group. This method is invoked both at runti...
virtual void NotifyWillBeDetached(LeapGraphicGroup toBeDetachedFrom)
Called by the system to notify that this graphic will be detached within the next frame....
Action< LeapGraphicGroup > OnAttachedToGroupEvent
ITransformer transformer
A utility getter that returns a transformer for this graphic. Even if the space anchor for this graph...
bool willbeAttached
Returns whether or not this graphic will be attached to a group within the next frame....
virtual void OnAssignFeatureData(List< LeapFeatureData > data)
Called by the system whenever feature data is re-assigned to this graphic. This is only called at edi...
Type preferredRendererType
Returns the type this graphic prefers to be attached to. When calling LeapGraphicRenderer....
LeapGraphicRenderer _attachedRenderer
Action OnDetachedFromGroupEvent
List< LeapGraphicGroup > groups
Returns a list of all graphic groups contained withinin this renderer. This getter returns a regular ...
Represents an ordered collection of objects of type BaseType.
abstract void Add(BaseType obj)