Beispiel #1
0
        /// <summary>
        /// Imports the corresponding asset.
        /// </summary>
        public override void Import()
        {
            var isImporterDirty = false;

            var clip = (ShouldImportAsOriginalWorkflow)
                    ? AssetDatabase.LoadAssetAtPath <AnimationClip>(AssetPath.Replace(".motion3.json", ".anim"))
                    : null;

            // Convert motion.
            var animationClip = (clip == null)
                                ? Motion3Json.ToAnimationClip(ShouldImportAsOriginalWorkflow, ShouldClearAnimationCurves)
                                : Motion3Json.ToAnimationClip(clip, ShouldImportAsOriginalWorkflow, ShouldClearAnimationCurves);


            // Create animation clip.
            if (AnimationClip == null)
            {
                AssetDatabase.CreateAsset(animationClip, AssetPath.Replace(".motion3.json", ".anim"));


                AnimationClip = animationClip;


                isImporterDirty = true;
            }

            // Update animation clip.
            else
            {
                EditorUtility.CopySerialized(animationClip, AnimationClip);
                EditorUtility.SetDirty(AnimationClip);


                // Log event.
                CubismImporter.LogReimport(AssetPath, AssetDatabase.GUIDToAssetPath(_animationClipGuid));
            }


            // Trigger event.
            CubismImporter.SendMotionImportEvent(this, AnimationClip);


            // Apply changes.
            if (isImporterDirty)
            {
                Save();
            }
            else
            {
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }
        }
        /// <summary>
        /// Imports the corresponding asset.
        /// </summary>
        public override void Import()
        {
            var isImporterDirty = false;


            // Convert motion.
            var animationClip = Motion3Json.ToAnimationClip();


            // Create animation clip.
            if (AnimationClip == null)
            {
                AssetDatabase.CreateAsset(animationClip, AssetPath.Replace(".motion3.json", ".anim"));


                AnimationClip = animationClip;


                isImporterDirty = true;
            }

            // Update animation clip.
            else
            {
                EditorUtility.CopySerialized(animationClip, AnimationClip);
                EditorUtility.SetDirty(AnimationClip);


                // Log event.
                CubismImporter.LogReimport(AssetPath, AssetDatabase.GUIDToAssetPath(_animationClipGuid));
            }


            // Trigger event.
            CubismImporter.SendMotionImportEvent(this, animationClip);


            // Apply changes.
            if (isImporterDirty)
            {
                Save();
            }
            else
            {
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }
        }
Beispiel #3
0
 // ReSharper disable once UnusedMember.Local
 private static void RegisterImporter()
 {
     CubismImporter.RegisterImporter <CubismMotion3JsonImporter>(".motion3.json");
 }
        /// <summary>
        /// Imports the corresponding asset.
        /// </summary>
        public override void Import()
        {
            var isImporterDirty = false;


            // Instantiate model source and model.
            var model = Model3Json.ToModel(CubismImporter.OnPickMaterial, CubismImporter.OnPickTexture);
            var moc   = model.Moc;


            // Create moc asset.
            if (MocAsset == null)
            {
                AssetDatabase.CreateAsset(moc, AssetPath.Replace(".model3.json", ".asset"));


                MocAsset = moc;


                isImporterDirty = true;
            }


            // Create model prefab.
            if (ModelPrefab == null)
            {
                // Trigger event.
                CubismImporter.SendModelImportEvent(this, model);


                foreach (var texture in Model3Json.Textures)
                {
                    CubismImporter.SendModelTextureImportEvent(this, model, texture);
                }


                // Create prefab and trigger saving of changes.
                ModelPrefab = PrefabUtility.CreatePrefab(AssetPath.Replace(".model3.json", ".prefab"), model.gameObject);


                isImporterDirty = true;
            }


            // Update model prefab.
            else
            {
                // Copy all user data over from previous model.
                var source = Object.Instantiate(ModelPrefab).FindCubismModel();


                CopyUserData(source, model);
                Object.DestroyImmediate(source.gameObject, true);


                // Trigger events.
                CubismImporter.SendModelImportEvent(this, model);


                foreach (var texture in Model3Json.Textures)
                {
                    CubismImporter.SendModelTextureImportEvent(this, model, texture);
                }


                // Reset moc reference.
                CubismModel.ResetMocReference(model, MocAsset);

                // Replace prefab.
                ModelPrefab = PrefabUtility.ReplacePrefab(model.gameObject, ModelPrefab, ReplacePrefabOptions.ConnectToPrefab);


                // Log event.
                CubismImporter.LogReimport(AssetPath, AssetDatabase.GUIDToAssetPath(_modelPrefabGuid));
            }


            // Clean up.
            Object.DestroyImmediate(model.gameObject, true);


            // Update moc asset.
            if (MocAsset != null)
            {
                EditorUtility.CopySerialized(moc, MocAsset);


                // Revive by force to make instance using the new Moc.
                CubismMoc.ResetUnmanagedMoc(MocAsset);


                EditorUtility.SetDirty(MocAsset);
            }

            // Save state and assets.
            if (isImporterDirty)
            {
                Save();
            }
            else
            {
                AssetDatabase.SaveAssets();
            }
        }
 // ReSharper disable once UnusedMember.Local
 private static void RegisterImporter()
 {
     CubismImporter.RegisterImporter <CubismExpression3JsonImporter>(".exp3.json");
 }