Ejemplo n.º 1
0
        public static void LoadVrmAsync(string path, Action <GameObject> onLoaded, Action <Exception> onError = null, bool show = true)
        {
            var context = new VRMImporterContext(UnityPath.FromFullpath(path));

            context.ParseGlb(File.ReadAllBytes(path));
            LoadVrmAsync(context, onLoaded, onError, show);
        }
Ejemplo n.º 2
0
 protected override UnityPath GetAssetPath(UnityPath prefabPath, UnityEngine.Object o)
 {
     if (o is BlendShapeAvatar ||
         o is BlendShapeClip)
     {
         var dir       = prefabPath.GetAssetFolder(".BlendShapes");
         var assetPath = dir.Child(o.name.EscapeFilePath() + ".asset");
         return(assetPath);
     }
     else if (o is Avatar)
     {
         var dir       = prefabPath.GetAssetFolder(".Avatar");
         var assetPath = dir.Child(o.name.EscapeFilePath() + ".asset");
         return(assetPath);
     }
     else if (o is VRMMetaObject)
     {
         var dir       = prefabPath.GetAssetFolder(".MetaObject");
         var assetPath = dir.Child(o.name.EscapeFilePath() + ".asset");
         return(assetPath);
     }
     else if (o is UniHumanoid.AvatarDescription)
     {
         var dir       = prefabPath.GetAssetFolder(".AvatarDescription");
         var assetPath = dir.Child(o.name.EscapeFilePath() + ".asset");
         return(assetPath);
     }
     else
     {
         return(base.GetAssetPath(prefabPath, o));
     }
 }
Ejemplo n.º 3
0
        private static void ImportVci(UnityPath path)
        {
            if (!path.IsUnderAssetsFolder)
            {
                throw new Exception();
            }
            var importer = new VCIImporter();

            importer.ParseGlb(File.ReadAllBytes(path.FullPath));

            var prefabPath = path.Parent.Child(path.FileNameWithoutExtension + ".prefab");

            // save texture assets !
            importer.ExtranctImages(prefabPath);
            importer.ExtractAudio(prefabPath);
            importer.ExtractEffekseer(prefabPath);

            EditorApplication.delayCall += () =>
            {
                //
                // after textures imported
                //
                importer.Load();
                importer.SetupCorutine().CoroutinetoEnd();
                importer.SetupPhysics();
                importer.SetupAttachable();
                importer.SetupEffekseer();
                importer.SetupText();
                importer.SetupSpringBone();
                importer.SaveAsAsset(prefabPath);
                importer.EditorDestroyRoot();
            };
        }
Ejemplo n.º 4
0
        public static void OpenImportMenu()
        {
            var path = EditorUtility.OpenFilePanel("open vrm", "", "vrm");

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

            if (Application.isPlaying)
            {
                // import vrm to scene without asset creation
                ImportRuntime(path);
            }
            else
            {
                // import vrm to asset
                if (path.StartsWithUnityAssetPath())
                {
                    Debug.LogWarningFormat("disallow import from folder under the Assets");
                    return;
                }

                var prefabPath = EditorUtility.SaveFilePanel("save prefab", "Assets", Path.GetFileNameWithoutExtension(path), "prefab");
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                vrmAssetPostprocessor.ImportVrmAndCreatePrefab(path, UnityPath.FromFullpath(prefabPath));
            }
        }
