示例#1
0
        static List <Collider2D> AttachBoundingBoxRagdollColliders(Bone b, GameObject go, Skeleton skeleton, float gravityScale)
        {
            const string AttachmentNameMarker = "ragdoll";
            var          colliders            = new List <Collider2D>();
            var          skin = skeleton.Skin ?? skeleton.Data.DefaultSkin;

            var attachments = new List <Attachment>();

            foreach (Slot s in skeleton.Slots)
            {
                if (s.bone == b)
                {
                    skin.FindAttachmentsForSlot(skeleton.Slots.IndexOf(s), attachments);
                    foreach (var a in attachments)
                    {
                        var bbAttachment = a as BoundingBoxAttachment;
                        if (bbAttachment != null)
                        {
                            if (!a.Name.ToLower().Contains(AttachmentNameMarker))
                            {
                                continue;
                            }

                            var bbCollider = SkeletonUtility.AddBoundingBoxAsComponent(bbAttachment, s, go, isTrigger: false, isKinematic: false, gravityScale: gravityScale);
                            colliders.Add(bbCollider);
                        }
                    }
                }
            }

            return(colliders);
        }
示例#2
0
        private static List <Collider2D> AttachBoundingBoxRagdollColliders(Bone b, GameObject go, Skeleton skeleton)
        {
            List <Collider2D> list = new List <Collider2D>();
            Skin skin = skeleton.Skin ?? skeleton.Data.DefaultSkin;
            List <Attachment> list2 = new List <Attachment>();

            foreach (Slot slot in skeleton.Slots)
            {
                if (slot.bone == b)
                {
                    skin.FindAttachmentsForSlot(skeleton.Slots.IndexOf(slot), list2);
                    foreach (Attachment attachment in list2)
                    {
                        BoundingBoxAttachment boundingBoxAttachment = attachment as BoundingBoxAttachment;
                        if (boundingBoxAttachment != null)
                        {
                            if (attachment.Name.ToLower().Contains("ragdoll"))
                            {
                                PolygonCollider2D item = SkeletonUtility.AddBoundingBoxAsComponent(boundingBoxAttachment, go, false);
                                list.Add(item);
                            }
                        }
                    }
                }
            }
            return(list);
        }
示例#3
0
        private static List <Collider2D> AttachBoundingBoxRagdollColliders(Bone b, GameObject go, Skeleton skeleton, float gravityScale)
        {
            Skin defaultSkin;
            List <Collider2D> list = new List <Collider2D>();
            Skin skin1             = skeleton.Skin;

            if (skin1 != null)
            {
                defaultSkin = skin1;
            }
            else
            {
                defaultSkin = skeleton.Data.DefaultSkin;
            }
            List <Attachment> attachments = new List <Attachment>();

            foreach (Slot slot in skeleton.Slots)
            {
                if (slot.bone == b)
                {
                    defaultSkin.FindAttachmentsForSlot(skeleton.Slots.IndexOf(slot), attachments);
                    foreach (Attachment attachment in attachments)
                    {
                        BoundingBoxAttachment box = attachment as BoundingBoxAttachment;
                        if ((box != null) && attachment.Name.ToLower().Contains("ragdoll"))
                        {
                            PolygonCollider2D item = SkeletonUtility.AddBoundingBoxAsComponent(box, slot, go, false, false, gravityScale);
                            list.Add(item);
                        }
                    }
                }
            }
            return(list);
        }
