コード例 #1
0
        void OnEnable()
        {
            if (script == null)
            {
                return;
            }
            if (Application.isPlaying)
            {
                return;
            }

            // Autodetection
            if (script.references.IsEmpty(false))
            {
                Animator animator = script.gameObject.GetComponent <Animator>();

                if (animator == null && script.references.root != null)
                {
                    animator = script.references.root.GetComponentInChildren <Animator>();
                    if (animator == null)
                    {
                        animator = GetAnimatorInParents(script.references.root);
                    }
                }

                if (animator != null)
                {
                    script.references = BipedRagdollReferences.FromAvatar(animator);
                }
                else
                {
                    BipedReferences r = new BipedReferences();
                    BipedReferences.AutoDetectReferences(ref r, script.transform, BipedReferences.AutoDetectParams.Default);
                    if (r.isFilled)
                    {
                        script.references = BipedRagdollReferences.FromBipedReferences(r);
                    }
                }

                if (!OnRoot())
                {
                    Debug.LogWarning("BipedRagdollCreator must be added to the root of the character. Destroying the component.");
                    DestroyImmediate(script);
                    return;
                }

                string msg = string.Empty;
                if (script.references.IsValid(ref msg))
                {
                    script.options = BipedRagdollCreator.AutodetectOptions(script.references);
                    //BipedRagdollCreator.Create(script.references, script.options);

                    //if (animator != null) DestroyImmediate(animator);
                    //if (script.GetComponent<Animation>() != null) DestroyImmediate(script.GetComponent<Animation>());
                }
            }
        }