Copying and Pasting cs Code
In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.
For example, you can follow the pattern in this listing: public List BuildAnimationClips(GameObject root, Entity entity, string scmlAssetPath)
{
var allAnimClips = AssetDatabase.LoadAllAssetRepresentationsAtPath(scmlAssetPath).OfType().ToList();
Debug.Log(string.Format("Found {0} animation clips at {1}", allAnimClips.Count, scmlAssetPath));
var newAnimClips = new List();
foreach (var animation in entity.Animations)
{
var animClip = MakeAnimationClip(root, animation, Path.GetDirectoryName(scmlAssetPath));
Debug.Log(string.Format("Added animClip({0}) to asset path ({1}) WrapMode:{2}", animClip.name, scmlAssetPath, animClip.wrapMode));
newAnimClips.Add(animClip);
var originalAnimClip = allAnimClips.Where(clip => clip.name == animClip.name).FirstOrDefault();
if (originalAnimClip != null)
{
Debug.Log("Replacing animation clip " + animClip.name);
EditorUtility.CopySerialized(animClip, originalAnimClip);
allAnimClips.Remove(originalAnimClip);
}
else
AssetDatabase.AddObjectToAsset(animClip, scmlAssetPath);
}
//Remove any animation clips that are no longer present in the SCML
foreach(var clip in allAnimClips)
{
//This may be a bad idea
UnityEngine.Object.DestroyImmediate(clip, true);
}
return newAnimClips;
}
{
var allAnimClips = AssetDatabase.LoadAllAssetRepresentationsAtPath(scmlAssetPath).OfType
Debug.Log(string.Format("Found {0} animation clips at {1}", allAnimClips.Count, scmlAssetPath));
var newAnimClips = new List
foreach (var animation in entity.Animations)
{
var animClip = MakeAnimationClip(root, animation, Path.GetDirectoryName(scmlAssetPath));
Debug.Log(string.Format("Added animClip({0}) to asset path ({1}) WrapMode:{2}", animClip.name, scmlAssetPath, animClip.wrapMode));
newAnimClips.Add(animClip);
var originalAnimClip = allAnimClips.Where(clip => clip.name == animClip.name).FirstOrDefault();
if (originalAnimClip != null)
{
Debug.Log("Replacing animation clip " + animClip.name);
EditorUtility.CopySerialized(animClip, originalAnimClip);
allAnimClips.Remove(originalAnimClip);
}
else
AssetDatabase.AddObjectToAsset(animClip, scmlAssetPath);
}
//Remove any animation clips that are no longer present in the SCML
foreach(var clip in allAnimClips)
{
//This may be a bad idea
UnityEngine.Object.DestroyImmediate(clip, true);
}
return newAnimClips;
}