Get inspiration from 5400 company's source code, don't want to share it alone
Almost like the big company 5400, 5400 company became a big company in the last wave of 2000 by relying on the page tour.
So far, we should still rely on page games to make money
They claim to have started unity3d development in 2012. This open source is almost the same as the game source (released to the Web platform) from 2012 to 2013
using System.Collections; using System.Collections.Generic; using UnityEngine; public class RoleBattleManager { private List<int> preCmds = new List<int>(); RoleCtrl owner; float lastAttackTime; // 0.2 seconds for common cd int CommonCD = 200; int currSkillId; public RoleBattleManager(RoleCtrl owner) { this.owner = owner; } //public void NormalAttack() { // int comboId = GetLastCombo(); // if(comboId==0) //} public void NormalAttack(int skillId) { //if (owner.isActive==false) { // return; //} //TODO: it's better to judge whether or not by Transition rather than by name, because the name may be changed string stateName = owner.fsm.currentStateName; if (stateName == "Dead" || stateName == "Skill") { return; } //There are multiple moves, and the last one can connect to the current skillId if (preCmds.Count > 0 && preCmds[preCmds.Count - 1]==skillId-1) { preCmds.Add(skillId); return; } if (IsComboCooldown()) { preCmds.Add(skillId); return; } //theOwner.motor.TurnToControlStickDir(); //Util.MogoUtils.LookAtTargetInRange(theOwner.Transform, 6, 360); //(skillManager as PlayerSkillManager).ResetCoolTime(nextskill); //EntityMyself.preSkillTime = Time.realtimeSinceStartup; //theOwner.CastSkill(nextskill); ResetCoolTime(skillId); int index = skillId % 100; owner.DoAttackDirect(index);//Trigger PlayAttack through animation to call special effects var skillLevel = SkillExtDBModel.Instance.GetBySkillInfoId(skillId); if(skillLevel.cd>0) owner.Invoke(NextCmd, skillLevel.cd); } public int GetLastCombo() { if (preCmds.Count == 0) return 0; else return preCmds[preCmds.Count - 1]; } public bool IsAttackDone() { return preCmds.Count == 0; } private void ResetCoolTime(int skillId) { currSkillId = skillId; lastAttackTime = Time.realtimeSinceStartup; } private bool IsComboCooldown() { int attackInterval = (int)((Time.realtimeSinceStartup - lastAttackTime) * 1000); if (attackInterval < CommonCD) { Debug.Log("common attack cool down time"); return true; } return false; } public void NextCmd() { if (preCmds.Count == 0) { return; } int skillId = preCmds[0]; preCmds.RemoveAt(0); NormalAttack(skillId); } }
This source code may not be directly used, partially annotated or developed by yourself
But the basic principle is the leverage
5400 company's original timer TimerHeap is encapsulated, so I used Invoke as the timer in the extension development
The basic principle is to refer to the source code of 5400 company:
[start]
Normal attack - > cache with CD
Attack if there is no CD and delay the execution of the next combo according to the CD (end if there is no combo)
Delay execution, execute combo call - > link to common attack at the beginning
It simply implements a closure to achieve continuous common attacks
This method may be taught by general training institutions, which is the conclusion of practice, and it is very simple. It's worth learning and thinking