本文整理汇总了C#中UnityEditor.AddState方法的典型用法代码示例。如果您正苦于以下问题:C# UnityEditor.AddState方法的具体用法?C# UnityEditor.AddState怎么用?C# UnityEditor.AddState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEditor
的用法示例。
在下文中一共展示了UnityEditor.AddState方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImprtState
/// <summary>
/// Imprts the state.
/// </summary>
/// <param name="animator">Animator.</param>
/// <param name="aryClip">Ary clip.</param>
/// <param name="machine">Machine.</param>
public static void ImprtState(Animator animator, List<string> aryClipPath,
UnityEditor.Animations.AnimatorStateMachine machine, int nOffsetX, int nOffsetY)
{
machine.entryPosition = new Vector3(machine.entryPosition.x + nOffsetX, machine.entryPosition.y, 0);
machine.anyStatePosition = new Vector3(machine.entryPosition.x, machine.entryPosition.y - nOffsetY, 0);
machine.exitPosition = new Vector3(machine.entryPosition.x, machine.entryPosition.y + nOffsetY, 0);
for(int i=0; i<aryClipPath.Count; i++)
{
ModelImporter imp = ModelImporter.GetAtPath(aryClipPath[i]) as ModelImporter;
if (!imp)
throw new System.NullReferenceException(aryClipPath[i]);
ApplyRootMotionBoneName(imp, imp.transformPaths[1]);
string szClipName = imp.assetPath.Substring(
imp.assetPath.LastIndexOf('@') + 1);
szClipName = szClipName.Remove(szClipName.LastIndexOf('.'));
ModelImporterClipAnimation clipImp = new ModelImporterClipAnimation ();
if (imp.clipAnimations.Length > 0)
clipImp = imp.clipAnimations[0];
// load animation clip
AnimationClip clip = AssetDatabase.LoadAssetAtPath(imp.assetPath, typeof(AnimationClip)) as AnimationClip;
if (clip)
{
AnimationClipSettings set = AnimationUtility.GetAnimationClipSettings(clip);
if (set != default(AnimationClipSettings))
{
clipImp.firstFrame = set.startTime * clip.frameRate;
clipImp.lastFrame = set.stopTime * clip.frameRate;
}
}
clipImp.maskType = ClipAnimationMaskType.CreateFromThisModel;
clipImp.keepOriginalOrientation = true;
clipImp.keepOriginalPositionXZ = true;
clipImp.keepOriginalPositionY = true;
clipImp.lockRootRotation = true;
clipImp.lockRootHeightY = true;
clipImp.name = szClipName;
// set loop animation
string[] aryFiliter = {
"idle", "move", "run", "walk", "fly", "turn"
};
foreach(string fliter in aryFiliter)
{
if (szClipName.ToLower().Contains(fliter))
{
clipImp.loopTime = true;
break;
}
}
imp.clipAnimations = new ModelImporterClipAnimation[]{clipImp};
// reset model importer
imp.SaveAndReimport();
Object[] aryClip = AssetDatabase.LoadAllAssetsAtPath(imp.assetPath);
for(int c=0; c<aryClip.Length; c++)
{
Object o = aryClip[c];
if (o.GetType() == typeof(AnimationClip) && !o.name.Contains(SearchFileType.preview.ToString()))
{
Vector3 vStatePosition = new Vector3(machine.entryPosition.x + 200, machine.entryPosition.y + i * 65, 0);
// create animator state
UnityEditor.Animations.AnimatorState state = machine.AddState(o.name, vStatePosition);
if (state)
{
state.motion = o as Motion;
// set default state
if (state.name.ToLower().Contains(aryFiliter[0]))
{
machine.defaultState = state;
}
}
}
}
}
}