Exemplo n.º 1
0
            /*
             * ボーンを移動する前に実行される
             * SetuperExpandOptionから呼び出し
             */
            public void BeforeMoveArmature()
            {
                if (expandOption.original_bones == null)
                {
                    return;
                }
                for (int i = 0; i < expandOption.original_bones.Length; i++)
                {
                    OriginalBone originalBone = expandOption.original_bones[i];

                    Transform fromBone = PrefabData.GetCloth().transform.Find(originalBone.from);
                    Transform toBone   = PrefabData.GetAvatar().transform.Find(originalBone.to);

                    if (fromBone != null && toBone != null)
                    {
                        AppendIDToBone(fromBone);

                        fromBone.SetParent(toBone);
                    }
                }
            }
            private void ProcessCustomOperation(CustomOperation customOperation, bool isCheck)
            {
                switch (customOperation.operation_type.ToUpper())
                {
                case "DELETE_OBJECT":
                    if (!isCheck)
                    {
                        return;
                    }

                    for (int i = 0; i < customOperation.target_object_list.Length; i++)
                    {
                        string targetObjectName = customOperation.target_object_list[i];
                        if (!customOperation.is_avatar_object)
                        {
                            targetObjectName = AppendID(targetObjectName);
                        }

                        Transform target = PrefabData.GetAvatar().transform.Find(targetObjectName);
                        if (target == null)
                        {
                            return;
                        }
                        if (isDeleteIsEditorOnlyTag)
                        {
                            GameObjectUtil.SetEditorOnly(target.gameObject);
                        }
                        else
                        {
                            GameObject.DestroyImmediate(target.gameObject);
                        }
                    }
                    break;

                case "NOT_DELETE_OBJECT":
                    if (isCheck)
                    {
                        return;
                    }

                    for (int i = 0; i < customOperation.target_object_list.Length; i++)
                    {
                        string targetObjectName = customOperation.target_object_list[i];
                        if (!customOperation.is_avatar_object)
                        {
                            targetObjectName = AppendID(targetObjectName);
                        }

                        Transform target = PrefabData.GetAvatar().transform.Find(targetObjectName);
                        if (target == null)
                        {
                            return;
                        }
                        if (isDeleteIsEditorOnlyTag)
                        {
                            GameObjectUtil.SetEditorOnly(target.gameObject);
                        }
                        else
                        {
                            GameObject.DestroyImmediate(target.gameObject);
                        }
                    }
                    break;

                case "ENABLE_OBJECT":
                    if (!isCheck)
                    {
                        return;
                    }

                    for (int i = 0; i < customOperation.target_object_list.Length; i++)
                    {
                        string targetObjectName = customOperation.target_object_list[i];
                        if (!customOperation.is_avatar_object)
                        {
                            targetObjectName = AppendID(targetObjectName);
                        }

                        Transform target = PrefabData.GetAvatar().transform.Find(targetObjectName);
                        if (target != null)
                        {
                            target.gameObject.SetActive(true);
                        }
                    }
                    break;

                case "DISABLE_OBJECT":
                    if (!isCheck)
                    {
                        return;
                    }

                    for (int i = 0; i < customOperation.target_object_list.Length; i++)
                    {
                        string targetObjectName = customOperation.target_object_list[i];
                        if (!customOperation.is_avatar_object)
                        {
                            targetObjectName = AppendID(targetObjectName);
                        }

                        Transform target = PrefabData.GetAvatar().transform.Find(targetObjectName);
                        if (target != null)
                        {
                            target.gameObject.SetActive(false);
                        }
                    }
                    break;

                case "SET_MATERIAL":
                    if (!isCheck)
                    {
                        return;
                    }

                    string assetsPath = Path.GetDirectoryName(basePath) + "/";
                    string matPath    = FileUtil.GetPathFromRelative(assetsPath, customOperation.argument);
                    //AssetDatabase.LoadAssetAtPathは'C:example/'などのフルパスじゃなくて'Assets/Example'じゃないといけない
                    matPath = FileUtil.RemoveBasePath(matPath);
                    Material material = AssetDatabase.LoadAssetAtPath <Material>(matPath);

                    if (material != null)
                    {
                        for (int i = 0; i < customOperation.target_object_list.Length; i++)
                        {
                            string targetObjectName = customOperation.target_object_list[i];
                            if (!customOperation.is_avatar_object)
                            {
                                targetObjectName = AppendID(targetObjectName);
                            }

                            Transform target = PrefabData.GetAvatar().transform.Find(targetObjectName);
                            if (target != null)
                            {
                                SkinnedMeshRenderer meshRenderer = target.gameObject.GetComponent <SkinnedMeshRenderer>();
                                if (meshRenderer != null)
                                {
                                    meshRenderer.material = material;
                                }
                            }
                        }
                    }
                    break;

                //MoveObjectは服側を参照するため、IDを付ける必要はない
                case "MOVE_OBJECT":
                    if (!isCheck)
                    {
                        return;
                    }
                    //move_objectが無い、空の場合は何もしない
                    if (customOperation.move_object_list != null && customOperation.move_object_list.Length > 0)
                    {
                        for (int i = 0; i < customOperation.move_object_list.Length; i++)
                        {
                            MoveObject moveObject = customOperation.move_object_list[i];

                            //移動させるオブジェクト
                            Transform fromObject = PrefabData.GetCloth().transform.Find(moveObject.from);
                            //移動先のオブジェクト (移動先オブジェクトの子要素になる)
                            Transform toObject = PrefabData.GetAvatar().transform.Find(moveObject.to);

                            if (fromObject != null && toObject != null)
                            {
                                //そのオブジェクトと子オブジェクトにIDをつける
                                AppendIDToObject(fromObject);

                                fromObject.SetParent(toObject);
                            }
                        }
                    }
                    break;

                case "NONE":
                    break;
                }
            }