浏览代码

move to relative paths for 4D frame data

/main
Lasse Jon Fuglsang Pedersen 5 年前
当前提交
31a7aa79
共有 2 个文件被更改,包括 42 次插入28 次删除
  1. 3
      Editor/SkinDeformationClipEditor.cs
  2. 67
      Runtime/SkinDeformationClip.cs

3
Editor/SkinDeformationClipEditor.cs


clip.version++;
EditorUtility.SetDirty(clip);
AssetDatabase.SaveAssets();
clip.SaveFrameData(AssetDatabase.GetAssetPath(clip.GetInstanceID()) + "_frames.bin");
clip.SaveFrameData();
}
}
catch (Exception ex)

67
Runtime/SkinDeformationClip.cs


using System;
using System.IO;
using System.Text.RegularExpressions;
#if UNITY_EDITOR
using UnityEditor;
using System.Text.RegularExpressions;
#endif
namespace Unity.DemoTeam.DigitalHuman
{

public NativeFrameStream frameData;
[HideInInspector]
public string frameDataFilename = null;
public string frameDataStreamingAssetsPath = null;
[HideInInspector]
private bool frameDataPending = true;

{
Debug.Log("hotloading frame data");
LoadFrameData(frameDataFilename);
LoadFrameData();
}
var floatPtr = (float*)frameData.ReadFrame(frameIndex);

{
if (frameDataPending)
{
LoadFrameData(frameDataFilename);
LoadFrameData();
}
}

UnloadFrameData();
}
void LoadFrameData(string filename)
void LoadFrameData()
#if !UNITY_EDITOR
filename = Application.streamingAssetsPath + Regex.Replace(frameDataFilename, "^Assets", "");
#if UNITY_EDITOR
string filename = AssetDatabase.GetAssetPath(this) + "_frames.bin";
#else
string filename = Application.streamingAssetsPath + frameDataStreamingAssetsPath;
Debug.Log("LoadFrameData " + filename + ")");
#endif

frameDataPending = true;
}
public void SaveFrameData(string filename)
#if UNITY_EDITOR
public void SaveFrameData()
string filenameAsset = AssetDatabase.GetAssetPath(this);
string filenameFrameData = filenameAsset + "_frames.bin";
if (File.Exists(filename))
File.Delete(filename);
if (File.Exists(filenameFrameData))
File.Delete(filenameFrameData);
//if (filename != frameDataFilename)
//{
// if (File.Exists(frameDataFilename))
// File.Delete(frameDataFilename);
// if (File.Exists(frameDataFilename + ".meta"))
// File.Delete(frameDataFilename + ".meta");
//}
using (FileStream stream = File.Create(filename))
using (FileStream stream = File.Create(filenameFrameData))
{
using (BinaryWriter writer = new BinaryWriter(stream))
{

writer.Flush();
}
frameDataFilename = filename;
#endif
[ContextMenu("Copy To StreamingAssets")]
public void CopyToStreamingAssets()
#if UNITY_EDITOR
[ContextMenu("Save To StreamingAssets")]
public void SaveToStreamingAssets()
Debug.Log("staging framedata for " + name);
var pathRel = Regex.Replace(frameDataFilename, "^Assets", "");
var copySrc = Application.dataPath + pathRel;
var copyDst = Application.streamingAssetsPath + pathRel;
string filenameAsset = AssetDatabase.GetAssetPath(this);
string filenameFrameData = filenameAsset + "_frames.bin";
frameDataStreamingAssetsPath = "/SkinDeformationClip/" + AssetDatabase.AssetPathToGUID(filenameAsset) + "__" + this.name;
var copySrc = filenameFrameData;
var copyDst = Application.streamingAssetsPath + frameDataStreamingAssetsPath;
//Debug.Log("filenameAsset: " + filenameAsset);
//Debug.Log("copySrc: " + copySrc);
//Debug.Log("copyDst: " + copyDst);
var copyDstDir = copyDst.Substring(0, copyDst.LastIndexOf('/'));
try
{

Debug.LogError(ex.ToString());
}
}
#endif
}
#if UNITY_EDITOR

var clips = Resources.FindObjectsOfTypeAll<SkinDeformationClip>();
foreach (var clip in clips)
{
clip.CopyToStreamingAssets();
clip.SaveToStreamingAssets();
EditorUtility.SetDirty(clip);
AssetDatabase.SaveAssets();
}
}
#endif
正在加载...
取消
保存