private void CreateAsset(MemoryStream ms, bool isTextAsset) { AssetDatabase.Refresh(); if (!isTextAsset) { string ext = "asset"; CRAnimationAsset animationAsset = CRAnimationAsset.CreateInstance <CRAnimationAsset>(); animationAsset.Bytes = ms.ToArray(); CRAnimationAsset animationAssetOld = crAnimation_.activeAnimation; string path = AssetDatabase.GetAssetPath(animationAssetOld); string name = animationAssetOld.name; int index = path.IndexOf(name + "." + ext); string newFolder = path.Substring(0, index); string newPath = EditorUtility.SaveFilePanelInProject("CaronteFX - Rebake animation", name + "_rebake", ext, "Select destination file name...", newFolder); if (newPath != string.Empty) { AssetDatabase.CreateAsset(animationAsset, newPath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); crAnimation_.AddAnimation(animationAsset); EditorGUIUtility.PingObject(animationAsset); } } else { string ext = "bytes"; TextAsset textAsset = crAnimation_.activeAnimationText; string path = AssetDatabase.GetAssetPath(textAsset); string name = textAsset.name; int index = path.IndexOf(name + "." + ext); string newFolder = path.Substring(0, index); string newPath = EditorUtility.SaveFilePanelInProject("CaronteFX - Rebake animation", name + "_rebake", ext, "Select destination file name...", newFolder); if (newPath != string.Empty) { FileStream fs = new FileStream(newPath, FileMode.Create); byte[] arrByte = ms.ToArray(); fs.Write(arrByte, 0, arrByte.Length); fs.Close(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); TextAsset crAnimationText = (TextAsset)AssetDatabase.LoadAssetAtPath(newPath, typeof(TextAsset)); crAnimation_.AddAnimation(crAnimationText); EditorGUIUtility.PingObject(crAnimationText); } } EditorUtility.SetDirty(crAnimation_); }
private CRAnimationAsset ConvertTextAssetToCRAnimationAsset(TextAsset textAsset, out string oldAssetPath) { oldAssetPath = AssetDatabase.GetAssetPath(textAsset.GetInstanceID()); int index = oldAssetPath.IndexOf(textAsset.name + ".bytes"); string assetDirectiory = oldAssetPath.Substring(0, index); string crAnimationFilePath = AssetDatabase.GenerateUniqueAssetPath(assetDirectiory + textAsset.name + ".asset"); CRAnimationAsset crAnimationAsset = CRAnimationAsset.CreateInstance <CRAnimationAsset>(); crAnimationAsset.Bytes = textAsset.bytes; AssetDatabase.CreateAsset(crAnimationAsset, crAnimationFilePath); return(crAnimationAsset); }