public void Add(ActType actType) { if (actComponet.ContainsKey(actType)) { return; } ActComponent act = null; switch (actType) { case ActType.Null: break; case ActType.Anim: act = new AnimComponent(this); break; case ActType.Audio: act = new AudioComponent(this); break; case ActType.Effect: act = new EffectComponent(this); break; default: break; } if (act != null) { actComponet.Add(actType, act); } }
public void UpperAnim(EntityBase entity, AnimComponent ac) { SkillStatusComponent sc = entity.GetComp <SkillStatusComponent>(); if (sc.m_skillStstus != SkillStatusEnum.Finish && sc.m_skillStstus != SkillStatusEnum.None) { string attackAnimName = "null"; switch (sc.m_skillStstus) { case SkillStatusEnum.Before: attackAnimName = sc.m_currentSkillData.BeforeInfo.m_AnimName; break; case SkillStatusEnum.Current: attackAnimName = sc.m_currentSkillData.CurrentInfo.m_AnimName; break; case SkillStatusEnum.Later: attackAnimName = sc.m_currentSkillData.LaterInfo.m_AnimName; break; } if (attackAnimName != "null") { //TODO 将来可能对动画做追赶 ac.anim.Play(attackAnimName, 1); } else { ac.anim.Play("empty", 1); } } }
/// <summary> /// Resets the state of the model. This includes position, rotation, and velocity of every frame (bone). /// It does it by playing idle anim, setting it's time to 0, and sampling from it. /// </summary> public void ResetModelState() { var state = PlayAnim(AnimGroup.WalkCycle, AnimIndex.Idle); state.normalizedTime = 0; AnimComponent.Sample(); }
void Awake() { Owner = GetComponent("Agent") as Agent; animComponent = GetComponent <AnimComponent>(); Owner.BlackBoard.Health = Owner.BlackBoard.MaxHealth; Owner.canBlock = false; }
public void TurnAnimLogic(EntityBase entity) { AnimComponent ac = entity.GetComp <AnimComponent>(); PlayerComponent pc = entity.GetComp <PlayerComponent>(); Vector3 rot = ac.waistNode.transform.eulerAngles; Vector3 aimWaistDir = pc.faceDir.ToVector(); if (entity.GetExistComp <SelfComponent>()) { aimWaistDir = InputSystem.skillDirCache; } float euler = Mathf.Atan2(aimWaistDir.x, aimWaistDir.z) * Mathf.Rad2Deg; if (aimWaistDir.z == 0) { euler = 0; } float amend = 0; rot.x = ac.waistNode.transform.eulerAngles.x; rot.y = euler - 90 + amend; rot.z = ac.waistNode.transform.eulerAngles.z; ac.waistNode.transform.eulerAngles = rot; }
private void ShowAnimComponent(AnimComponent animComponent) { AnimationClip gameClip = EditorGUILayout.ObjectField(animComponent.animClip, typeof(AnimationClip), false) as AnimationClip; if (animComponent.animClip != gameClip) { animComponent.SetAnimClip(gameClip); } }
public void StopActiveAnimations(Model anim_model) { AnimComponent ac = anim_model.Components[anim_model.animComponentID] as AnimComponent; List <AnimData> ad_list = ac.getActiveAnimations(); foreach (AnimData ad in ad_list) { ad.IsPlaying = false; } }
public int queryAnimationFrameCount(Model anim_model, string Anim) { AnimComponent ac = anim_model.Components[anim_model.animComponentID] as AnimComponent; AnimData ad = ac.getAnimation(Anim); if (ad != null) { return((ad.FrameEnd == 0 ? ad.animMeta.FrameCount : ad.FrameEnd) - (ad.FrameStart != 0 ? ad.FrameStart : 0)); } return(-1); }
public int queryAnimationFrame(Model anim_model, string Anim) { AnimComponent ac = anim_model.Components[anim_model.animComponentID] as AnimComponent; AnimData ad = ac.getAnimation(Anim); if (ad != null) { return(ad.ActiveFrame); } return(-1); }
public void StopActiveLoopAnimations(Model anim_model) { AnimComponent ac = anim_model.Components[anim_model.animComponentID] as AnimComponent; List <AnimData> ad_list = ac.getActiveAnimations(); foreach (AnimData ad in ad_list) { if (ad.AnimType == libMBIN.NMS.Toolkit.TkAnimationData.AnimTypeEnum.Loop) { ad.IsPlaying = false; } } }
public void StartAnimation(Model anim_model, string Anim) { AnimComponent ac = anim_model.Components[anim_model.animComponentID] as AnimComponent; AnimData ad = ac.getAnimation(Anim); if (ad != null) { if (!ad.IsPlaying) { ad.IsPlaying = true; } } }
private void LoadAllSkill() { string path = "Assets/" + gameObject.name + ".txt"; if (File.Exists(path)) { string str = File.ReadAllText(path); List <SkillJson> skills = JsonConvert.DeserializeObject <List <SkillJson> >(str); //遍历解析出来的Json列表 foreach (var item in skills) { //根据item的技能名字来加上技能列表 skillsList.Add(item.name, new List <ComponentBase>()); //遍历对应名字的技能列表 foreach (var ite in item.skills) { //遍历每个技能的属性 foreach (var it in ite.Value) { if (ite.Key.Equals("动画")) { AnimationClip clip = AssetDatabase.LoadAssetAtPath <AnimationClip>("Assets/GameDate/Anim/" + it + ".anim"); print("++++++++" + "Assets/GameDate/Anim/" + it + ".anim"); AnimComponent _anim = new AnimComponent(this); _anim.SetAnimClip(clip); print(clip); skillsList[item.name].Add(_anim); } else if (ite.Key.Equals("音效")) { AudioClip clip = AssetDatabase.LoadAssetAtPath <AudioClip>("Assets/GameDate/Audio/" + it + ".mp3"); AudioComponent _audio = new AudioComponent(this); _audio.SetAudioClip(clip); skillsList[item.name].Add(_audio); } else if (ite.Key.Equals("特效")) { GameObject clip = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/GameDate/Effect/Skill/" + it + ".prefab"); EffectsComponent _effect = new EffectsComponent(this); _effect.SetGameClip(clip); skillsList[item.name].Add(_effect); } } } } } }
public void AnimLogic(EntityBase entity) { LifeComponent lc = entity.GetComp <LifeComponent>(); AnimComponent ac = entity.GetComp <AnimComponent>(); MoveComponent mc = entity.GetComp <MoveComponent>(); PlayerComponent pc = entity.GetComp <PlayerComponent>(); PerfabComponent pbc = entity.GetComp <PerfabComponent>(); if (lc.Life <= 0) { ac.anim.Play("empty", 1); ac.anim.Play("die"); return; } //移动逻辑 if (Vector3.Distance(mc.pos.ToVector(), pbc.perfab.transform.position) > .05f) { Vector3 Dir = mc.dir.ToVector(); if (Dir == Vector3.zero) { Dir = mc.pos.ToVector() - pbc.perfab.transform.position; } TurnStatus status = GetTurnStatus(Dir, pc.faceDir.ToVector()); //身体移动方向 SetBodyDir(status, Dir, ac.perfab); //播放不同动画 SetMoveAnim(status, ac.anim); } else { Vector3 Dir = pc.faceDir.ToVector(); if (entity.GetExistComp <SelfComponent>()) { Dir = InputSystem.skillDirCache; } ac.anim.Play("wait"); if (pc.faceDir.ToVector() != Vector3.zero) { ac.perfab.transform.forward = Dir; } } //上层动画 UpperAnim(entity, ac); }
public override void OnEntityOptimizeCreate(EntityBase entity) { if (GetAllExistComp(new string[] { "AssetComponent", "TransfromComponent" }, entity)) { Debug.Log("接收到创建 "); AddComp(entity); AssetComponent ac = entity.GetComp <AssetComponent>(); TransfromComponent tc = entity.GetComp <TransfromComponent>(); PerfabComponent comp = entity.GetComp <PerfabComponent>(); comp.perfab = GameObjectManager.CreateGameObject(ac.m_assetName); comp.hardPoint = comp.perfab.GetComponent <HardPointComponent>(); if (tc.parentID == 0) { comp.perfab.transform.position = tc.pos.ToVector(); } else { EntityBase parent = m_world.GetEntity(tc.parentID); //if (parent.GetExistComp<PerfabComponent>()) //{ // PerfabComponent pc = parent.GetComp<PerfabComponent>(); // comp.perfab.transform.SetParent(pc.perfab.transform); //} comp.perfab.transform.localPosition = tc.pos.ToVector(); } //创建动画组件 if (comp.perfab.GetComponent <Animator>() != null) { AnimComponent anc = entity.AddComp <AnimComponent>(); anc.anim = comp.perfab.GetComponent <Animator>(); anc.perfab = comp.perfab; anc.waistNode = comp.hardPoint.waistNode; } } }
void Awake() { Owner = GetComponent("Agent") as Agent; animComponent = GetComponent <AnimComponent>(); }
public void update(float dt) { //Clear queues for all the joints foreach (Model anim_model in AnimScenes) { foreach (Joint jt in anim_model.parentScene.jointDict.Values) { jt.PositionQueue.Clear(); jt.ScaleQueue.Clear(); jt.RotationQueue.Clear(); } } foreach (Model anim_model in AnimScenes) { AnimComponent ac = anim_model._components[anim_model.hasComponent(typeof(AnimComponent))] as AnimComponent; bool found_first_active_anim = false; foreach (AnimData ad in ac.Animations) { if (ad.IsPlaying) { if (!ad.loaded) { ad.loadData(); } found_first_active_anim = true; //Load updated local joint transforms foreach (libMBIN.NMS.Toolkit.TkAnimNodeData node in ad.animMeta.NodeData) { if (!anim_model.parentScene.jointDict.ContainsKey(node.Node)) { continue; } Joint jt = anim_model.parentScene.jointDict[node.Node]; //Transforms Vector3 p = new Vector3(); Vector3 s = new Vector3(); Quaternion q = new Quaternion(); ad.getCurrentTransform(ref p, ref s, ref q, node.Node); jt.RotationQueue.Add(q); jt.PositionQueue.Add(p); jt.ScaleQueue.Add(s); //ad.applyNodeTransform(tj, node.Node); } //Once the current frame data is fetched, progress to the next frame ad.update(dt); } } //Calculate Blending Factors List <float> blendingFactors = new List <float>(); float totalWeight = 1.0f; foreach (AnimData ad in ac.Animations) { if (ad.AnimType == libMBIN.NMS.Toolkit.TkAnimationData.AnimTypeEnum.OneShot) { //Calculate blending factor based on the animation progress //float bF = ad.ActiveFrame / (ad.FrameEnd - ad.FrameStart); float bF = 0.0f; blendingFactors.Add(bF); totalWeight -= bF; } else { blendingFactors.Add(1.0f); } } //Blend Transforms and apply foreach (Joint jt in anim_model.parentScene.jointDict.Values) { if (jt.PositionQueue.Count == 0) { //Keep last transforms jt.localPosition = jt._localPosition; jt.localScale = jt._localScale; jt.localRotation = jt._localRotation; continue; } float blendFactor = 1.0f / jt.PositionQueue.Count; Vector3 p = new Vector3(); Vector3 s = new Vector3(); Quaternion q = new Quaternion(); for (int i = 0; i < jt.PositionQueue.Count; i++) { q += blendFactor * jt.RotationQueue[i]; p += blendFactor * jt.PositionQueue[i]; s += blendFactor * jt.ScaleQueue[i]; } jt.localRotation = Matrix4.CreateFromQuaternion(q); jt.localPosition = p; jt.localScale = s; } } }
void Awake() { Owner = GetComponent("Agent") as Agent; animComponent = GetComponent <AnimComponent>(); Owner.canBlock = true; }
private void LoadTagDataFromFile(EndianBinaryReader reader, int tagCount) { for (int i = 0; i < tagCount; i++) { long tagStart = reader.BaseStream.Position; string tagName = reader.ReadString(4); int tagSize = reader.ReadInt32(); switch (tagName) { case "TTK1": LoopMode = (LoopType)reader.ReadByte(); // 0 = Play Once. 2 = Loop (Assumed from BCK) byte angleMultiplier = reader.ReadByte(); // Multiply Angle Value by pow(2, angleMultiplier) (Assumed from BCK) AnimLengthInFrames = reader.ReadInt16(); short textureAnimEntryCount = (short)(reader.ReadInt16() / 3); // 3 for each material. BTK stores U, V, and W separately, so you need to divide by three. short numScaleFloatEntries = reader.ReadInt16(); short numRotationShortEntries = reader.ReadInt16(); short numTranslateFloatEntries = reader.ReadInt16(); int animDataOffset = reader.ReadInt32(); int remapTableOffset = reader.ReadInt32(); int stringTableOffset = reader.ReadInt32(); int textureIndexTableOffset = reader.ReadInt32(); int textureCenterTableOffset = reader.ReadInt32(); int scaleDataOffset = reader.ReadInt32(); int rotationDataOffset = reader.ReadInt32(); int translateDataOffset = reader.ReadInt32(); // Read array of scale data float[] scaleData = new float[numScaleFloatEntries]; reader.BaseStream.Position = tagStart + scaleDataOffset; for (int j = 0; j < numScaleFloatEntries; j++) { scaleData[j] = reader.ReadSingle(); } // Read array of rotation data (but don't convert it) float[] rotationData = new float[numRotationShortEntries]; reader.BaseStream.Position = tagStart + rotationDataOffset; for (int j = 0; j < numRotationShortEntries; j++) { rotationData[j] = reader.ReadInt16(); } // Read array of translation/position data float[] translationData = new float[numTranslateFloatEntries]; reader.BaseStream.Position = tagStart + translateDataOffset; for (int j = 0; j < numTranslateFloatEntries; j++) { translationData[j] = reader.ReadSingle(); } // Remap Table (probably matches MAT3's remap table?) m_remapTable = new short[textureAnimEntryCount]; reader.BaseStream.Position = tagStart + remapTableOffset; for (int j = 0; j < textureAnimEntryCount; j++) { m_remapTable[j] = reader.ReadInt16(); } // String Table which gives us material names. reader.BaseStream.Position = tagStart + stringTableOffset; StringTable stringTable = StringTable.FromStream(reader); // Texture Index table which tells us which texture index of this material to modify (?) byte[] texMtxIndexTable = new byte[textureAnimEntryCount]; reader.BaseStream.Position = tagStart + textureIndexTableOffset; for (int j = 0; j < textureAnimEntryCount; j++) { texMtxIndexTable[j] = reader.ReadByte(); } // Texture Centers Vector3[] textureCenters = new Vector3[textureAnimEntryCount]; reader.BaseStream.Position = tagStart + textureCenterTableOffset; for (int j = 0; j < textureAnimEntryCount; j++) { textureCenters[j] = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); } // Read the data for each joint that this animation. m_animationData = new List <MaterialAnim>(); float rotScale = (float)Math.Pow(2f, angleMultiplier) * (180 / 32768f); reader.BaseStream.Position = tagStart + animDataOffset; for (int j = 0; j < textureAnimEntryCount; j++) { AnimComponent texU = ReadAnimComponent(reader); AnimComponent texV = ReadAnimComponent(reader); AnimComponent texW = ReadAnimComponent(reader); MaterialAnim anim = new MaterialAnim(); anim.Name = stringTable[j]; anim.TexMatrixIndex = texMtxIndexTable[j]; anim.Center = textureCenters[j]; anim.ScalesX = ReadComp(scaleData, texU.Scale); anim.ScalesY = ReadComp(scaleData, texV.Scale); anim.ScalesZ = ReadComp(scaleData, texW.Scale); anim.RotationsX = ReadComp(rotationData, texU.Rotation); anim.RotationsY = ReadComp(rotationData, texV.Rotation); anim.RotationsZ = ReadComp(rotationData, texW.Rotation); // Convert all of the rotations from compressed shorts back into -180, 180 ConvertRotation(anim.RotationsX, rotScale); ConvertRotation(anim.RotationsY, rotScale); ConvertRotation(anim.RotationsZ, rotScale); anim.TranslationsX = ReadComp(translationData, texU.Translation); anim.TranslationsY = ReadComp(translationData, texV.Translation); anim.TranslationsZ = ReadComp(translationData, texW.Translation); m_animationData.Add(anim); } break; } // Skip the stream reader to the start of the next tag since it gets moved around during loading. reader.BaseStream.Position = tagStart + tagSize; } }
public void AddAnimObject(AnimComponent a) { ACManager.Add(a); }