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); }
public void ConvertTextAssetsToCRAnimationAssets() { TextAsset textAnimation = ac_.activeAnimationText; if (textAnimation != null) { string oldAssetPath; CRAnimationAsset crAnimationAsset = ConvertTextAssetToCRAnimationAsset(textAnimation, out oldAssetPath); ac_.activeAnimationText = null; ac_.RemoveAnimation(textAnimation); AssetDatabase.DeleteAsset(oldAssetPath); ac_.AddAnimationAndSetActive(crAnimationAsset); } List <CRAnimationAsset> listCRAnimationAsset = ac_.listAnimations; List <TextAsset> listTextAsset = ac_.listAnimationsText; int lastAnimationAssets = listTextAsset.Count - 1; for (int i = lastAnimationAssets; i >= 0; i--) { TextAsset textAsset = listTextAsset[i]; string oldAssetPath; CRAnimationAsset crAnimationAsset = ConvertTextAssetToCRAnimationAsset(textAsset, out oldAssetPath); listTextAsset.RemoveAt(i); listCRAnimationAsset.Add(crAnimationAsset); AssetDatabase.DeleteAsset(oldAssetPath); } listCRAnimationAsset.Reverse(); AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); EditorUtility.SetDirty(ac_); }
private TextAsset ConvertCRAnimationAssetToTextAsset(CRAnimationAsset crAnimationAsset, out string oldAssetPath) { oldAssetPath = AssetDatabase.GetAssetPath(crAnimationAsset.GetInstanceID()); int index = oldAssetPath.IndexOf(crAnimationAsset.name + ".asset"); string assetDirectiory = oldAssetPath.Substring(0, index); string cacheFilePath = AssetDatabase.GenerateUniqueAssetPath(assetDirectiory + crAnimationAsset.name + ".bytes"); FileStream fs = new FileStream(cacheFilePath, FileMode.Create); byte[] arrByte = crAnimationAsset.Bytes; fs.Write(arrByte, 0, arrByte.Length); fs.Close(); AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); TextAsset crAnimationText = (TextAsset)AssetDatabase.LoadAssetAtPath(cacheFilePath, typeof(TextAsset)); return(crAnimationText); }