当前位置: 首页>>代码示例>>C#>>正文


C# UnityEditor.AddState方法代码示例

本文整理汇总了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;
						}
					}
				}
			}
		}
	}
开发者ID:oathx,项目名称:Six,代码行数:92,代码来源:XmlEditorHelper.cs


注:本文中的UnityEditor.AddState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。