示例#4
0
    public void HandleReset(SkeletonRenderer renderer)
    {
        if (slotName == null || slotName == "")
        {
            return;
        }

        hasReset = true;

        ClearColliders();
        colliderTable.Clear();

        if (skeletonRenderer.skeleton == null)
        {
            skeletonRenderer.OnReset -= HandleReset;
            skeletonRenderer.Reset();
            skeletonRenderer.OnReset += 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 HandleReset(SkeletonRenderer renderer)
    {
        if (this.slotName == null || this.slotName == string.Empty)
        {
            return;
        }
        this.hasReset = true;
        this.ClearColliders();
        this.colliderTable.Clear();
        if (this.skeletonRenderer.skeleton == null)
        {
            SkeletonRenderer expr_4F = this.skeletonRenderer;
            expr_4F.OnReset = (SkeletonRenderer.SkeletonRendererDelegate)Delegate.Remove(expr_4F.OnReset, new SkeletonRenderer.SkeletonRendererDelegate(this.HandleReset));
            this.skeletonRenderer.Reset();
            SkeletonRenderer expr_81 = this.skeletonRenderer;
            expr_81.OnReset = (SkeletonRenderer.SkeletonRendererDelegate)Delegate.Combine(expr_81.OnReset, new SkeletonRenderer.SkeletonRendererDelegate(this.HandleReset));
        }
        Skeleton skeleton = this.skeletonRenderer.skeleton;

        this.slot = skeleton.FindSlot(this.slotName);
        int slotIndex = skeleton.FindSlotIndex(this.slotName);

        foreach (Skin current in skeleton.Data.Skins)
        {
            List <string> list = new List <string>();
            current.FindNamesForSlot(slotIndex, list);
            using (List <string> .Enumerator enumerator2 = list.GetEnumerator())
            {
                while (enumerator2.MoveNext())
                {
                    string     current2   = enumerator2.get_Current();
                    Attachment attachment = current.GetAttachment(slotIndex, current2);
                    if (attachment is BoundingBoxAttachment)
                    {
                        PolygonCollider2D polygonCollider2D = SkeletonUtility.AddBoundingBoxAsComponent((BoundingBoxAttachment)attachment, base.get_gameObject(), true);
                        polygonCollider2D.set_enabled(false);
                        polygonCollider2D.set_hideFlags(2);
                        this.colliderTable.Add((BoundingBoxAttachment)attachment, polygonCollider2D);
                        this.attachmentNameTable.Add((BoundingBoxAttachment)attachment, current2);
                    }
                }
            }
        }
        if (this.colliderTable.get_Count() == 0)
        {
            this.valid = false;
        }
        else
        {
            this.valid = true;
        }
        if (!this.valid)
        {
            Debug.LogWarning("Bounding Box Follower not valid! Slot [" + this.slotName + "] does not contain any Bounding Box Attachments!");
        }
    }
    public void HandleRebuild(SkeletonRenderer renderer)
    {
        if (string.IsNullOrEmpty(slotName))
        {
            return;
        }

        ClearColliders();

        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: " + slotName);
                    }
#endif

                    if (boundingBoxAttachment != null)
                    {
                        var bbCollider = SkeletonUtility.AddBoundingBoxAsComponent(boundingBoxAttachment, slot, gameObject, true);
                        bbCollider.enabled   = true;
                        bbCollider.hideFlags = HideFlags.NotEditable;
                        bbCollider.isTrigger = IsTrigger;
                        currentCollider      = bbCollider;
                    }
                }
            }
        }
    }
        static List <Collider2D> AttachBoundingBoxRagdollColliders(Bone b, GameObject go, Skeleton skeleton, float gravityScale)
        {
            const string AttachmentNameMarker = "ragdoll";
            var          colliders            = new List <Collider2D>();
            var          skin = skeleton.Skin ?? skeleton.Data.DefaultSkin;

            var skinEntries = new List <Skin.SkinEntry>();

            foreach (Slot slot in skeleton.Slots)
            {
                if (slot.Bone == b)
                {
                    skin.GetAttachments(skeleton.Slots.IndexOf(slot), skinEntries);

                    bool bbAttachmentAdded = false;
                    foreach (var entry in skinEntries)
                    {
                        var bbAttachment = entry.Attachment as BoundingBoxAttachment;
                        if (bbAttachment != null)
                        {
                            if (!entry.Name.ToLower().Contains(AttachmentNameMarker))
                            {
                                continue;
                            }

                            bbAttachmentAdded = true;
                            var bbCollider = SkeletonUtility.AddBoundingBoxAsComponent(bbAttachment, slot, go, isTrigger: false);
                            colliders.Add(bbCollider);
                        }
                    }

                    if (bbAttachmentAdded)
                    {
                        SkeletonUtility.AddBoneRigidbody2D(go, isKinematic: false, gravityScale: gravityScale);
                    }
                }
            }

            return(colliders);
        }
