10using System.Collections.Generic;
19 public partial class LeapGraphicRenderer : MonoBehaviour, ISerializationCallbackReceiver {
26 #region INSPECTOR FIELDS
29 private bool _lastSpaceWasNull =
true;
32 private List<LeapGraphicGroup> _groups =
new List<LeapGraphicGroup>();
35 #region PUBLIC RUNTIME API
51 public List<LeapGraphicGroup>
groups {
62 return _groups.Query().FirstOrDefault(g => g.name == name);
81 foreach (var group
in groups) {
82 if (group.name == graphic.favoriteGroupName) {
83 if (group.TryAddGraphic(graphic)) {
91 Type preferredType = graphic.preferredRendererType;
92 if (preferredType !=
null) {
93 foreach (var group
in groups) {
95 if (preferredType == rendererType ||
96 rendererType.IsSubclassOf(preferredType)) {
97 if (targetGroup ==
null || group.toBeAttachedCount < targetGroup.toBeAttachedCount) {
104 if (targetGroup !=
null && targetGroup.TryAddGraphic(graphic)) {
109 foreach (var group
in groups) {
110 if (group.renderingMethod.IsValidGraphic(graphic)) {
111 if (targetGroup ==
null || group.toBeAttachedCount < targetGroup.toBeAttachedCount) {
117 if (targetGroup !=
null && targetGroup.TryAddGraphic(graphic)) {
127 #region UNITY CALLBACKS
128 private void OnValidate() {
130 if (!InternalUtility.IsPrefab(
this)) {
131 if (!Application.isPlaying) {
132 editor.ScheduleRebuild();
139 private void OnDestroy() {
145 private void OnEnable() {
148 foreach (var group
in _groups) {
149 foreach (var feature
in group.features) {
150 LeapSpriteFeature spriteFeature = feature as LeapSpriteFeature;
151 if (spriteFeature !=
null) {
152 foreach (var data
in spriteFeature.featureData) {
159 UnityEditor.Undo.undoRedoPerformed -= onUndoRedoPerformed;
160 UnityEditor.Undo.undoRedoPerformed += onUndoRedoPerformed;
163 if (Application.isPlaying) {
164 if (_space !=
null) {
167 _lastSpaceWasNull =
false;
170 foreach (var group
in _groups) {
176 private void OnDisable() {
177 if (Application.isPlaying) {
178 foreach (var group
in _groups) {
184 UnityEditor.Undo.undoRedoPerformed += onUndoRedoPerformed;
188 private void LateUpdate() {
191 if (InternalUtility.IsPrefab(
this)) {
195 if (!Application.isPlaying) {
196 editor.DoLateUpdateEditor();
200 doLateUpdateRuntime();
205 #region PRIVATE IMPLEMENTATION
207 private LeapGraphicRenderer() {
209 editor =
new EditorApi(
this);
213 private void doLateUpdateRuntime() {
217 if (_space !=
null) {
219 using (
new ProfilerSample(
"Refresh space data")) {
224 foreach (var group
in _groups) {
225 group.UpdateRenderer();
230 var origSpace = _space;
232 var spaces = Pool<List<LeapSpace>>.Spawn();
235 GetComponents<LeapSpace>(spaces);
236 _space = spaces.Query().FirstOrDefault(s => s.enabled);
240 Pool<List<LeapSpace>>.Recycle(spaces);
244 bool didUndoRedo =
false;
246 if (_didUndoRedoThisFrame) {
248 _didUndoRedoThisFrame =
false;
252 if (Application.isPlaying
253 && (origSpace != _space
254 || (_space ==
null && !_lastSpaceWasNull))
257 onRuntimeSpaceChanged();
260 _lastSpaceWasNull = _space ==
null;
264 private bool _didUndoRedoThisFrame =
false;
266 private void onUndoRedoPerformed() {
267 _didUndoRedoThisFrame =
true;
271 private void onRuntimeSpaceChanged() {
274 if (_space !=
null) {
286 foreach (var group
in _groups) {
287 group.RefreshGraphicAnchors();
294 foreach (var group
in _groups) {
LeapRenderingMethod renderingMethod
Gets the rendering method used for this group. This can only be changed at edit time using either the...
const string FEATURE_PREFIX
const string PROPERTY_PREFIX
bool TryAddGraphic(LeapGraphic graphic)
Tries to add the given graphic to any group attached to this graphic. First, it will try to be attach...
const string FEATURE_MOVEMENT_FULL
LeapGraphicGroup FindGroup(string name)
Searches the group list for a group with the given name. If there is no group with the given name,...
void validateSpaceComponent()
LeapSpace space
Returns the leap space that is currently attached to this graphic renderer.
const string FEATURE_MOVEMENT_TRANSLATION
void OnAfterDeserialize()
List< LeapGraphicGroup > groups
Returns a list of all graphic groups contained withinin this renderer. This getter returns a regular ...
void RecalculateTransformers()
Call to update all transformers in the space. Call this whenever any anchor or parent of an anchor ch...
void RebuildHierarchy()
Call to traverse the entire hierarchy and rebuild the relationship between anchors....