Ejemplo n.º 5
0
        private void PrefabsGUI()
        {
            using (new EditorGUILayout.HorizontalScope())
            {
                var dir = GetDirectoryForAddingPrefab();

                if (GUILayout.Button("Add Prefab"))
                {
                    var path = EditorUtility.OpenFilePanel("Select Prefabs", dir, "prefab");
                    if (!string.IsNullOrEmpty(path))
                    {
                        AddPrefab(UnityPath.ToAsset(path));
                    }
                }

                if (GUILayout.Button("Add Prefabs In Folder"))
                {
                    dir = EditorUtility.OpenFolderPanel("Select Folder", dir, null);
                    if (!string.IsNullOrEmpty(dir))
                    {
                        foreach (var path in UnityPath.EnumerateFiles(dir, "*.prefab"))
                        {
                            AddPrefab(path);
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private static glTF_VCAST_vci_audio FromAudioClip(glTF gltf, AudioClip clip)
        {
#if UNITY_EDITOR
            if (Application.isPlaying)
#endif
            {
                var bytes     = WaveUtil.GetWaveBinary(clip);
                var viewIndex = gltf.ExtendBufferAndGetViewIndex(0, bytes);
                return(new glTF_VCAST_vci_audio
                {
                    name = clip.name,
                    mimeType = "audio/wav",
                    bufferView = viewIndex,
                });
            }
#if UNITY_EDITOR
            else
            {
                var path = UnityPath.FromAsset(clip);
                if (!path.IsUnderAssetsFolder)
                {
                    return(null);
                }
                if (path.Extension.ToLower() == ".wav")
                {
                    var bytes     = File.ReadAllBytes(path.FullPath);
                    var viewIndex = gltf.ExtendBufferAndGetViewIndex(0, bytes);
                    return(new glTF_VCAST_vci_audio
                    {
                        name = clip.name,
                        mimeType = "audio/wav",
                        bufferView = viewIndex,
                    });
                }
                else if (path.Extension.ToLower() == ".mp3")
                {
                    var bytes     = File.ReadAllBytes(path.FullPath);
                    var viewIndex = gltf.ExtendBufferAndGetViewIndex(0, bytes);
                    return(new glTF_VCAST_vci_audio
                    {
                        name = clip.name,
                        mimeType = "audio/mp3",
                        bufferView = viewIndex,
                    });
                }
                else
                {
                    // Convert to wav
                    var bytes     = WaveUtil.GetWaveBinary(clip);
                    var viewIndex = gltf.ExtendBufferAndGetViewIndex(0, bytes);
                    return(new glTF_VCAST_vci_audio
                    {
                        name = clip.name,
                        mimeType = "audio/wav",
                        bufferView = viewIndex,
                    });
                }
            }
#endif
        }
Ejemplo n.º 7
0
        static void ImportVrm(UnityPath path)
        {
            if (!path.IsUnderAssetsFolder)
            {
                throw new Exception();
            }
            var context = new VRMImporterContext();

            context.ParseGlb(File.ReadAllBytes(path.FullPath));

            var prefabPath = path.Parent.Child(path.FileNameWithoutExtension + ".prefab");

            // save texture assets !
            context.ExtractImages(prefabPath);

            EditorApplication.delayCall += () =>
            {
                //
                // after textures imported
                //
                context.Load();
                context.SaveAsAsset(prefabPath);
                context.EditorDestroyRoot();
            };
        }
Ejemplo n.º 8
0
    public IEnumerator Action()
    {
        List <SQLiteConnectFactory.Link> links = sqliteLinks.Links;
        int completed = 0;
        int capacity  = links.Count;

        IsDone   = false;
        Progress = 0.0f;

        while (completed < capacity)
        {
            string assetPath      = links[completed].DBPath;
            string persistentPath = UnityPath.Combinate(assetPath, UnityPath.AssetPath.Persistent);

            if (!UnityPath.Exist(persistentPath))
            {
                yield return(AndroidCopy.Copy(assetPath, persistentPath));
            }

            completed++;
            Progress = completed * 1.0f / capacity;
            //Debugger.Log("Copy progress: " + Progress);
        }
        IsDone = true;
        yield break;
    }
Ejemplo n.º 9
0
        static void TraverseItem(ListTreeNode <JsonValue> node, JsonFormatter f, UnityPath dir)
        {
            var title = GetTitle(node);

            if (string.IsNullOrEmpty(title))
            {
                Traverse(node, f, dir);
            }
            else
            {
                // ref
                f.BeginMap();
                f.Key("$ref");
                var fileName = string.Format("{0}.schema.json", title);
                f.Value(fileName);
                f.EndMap();

                // new formatter
                {
                    var subFormatter = new JsonFormatter(4);

                    subFormatter.BeginMap();
                    foreach (var _kv in node.ObjectItems())
                    {
                        subFormatter.Key(_kv.Key.GetUtf8String());
                        Traverse(_kv.Value, subFormatter, dir);
                    }
                    subFormatter.EndMap();

                    var subJson = subFormatter.ToString();
                    var path    = dir.Child(fileName);
                    File.WriteAllText(path.FullPath, subJson);
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// コピー元のアバターのBlendShapeClipを基に、コピー先のアバターのBlendShapeClipを書き替えます。
        /// </summary>
        /// <param name="sourceClip"></param>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        private static void CopyBlendShapeClip(BlendShapeClip sourceClip, GameObject source, GameObject destination)
        {
            var destinationBlendShapeAvatar = destination.GetComponent <VRMBlendShapeProxy>().BlendShapeAvatar;

            var destinationClip = sourceClip.Preset != BlendShapePreset.Unknown
                ? destinationBlendShapeAvatar.GetClip(sourceClip.Preset)
                : destinationBlendShapeAvatar.GetClip(sourceClip.BlendShapeName);

            if (sourceClip == destinationClip)
            {
                return;
            }

            if (!destinationClip)
            {
                destinationClip = BlendShapeAvatar.CreateBlendShapeClip(
                    UnityPath.FromAsset(destinationBlendShapeAvatar)
                    .Parent.Child(Path.GetFileName(AssetDatabase.GetAssetPath(sourceClip))).Value
                    );
                destinationBlendShapeAvatar.Clips.Add(destinationClip);
                EditorUtility.SetDirty(destinationBlendShapeAvatar);
            }

            destinationClip.Values = sourceClip.Values
                                     .Select(binding => CopyVRMBlendShapes.CopyBlendShapeBinding(binding, source, destination)).ToArray();

            destinationClip.MaterialValues = sourceClip.MaterialValues.ToArray();

            EditorUtility.SetDirty(destinationClip);
        }
Ejemplo n.º 11
0
        static void Traverse(JsonNode node, JsonFormatter f, UnityPath dir)
        {
            switch (node.Value.ValueType)
            {
            case JsonValueType.Array:
                f.BeginList();
                foreach (var x in node.ArrayItems)
                {
                    TraverseItem(x, f, dir);
                }
                f.EndList();
                break;

            case JsonValueType.Object:
                //Debug.LogFormat("title: {0}", title);
            {
                f.BeginMap();
                foreach (var kv in node.ObjectItems)
                {
                    f.Key(kv.Key);
                    TraverseItem(kv.Value, f, dir);
                }
                f.EndMap();
            }
            break;

            default:
                f.Value(node);
                break;
            }
        }
Ejemplo n.º 12
0
 static void Traverse(ListTreeNode <JsonValue> node, JsonFormatter f, UnityPath dir)
 {
     if (node.IsArray())
     {
         f.BeginList();
         foreach (var x in node.ArrayItems())
         {
             TraverseItem(x, f, dir);
         }
         f.EndList();
     }
     else if (node.IsMap())
     {
         f.BeginMap();
         foreach (var kv in node.ObjectItems())
         {
             f.Key(kv.Key.GetUtf8String());
             TraverseItem(kv.Value, f, dir);
         }
         f.EndMap();
     }
     else
     {
         f.Value(node);
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="src"></param>
 /// <param name="prefabPath"></param>
 /// <param name="context"></param>
 static void ImportDelayed(string src, UnityPath prefabPath, ImporterContext context)
 {
     EditorApplication.delayCall += () =>
     {
         //
         // After textures imported(To ensure TextureImporter be accessible).
         //
         try
         {
             context.Load();
             context.SaveAsAsset(prefabPath);
             context.EditorDestroyRoot();
         }
         catch (UniGLTFNotSupportedException ex)
         {
             Debug.LogWarningFormat("{0}: {1}",
                                    src,
                                    ex.Message
                                    );
             context.EditorDestroyRootAndAssets();
         }
         catch (Exception ex)
         {
             Debug.LogErrorFormat("import error: {0}", src);
             Debug.LogErrorFormat("{0}", ex);
             context.EditorDestroyRootAndAssets();
         }
     };
 }
Ejemplo n.º 14
0
        public static void SyncSpriteArgs()
        {
            // get paths to Sprite args
            string[] guids = AssetDatabase.FindAssets($"t:{nameof(SpriteArgs)}");

            Type spriteArgsType = typeof(SpriteArgs);
            Type spriteType     = typeof(Sprite);

            foreach (string guid in guids)
            {
                PathString path = AssetDatabase.GUIDToAssetPath(guid);
                SpriteArgs args = AssetDatabase.LoadAssetAtPath <SpriteArgs>(path);

                string head = path.RelativeTo("So").ToString('/', false);

                foreach (FieldInfo f in spriteArgsType.GetFields())
                {
                    if (f.FieldType != spriteType)
                    {
                        continue;
                    }

                    UnityPath spritePath = "Assets/Art/Sprites/" + head + $"@{f.Name}.png";

                    Sprite sprite = AssetDatabase.LoadAssetAtPath <Sprite>(spritePath.AssetDatabaseAssetPath);
                    if (sprite != null)
                    {
                        f.SetValue(args, sprite);
                    }
                }
            }

            AssetDatabase.Refresh();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// アセットをプレハブが置かれているディレクトリの直下のフォルダへ複製します。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">複製元のオブジェクト。</param>
        /// <param name="prefabInstance">プレハブインスタンス。</param>
        /// <param name="fileName">ファイル名が複製元と異なる場合に指定。</param>
        /// <returns></returns>
        internal static T DuplicateAssetToFolder <T>(
            T source,
            GameObject prefabInstance,
            string fileName = ""
            ) where T : Object
        {
            string destinationFileName;

            if (string.IsNullOrEmpty(fileName))
            {
                var sourceUnityPath = UnityPath.FromAsset(source);
                if (!sourceUnityPath.IsUnderAssetsFolder || AssetDatabase.IsSubAsset(source))
                {
                    destinationFileName = source.name.EscapeFilePath() + ".asset";
                }
                else
                {
                    destinationFileName = Path.GetFileName(sourceUnityPath.Value);
                }
            }
            else
            {
                destinationFileName = fileName;
            }

            return(Duplicator.DuplicateAsset(
                       source,
                       destinationPath: Duplicator.DetermineAssetPath(prefabInstance, typeof(T), destinationFileName)
                       ));
        }
Ejemplo n.º 16
0
        static void ImportMenu()
        {
            var path = EditorUtility.OpenFilePanel("open vrm", "", "vrm");

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

            if (Application.isPlaying)
            {
                ImportRuntime(path);
                return;
            }

            if (path.StartsWithUnityAssetPath())
            {
                Debug.LogWarningFormat("disallow import from folder under the Assets");
                return;
            }

            var prefabPath = EditorUtility.SaveFilePanel("save prefab", "Assets", Path.GetFileNameWithoutExtension(path), "prefab");

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

            ImportAsset(path, UnityPath.FromFullpath(prefabPath));
        }
Ejemplo n.º 17
0
        void Restore()
        {
            var assetPath = UnityPath.FromAsset(this);

            if (assetPath.IsNull)
            {
                return;
            }


            foreach (var x in assetPath.Parent.ChildFiles)
            {
                var clip = UnityEditor.AssetDatabase.LoadAssetAtPath <BlendShapeClip>(x.Value);
                if (clip == null)
                {
                    continue;
                }

                if (!Clips.Contains(clip))
                {
                    Clips.Add(clip);
                }

                Debug.LogFormat("{0}", clip.name);
            }
            Clips = Clips.OrderBy(x => BlendShapeKey.CreateFrom(x)).ToList();
        }
Ejemplo n.º 18
0
        public static Task <GameObject> LoadVrmAsync(string path, bool show = true)
        {
            var context = new VRMImporterContext(UnityPath.FromFullpath(path));

            context.ParseGlb(File.ReadAllBytes(path));
            return(LoadVrmAsyncInternal(context, show).ToTask());
        }
Ejemplo n.º 19
0
        static void ImportMenu()
        {
            var path = EditorUtility.OpenFilePanel("open vrm", "", "vrm");

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

            if (Application.isPlaying)
            {
                // load into scene
                var parser = new GltfParser();
                parser.ParsePath(path);

                using (var context = new VRMImporterContext(parser))
                {
                    context.Load();
                    context.EnableUpdateWhenOffscreen();
                    context.ShowMeshes();
                    context.DisposeOnGameObjectDestroyed();
                    Selection.activeGameObject = context.Root;
                }
            }
            else
            {
                if (path.StartsWithUnityAssetPath())
                {
                    Debug.LogWarningFormat("disallow import from folder under the Assets");
                    return;
                }

                var assetPath = EditorUtility.SaveFilePanel("save prefab", "Assets", Path.GetFileNameWithoutExtension(path), "prefab");
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                if (!assetPath.StartsWithUnityAssetPath())
                {
                    Debug.LogWarningFormat("out of asset path: {0}", assetPath);
                    return;
                }

                // import as asset
                var prefabPath = UnityPath.FromUnityPath(assetPath);
                var parser     = new GltfParser();
                parser.ParseGlb(File.ReadAllBytes(path));

                Action <IEnumerable <string> > onCompleted = texturePaths =>
                {
                    //
                    // after textures imported
                    //
                    var map = texturePaths.Select(x =>
                    {
                        var texture = AssetDatabase.LoadAssetAtPath(x, typeof(Texture2D));
                        return(texture.name, texture);
                    }).ToArray();
Ejemplo n.º 20
0
        static void ImportMenu()
        {
            var path = EditorUtility.OpenFilePanel("open vrm", "", "vrm");

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

            if (Application.isPlaying)
            {
                // load into scene
                var parser = new GltfParser();
                parser.ParsePath(path);
                var context = new VRMImporterContext(parser);
                context.Load();
                context.ShowMeshes();
                context.EnableUpdateWhenOffscreen();
                Selection.activeGameObject = context.Root;
            }
            else
            {
                if (path.StartsWithUnityAssetPath())
                {
                    Debug.LogWarningFormat("disallow import from folder under the Assets");
                    return;
                }

                var assetPath = EditorUtility.SaveFilePanel("save prefab", "Assets", Path.GetFileNameWithoutExtension(path), "prefab");
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                if (!assetPath.StartsWithUnityAssetPath())
                {
                    Debug.LogWarningFormat("out of asset path: {0}", assetPath);
                    return;
                }

                // import as asset
                var prefabPath = UnityPath.FromUnityPath(assetPath);
                var parser     = new GltfParser();
                parser.ParseGlb(File.ReadAllBytes(path));
                var context = new VRMImporterContext(parser);
                var editor  = new VRMEditorImporterContext(context);
                editor.ExtractImages(prefabPath);

                EditorApplication.delayCall += () =>
                {
                    //
                    // after textures imported
                    //
                    context.Load();
                    editor.SaveAsAsset(prefabPath);
                    editor.Dispose();
                };
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        ///	This makes it easy to create, name and place unique new ScriptableObject asset files.
        /// The path should point to the indented file dir/path/soname. The .asset extension should be
        /// included in the path. The change will not show up in the editor without a call to AssetDatabase.Refresh()
        /// </summary>
        public static TSo CreateSoAsset <TSo>(UnityPath path) where TSo : ScriptableObject
        {
            TSo asset = ScriptableObject.CreateInstance <TSo>();

            AssetDatabase.CreateAsset(asset, path.AssetDatabaseAssetPath);
            AssetDatabase.SaveAssets();
            return(asset);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// This function is really a function contructor for a common pattern. This function 1) Attempts
        /// to load a So at a location. 2) if the so dosen't exist at the location, creates it. 3) Calls the
        /// populator on the So and the pop object, with the intention that the data in the pop object
        /// is used to populate the So. 4) Returns the So.
        /// </summary>
        /// <returns></returns>
        public static TSo PopulateOrCreateAssetFrom <TSo, TPopulator>(UnityPath path, TPopulator pop, Action <TSo, TPopulator> populator)
            where TSo : ScriptableObject
        {
            TSo obj = LoadOrCreateSoAsset <TSo>(path);

            populator(obj, pop);
            return(obj);
        }
Ejemplo n.º 23
0
        /// <summary>
        ///	This makes it easy to create, name and place unique new ScriptableObject asset files using the type name.
        /// The path should point to the indented file dir/path/soname. The .asset extension should be
        /// included in the path. The change will not show up in the editor without a call to AssetDatabase.Refresh()
        /// </summary>
        public static ScriptableObject CreateSoAsset(UnityPath path, string type)
        {
            path.Path.CreateIfNotExistsDirectory();
            ScriptableObject asset = ScriptableObject.CreateInstance(type);

            AssetDatabase.CreateAsset(asset, path.AssetDatabaseAssetPath);
            AssetDatabase.SaveAssets();
            return(asset);
        }
Ejemplo n.º 24
0
        static void PreExport(Shader shader)
        {
            var path = UnityPath.FromUnityPath(EXPORT_DIR + EscapeShaderName(shader.name) + ".cs");

            Debug.LogFormat("PreExport: {0}", path.FullPath);

            var props = ShaderProps.FromShader(shader);

            File.WriteAllText(path.FullPath, props.ToString(shader.name));
        }
Ejemplo n.º 25
0
        private static bool TryCreateAsset(out T asset)
        {
            asset = CreateInstance <T>();
            var path = Path.assetPath;

            UnityPath.CreateDirectoryInEditor(path);
            AssetDatabase.CreateAsset(asset, path);
            AssetDatabase.SaveAssets();
            return(asset != null);
        }
Ejemplo n.º 26
0
    static void GanerateTriangle()
    {
        Vector2[] polygon    = { new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 0), };
        string    savePath   = UnityPath.FullToAssetDatabasePath(EditorUtility.SaveFilePanel("Save Mesh", Application.dataPath, "Triangle", "asset"));
        string    formatPath = savePath.Replace(".asset", "{0}.asset");

        AssetDatabase.CreateAsset(MeshGenerater.Polygon2D(polygon, Vector3.back, Vector3.up), string.Format(formatPath, "Plane"));
        AssetDatabase.CreateAsset(MeshGenerater.PillarForCollider(polygon, Vector3.back, Vector3.up), string.Format(formatPath, "Collider"));
        AssetDatabase.Refresh();
    }
Ejemplo n.º 27
0
    private void SerializeConfigFile(FileConfig config)
    {
        string configFilePath = PlayerPrefs.GetString(localPathKey);
        string tempXml        = UnityPath.Combinate("temp.xml", UnityPath.AssetPath.Persistent);

        XmlEncoder.Serialize <FileConfig>(tempXml, config);
        XmlEncoder.Encode(tempXml, configFilePath);

        File.Delete(tempXml);
    }
        /// <summary>
        /// 表情の設定を行うアニメーションクリップを作成します。
        /// </summary>
        /// <param name="avatar"></param>
        /// <param name="vrmBlendShape"></param>
        /// <param name="clips"></param>
        /// <returns></returns>
        private static AnimationClip CreateFeeling(
            GameObject avatar,
            VRMBlendShapeClip clip,
            ref IEnumerable <VRMBlendShapeClip> clips
            )
        {
            var fileName = clip.Preset + ".anim";

#if VRC_SDK_VRCSDK2
            var anim = Duplicator.DuplicateAssetToFolder <AnimationClip>(
                source: UnityPath.FromUnityPath(Converter.RootFolderPath).Child("animations")
                .Child(BlendShapeReplacer.MappingBlendShapeToVRChatAnim[clip.Preset] + ".anim")
                .LoadAsset <AnimationClip>(),
                prefabInstance: avatar,
                fileName
                );

            Transform transform = avatar.transform.Find(VRChatUtility.AutoBlinkMeshPath);
            if (transform.GetComponent <Animator>())
            {
                var curve = new AnimationCurve();
                foreach (var(seconds, value) in BlendShapeReplacer.NeutralAndBlinkStopperWeights)
                {
                    curve.AddKey(new Keyframe(seconds, value));
                }
                anim.SetCurve(
                    VRChatUtility.AutoBlinkMeshPath,
                    typeof(Behaviour),
                    "m_Enabled",
                    curve
                    );

                clips = BlendShapeReplacer.DuplicateShapeKeyToUnique(avatar, clip, clips);
            }
#else
            var anim = new AnimationClip();
            AssetDatabase.CreateAsset(
                anim,
                Duplicator.DetermineAssetPath(prefabInstance: avatar, typeof(AnimationClip), fileName)
                );
            clips = BlendShapeReplacer.DuplicateShapeKeyToUnique(avatar, clip, clips);
#endif

            SetBlendShapeCurves(
                avatar,
                animationClip: anim,
                clip: clip,
                keys: new Dictionary <float, float> {
                { 0, 1 },
                { anim.length, 1 },
            }
                );

            return(anim);
        }
Ejemplo n.º 29
0
        public static void IntegrateSelected(GameObject go)
        {
            var meshWithMaterials = StaticMeshIntegrator.Integrate(go.transform);

            // save as asset
            var assetPath = "";

#if UNITY_2018_2_OR_NEWER
            var prefab = PrefabUtility.GetCorrespondingObjectFromSource(go);
#else
            var prefab = PrefabUtility.GetPrefabParent(go);
#endif
            if (prefab != null)
            {
                var prefabPath = AssetDatabase.GetAssetPath(prefab);
                assetPath = string.Format("{0}/{1}_{2}{3}",
                                          Path.GetDirectoryName(prefabPath),
                                          Path.GetFileNameWithoutExtension(prefabPath),
                                          go.name,
                                          ASSET_SUFFIX
                                          );
            }
            else
            {
                var path = EditorUtility.SaveFilePanel(
                    "Save mesh",
                    "Assets",
                    go.name + ".asset",
                    "asset");
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }
                assetPath = UnityPath.FromFullpath(path).Value;
            }

            assetPath = AssetDatabase.GenerateUniqueAssetPath(assetPath);
            Debug.LogFormat("CreateAsset: {0}", assetPath);
            AssetDatabase.CreateAsset(meshWithMaterials.Mesh, assetPath);

            // add component
            var meshObject = new GameObject(go.name + ".static_meshes_integrated");
            if (go.transform.parent != null)
            {
                meshObject.transform.SetParent(go.transform.parent, false);
            }
            meshObject.transform.localPosition = go.transform.localPosition;
            meshObject.transform.localRotation = go.transform.localRotation;
            meshObject.transform.localScale    = go.transform.localScale;

            var filter = meshObject.AddComponent <MeshFilter>();
            filter.sharedMesh = meshWithMaterials.Mesh;
            var renderer = meshObject.AddComponent <MeshRenderer>();
            renderer.sharedMaterials = meshWithMaterials.Materials;
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Attempts to load an SoAsset. If not found, creates it. Path should include the .asset extension.
        /// The change will not show up in the editor without a call to AssetDatabase.Refresh()
        /// </summary>
        /// <typeparam name="TSo"></typeparam>
        /// <param name="path"></param>
        /// <param name="autoRefesh"></param>
        /// <returns></returns>
        public static ScriptableObject LoadOrCreateSoAsset(UnityPath path, string type)
        {
            ScriptableObject obj = AssetDatabase.LoadAssetAtPath <ScriptableObject>(path.AssetDatabaseAssetPath);

            if (obj == null)
            {
                obj = CreateSoAsset(path, type);
            }

            return(obj);
        }