Exemplo n.º 1
0
        /// <summary>
        /// 情報をコピーします。
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        private static void CopyInformation(GameObject source, GameObject destination)
        {
            var sourceMeta      = source.GetComponent <VRMMeta>().Meta;
            var destinationMeta = destination.GetComponent <VRMMeta>().Meta;

            destinationMeta.Title              = sourceMeta.Title;
            destinationMeta.Version            = sourceMeta.Version;
            destinationMeta.Author             = sourceMeta.Author;
            destinationMeta.ContactInformation = sourceMeta.ContactInformation;
            destinationMeta.Reference          = sourceMeta.Reference;

            destinationMeta.Thumbnail = sourceMeta.Thumbnail;
            if (!destinationMeta.Thumbnail)
            {
                return;
            }

            var sourceThumbnailPath = AssetDatabase.GetAssetPath(destinationMeta.Thumbnail);

            if (UnityPath.FromUnityPath(sourceThumbnailPath).Parent.Value
                != UnityPath.FromAsset(source).GetAssetFolder(suffix: ".Textures").Value)
            {
                return;
            }

            var destinationPrefabPath = CopyVRMSettings.GetPrefabAssetPath(destination);

            if (string.IsNullOrEmpty(destinationPrefabPath))
            {
                return;
            }

            var destinationThumbnailPath = UnityPath.FromUnityPath(destinationPrefabPath)
                                           .GetAssetFolder(suffix: ".Textures")
                                           .Child(Path.GetFileName(sourceThumbnailPath)).GenerateUniqueAssetPath().Value;

            AssetDatabase.CopyAsset(sourceThumbnailPath, destinationThumbnailPath);
            destinationMeta.Thumbnail = AssetDatabase.LoadAssetAtPath <Texture2D>(destinationThumbnailPath);
        }
Exemplo n.º 2
0
        private void OnWizardCreate()
        {
            var components = new List <Type>();

            if (this.metaInformation)
            {
                components.Add(typeof(VRMMeta));
            }
            if (this.vrmBlendShape)
            {
                components.Add(typeof(VRMBlendShapeProxy));
            }
            if (this.firstPerson)
            {
                components.Add(typeof(VRMFirstPerson));
            }
            if (this.lookAt)
            {
                components.Add(typeof(VRMLookAtHead));
            }
            if (this.vrmSpringBone)
            {
                components.Add(typeof(VRMSpringBone));
            }

            CopyVRMSettings.Copy(
                source: this.sourceAvatar.gameObject,
                destination: this.destinationAvatar.gameObject,
                components
                );

            EditorUtility.DisplayDialog(
                MenuItems.Name + "-" + MenuItems.Version,
                Gettext._("Settings copying and pasting is completed."),
                Gettext._("OK")
                );
        }
Exemplo n.º 3
0
        protected override bool DrawWizardGUI()
        {
            base.DrawWizardGUI();
            this.isValid = true;

            if (!this.metaInformation && !this.vrmBlendShape && !this.firstPerson && !this.vrmSpringBone)
            {
                this.isValid = false;
                return(true);
            }

            EditorGUILayout.HelpBox(string.Format(
                                        this.vrmBlendShape
                    ? Gettext._("“{0}”and its VRMBlendShapes will be overwritten.")
                    : Gettext._("“{0}”will be overwritten."),
                                        "Destination Avatar"
                                        ), MessageType.None);

            if (this.sourceAvatar && this.destinationAvatar &&
                CopyVRMSettings.GetPrefabAssetPath(this.sourceAvatar.gameObject)
                == CopyVRMSettings.GetPrefabAssetPath(this.destinationAvatar.gameObject))
            {
                EditorGUILayout.HelpBox(string.Format(
                                            Gettext._("“{0}” and “{1}” are instances of same prefab."),
                                            "Source Avatar",
                                            "Destination Avatar"
                                            ), MessageType.Error);
                this.isValid = false;
            }

            foreach (var labelAndAnimator in new Dictionary <string, Animator> {
                { "Source Avatar", this.sourceAvatar },
                { "Destination Avatar", this.destinationAvatar },
            })
            {
                if (!labelAndAnimator.Value)
                {
                    this.isValid = false;
                    continue;
                }

                Transform transform = labelAndAnimator.Value.transform;
                if (transform != transform.root)
                {
                    EditorGUILayout.HelpBox(
                        string.Format(Gettext._("“{0}” is not root object."), labelAndAnimator.Key),
                        MessageType.Error
                        );
                    this.isValid = false;
                    continue;
                }

                foreach (var typeAndPropertyName in CopyVRMSettings.RequiredComponentsAndFields)
                {
                    var component = labelAndAnimator.Value.GetComponent(typeAndPropertyName.Key);
                    if (!labelAndAnimator.Value.GetComponent(typeAndPropertyName.Key))
                    {
                        EditorGUILayout.HelpBox(string.Format(
                                                    Gettext._("“{0}” is not set “{1}” component."),
                                                    labelAndAnimator.Key,
                                                    typeAndPropertyName.Key
                                                    ), MessageType.Error);
                        this.isValid = false;
                        continue;
                    }

                    if (string.IsNullOrEmpty(typeAndPropertyName.Value))
                    {
                        continue;
                    }

                    if (typeAndPropertyName.Key.GetField(
                            name: typeAndPropertyName.Value,
                            bindingAttr: BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public
                            ).GetValue(obj: component) == null)
                    {
                        EditorGUILayout.HelpBox(string.Format(
                                                    Gettext._("“{0}”’s “{1}” is null."),
                                                    labelAndAnimator.Key,
                                                    typeAndPropertyName.Key + "." + typeAndPropertyName.Value
                                                    ), MessageType.Error);
                        this.isValid = false;
                        continue;
                    }
                }
            }

            return(true);
        }