Ejemplo n.º 1
0
            public void Trigger(PuppetMaster puppetMaster, bool switchBehaviourEnabled = true)
            {
                unityEvent.Invoke();
                foreach (AnimatorEvent animatorEvent in animations)
                {
                    animatorEvent.Activate(puppetMaster.targetAnimator, puppetMaster.targetAnimation);
                }

                if (switchBehaviour)
                {
                    bool found = false;

                    foreach (BehaviourBase behaviour in puppetMaster.behaviours)
                    {
                        //if (behaviour != null && behaviour.GetType() == System.Type.GetType(switchToBehaviour)) {
                        if (behaviour != null && (behaviour.GetType().ToString() == "RootMotion.Dynamics." + switchToBehaviour || behaviour.GetType().ToString() == switchToBehaviour))
                        {
                            found = true;
                            //behaviour.Activate();
                            behaviour.enabled = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        Debug.LogWarning("No Puppet Behaviour of type '" + switchToBehaviour + "' was found. Can not switch to the behaviour, please check the spelling (also for empty spaces).");
                    }
                }
            }
Ejemplo n.º 2
0
        public static void PositionRagdoll(PuppetMaster puppetMaster)
        {
            Rigidbody[] rigidbodies = puppetMaster.transform.GetComponentsInChildren<Rigidbody>();
            if (rigidbodies.Length == 0) return;

            foreach (Muscle m in puppetMaster.muscles) if (m.joint == null || m.target == null) return;

            Vector3[] swingAxes = new Vector3[rigidbodies.Length];

            for (int i = 0; i < rigidbodies.Length; i++) {
                if (rigidbodies[i].transform.childCount == 1) {
                    swingAxes[i] = rigidbodies[i].transform.InverseTransformDirection(rigidbodies[i].transform.GetChild(0).position - rigidbodies[i].transform.position);
                }
            }

            foreach (Rigidbody r in rigidbodies) {
                foreach (Muscle m in puppetMaster.muscles) {
                    if (m.joint.GetComponent<Rigidbody>() == r) {
                        r.transform.position = m.target.position;
                    }
                }
            }

            for (int i = 0; i < rigidbodies.Length; i++) {
                if (rigidbodies[i].transform.childCount == 1) {
                    Vector3 childPosition = rigidbodies[i].transform.GetChild(0).position;

                    rigidbodies[i].transform.rotation = Quaternion.FromToRotation(rigidbodies[i].transform.rotation * swingAxes[i], childPosition - rigidbodies[i].transform.position) * rigidbodies[i].transform.rotation;
                    rigidbodies[i].transform.GetChild(0).position = childPosition;
                }
            }
        }
Ejemplo n.º 3
0
        void Awake()
        {
            puppetMaster = GetComponent<PuppetMaster>();

            // Assign the ragdoll layers.
            puppetMaster.gameObject.layer = ragdollLayer;
            foreach (Muscle m in puppetMaster.muscles) m.joint.gameObject.layer = ragdollLayer;

            // Assign the character controller layer
            characterController.gameObject.layer = characterControllerLayer;

            // Ignore collisions between the ragdoll and the character controller
            Physics.IgnoreLayerCollision(characterControllerLayer, ragdollLayer);

            // Ignore collisions between character controllers
            Physics.IgnoreLayerCollision(characterControllerLayer, characterControllerLayer);

            // Ignore collisions between the puppet-damaging layers and the character controller layer
            int[] characterIgnoreIndexes = LayerMaskExtensions.MaskToNumbers(ignoreCollisionWithCharacterController);
            foreach (int index in characterIgnoreIndexes) {
                Physics.IgnoreLayerCollision(characterControllerLayer, index);
            }

            // Ignore collisions between the ragdoll and the ignoreCollisionWithRagdoll layers
            int[] ragdollIgnoreIndexes = LayerMaskExtensions.MaskToNumbers(ignoreCollisionWithRagdoll);
            foreach (int index in ragdollIgnoreIndexes) {
                Physics.IgnoreLayerCollision(ragdollLayer, index);
            }

            Destroy(this);
        }
Ejemplo n.º 4
0
            public bool Update(List <PuppetMaster> puppets, PuppetMaster puppetMaster)
            {
                if (puppetsPerFrame >= puppets.Count)
                {
                    return(true);
                }

                if (index >= puppets.Count)
                {
                    return(false);
                }

                for (int i = 0; i < puppetsPerFrame; i++)
                {
                    int o = index + i;
                    if (o >= puppets.Count)
                    {
                        o -= puppets.Count;
                    }

                    if (puppets[o] == puppetMaster)
                    {
                        return(true);
                    }
                }

                return(false);
            }
 private Rigidbody GetRigidbody(PuppetMaster puppetMaster, Transform target)
 {
     foreach (Muscle m in puppetMaster.muscles) {
         if (m.target == target) return m.joint.GetComponent<Rigidbody>();
     }
     return null;
 }
        /// <summary>
        /// Applies this config to the specified PuppetMaster.
        /// </summary>
        /// <param name="p">P.</param>
        public void ApplyTo(PuppetMaster p)
        {
            if (p.targetRoot == null)
            {
                Debug.LogWarning("Please assign 'Target Root' for PuppetMaster using a Humanoid Config.", p.transform);
                return;
            }

            if (p.targetAnimator == null)
            {
                Debug.LogError("PuppetMaster 'Target Root' does not have an Animator component. Can not use Humanoid Config.", p.transform);
                return;
            }

            if (!p.targetAnimator.isHuman)
            {
                Debug.LogError("PuppetMaster target is not a Humanoid. Can not use Humanoid Config.", p.transform);
                return;
            }

            p.state                       = state;
            p.stateSettings               = stateSettings;
            p.mode                        = mode;
            p.blendTime                   = blendTime;
            p.fixTargetTransforms         = fixTargetTransforms;
            p.solverIterationCount        = solverIterationCount;
            p.visualizeTargetPose         = visualizeTargetPose;
            p.mappingWeight               = mappingWeight;
            p.pinWeight                   = pinWeight;
            p.muscleWeight                = muscleWeight;
            p.muscleSpring                = muscleSpring;
            p.muscleDamper                = muscleDamper;
            p.pinPow                      = pinPow;
            p.pinDistanceFalloff          = pinDistanceFalloff;
            p.angularPinning              = angularPinning;
            p.updateJointAnchors          = updateJointAnchors;
            p.supportTranslationAnimation = supportTranslationAnimation;
            p.angularLimits               = angularLimits;
            p.internalCollisions          = internalCollisions;

            for (int i = 0; i < muscles.Length; i++)
            {
                var m = GetMuscle(muscles[i].bone, p.targetAnimator, p);
                if (m == null && i < p.muscles.Length)
                {
                    m = p.muscles[i];
                }

                if (m != null)
                {
                    var h = muscles[i];
                    m.props.group         = h.props.group;
                    m.props.mappingWeight = h.props.mappingWeight;
                    //m.props.mapPosition = h.props.mapPosition;
                    m.props.muscleDamper = h.props.muscleDamper;
                    m.props.muscleWeight = h.props.muscleWeight;
                    m.props.pinWeight    = h.props.pinWeight;
                }
            }
        }
Ejemplo n.º 7
0
 public void Register(PuppetMaster puppetMaster)
 {
     if (_puppets.Contains(puppetMaster))
     {
         return;
     }
     _puppets.Add(puppetMaster);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Sets up a Puppet from the specified ragdoll and target characters.
 /// </summary>
 public static PuppetMaster SetUp(Transform target, Transform ragdoll, int characterControllerLayer, int ragdollLayer)
 {
     if (ragdoll != target)
     {
         PuppetMaster puppetMaster = ragdoll.gameObject.AddComponent <PuppetMaster>();
         puppetMaster.SetUpTo(target, characterControllerLayer, ragdollLayer);
         return(puppetMaster);
     }
     else
     {
         return(SetUp(ragdoll, characterControllerLayer, ragdollLayer));
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Sets up a Puppet using a single ragdoll character. This will duplicate the ragdoll character, remove the ragdoll components from the original and use it as the animated target.
        /// </summary>
        public static PuppetMaster SetUp(Transform target, int characterControllerLayer, int ragdollLayer)
        {
            Transform ragdoll = ((GameObject)GameObject.Instantiate(target.gameObject, target.position, target.rotation)).transform;

            PuppetMaster puppetMaster = ragdoll.gameObject.AddComponent <PuppetMaster>();

            puppetMaster.SetUpTo(target, characterControllerLayer, ragdollLayer);

            // Clean up the target from all the ragdoll components
            RemoveRagdollComponents(target, characterControllerLayer);

            return(puppetMaster);
        }
Ejemplo n.º 10
0
        public static void PositionRagdoll(PuppetMaster puppetMaster)
        {
            Rigidbody[] rigidbodies = puppetMaster.transform.GetComponentsInChildren <Rigidbody>();
            if (rigidbodies.Length == 0)
            {
                return;
            }

            foreach (Muscle m in puppetMaster.muscles)
            {
                if (m.joint == null || m.target == null)
                {
                    return;
                }
            }

            Vector3[] swingAxes = new Vector3[rigidbodies.Length];

            for (int i = 0; i < rigidbodies.Length; i++)
            {
                if (rigidbodies[i].transform.childCount == 1)
                {
                    swingAxes[i] = rigidbodies[i].transform.InverseTransformDirection(rigidbodies[i].transform.GetChild(0).position - rigidbodies[i].transform.position);
                }
            }

            foreach (Rigidbody r in rigidbodies)
            {
                foreach (Muscle m in puppetMaster.muscles)
                {
                    if (m.joint.GetComponent <Rigidbody>() == r)
                    {
                        r.transform.position = m.target.position;
                    }
                }
            }

            for (int i = 0; i < rigidbodies.Length; i++)
            {
                if (rigidbodies[i].transform.childCount == 1)
                {
                    Vector3 childPosition = rigidbodies[i].transform.GetChild(0).position;

                    rigidbodies[i].transform.rotation             = Quaternion.FromToRotation(rigidbodies[i].transform.rotation * swingAxes[i], childPosition - rigidbodies[i].transform.position) * rigidbodies[i].transform.rotation;
                    rigidbodies[i].transform.GetChild(0).position = childPosition;
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the center of mass of a puppet.
        /// </summary>
        public static Vector3 GetCenterOfMass(PuppetMaster puppet)
        {
            Vector3 CoM = Vector3.zero;
            float   c   = 0f;

            for (int i = 0; i < puppet.muscles.Length; i++)
            {
                if (puppet.muscles[i].joint.gameObject.activeInHierarchy)
                {
                    CoM += puppet.muscles[i].rigidbody.worldCenterOfMass * puppet.muscles[i].rigidbody.mass;

                    c += puppet.muscles[i].rigidbody.mass;
                }
            }

            return(CoM / c);
        }
Ejemplo n.º 12
0
        // Called by PropMuscle when this prop is dropped
        public void Drop(PuppetMaster puppetMaster, int propMuscleIndex)
        {
            if (!puppetMaster.muscles[propMuscleIndex].joint.gameObject.activeInHierarchy)
            {
                transform.position = puppetMaster.muscles[propMuscleIndex].target.position;
                transform.rotation = puppetMaster.muscles[propMuscleIndex].target.rotation;
            }

            ReattachRigidbody();

            if (!puppetMaster.muscles[propMuscleIndex].joint.gameObject.activeInHierarchy || puppetMaster.muscles[propMuscleIndex].rigidbody.isKinematic)
            {
                r.velocity        = puppetMaster.muscles[propMuscleIndex].mappedVelocity;
                r.angularVelocity = puppetMaster.muscles[propMuscleIndex].mappedAngularVelocity;
            }

            transform.parent = defaultParent;

            meshRoot.parent        = transform;
            meshRoot.localPosition = Vector3.zero;
            meshRoot.localRotation = Quaternion.identity;

            for (int i = 0; i < colliders.Length; i++)
            {
                colliders[i].sharedMaterial = droppedMaterials[i];
            }

            puppetMaster.ResetInternalCollisions(puppetMaster.muscles[propMuscleIndex], false);
            puppetMaster.muscles[propMuscleIndex].colliders = emptyColliders;

            if (forceLayers)
            {
                foreach (Collider c in colliders)
                {
                    if (!c.isTrigger)
                    {
                        c.gameObject.layer = defaultLayer;
                    }
                }
            }

            isPickedUp = false;
            propMuscle = null;

            OnDrop(puppetMaster, propMuscleIndex);
        }
Ejemplo n.º 13
0
        public void Initiate(PuppetMaster puppetMaster)
        {
            this.puppetMaster = puppetMaster;
            initiated         = true;

            if (OnPreInitiate != null)
            {
                OnPreInitiate();
            }

            OnInitiate();

            if (OnPostInitiate != null)
            {
                OnPostInitiate();
            }
        }
Ejemplo n.º 14
0
        private Muscle GetMuscle(HumanBodyBones boneId, Animator animator, PuppetMaster puppetMaster)
        {
            Transform bone = animator.GetBoneTransform(boneId);

            if (bone == null)
            {
                return(null);
            }

            foreach (Muscle m in puppetMaster.muscles)
            {
                if (m.target == bone)
                {
                    return(m);
                }
            }

            return(null);
        }
Ejemplo n.º 15
0
        // Called by PropMuscle when this prop is picked up
        public void PickUp(PuppetMaster puppetMaster, int propMuscleIndex)
        {
            RemoveRigidbody();

            transform.parent   = puppetMaster.muscles[propMuscleIndex].transform;
            transform.position = puppetMaster.muscles[propMuscleIndex].transform.position;
            transform.rotation = puppetMaster.muscles[propMuscleIndex].transform.rotation;

            meshRoot.parent        = puppetMaster.muscles[propMuscleIndex].target;
            meshRoot.localPosition = Vector3.zero;
            meshRoot.localRotation = Quaternion.identity;

            puppetMaster.muscles[propMuscleIndex].props = muscleProps;

            if (pickedUpMaterial != null)
            {
                foreach (Collider c in colliders)
                {
                    c.sharedMaterial = pickedUpMaterial;
                }
            }

            if (forceLayers)
            {
                foreach (Collider c in colliders)
                {
                    if (!c.isTrigger)
                    {
                        c.gameObject.layer = puppetMaster.muscles[propMuscleIndex].joint.gameObject.layer;
                    }
                }
            }

            puppetMaster.muscles[propMuscleIndex].colliders = colliders;
            puppetMaster.UpdateInternalCollisions(puppetMaster.muscles[propMuscleIndex]);

            isPickedUp = true;
            propMuscle = puppetMaster.muscles[propMuscleIndex];

            OnPickUp(puppetMaster, propMuscleIndex);
        }
Ejemplo n.º 16
0
            public Leg(IKSolverFullBodyBiped solver, PuppetMaster puppetMaster, FullBodyBipedEffector effectorType)
            {
                this.solver = solver;
                effector    = solver.GetEffector(effectorType);
                chain       = solver.GetChain(effectorType);

                stepFrom = effector.bone.position;
                stepTo   = effector.bone.position;
                position = effector.bone.position;

                offset = effectorType == FullBodyBipedEffector.LeftFoot? Vector3.left: Vector3.right;

                stepTimer  = 0f;
                stepLength = 0f;

                muscle      = puppetMaster.GetMuscle(effector.bone);
                thighMuscle = puppetMaster.GetMuscle(chain.nodes[0].transform);

                mass          = muscle.rigidbody.mass;
                inertiaTensor = muscle.rigidbody.inertiaTensor;
            }
Ejemplo n.º 17
0
 public void Unregister(PuppetMaster puppetMaster)
 {
     _puppets.Remove(puppetMaster);
 }
Ejemplo n.º 18
0
 public bool UpdateMoveToTarget(PuppetMaster puppetMaster)
 {
     return(kinematicCollidersUpdateLimit.Update(_puppets, puppetMaster));
 }
Ejemplo n.º 19
0
 protected virtual void OnDrop(PuppetMaster puppetMaster, int propMuscleIndex)
 {
 }
Ejemplo n.º 20
0
 public bool UpdateFixed(PuppetMaster puppetMaster)
 {
     return(fixedUpdateLimit.Update(_puppets, puppetMaster));
 }
Ejemplo n.º 21
0
            public void Trigger(PuppetMaster puppetMaster, bool switchBehaviourEnabled = true)
            {
                unityEvent.Invoke();
                foreach (AnimatorEvent animatorEvent in animations) animatorEvent.Activate(puppetMaster.targetAnimator, puppetMaster.targetAnimation);

                if (switchBehaviour) {
                    bool found = false;

                    foreach (BehaviourBase behaviour in puppetMaster.behaviours) {
                        //if (behaviour != null && behaviour.GetType() == System.Type.GetType(switchToBehaviour)) {
                        if (behaviour != null && behaviour.GetType().ToString() == "RootMotion.Dynamics." + switchToBehaviour) {
                            found = true;
                            behaviour.Activate();
                            break;
                        }
                    }

                    if (!found) {
                        Debug.LogWarning("No Puppet Behaviour of type '" + switchToBehaviour + "' was found. Can not switch to the behaviour, please check the spelling (also for empty spaces).");
                    }
                }
            }
Ejemplo n.º 22
0
        public static void RealignRagdoll(PuppetMaster puppetMaster)
        {
            foreach (Muscle m in puppetMaster.muscles) {
                if (m.joint == null || m.joint.transform == null || m.target == null) {
                    Debug.LogWarning("Muscles incomplete, can not realign ragdoll.");
                    return;
                }
            }

            foreach (Muscle m in puppetMaster.muscles) {
                if (m.target != null) {
                    Transform[] children = new Transform[m.joint.transform.childCount];
                    for (int c = 0 ; c < children.Length; c++) {
                        children[c] = m.joint.transform.GetChild(c);
                    }

                    foreach (Transform c in children) c.parent = null;

                    BoxCollider box = m.joint.GetComponent<BoxCollider>();
                    Vector3 boxSizeWorldSpace = Vector3.zero;
                    Vector3 boxCenterWorldSpace = Vector3.zero;

                    if (box != null) {
                        boxSizeWorldSpace = box.transform.TransformVector(box.size);
                        boxCenterWorldSpace = box.transform.TransformVector(box.center);
                    }

                    CapsuleCollider capsule = m.joint.GetComponent<CapsuleCollider>();
                    Vector3 capsuleCenterWorldSpace = Vector3.zero;
                    Vector3 capsuleDirectionWorldSpace = Vector3.zero;

                    if (capsule != null) {
                        capsuleCenterWorldSpace = capsule.transform.TransformVector(capsule.center);
                        capsuleDirectionWorldSpace = capsule.transform.TransformVector(DirectionIntToVector3(capsule.direction));
                    }

                    SphereCollider sphere = m.joint.GetComponent<SphereCollider>();
                    Vector3 sphereCenterWorldSpace = Vector3.zero;

                    if (sphere != null) {
                        sphereCenterWorldSpace = sphere.transform.TransformVector(sphere.center);
                    }

                    Vector3 jointAxisWorldSpace = m.joint.transform.TransformVector(m.joint.axis);
                    Vector3 jointSecondaryAxisWorldSpace = m.joint.transform.TransformVector(m.joint.secondaryAxis);

                    // Rotate the bone
                    m.joint.transform.rotation = m.target.rotation;

                    if (box != null) {
                        box.size = box.transform.InverseTransformVector(boxSizeWorldSpace);
                        box.center = box.transform.InverseTransformVector(boxCenterWorldSpace);
                    }

                    if (capsule != null) {
                        capsule.center = capsule.transform.InverseTransformVector(capsuleCenterWorldSpace);
                        Vector3 directionLocalSpace = capsule.transform.InverseTransformDirection(capsuleDirectionWorldSpace);
                        capsule.direction = DirectionVector3ToInt(directionLocalSpace);
                    }

                    if (sphere != null) {
                        sphere.center = sphere.transform.InverseTransformVector(sphereCenterWorldSpace);
                    }

                    m.joint.axis = m.joint.transform.InverseTransformVector(jointAxisWorldSpace);
                    m.joint.secondaryAxis = m.joint.transform.InverseTransformVector(jointSecondaryAxisWorldSpace);

                    foreach (Transform c in children) c.parent = m.joint.transform;
                }
            }
        }
Ejemplo n.º 23
0
        public static void RealignRagdoll(PuppetMaster puppetMaster)
        {
            foreach (Muscle m in puppetMaster.muscles)
            {
                if (m.joint == null || m.joint.transform == null || m.target == null)
                {
                    Debug.LogWarning("Muscles incomplete, can not realign ragdoll.");
                    return;
                }
            }

            foreach (Muscle m in puppetMaster.muscles)
            {
                if (m.target != null)
                {
                    Transform[] children = new Transform[m.joint.transform.childCount];
                    for (int c = 0; c < children.Length; c++)
                    {
                        children[c] = m.joint.transform.GetChild(c);
                    }

                    foreach (Transform c in children)
                    {
                        c.parent = null;
                    }

                    BoxCollider box = m.joint.GetComponent <BoxCollider>();
                    Vector3     boxSizeWorldSpace   = Vector3.zero;
                    Vector3     boxCenterWorldSpace = Vector3.zero;

                    if (box != null)
                    {
                        boxSizeWorldSpace   = box.transform.TransformVector(box.size);
                        boxCenterWorldSpace = box.transform.TransformVector(box.center);
                    }

                    CapsuleCollider capsule = m.joint.GetComponent <CapsuleCollider>();
                    Vector3         capsuleCenterWorldSpace    = Vector3.zero;
                    Vector3         capsuleDirectionWorldSpace = Vector3.zero;

                    if (capsule != null)
                    {
                        capsuleCenterWorldSpace    = capsule.transform.TransformVector(capsule.center);
                        capsuleDirectionWorldSpace = capsule.transform.TransformVector(DirectionIntToVector3(capsule.direction));
                    }

                    SphereCollider sphere = m.joint.GetComponent <SphereCollider>();
                    Vector3        sphereCenterWorldSpace = Vector3.zero;

                    if (sphere != null)
                    {
                        sphereCenterWorldSpace = sphere.transform.TransformVector(sphere.center);
                    }

                    Vector3 jointAxisWorldSpace          = m.joint.transform.TransformVector(m.joint.axis);
                    Vector3 jointSecondaryAxisWorldSpace = m.joint.transform.TransformVector(m.joint.secondaryAxis);

                    // Rotate the bone
                    m.joint.transform.rotation = m.target.rotation;

                    if (box != null)
                    {
                        box.size   = box.transform.InverseTransformVector(boxSizeWorldSpace);
                        box.center = box.transform.InverseTransformVector(boxCenterWorldSpace);
                    }

                    if (capsule != null)
                    {
                        capsule.center = capsule.transform.InverseTransformVector(capsuleCenterWorldSpace);
                        Vector3 directionLocalSpace = capsule.transform.InverseTransformDirection(capsuleDirectionWorldSpace);
                        capsule.direction = DirectionVector3ToInt(directionLocalSpace);
                    }

                    if (sphere != null)
                    {
                        sphere.center = sphere.transform.InverseTransformVector(sphereCenterWorldSpace);
                    }

                    m.joint.axis          = m.joint.transform.InverseTransformVector(jointAxisWorldSpace);
                    m.joint.secondaryAxis = m.joint.transform.InverseTransformVector(jointSecondaryAxisWorldSpace);

                    foreach (Transform c in children)
                    {
                        c.parent = m.joint.transform;
                    }
                }
            }
        }
Ejemplo n.º 24
0
        public static bool AddPropMuscle(PuppetMaster script, ConfigurableJoint addPropMuscleTo, Vector3 position, Quaternion rotation, Vector3 additionalPinOffset, Transform targetParent = null)
        {
            var serializedObject = new SerializedObject(script);

            if (addPropMuscleTo != null)
            {
                bool isFlat = script.HierarchyIsFlat();

                var addToMuscle = script.GetMuscle(addPropMuscleTo);
                if (addToMuscle != null)
                {
                    GameObject go = new GameObject("Prop Muscle " + addPropMuscleTo.name);
                    go.layer              = addPropMuscleTo.gameObject.layer;
                    go.transform.parent   = isFlat ? script.transform : addPropMuscleTo.transform;
                    go.transform.position = position;
                    go.transform.rotation = rotation;

                    var r = go.AddComponent <Rigidbody>();

                    GameObject target = new GameObject("Prop Muscle Target " + addPropMuscleTo.name);
                    target.gameObject.layer   = addToMuscle.target.gameObject.layer;
                    target.transform.parent   = targetParent == null ? addToMuscle.target : targetParent;
                    target.transform.position = go.transform.position;
                    target.transform.rotation = go.transform.rotation;

                    var joint = go.AddComponent <ConfigurableJoint>();
                    joint.connectedBody  = addToMuscle.joint.gameObject.GetComponent <Rigidbody>();
                    joint.xMotion        = ConfigurableJointMotion.Locked;
                    joint.yMotion        = ConfigurableJointMotion.Locked;
                    joint.zMotion        = ConfigurableJointMotion.Locked;
                    joint.angularXMotion = ConfigurableJointMotion.Locked;
                    joint.angularYMotion = ConfigurableJointMotion.Locked;
                    joint.angularZMotion = ConfigurableJointMotion.Locked;

                    r.interpolation = joint.connectedBody.interpolation;

                    int newLength      = script.muscles.Length + 1;
                    int newMuscleIndex = newLength - 1;

                    SerializedProperty muscles = serializedObject.FindProperty("muscles");
                    muscles.InsertArrayElementAtIndex(newMuscleIndex);

                    muscles.GetArrayElementAtIndex(newMuscleIndex).FindPropertyRelative("index").intValue              = newMuscleIndex;
                    muscles.GetArrayElementAtIndex(newMuscleIndex).FindPropertyRelative("joint").objectReferenceValue  = joint;
                    muscles.GetArrayElementAtIndex(newMuscleIndex).FindPropertyRelative("target").objectReferenceValue = target.transform;
                    muscles.GetArrayElementAtIndex(newMuscleIndex).FindPropertyRelative("props").FindPropertyRelative("group").intValue = 8;
                    muscles.GetArrayElementAtIndex(newMuscleIndex).FindPropertyRelative("isPropMuscle").boolValue = true;
                    serializedObject.ApplyModifiedProperties();

                    var propMuscle  = joint.gameObject.AddComponent <PropMuscle>();
                    var propMuscleS = new SerializedObject(propMuscle);
                    propMuscleS.FindProperty("puppetMaster").objectReferenceValue = script;
                    propMuscleS.FindProperty("additionalPinOffset").vector3Value  = additionalPinOffset;

                    propMuscleS.ApplyModifiedProperties();

                    if (additionalPinOffset != Vector3.zero)
                    {
                        propMuscleS.Update();
                        ConfigurableJoint additionalJoint  = null;
                        Transform         additionalTarget = null;
                        PropMuscleInspector.AddAdditionalPinUnserialized(propMuscle, out additionalJoint, out additionalTarget);

                        muscles.GetArrayElementAtIndex(newMuscleIndex).FindPropertyRelative("additionalPin").objectReferenceValue       = additionalJoint;
                        muscles.GetArrayElementAtIndex(newMuscleIndex).FindPropertyRelative("additionalPinTarget").objectReferenceValue = additionalTarget;

                        propMuscleS.ApplyModifiedProperties();
                    }

                    serializedObject.ApplyModifiedProperties();
                    // TODO Do not add if addPropMuscleTo already has a PropMuscle

                    return(true);
                }
                else
                {
                    Debug.LogError("Can't add Prop Muscle to a ConfigurableJoint that is not in the list of PuppetMaster.muscles.", script.transform);
                    return(false);
                }
            }
            else
            {
                Debug.LogError("Please assign the ConfigurableJoint of the muscle you wish to add the Prop Muscle to.", script.transform);
                return(false);
            }
        }
Ejemplo n.º 25
0
        public void Initiate(PuppetMaster puppetMaster)
        {
            this.puppetMaster = puppetMaster;
            initiated = true;

            if (OnPreInitiate != null) OnPreInitiate();

            OnInitiate();

            if (OnPostInitiate != null) OnPostInitiate();
        }
Ejemplo n.º 26
0
 public bool UpdateFree(PuppetMaster puppetMaster)
 {
     return(freeUpdateLimit.Update(_puppets, puppetMaster));
 }