性能
- 对象池
- 享元
unity3d
- 方便测试
private void OnGUI()
{
if (GUILayout.Button("发射"))
{
Debug.Log("aaa");
}
}
- 反射创建对象
string className = string.Format("ARPGDemo.Skill.{0}AttackSelector", skillData.selectorType);
Type type=Type.GetType(className);
IAttackSelector selector =Activator.CreateInstance(type) as IAttackSelector;
- 通过GameObject取得transform类型
GameObject[] tempGoArray = GameObject.FindGameObjectsWithTag(data.attackTargetTags[i]);
argets.AddRange(tempGoArray.Select(g => g.transform));
4.协程
deployer.StartCoroutine(RepeatDamage(deployer));
private IEnumerator RepeatDamage(SkillDeployer deployer)
{
float atkTime = 0;
//间隔
do
{
//伤害生命
OnceDamage();
yield return new WaitForSeconds(data.atkInterval);
atkTime += data.atkInterval;
deployer.CalculateTargets();//重新计算模板
} while (atkTime<data.durationTime);//攻击时间没到
}
//单次伤害
private void OnceDamage()
{
Debug.Log("执行单次伤害中" + data.attackTargets);
float atk = data.atkRatio * data.owner.GetComponent<CharacterStatus>().attackvalue;
for (int i = 0; i < data.attackTargets.Length; i++)
{
data.attackTargets[i].GetComponent<CharacterStatus>().HP -= atk;
}
}
- 随机数
int index = Random.Range(0, skilldataarry.Count);