private void AddSkin(Skin skin, int slotIndex) { if (skin != null) { List <string> list = new List <string>(); skin.FindNamesForSlot(slotIndex, list); foreach (string item in list) { Attachment attachment = skin.GetAttachment(slotIndex, item); BoundingBoxAttachment boundingBoxAttachment = attachment as BoundingBoxAttachment; if (!DebugMessages || attachment == null || boundingBoxAttachment == null) { } if (boundingBoxAttachment != null && !colliderTable.ContainsKey(boundingBoxAttachment)) { PolygonCollider2D polygonCollider2D = SkeletonUtility.AddBoundingBoxAsComponent(boundingBoxAttachment, slot, base.gameObject, isTrigger); polygonCollider2D.enabled = false; polygonCollider2D.hideFlags = HideFlags.NotEditable; polygonCollider2D.isTrigger = IsTrigger; colliderTable.Add(boundingBoxAttachment, polygonCollider2D); nameTable.Add(boundingBoxAttachment, item); } } } }
void AddSkin(Skin skin, int slotIndex) { if (skin == null) { return; } var attachmentNames = new List <string>(); skin.FindNamesForSlot(slotIndex, attachmentNames); foreach (var skinKey in attachmentNames) { var attachment = skin.GetAttachment(slotIndex, skinKey); var boundingBoxAttachment = attachment as BoundingBoxAttachment; if (BoundingBoxFollower.DebugMessages && attachment != null && boundingBoxAttachment == null) { Debug.Log("BoundingBoxFollower tried to follow a slot that contains non-boundingbox attachments: " + slotName); } if (boundingBoxAttachment != null) { if (!colliderTable.ContainsKey(boundingBoxAttachment)) { var bbCollider = SkeletonUtility.AddBoundingBoxAsComponent(boundingBoxAttachment, slot, gameObject, isTrigger); bbCollider.enabled = false; bbCollider.hideFlags = HideFlags.NotEditable; bbCollider.isTrigger = IsTrigger; colliderTable.Add(boundingBoxAttachment, bbCollider); nameTable.Add(boundingBoxAttachment, skinKey); } } } }
private void AddSkin(Skin skin, int slotIndex) { if (skin != null) { List <string> names = new List <string>(); skin.FindNamesForSlot(slotIndex, names); foreach (string str in names) { Attachment attachment = skin.GetAttachment(slotIndex, str); BoundingBoxAttachment key = attachment as BoundingBoxAttachment; if ((DebugMessages && (attachment != null)) && (key == null)) { Debug.Log("BoundingBoxFollower tried to follow a slot that contains non-boundingbox attachments: " + this.slotName); } if ((key != null) && !this.colliderTable.ContainsKey(key)) { PolygonCollider2D colliderd = SkeletonUtility.AddBoundingBoxAsComponent(key, this.slot, base.gameObject, this.isTrigger, true, 0f); colliderd.enabled = false; colliderd.hideFlags = HideFlags.NotEditable; colliderd.isTrigger = this.IsTrigger; this.colliderTable.Add(key, colliderd); this.nameTable.Add(key, str); } } } }
public void HandleReset(SkeletonRenderer renderer) { if (slotName == null || slotName == "") { return; } hasReset = true; ClearColliders(); colliderTable.Clear(); if (skeletonRenderer.skeleton == null) { skeletonRenderer.OnRebuild -= HandleReset; skeletonRenderer.Initialize(false); skeletonRenderer.OnRebuild += HandleReset; } var skeleton = skeletonRenderer.skeleton; slot = skeleton.FindSlot(slotName); int slotIndex = skeleton.FindSlotIndex(slotName); foreach (var skin in skeleton.Data.Skins) { List <string> attachmentNames = new List <string>(); skin.FindNamesForSlot(slotIndex, attachmentNames); foreach (var name in attachmentNames) { var attachment = skin.GetAttachment(slotIndex, name); if (attachment is BoundingBoxAttachment) { var collider = SkeletonUtility.AddBoundingBoxAsComponent((BoundingBoxAttachment)attachment, gameObject, true); collider.enabled = false; collider.hideFlags = HideFlags.HideInInspector; colliderTable.Add((BoundingBoxAttachment)attachment, collider); attachmentNameTable.Add((BoundingBoxAttachment)attachment, name); } } } if (colliderTable.Count == 0) { valid = false; } else { valid = true; } if (!valid) { Debug.LogWarning("Bounding Box Follower not valid! Slot [" + slotName + "] does not contain any Bounding Box Attachments!"); } }
public void HandleRebuild(SkeletonRenderer renderer) { if (string.IsNullOrEmpty(this.slotName)) { return; } this.hasReset = true; this.ClearColliders(); this.colliderTable.Clear(); if (this.skeletonRenderer.skeleton == null) { SkeletonRenderer skeletonRenderer = this.skeletonRenderer; skeletonRenderer.OnRebuild = (SkeletonRenderer.SkeletonRendererDelegate)Delegate.Remove(skeletonRenderer.OnRebuild, new SkeletonRenderer.SkeletonRendererDelegate(this.HandleRebuild)); this.skeletonRenderer.Initialize(false); SkeletonRenderer skeletonRenderer2 = this.skeletonRenderer; skeletonRenderer2.OnRebuild = (SkeletonRenderer.SkeletonRendererDelegate)Delegate.Combine(skeletonRenderer2.OnRebuild, new SkeletonRenderer.SkeletonRendererDelegate(this.HandleRebuild)); } Skeleton skeleton = this.skeletonRenderer.skeleton; this.slot = skeleton.FindSlot(this.slotName); int slotIndex = skeleton.FindSlotIndex(this.slotName); if (base.gameObject.activeInHierarchy) { foreach (Skin skin in skeleton.Data.Skins) { List <string> list = new List <string>(); skin.FindNamesForSlot(slotIndex, list); foreach (string text in list) { Attachment attachment = skin.GetAttachment(slotIndex, text); BoundingBoxAttachment boundingBoxAttachment = attachment as BoundingBoxAttachment; if (boundingBoxAttachment != null) { PolygonCollider2D polygonCollider2D = SkeletonUtility.AddBoundingBoxAsComponent(boundingBoxAttachment, base.gameObject, true); polygonCollider2D.enabled = false; polygonCollider2D.hideFlags = HideFlags.NotEditable; polygonCollider2D.isTrigger = this.IsTrigger; this.colliderTable.Add(boundingBoxAttachment, polygonCollider2D); this.attachmentNameTable.Add(boundingBoxAttachment, text); } } } } }
public void HandleRebuild(SkeletonRenderer renderer) { if (string.IsNullOrEmpty(slotName)) { return; } hasReset = true; ClearColliders(); colliderTable.Clear(); if (skeletonRenderer.skeleton == null) { skeletonRenderer.OnRebuild -= HandleRebuild; skeletonRenderer.Initialize(false); skeletonRenderer.OnRebuild += HandleRebuild; } var skeleton = skeletonRenderer.skeleton; slot = skeleton.FindSlot(slotName); int slotIndex = skeleton.FindSlotIndex(slotName); if (this.gameObject.activeInHierarchy) { foreach (var skin in skeleton.Data.Skins) { var attachmentNames = new List <string>(); skin.FindNamesForSlot(slotIndex, attachmentNames); foreach (var attachmentName in attachmentNames) { var attachment = skin.GetAttachment(slotIndex, attachmentName); var boundingBoxAttachment = attachment as BoundingBoxAttachment; #if UNITY_EDITOR if (attachment != null && boundingBoxAttachment == null) { Debug.Log("BoundingBoxFollower tried to follow a slot that contains non-boundingbox attachments."); } #endif if (boundingBoxAttachment != null) { var bbCollider = SkeletonUtility.AddBoundingBoxAsComponent(boundingBoxAttachment, gameObject, true); bbCollider.enabled = false; bbCollider.hideFlags = HideFlags.NotEditable; colliderTable.Add(boundingBoxAttachment, bbCollider); attachmentNameTable.Add(boundingBoxAttachment, attachmentName); } } } } #if UNITY_EDITOR valid = colliderTable.Count != 0; if (!valid) { if (this.gameObject.activeInHierarchy) { Debug.LogWarning("Bounding Box Follower not valid! Slot [" + slotName + "] does not contain any Bounding Box Attachments!"); } else { Debug.LogWarning("Bounding Box Follower tried to rebuild as a prefab."); } } #endif }
/// <summary> /// Initialize and instantiate the BoundingBoxFollower colliders. This is method checks if the BoundingBoxFollower has already been initialized for the skeleton instance and slotName and prevents overwriting unless it detects a new setup.</summary> public void Initialize() { if (skeletonRenderer == null) { return; } skeletonRenderer.Initialize(false); if (string.IsNullOrEmpty(slotName)) { return; } // Don't reinitialize if the setup did not change. if (colliderTable.Count > 0 && slot != null // Slot is set and colliders already populated. && skeletonRenderer.skeleton == slot.Skeleton // Skeleton object did not change. && slotName == slot.data.name // Slot object did not change. ) { return; } DisposeColliders(); var skeleton = skeletonRenderer.skeleton; slot = skeleton.FindSlot(slotName); int slotIndex = skeleton.FindSlotIndex(slotName); if (slot == null) { if (BoundingBoxFollower.DebugMessages) { Debug.LogWarning(string.Format("Slot '{0}' not found for BoundingBoxFollower on '{1}'. (Previous colliders were disposed.)", slotName, this.gameObject.name)); } return; } if (this.gameObject.activeInHierarchy) { foreach (var skin in skeleton.Data.Skins) { var attachmentNames = new List <string>(); skin.FindNamesForSlot(slotIndex, attachmentNames); foreach (var skinKey in attachmentNames) { var attachment = skin.GetAttachment(slotIndex, skinKey); var boundingBoxAttachment = attachment as BoundingBoxAttachment; if (BoundingBoxFollower.DebugMessages && attachment != null && boundingBoxAttachment == null) { Debug.Log("BoundingBoxFollower tried to follow a slot that contains non-boundingbox attachments: " + slotName); } if (boundingBoxAttachment != null) { var bbCollider = SkeletonUtility.AddBoundingBoxAsComponent(boundingBoxAttachment, slot, gameObject, isTrigger); bbCollider.enabled = false; bbCollider.hideFlags = HideFlags.NotEditable; bbCollider.isTrigger = IsTrigger; colliderTable.Add(boundingBoxAttachment, bbCollider); nameTable.Add(boundingBoxAttachment, skinKey); } } } } if (BoundingBoxFollower.DebugMessages) { bool valid = colliderTable.Count != 0; if (!valid) { if (this.gameObject.activeInHierarchy) { Debug.LogWarning("Bounding Box Follower not valid! Slot [" + slotName + "] does not contain any Bounding Box Attachments!"); } else { Debug.LogWarning("Bounding Box Follower tried to rebuild as a prefab."); } } } }