void OnGUI()
    {
        EditorGUILayout.BeginVertical();

        root    = (Transform)EditorGUILayout.ObjectField("Ragdoll Root", root, typeof(Transform), true);
        folder  = EditorGUILayout.ObjectField("Destination Folder", folder, typeof(Object), false);
        ragdoll = (RagdollAsset)EditorGUILayout.ObjectField("Ragdoll to Update (Optional)", ragdoll, typeof(RagdollAsset), false);

        GUILayoutHelpers.HorzLine();

        GUI.enabled = (root != null) && ((ragdoll != null) || (folder != null));

        if (GUILayout.Button((ragdoll != null) ? "Update Ragdoll Asset" : "Create Ragdoll Asset"))
        {
            if (ragdoll != null)
            {
                ragdoll.Rebuild(root);
            }
            else
            {
                if (RagdollAsset.Create(root, Utils.SafeGetNewAssetPathFromPath(AssetDatabase.GetAssetPath(folder) + "/NewRagdoll")) == null)
                {
                    EditorUtility.DisplayDialog("Error", "No ragdoll components were found from the specified root.", "OK");
                }
            }
        }

        GUI.enabled = true;

        EditorGUILayout.EndVertical();
    }
예제 #2
0
    public static RagdollAsset Create(Transform root, string path)
    {
        List <Element> elements = new List <Element>();

        var bodies = root.GetComponentsInChildren <Rigidbody>(true);

        foreach (var rb in bodies)
        {
            var collider = rb.GetComponent <Collider>();
            if (collider != null)
            {
                var joint = rb.GetComponent <CharacterJoint>();

                var elem = new Element();
                elem.path      = Utils.GetChildPath(root, rb.transform);
                elem.collider  = ColliderDescription.New(collider);
                elem.rigidBody = RigidbodyDescription.New(rb);
                if (joint != null)
                {
                    elem.joint = CharacterJointDescription.New(joint, root);
                }

                elements.Add(elem);
            }
        }

        RagdollAsset asset = null;

        if (elements.Count > 0)
        {
            asset          = Utils.CreateAsset <RagdollAsset>(path);
            asset.elements = elements;
        }

        return(asset);
    }