// 播放某个UILayerContainer<AnimEntry>实例的ChildList //void PlayStateAnim(UILayerContainer<AnimEntry> layerContainer) void PlayStateAnim(UILayerContainerAnim layerContainer) { List <AnimEntry> animEntryList = layerContainer.ChildList; AnimEntry animEntry = animEntryList[0]; if (animEntryList.Count <= 0 || animEntry.tween == null) { return; } animEntry.tween.tweenFactor = 0; animEntry.tween.FromCurrentValue(); animEntry.tween.enabled = true; }
void AddTweenListener(AnimEntry preAnimEntry, AnimEntry animEntry) { // 为了防止有空的Tween值 if (preAnimEntry.tween == null || animEntry.tween == null) { return; } preAnimEntry.tween.OnFinished.AddListener(() => { animEntry.tween.tweenFactor = 0; animEntry.tween.FromCurrentValue(); animEntry.tween.enabled = true; }); }
void AddLastTweenCallback(UILayerContainerType type, AnimEntry lastAnimEntry) { if (lastAnimEntry.tween == null) { return; } lastAnimEntry.tween.OnFinished.AddListener(() => { UtilCommon.VoidDelegate callback; CallbackMap.TryGetValue(type, out callback); if (callback != null) { callback(gameObject); } }); }
void InitTween() { for (int i = 0; i < LayerContainerList.Count; i++) { //UILayerContainer<AnimEntry> layerContainer = LayerContainerList[i]; UILayerContainerAnim layerContainer = LayerContainerList[i]; for (int j = 0; j < layerContainer.ChildList.Count; j++) { AnimEntry animEntry = layerContainer.ChildList[j]; UIAnimType animType = animEntry.Type; if (animType == UIAnimType.Position) { animEntry.tween = TweenPos.Tween(gameObject, animEntry.Duration, animEntry.To); } if (animType == UIAnimType.Scale) { animEntry.tween = TweenScale.Tween(gameObject, animEntry.Duration, animEntry.To); } if (animType != UIAnimType.None) { animEntry.tween.tweenFactor = 0; animEntry.tween.enabled = false; } /* * // 在这里继续添加其他类型的 */ // 这里就是让ChildList按顺序去播放 if (j > 0) { AnimEntry preAnimEntry = layerContainer.ChildList[j - 1]; AddTweenListener(preAnimEntry, animEntry); } // 添加回调,在最后一个动作回调 if (j == layerContainer.ChildList.Count - 1) { AnimEntry lastAnimEntry = layerContainer.ChildList[j]; AddLastTweenCallback(layerContainer.Type, lastAnimEntry); } } } }
void OnPreprocessModel() { ModelImporter modelImporter = assetImporter as ModelImporter; modelImporter.materialName = ModelImporterMaterialName.BasedOnMaterialName; modelImporter.globalScale = 1; FileInfo fileInfo = new FileInfo (assetPath); if (fileInfo.Extension.ToLower() != ".fbx") { return; } string animConfigPath = Path.Combine (fileInfo.Directory.FullName, fileInfo.Name.Substring(0, fileInfo.Name.Length-4) + ".txt"); if (File.Exists(animConfigPath)) { StreamReader fileReader = new StreamReader(animConfigPath); List<string> fileLines = new List<string>(); string line; int count = 0; while((line=fileReader.ReadLine()) != null) { fileLines.Add(line); count ++; if(count > 10) break; } List<AnimEntry> animEntryList = new List<AnimEntry>(); foreach(string l in fileLines) { string[] contentAry = l.Split(new char[]{':', '-'}); if(contentAry.Length == 3) { AnimEntry animEntry = new AnimEntry(); animEntry.Name = contentAry[0]; if(int.TryParse(contentAry[1], out animEntry.StartFrame) && int.TryParse(contentAry[2], out animEntry.EndFrame)) { animEntryList.Add(animEntry); } } } if(animEntryList.Count > 0) { modelImporter.animationType = ModelImporterAnimationType.Legacy; modelImporter.importAnimation = true; ModelImporterClipAnimation[] clips = new ModelImporterClipAnimation[animEntryList.Count]; int index = 0; foreach(AnimEntry animEntry in animEntryList) { ModelImporterClipAnimation clipAnim = new ModelImporterClipAnimation(); if(animEntry.Name == "run" || animEntry.Name == "ready" || animEntry.Name == "idle" || animEntry.Name == "stand" || animEntry.Name == "airStay") clipAnim.wrapMode = WrapMode.Loop; clipAnim.name = animEntry.Name; clipAnim.firstFrame = animEntry.StartFrame; clipAnim.lastFrame = animEntry.EndFrame; clips[index] = clipAnim; index ++; } modelImporter.clipAnimations = clips; } } }
void OnPreprocessModel() { ModelImporter modelImporter = assetImporter as ModelImporter; FileInfo fileInfo = new FileInfo(assetPath); if (fileInfo.Extension.ToLower() != ".fbx") { return; } string animConfigPath = Path.Combine(fileInfo.Directory.FullName, fileInfo.Name.Substring(0, fileInfo.Name.Length - 4) + ".txt"); if (File.Exists(animConfigPath)) { StreamReader fileReader = new StreamReader(animConfigPath); List <string> fileLines = new List <string>(); string line; int count = 0; while ((line = fileReader.ReadLine()) != null) { fileLines.Add(line); count++; if (count > 10) { break; } } List <AnimEntry> animEntryList = new List <AnimEntry>(); foreach (string l in fileLines) { string[] contentAry = l.Split(new char[] { ':', '-' }); if (contentAry.Length == 3) { AnimEntry animEntry = new AnimEntry(); animEntry.Name = contentAry[0]; if (int.TryParse(contentAry[1], out animEntry.StartFrame) && int.TryParse(contentAry[2], out animEntry.EndFrame)) { animEntryList.Add(animEntry); } } } if (animEntryList.Count > 0) { modelImporter.animationType = ModelImporterAnimationType.Legacy; modelImporter.importAnimation = true; ModelImporterClipAnimation[] clips = new ModelImporterClipAnimation[animEntryList.Count]; int index = 0; foreach (AnimEntry animEntry in animEntryList) { ModelImporterClipAnimation clipAnim = new ModelImporterClipAnimation(); clipAnim.loop = (animEntry.Name == "run" || animEntry.Name == "ready" || animEntry.Name == "idle"); clipAnim.name = animEntry.Name; clipAnim.firstFrame = animEntry.StartFrame; clipAnim.lastFrame = animEntry.EndFrame; clips[index] = clipAnim; index++; } modelImporter.clipAnimations = clips; } } }