示例#8
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(mode);
        if (EditorGUI.EndChangeCheck())
        {
            containsOverrides = mode.enumValueIndex == 1;
            containsFollows   = mode.enumValueIndex == 0;
        }

        EditorGUI.BeginDisabledGroup(multiObject);
        {
            string str = boneName.stringValue;
            if (str == "")
            {
                str = "<None>";
            }
            if (multiObject)
            {
                str = "<Multiple>";
            }

            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Bone");

            if (GUILayout.Button(str, EditorStyles.popup))
            {
                BoneSelectorContextMenu(str, ((SkeletonUtilityBone)target).skeletonUtility.skeletonRenderer.skeleton.Bones, "<None>", TargetBoneSelected);
            }

            GUILayout.EndHorizontal();
        }
        EditorGUI.EndDisabledGroup();

        EditorGUILayout.PropertyField(zPosition);
        EditorGUILayout.PropertyField(position);
        EditorGUILayout.PropertyField(rotation);
        EditorGUILayout.PropertyField(scale);
        // MITCH
//		EditorGUILayout.PropertyField(flip);

        EditorGUI.BeginDisabledGroup(containsFollows);
        {
            EditorGUILayout.PropertyField(overrideAlpha);
            EditorGUILayout.PropertyField(parentReference);

            // MITCH
//			EditorGUI.BeginDisabledGroup(multiObject || !flip.boolValue);
//			{
//				EditorGUI.BeginChangeCheck();
//				EditorGUILayout.PropertyField(flipX);
//				if (EditorGUI.EndChangeCheck()) {
//					FlipX(flipX.boolValue);
//				}
//			}
//			EditorGUI.EndDisabledGroup();
        }
        EditorGUI.EndDisabledGroup();

        EditorGUILayout.Space();

        GUILayout.BeginHorizontal();
        {
            EditorGUI.BeginDisabledGroup(multiObject || !utilityBone.valid || utilityBone.bone == null || utilityBone.bone.Children.Count == 0);
            {
                if (GUILayout.Button(new GUIContent("Add Child", SpineEditorUtilities.Icons.bone), GUILayout.Width(150), GUILayout.Height(24)))
                {
                    BoneSelectorContextMenu("", utilityBone.bone.Children, "<Recursively>", SpawnChildBoneSelected);
                }
            }
            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginDisabledGroup(multiObject || !utilityBone.valid || utilityBone.bone == null || containsOverrides);
            {
                if (GUILayout.Button(new GUIContent("Add Override", SpineEditorUtilities.Icons.poseBones), GUILayout.Width(150), GUILayout.Height(24)))
                {
                    SpawnOverride();
                }
            }
            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginDisabledGroup(multiObject || !utilityBone.valid || !canCreateHingeChain);
            {
                if (GUILayout.Button(new GUIContent("Create Hinge Chain", SpineEditorUtilities.Icons.hingeChain), GUILayout.Width(150), GUILayout.Height(24)))
                {
                    CreateHingeChain();
                }
            }
            EditorGUI.EndDisabledGroup();
        }
        GUILayout.EndHorizontal();

        EditorGUI.BeginDisabledGroup(multiObject || boundingBoxTable.Count == 0);
        EditorGUILayout.LabelField(new GUIContent("Bounding Boxes", SpineEditorUtilities.Icons.boundingBox), EditorStyles.boldLabel);

        foreach (var entry in boundingBoxTable)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.LabelField(entry.Key.Data.Name);
            EditorGUI.indentLevel++;
            foreach (var box in entry.Value)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(30);
                if (GUILayout.Button(box.Name, GUILayout.Width(200)))
                {
                    var child = utilityBone.transform.FindChild("[BoundingBox]" + box.Name);
                    if (child != null)
                    {
                        var originalCollider = child.GetComponent <PolygonCollider2D>();
                        var updatedCollider  = SkeletonUtility.AddBoundingBoxAsComponent(box, child.gameObject, originalCollider.isTrigger);
                        originalCollider.points = updatedCollider.points;
                        if (EditorApplication.isPlaying)
                        {
                            Destroy(updatedCollider);
                        }
                        else
                        {
                            DestroyImmediate(updatedCollider);
                        }
                    }
                    else
                    {
                        utilityBone.AddBoundingBox(currentSkinName, entry.Key.Data.Name, box.Name);
                    }
                }
                GUILayout.EndHorizontal();
            }
        }

        EditorGUI.EndDisabledGroup();

        serializedObject.ApplyModifiedProperties();
    }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(mode);
            if (EditorGUI.EndChangeCheck())
            {
                containsOverrides = mode.enumValueIndex == 1;
                containsFollows   = mode.enumValueIndex == 0;
            }

            using (new EditorGUI.DisabledGroupScope(multiObject)) {
                string str = boneName.stringValue;
                if (str == "")
                {
                    str = "<None>";
                }
                if (multiObject)
                {
                    str = "<Multiple>";
                }

                using (new GUILayout.HorizontalScope()) {
                    EditorGUILayout.PrefixLabel("Bone");
                    if (GUILayout.Button(str, EditorStyles.popup))
                    {
                        BoneSelectorContextMenu(str, ((SkeletonUtilityBone)target).hierarchy.skeletonRenderer.skeleton.Bones, "<None>", TargetBoneSelected);
                    }
                }
            }

            EditorGUILayout.PropertyField(zPosition);
            EditorGUILayout.PropertyField(position);
            EditorGUILayout.PropertyField(rotation);
            EditorGUILayout.PropertyField(scale);

            using (new EditorGUI.DisabledGroupScope(containsFollows)) {
                EditorGUILayout.PropertyField(overrideAlpha);
                EditorGUILayout.PropertyField(parentReference);
            }

            EditorGUILayout.Space();

            using (new GUILayout.HorizontalScope()) {
                EditorGUILayout.Space();
                using (new EditorGUI.DisabledGroupScope(multiObject || !utilityBone.valid || utilityBone.bone == null || utilityBone.bone.Children.Count == 0)) {
                    if (GUILayout.Button(SpineInspectorUtility.TempContent("Add Child Bone", Icons.bone), GUILayout.MinWidth(120), GUILayout.Height(24)))
                    {
                        BoneSelectorContextMenu("", utilityBone.bone.Children, "<Recursively>", SpawnChildBoneSelected);
                    }
                }
                using (new EditorGUI.DisabledGroupScope(multiObject || !utilityBone.valid || utilityBone.bone == null || containsOverrides)) {
                    if (GUILayout.Button(SpineInspectorUtility.TempContent("Add Override", Icons.poseBones), GUILayout.MinWidth(120), GUILayout.Height(24)))
                    {
                        SpawnOverride();
                    }
                }
                EditorGUILayout.Space();
            }
            EditorGUILayout.Space();
            using (new GUILayout.HorizontalScope()) {
                EditorGUILayout.Space();
                using (new EditorGUI.DisabledGroupScope(multiObject || !utilityBone.valid || !canCreateHingeChain)) {
                    if (GUILayout.Button(SpineInspectorUtility.TempContent("Create 3D Hinge Chain", Icons.hingeChain), GUILayout.MinWidth(120), GUILayout.Height(24)))
                    {
                        CreateHingeChain();
                    }
                    if (GUILayout.Button(SpineInspectorUtility.TempContent("Create 2D Hinge Chain", Icons.hingeChain), GUILayout.MinWidth(120), GUILayout.Height(24)))
                    {
                        CreateHingeChain2D();
                    }
                }
                EditorGUILayout.Space();
            }

            using (new EditorGUI.DisabledGroupScope(multiObject || boundingBoxTable.Count == 0)) {
                EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Bounding Boxes", Icons.boundingBox), EditorStyles.boldLabel);

                foreach (var entry in boundingBoxTable)
                {
                    Slot slot          = entry.Key;
                    var  boundingBoxes = entry.Value;

                    EditorGUI.indentLevel++;
                    EditorGUILayout.LabelField(slot.Data.Name);
                    EditorGUI.indentLevel++;
                    {
                        foreach (var box in boundingBoxes)
                        {
                            using (new GUILayout.HorizontalScope()) {
                                GUILayout.Space(30);
                                string buttonLabel = box.IsWeighted() ? box.Name + " (!)" : box.Name;
                                if (GUILayout.Button(buttonLabel, GUILayout.Width(200)))
                                {
                                    utilityBone.bone.Skeleton.UpdateWorldTransform();
                                    var bbTransform = utilityBone.transform.Find("[BoundingBox]" + box.Name);                                     // Use FindChild in older versions of Unity.
                                    if (bbTransform != null)
                                    {
                                        var originalCollider = bbTransform.GetComponent <PolygonCollider2D>();
                                        if (originalCollider != null)
                                        {
                                            SkeletonUtility.SetColliderPointsLocal(originalCollider, slot, box);
                                        }
                                        else
                                        {
                                            SkeletonUtility.AddBoundingBoxAsComponent(box, slot, bbTransform.gameObject);
                                        }
                                    }
                                    else
                                    {
                                        var newPolygonCollider = SkeletonUtility.AddBoundingBoxGameObject(null, box, slot, utilityBone.transform);
                                        bbTransform = newPolygonCollider.transform;
                                    }
                                    EditorGUIUtility.PingObject(bbTransform);
                                }
                            }
                        }
                    }
                    EditorGUI.indentLevel--;
                    EditorGUI.indentLevel--;
                }
            }

            BoneFollowerInspector.RecommendRigidbodyButton(utilityBone);

            serializedObject.ApplyModifiedProperties();
        }
