public override LeapFeatureData CreateFeatureDataForGraphic(LeapGraphic graphic) { DataType data = new DataType(); data.graphic = graphic; return(data); }
/// <summary> /// Tries to add the given graphic to any group attached to this graphic. First, it /// will try to be attached to a group that has its preferred renderer type, and if /// there are multiple such groups it will choose the group with the smallest graphic /// count. /// /// If no group has the preferred renderer type, it will try to attach to a group /// that supports this type of graphic, again choosing the group with the smallest /// graphic count. /// /// If no such group is found, the attach will fail and this method will return false. /// </summary> public bool TryAddGraphic(LeapGraphic graphic) { LeapGraphicGroup targetGroup = null; //First try to attatch to a group that is preferred Type preferredType = graphic.preferredRendererType; if (preferredType != null) { foreach (var group in groups) { Type rendererType = group.renderingMethod.GetType(); if (preferredType == rendererType || rendererType.IsSubclassOf(preferredType)) { if (targetGroup == null || group.toBeAttachedCount < targetGroup.toBeAttachedCount) { targetGroup = group; } } } } if (targetGroup != null && targetGroup.TryAddGraphic(graphic)) { return(true); } //If we failed, try to attach to a group that will take us foreach (var group in groups) { if (group.renderingMethod.IsValidGraphic(graphic)) { if (targetGroup == null || group.toBeAttachedCount < targetGroup.toBeAttachedCount) { targetGroup = group; } } } if (targetGroup != null && targetGroup.TryAddGraphic(graphic)) { return(true); } return(false); }
public abstract bool IsValidGraphic(LeapGraphic graphic);
/// <summary> /// Tries to remove the given graphic from this group. This can safely be called /// during runtime or edit time. This method can fail under the following /// conditions: /// - The graphic is not attached to this group. /// - It is runtime and add/remove is not supported by this group. /// /// At runtime the actual detachment is delayed until LateUpdate for efficiency /// reasons. Expect that even if this method returns true that the graphic will /// not actually be detached until the end of LateUpdate. /// </summary> public bool TryRemoveGraphic(LeapGraphic graphic) { Assert.IsNotNull(graphic); if (!addRemoveSupportedOrEditTime()) { return(false); } #if UNITY_EDITOR if (Application.isPlaying) #endif { if (_toDetach.Contains(graphic)) { return(false); } if (_toAttach.Contains(graphic)) { graphic.CancelWillBeAttached(); graphic.isRepresentationDirty = true; _toAttach.Remove(graphic); return(true); } } int graphicIndex = _graphics.IndexOf(graphic); if (graphicIndex < 0) { return(false); } #if UNITY_EDITOR if (!Application.isPlaying) { Undo.RecordObject(graphic, "Removed graphic from group"); Undo.RecordObject(_renderer, "Removed graphic from group"); graphic.OnDetachedFromGroup(); _graphics.RemoveAt(graphicIndex); RebuildFeatureData(); RebuildFeatureSupportInfo(); if (_renderer.space != null) { _renderer.space.RebuildHierarchy(); _renderer.space.RecalculateTransformers(); } _renderer.editor.ScheduleRebuild(); } else #endif { if (_toDetach.Contains(graphic)) { return(false); } graphic.NotifyWillBeDetached(this); _toDetach.Add(graphic); } return(true); }
/// <summary> /// Tries to add the given graphic to this group. This can safely be called /// during runtime or edit time. This method can fail under the following /// conditions: /// - The graphic is already attached to this group. /// - The graphic is already attached to a different group. /// - It is runtime and add/remove is not supported by this group. /// /// At runtime the actual attachment is delayed until LateUpdate for efficiency /// reasons. Expect that even if this method returns true that the graphic will /// not actually be attached until the end of LateUpdate. /// </summary> public bool TryAddGraphic(LeapGraphic graphic) { Assert.IsNotNull(graphic); if (graphic.willbeAttached || (graphic.isAttachedToGroup && !graphic.willbeDetached)) { return(false); } if (!addRemoveSupportedOrEditTime()) { return(false); } #if UNITY_EDITOR if (!Application.isPlaying) { Undo.RecordObject(graphic, "Added graphic to group"); } else #endif { if (_toAttach.Contains(graphic)) { return(false); } if (_toDetach.Contains(graphic)) { graphic.CancelWillBeDetached(); graphic.isRepresentationDirty = true; _toDetach.Remove(graphic); return(true); } } if (_graphics.Contains(graphic)) { if (graphic.attachedGroup == null) { //detatch and re-add, it forgot it was attached! //This can easily happen at edit time due to prefab shenanigans graphic.OnDetachedFromGroup(); _graphics.Remove(graphic); } else { Debug.LogWarning("Could not add graphic because it was already a part of this group."); return(false); } } #if UNITY_EDITOR if (!Application.isPlaying) { int newIndex = _graphics.Count; _graphics.Add(graphic); LeapSpaceAnchor anchor = _renderer.space == null ? null : LeapSpaceAnchor.GetAnchor(graphic.transform); RebuildFeatureData(); RebuildFeatureSupportInfo(); graphic.OnAttachedToGroup(this, anchor); if (_renderer.space != null) { _renderer.space.RebuildHierarchy(); _renderer.space.RecalculateTransformers(); } _renderer.editor.ScheduleRebuild(); } else #endif { if (_toAttach.Contains(graphic)) { return(false); } graphic.NotifyWillBeAttached(this); _toAttach.Add(graphic); } return(true); }
/// <summary> /// Tries to add the given graphic to any group attached to this graphic. First, it /// will try to be attached to a group that has its preferred renderer type, and if /// there are multiple such groups it will choose the group with the smallest graphic /// count. /// /// If no group has the preferred renderer type, it will try to attach to a group /// that supports this type of graphic, again choosing the group with the smallest /// graphic count. /// /// If no such group is found, the attach will fail and this method will return false. /// </summary> public bool TryAddGraphic(LeapGraphic graphic) { LeapGraphicGroup targetGroup = null; //First just try to attach to a group that is its favorite foreach (var group in groups) { if (group.name == graphic.favoriteGroupName) { if (group.TryAddGraphic(graphic)) { return(true); } } } //Then try to attatch to a group that is of the preferred type //Choose the preferred group with the least graphics Type preferredType = graphic.preferredRendererType; if (preferredType != null) { foreach (var group in groups) { Type rendererType = group.renderingMethod.GetType(); if (preferredType == rendererType || rendererType.IsSubclassOf(preferredType)) { if (targetGroup == null || group.toBeAttachedCount < targetGroup.toBeAttachedCount) { targetGroup = group; } } } } if (targetGroup != null && targetGroup.TryAddGraphic(graphic)) { return(true); } //If we failed, just try to attach to any group that will take us foreach (var group in groups) { if (group.renderingMethod.IsValidGraphic(graphic)) { if (targetGroup == null || group.toBeAttachedCount < targetGroup.toBeAttachedCount) { targetGroup = group; } } } if (targetGroup != null && targetGroup.TryAddGraphic(graphic)) { return(true); } //Unable to find any group that would accept the graphic :( return(false); }
public abstract LeapFeatureData CreateFeatureDataForGraphic(LeapGraphic graphic);
public EditorApi(LeapGraphic graphic) { _graphic = graphic; }
public static LeapSpriteData Sprite(this LeapGraphic graphic) { return(graphic.GetFeatureData <LeapSpriteData>()); }
public static LeapTextureData Texture(this LeapGraphic graphic) { return(graphic.GetFeatureData <LeapTextureData>()); }
public override LeapFeatureData CreateFeatureDataForGraphic(LeapGraphic graphic) { return(new DataType()); }