update 1.2.0
This commit is contained in:
@@ -2,11 +2,54 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.Animations;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
namespace EmeraldAI.Utility
|
||||
{
|
||||
public class EmeraldAnimatorGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a unique copy of the passed Animation Profile and clears the copy's Animator Controller.
|
||||
/// </summary>
|
||||
public static void CopyAnimationProfile (AnimationProfile AnimationProfileRef)
|
||||
{
|
||||
var SerializedReferenceAP = new SerializedObject(AnimationProfileRef);
|
||||
|
||||
SerializedReferenceAP.Update();
|
||||
|
||||
//Get the path of the selected asset
|
||||
string assetPath = AssetDatabase.GetAssetPath(AnimationProfileRef);
|
||||
string assetDirectory = Path.GetDirectoryName(assetPath);
|
||||
string assetName = Path.GetFileNameWithoutExtension(assetPath);
|
||||
string assetExtension = Path.GetExtension(assetPath);
|
||||
|
||||
//Create a unique path for the duplicate asset
|
||||
string duplicateAssetPath = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(assetDirectory, assetName + " Copy" + assetExtension));
|
||||
|
||||
//Duplicate the asset
|
||||
AssetDatabase.CopyAsset(assetPath, duplicateAssetPath);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
//Select the duplicated asset in the Project window
|
||||
UnityEngine.Object duplicateAsset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(duplicateAssetPath);
|
||||
Selection.activeObject = duplicateAsset;
|
||||
|
||||
//Clear the copy's Animator Controller.
|
||||
AnimationProfile AnimationProfileCopy = AssetDatabase.LoadAssetAtPath<AnimationProfile>(duplicateAssetPath);
|
||||
var SerializedCopyAP = new SerializedObject(AnimationProfileCopy);
|
||||
SerializedCopyAP.Update();
|
||||
AnimationProfileCopy.AIAnimator = null;
|
||||
AnimationProfileCopy.AnimatorControllerGenerated = false;
|
||||
AnimationProfileCopy.FilePath = "";
|
||||
SerializedCopyAP.ApplyModifiedProperties();
|
||||
|
||||
SerializedReferenceAP.ApplyModifiedProperties();
|
||||
|
||||
EditorUtility.SetDirty(AnimationProfileCopy);
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates an Animator Controller using the passed EmeraldAnimation values. This is done by searching each state by name and applying the proper animation, animation speed, and mirroring values.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user