示例#10
0
    List <Collider2D> AttachBoundingBoxRagdollColliders(Bone b)
    {
        List <Collider2D> colliders = new List <Collider2D>();
        Transform         t         = boneTable[b];
        GameObject        go        = t.gameObject;
        var skin = skeleton.Skin;

        if (skin == null)
        {
            skin = skeleton.Data.DefaultSkin;
        }

        bool flipX = b.WorldFlipX;
        bool flipY = b.WorldFlipY;

        List <Attachment> attachments = new List <Attachment>();

        foreach (Slot s in skeleton.Slots)
        {
            if (s.Bone == b)
            {
                skin.FindAttachmentsForSlot(skeleton.Slots.IndexOf(s), attachments);
                foreach (var a in attachments)
                {
                    if (a is BoundingBoxAttachment)
                    {
                        if (!a.Name.ToLower().Contains("ragdoll"))
                        {
                            continue;
                        }

                        var collider = SkeletonUtility.AddBoundingBoxAsComponent((BoundingBoxAttachment)a, go, false);

                        if (flipX || flipY)
                        {
                            Vector2[] points = collider.points;

                            for (int i = 0; i < points.Length; i++)
                            {
                                if (flipX)
                                {
                                    points[i].x *= -1;
                                }

                                if (flipY)
                                {
                                    points[i].y *= -1;
                                }
                            }

                            collider.points = points;
                        }

                        colliders.Add(collider);
                    }
                }
            }
        }

        return(colliders);
    }