Exemplo n.º 1
0
        private void OnWizardCreate()
        {
            CombineMeshesAndSubMeshes.Combine(
                root: this.root,
                notCombineRendererObjectNames: this.notCombineRendererObjectNames.Except(new[] { "" }),
                destinationObjectName: this.destinationObjectName
                );

            EditorUtility.DisplayDialog(
                CombineMeshesAndSubMeshes.Name,
                "メッシュ、およびマテリアルが同一であるサブメッシュの結合が完了しました。",
                "OK"
                );
        }
Exemplo n.º 2
0
        /// <summary>
        /// プレハブが依存しているメッシュを複製・結合します。
        /// </summary>
        /// <param name="prefabInstance"></param>
        /// <param name="combineMeshesAndSubMeshes"></param>
        /// <param name="notCombineRendererObjectNames"></param>
        private static void DuplicateAndCombineMeshes(
            GameObject prefabInstance,
            bool combineMeshesAndSubMeshes,
            IEnumerable <string> notCombineRendererObjectNames
            )
        {
            var faceMeshRenderer
                = combineMeshesAndSubMeshes ? null : Duplicator.GetFaceMeshRenderer(prefabInstance: prefabInstance);

            var sameNameTransform = prefabInstance.transform.Find(VRChatUtility.AutoBlinkMeshPath);

            if (sameNameTransform && (combineMeshesAndSubMeshes || faceMeshRenderer.transform != sameNameTransform))
            {
                sameNameTransform.name += "-" + VRChatUtility.AutoBlinkMeshPath;
            }

            var prefabPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(prefabInstance);

            if (combineMeshesAndSubMeshes)
            {
                CombineMeshesAndSubMeshes.Combine(
                    root: prefabInstance,
                    notCombineRendererObjectNames,
                    destinationObjectName: VRChatUtility.AutoBlinkMeshPath
                    );
            }
            else
            {
                if (faceMeshRenderer.transform != sameNameTransform)
                {
                    faceMeshRenderer.transform.parent = prefabInstance.transform;
                    faceMeshRenderer.transform.name   = VRChatUtility.AutoBlinkMeshPath;
                }
            }
            PrefabUtility.SaveAsPrefabAssetAndConnect(prefabInstance, prefabPath, InteractionMode.AutomatedAction);

            var alreadyDuplicatedMeshes = new Dictionary <Mesh, Mesh>();

            foreach (var renderer in prefabInstance.GetComponentsInChildren <SkinnedMeshRenderer>())
            {
                if (combineMeshesAndSubMeshes && renderer.name == VRChatUtility.AutoBlinkMeshPath)
                {
                    continue;
                }

                var mesh = renderer.sharedMesh;
                renderer.sharedMesh = alreadyDuplicatedMeshes.ContainsKey(mesh)
                    ? alreadyDuplicatedMeshes[mesh]
                    : Duplicator.DuplicateAssetToFolder <Mesh>(
                    source: mesh,
                    prefabInstance,
                    fileName: Path.GetFileNameWithoutExtension(AssetDatabase.GetAssetPath(mesh))
                    == VRChatUtility.AutoBlinkMeshPath + ".asset"
                            ? VRChatUtility.AutoBlinkMeshPath + "-" + VRChatUtility.AutoBlinkMeshPath + ".asset"
                            : ""
                    );
                alreadyDuplicatedMeshes[mesh] = renderer.sharedMesh;
            }

            foreach (var filter in prefabInstance.GetComponentsInChildren <MeshFilter>())
            {
                Mesh mesh = filter.sharedMesh;
                filter.sharedMesh = alreadyDuplicatedMeshes.ContainsKey(mesh)
                    ? alreadyDuplicatedMeshes[mesh]
                    : Duplicator.DuplicateAssetToFolder <Mesh>(
                    source: mesh,
                    prefabInstance,
                    fileName: Path.GetFileNameWithoutExtension(AssetDatabase.GetAssetPath(mesh))
                    == VRChatUtility.AutoBlinkMeshPath + ".asset"
                            ? VRChatUtility.AutoBlinkMeshPath + "-" + VRChatUtility.AutoBlinkMeshPath + ".asset"
                            : ""
                    );
                alreadyDuplicatedMeshes[mesh] = filter.sharedMesh;
            }
        }