void Awake()
        {
            minifig     = GetComponent <Minifig>();
            controller  = GetComponent <CharacterController>();
            animator    = GetComponent <Animator>();
            audioSource = GetComponent <AudioSource>();

            // Initialise animation.
            animator.SetBool(groundedHash, true);
        }
示例#2
0
        void Awake()
        {
            minifig     = GetComponent <Minifig>();
            controller  = GetComponent <CharacterController>();
            animator    = GetComponent <Animator>();
            audioSource = GetComponent <AudioSource>();

            // Initialise animation.
            animator.SetBool(groundedHash, true);

            // Make sure the Character Controller is grounded if starting on the ground.
            controller.Move(Vector3.down * 0.01f);
        }
示例#3
0
        public static void Explode(Minifig minifig, Transform leftArmTip, Transform rightArmTip, Transform leftLegTip, Transform rightLegTip, Transform head, Vector3 speed, float angularSpeed)
        {
            const float spreadForce = 6.0f;
            const float removeDelay = 3.0f;

            // FIXME Add speed, angularSpeed and spreadForce to rigid body.

            // Use wrist, arm and armUp transforms.
            ExplodeLimb(minifig.transform, "Left arm", minifig.GetLeftArm(), leftArmTip.parent.parent.parent, leftArmTip.parent.parent, leftArmTip, 0.3f, speed, angularSpeed, spreadForce, removeDelay);
            ExplodeLimb(minifig.transform, "Right arm", minifig.GetRightArm(), rightArmTip.parent.parent.parent, rightArmTip.parent.parent, rightArmTip, 0.3f, speed, angularSpeed, spreadForce, removeDelay);

            var leftHandTransforms = new List <Transform> {
                leftArmTip, leftArmTip.parent
            };
            var rightHandTransforms = new List <Transform> {
                rightArmTip, rightArmTip.parent
            };
            var leftHandColliderCenters = new List <Vector3> {
                Vector3.forward * 0.2f, Vector3.zero
            };
            var rightHandColliderCenters = new List <Vector3> {
                Vector3.back * 0.2f, Vector3.zero
            };
            var handColliderSizes = new List <Vector3> {
                new Vector3(0.4f, 0.4f, 0.4f), new Vector3(0.2f, 0.4f, 0.2f)
            };
            var handColliderInitialTriggers = new List <bool> {
                false, true
            };

            ExplodeWithTransforms(minifig.transform, "Left hand", new List <Transform> {
                minifig.GetLeftHand()
            }, leftHandTransforms, leftHandColliderCenters, handColliderSizes, handColliderInitialTriggers, speed, angularSpeed, spreadForce, removeDelay);
            ExplodeWithTransforms(minifig.transform, "Right hand", new List <Transform> {
                minifig.GetRightHand()
            }, rightHandTransforms, rightHandColliderCenters, handColliderSizes, handColliderInitialTriggers, speed, angularSpeed, spreadForce, removeDelay);

            // Use foot, leg and legUp transforms.
            ExplodeLimb(minifig.transform, "Left leg", minifig.GetLeftLeg(), leftLegTip.parent.parent, leftLegTip.parent, leftLegTip, 0.5f, speed, angularSpeed, spreadForce, removeDelay);
            ExplodeLimb(minifig.transform, "Right leg", minifig.GetRightLeg(), rightLegTip.parent.parent, rightLegTip.parent, rightLegTip, 0.5f, speed, angularSpeed, spreadForce, removeDelay);

            // Use hip transform.
            var hipTransforms = new List <Transform> {
                leftLegTip.parent.parent.parent, leftLegTip.parent.parent.parent, leftLegTip.parent.parent.parent, leftLegTip.parent.parent.parent
            };
            var hipColliderCenters = new List <Vector3> {
                Vector3.up * 0.4f, Vector3.zero, new Vector3(0.0f, 0.7f, 0.4f), new Vector3(0.0f, 0.7f, -0.4f)
            };
            var hipColliderSizes = new List <Vector3> {
                new Vector3(0.8f, 0.2f, 1.6f), new Vector3(0.7f, 0.7f, 0.2f), new Vector3(0.4f, 0.4f, 0.4f), new Vector3(0.4f, 0.4f, 0.4f)
            };
            var hipColliderInitialTriggers = new List <bool> {
                false, false, true, true
            };

            ExplodeWithTransforms(minifig.transform, "Hip", minifig.GetHip(), hipTransforms, hipColliderCenters, hipColliderSizes, hipColliderInitialTriggers, speed, angularSpeed, spreadForce, removeDelay);

            // Use spine05 and spine01 transforms.
            var torsoTransforms = new List <Transform> {
                head.parent.parent.parent.parent, head.parent.parent.parent.parent.parent.parent.parent.parent
            };
            var torsoColliderCenters = new List <Vector3> {
                Vector3.up * 0.1f, Vector3.up * 0.3f
            };
            var torsoColliderSizes = new List <Vector3> {
                new Vector3(0.8f, 0.5f, 1.2f), new Vector3(0.8f, 0.5f, 1.4f)
            };
            var torsoColliderInitialTriggers = new List <bool> {
                false, false
            };

            ExplodeWithTransforms(minifig.transform, "Torso", minifig.GetTorso(), torsoTransforms, torsoColliderCenters, torsoColliderSizes, torsoColliderInitialTriggers, speed, angularSpeed, spreadForce, removeDelay);

            var headTransforms = new List <Transform> {
                head
            };
            var headColliderCenters = new List <Vector3> {
                Vector3.up * 0.48f
            };
            var headColliderSizes = new List <Vector3> {
                new Vector3(0.8f, 0.96f, 0.8f)
            };
            var headColliderInitialTriggers = new List <bool> {
                false
            };

            ExplodeWithTransforms(minifig.transform, "Head", minifig.GetHead(), headTransforms, headColliderCenters, headColliderSizes, headColliderInitialTriggers, speed, angularSpeed, spreadForce, removeDelay);

            var headAccessory = minifig.GetHeadAccessory();

            if (headAccessory)
            {
                var headAccessoryTransforms = new List <Transform> {
                    head.GetChild(0)
                };
                // FIXME Get correct colliders for accessories.
                var headAccessoryColliderCenters = new List <Vector3> {
                    Vector3.zero
                };
                var headAccessoryColliderSizes = new List <Vector3> {
                    new Vector3(0.8f, 0.96f, 0.8f)
                };
                var headAccessoryColliderInitialTriggers = new List <bool> {
                    true
                };
                ExplodeWithTransforms(minifig.transform, "Head accessory", new List <Transform> {
                    headAccessory
                }, headAccessoryTransforms, headAccessoryColliderCenters, headAccessoryColliderSizes, headAccessoryColliderInitialTriggers, speed, angularSpeed, spreadForce + 1.5f, removeDelay, false);
            }

            // Hack for Santa's beard.
            var beardParent = head.GetChild(1);

            if (beardParent.childCount > 0)
            {
                var beardAccessory = beardParent.GetChild(0);
                if (beardAccessory)
                {
                    var beardAccessoryTransforms = new List <Transform> {
                        beardAccessory
                    };
                    var beardAccessoryColliderCenters = new List <Vector3> {
                        Vector3.forward * 0.2f
                    };
                    var beardAccessoryColliderSizes = new List <Vector3> {
                        new Vector3(0.8f, 0.96f, 0.8f)
                    };
                    var beardAccessoryColliderInitialTriggers = new List <bool> {
                        true
                    };
                    ExplodeWithTransforms(minifig.transform, "Beard accessory", new List <Transform> {
                        beardAccessory
                    }, beardAccessoryTransforms, beardAccessoryColliderCenters, beardAccessoryColliderSizes, beardAccessoryColliderInitialTriggers, speed, angularSpeed, spreadForce + 1.5f, removeDelay, false);
                }
            }
        }