예제 #1
0
        /// <summary>
        /// 剛体のグローバル座標化
        /// </summary>
        /// <param name='joints'>ジョイントのゲームオブジェクト</param>
        void GlobalizeRigidbody(GameObject[] joints)
        {
            Transform physics_root_transform = root_game_object_.transform.Find("Physics");
            PhysicsManager physics_manager = physics_root_transform.gameObject.GetComponent<PhysicsManager>();

            if ((null != joints) && (0 < joints.Length)) {
                // PhysicsManagerに移動前の状態を覚えさせる(幾つか重複しているので重複は削除)
                physics_manager.connect_bone_list = joints.Select(x=>x.gameObject)
                                                            .Distinct()
                                                            .Select(x=>new PhysicsManager.ConnectBone(x, x.transform.parent.gameObject))
                                                            .ToArray();

                //isKinematicで無くConfigurableJointを持つ場合はグローバル座標化
                foreach (ConfigurableJoint joint in joints.Where(x=>!x.GetComponent<Rigidbody>().isKinematic)
                                                            .Select(x=>x.GetComponent<ConfigurableJoint>())) {
                    joint.transform.parent = physics_root_transform;
                }
            }
        }