Пример #1
0
        // PhysicsPlaneSkirtをコピー先に追加する
        private static void AddPhysicsPlaneComponent(GameObject[] copys, GameObject[] origins)
        {
            // オリジナルのPhysicsObjectPlaneSkirtコンポーネントを取得
            var orgPhysicsComponents = origins.Select(a => a.GetComponent <PhysicsObjectPlaneSkirt>()).Where(a => a != null).ToList();

            // コピー先のPhysicsObjectPlaneSkirtが必要な名前リスト
            var copyPhysicsNames = copys.Select(a => a.name).Intersect(orgPhysicsComponents.Select(a => a.name)).ToList();

            foreach (var obj in copys)
            {
                foreach (var name in copyPhysicsNames)
                {
                    if (obj.name.Equals(name))
                    {
                        var compo = obj.AddComponent <PhysicsObjectPlaneSkirt>();

                        foreach (var org in orgPhysicsComponents)
                        {
                            if (org.name.Equals(obj.name))
                            {
                                compo.m_CheckKneeL = org.m_CheckKneeL;
                                compo.m_CheckKneeR = org.m_CheckKneeR;
                                compo.m_DrawGizmos = org.m_DrawGizmos;
                                compo.m_Inside     = org.m_Inside;
                                compo.m_KneeRadius = org.m_KneeRadius;
                                compo.m_Length     = org.m_Length;
                                compo.m_MoveAngle  = org.m_MoveAngle;
                                compo.m_OffsetY    = org.m_OffsetY;
                                compo.m_Outside    = org.m_Outside;
                            }
                        }
                    }
                }
            }

            // オリジナルでSkirtControllerがついているオブジェクト名と同名のオブジェクトをコピー先で取得する
            var orgSkirt  = origins.Where(a => a.GetComponent <SkirtController>()).ToList();
            var copySkirt = copys.Where(a => a.name.Equals(orgSkirt[0].name)).ToList();

            var orgController  = orgSkirt[0].GetComponent <SkirtController>();
            var copyController = copySkirt[0].AddComponent <SkirtController>();

            copyController._isAxisX             = orgController._isAxisX;
            copyController._LegAngleCoefficient = orgController._LegAngleCoefficient;
            copyController.m_KneeRadius         = orgController.m_KneeRadius;
            copyController.m_DrawGizmos         = orgController.m_DrawGizmos;

            // コピーのRoot
            var copyRoot = copys[0].GetRoot();

            copyController.m_ThighBoneL = GameObjectExtensions.SearchGameObject(copyRoot, orgController.m_ThighBoneL.name);
            copyController.m_ThighBoneR = GameObjectExtensions.SearchGameObject(copyRoot, orgController.m_ThighBoneR.name);
            copyController.m_KneeBoneL  = GameObjectExtensions.SearchGameObject(copyRoot, orgController.m_KneeBoneL.name);
            copyController.m_KneeBoneR  = GameObjectExtensions.SearchGameObject(copyRoot, orgController.m_KneeBoneR.name);
        }
Пример #2
0
        /// <summary>
        /// オリジナルからコピー先へコピーする
        /// </summary>
        public static void Copy(GameObject original, GameObject copy)
        {
            // 念のためオブジェクトのrootを取得
            original = GameObjectExtensions.GetRoot(original);
            copy     = GameObjectExtensions.GetRoot(copy);

            // originalのSpring系のコンポーネントがアタッチされている全オブジェクトを取得する

            // originalの全オブジェクトを取得
            var originalChildrens = GameObjectExtensions.GetChildren(original);

            // copyの全オブジェクトを取得
            var copyChildrens = GameObjectExtensions.GetChildren(copy);

            //************************
            // DynamicBoneColliderのコピー
            //************************

            // originalからDynamicBoneColliderがアタッチされているオブジェクトを取得
            var colliders = originalChildrens.Where(a => a.GetComponent <DynamicBoneCollider>()).ToList();

            // colliderListの親を取得
            var colliderParents = colliders.Select(a => a.GetParent()).ToList();

            // Boneの配列に受け渡す用
            List <GameObject> colliderObjs = new List <GameObject>();

            foreach (var child in copyChildrens)
            {
                foreach (var parent in colliderParents)
                {
                    foreach (var collider in colliders)
                    {
                        if (child.name.Equals(parent.name) && parent.name.Equals(collider.GetParent().name))
                        {
                            // 同じ階層に複数Colliderがあると重複分複製してしまうので判定
                            bool isDuplication = false;

                            foreach (var obj in colliderObjs)
                            {
                                if (collider.name.Contains(obj.name))
                                {
                                    isDuplication = true;
                                    break;
                                }
                            }

                            if (!isDuplication)
                            {
                                colliderObjs.Add(CreateCopyObject(collider, child));
                            }
                        }
                    }
                }
            }

            // Colliderのオブジェクトを追加したので更新
            originalChildrens = GameObjectExtensions.GetChildren(original);
            copyChildrens     = GameObjectExtensions.GetChildren(copy);

            //************************
            // DynamicBoneのコピー
            //************************

            // originalからDynamicBoneがアタッチされているオブジェクトを取得
            var bones = originalChildrens.Where(a => a.GetComponent <DynamicBone>()).ToList();

            List <DynamicBone> boneObjs = new List <DynamicBone>();

            foreach (var child in copyChildrens)
            {
                foreach (var bone in bones)
                {
                    if (child.name.Equals(bone.name))
                    {
                        DynamicBone boneCompo = null;


                        boneCompo = AddBoneComponent(bone, copyChildrens, child);

                        if (boneCompo != null)
                        {
                            boneObjs.Add(boneCompo);
                        }
                    }
                }
            }



            // Colliderのオブジェクトを追加したので更新
            originalChildrens = GameObjectExtensions.GetChildren(original);
            copyChildrens     = GameObjectExtensions.GetChildren(copy);

            //************************
            // SpringManagerのコピー
            //************************

            // SpringMangerをもつオブジェクトを抜き出す
            var managerlist = originalChildrens.Where(a => a.GetComponent <SpringManager>()).ToList();

            managerlist.ForEach(print);

            foreach (var item in managerlist)
            {
                var obj = GameObjectExtensions.SearchGameObject(copy, item.name);

                if (obj != null)
                {
                    AddMangerComponent(obj, copyChildrens, item);
                }
            }

            print(original.name + "から" + copy.name + "へ揺れ物系をコピーしました。");
        }