669 lines
16 KiB
C#
669 lines
16 KiB
C#
|
|
using System.Net.Security;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
using System.CodeDom;
|
|
using UnityEngine;
|
|
|
|
namespace BF
|
|
{
|
|
public class BattlePool
|
|
{
|
|
private bool isClear = false;
|
|
private List<BattleControlBoxCollider> boxColliderList;
|
|
private List<BattleControlSphereCollider> sphereColliderList;
|
|
private List<BattleControlBoxBullet> boxBulletList;
|
|
private List<BattleControlSphereBullet> sphereBulletList;
|
|
private List<BattleContinuousTarget> continuousTargeList;
|
|
private List<BattleControlColliderContainer> colliderContainerList;
|
|
private List<BattleEffectNumber> allEffectNumberList;
|
|
private List<BattleSkillToast> allSkillToastList;
|
|
private List<BattleEffectNumber> effectNumberList;
|
|
private List<BattleEffectNumber> effectNumberRedList;
|
|
private List<BattleEffectNumber> effectNumberGreenList;
|
|
private List<BattleEffectNumber> effectNumberYellowList;
|
|
private List<BattleHpBar> hpBarAtkList;
|
|
private List<BattleHpBar> hpBarDefList;
|
|
private List<BattleSkillToast> skillToastList;
|
|
private GameObject poolNode;
|
|
private Transform sceneNode;
|
|
private GameObject cacheEffectText;
|
|
private GameObject cacheEffectTextRed;
|
|
private GameObject cacheEffectTextGreen;
|
|
private GameObject cacheEffectTextYellow;
|
|
private GameObject cacheShadow;
|
|
private Transform numberRoot;
|
|
private GameObject cacheHpAtk;
|
|
private GameObject cacheHpDef;
|
|
private Transform hpRoot;
|
|
private GameObject cacheSkillToast;
|
|
private Transform skillToastRoot;
|
|
private static int colliderUniqueId;
|
|
|
|
public void Init()
|
|
{
|
|
isClear = false;
|
|
if (poolNode == null)
|
|
{
|
|
poolNode = new GameObject(BattleConst.BATTLE_POOL_NAME);
|
|
poolNode.SetActive(false);
|
|
GameObject.DontDestroyOnLoad(poolNode);
|
|
}
|
|
if (ReferenceEquals(boxColliderList, null))
|
|
{
|
|
boxColliderList = new List<BattleControlBoxCollider>();
|
|
}
|
|
if (ReferenceEquals(sphereColliderList, null))
|
|
{
|
|
sphereColliderList = new List<BattleControlSphereCollider>();
|
|
}
|
|
if (ReferenceEquals(boxBulletList, null))
|
|
{
|
|
boxBulletList = new List<BattleControlBoxBullet>();
|
|
}
|
|
if (ReferenceEquals(sphereBulletList, null))
|
|
{
|
|
sphereBulletList = new List<BattleControlSphereBullet>();
|
|
}
|
|
if (ReferenceEquals(continuousTargeList, null))
|
|
{
|
|
continuousTargeList = new List<BattleContinuousTarget>();
|
|
}
|
|
if (ReferenceEquals(colliderContainerList, null))
|
|
{
|
|
colliderContainerList = new List<BattleControlColliderContainer>();
|
|
}
|
|
if (ReferenceEquals(effectNumberList, null))
|
|
{
|
|
effectNumberList = new List<BattleEffectNumber>();
|
|
}
|
|
if (ReferenceEquals(effectNumberYellowList, null))
|
|
{
|
|
effectNumberYellowList = new List<BattleEffectNumber>();
|
|
}
|
|
if (ReferenceEquals(effectNumberGreenList, null))
|
|
{
|
|
effectNumberGreenList = new List<BattleEffectNumber>();
|
|
}
|
|
if (ReferenceEquals(effectNumberRedList, null))
|
|
{
|
|
effectNumberRedList = new List<BattleEffectNumber>();
|
|
}
|
|
if (ReferenceEquals(allEffectNumberList, null))
|
|
{
|
|
allEffectNumberList = new List<BattleEffectNumber>();
|
|
}
|
|
if (ReferenceEquals(allSkillToastList, null))
|
|
{
|
|
allSkillToastList = new List<BattleSkillToast>();
|
|
}
|
|
if (ReferenceEquals(hpBarAtkList, null))
|
|
{
|
|
hpBarAtkList = new List<BattleHpBar>();
|
|
}
|
|
if (ReferenceEquals(hpBarDefList, null))
|
|
{
|
|
hpBarDefList = new List<BattleHpBar>();
|
|
}
|
|
if (ReferenceEquals(skillToastList, null))
|
|
{
|
|
skillToastList = new List<BattleSkillToast>();
|
|
}
|
|
}
|
|
|
|
public void SetSceneNode(Transform sceneNode)
|
|
{
|
|
this.sceneNode = sceneNode;
|
|
}
|
|
|
|
public void SetShadow(GameObject shadow)
|
|
{
|
|
this.cacheShadow = shadow;
|
|
}
|
|
|
|
public GameObject GetShadow()
|
|
{
|
|
return GameObject.Instantiate(this.cacheShadow);
|
|
}
|
|
|
|
public void SetEffectText(GameObject effectText, GameObject effectTextRed, GameObject effectTextGreen, GameObject effectTextYellow, Transform numberRoot)
|
|
{
|
|
this.cacheEffectText = effectText;
|
|
this.cacheEffectTextRed = effectTextRed;
|
|
this.cacheEffectTextGreen = effectTextGreen;
|
|
this.cacheEffectTextYellow = effectTextYellow;
|
|
this.numberRoot = numberRoot;
|
|
}
|
|
|
|
public void SetHpBar(GameObject hpAtk, GameObject hpDef, Transform numberRoot)
|
|
{
|
|
this.cacheHpAtk = hpAtk;
|
|
this.cacheHpDef = hpDef;
|
|
this.hpRoot = numberRoot;
|
|
}
|
|
|
|
public void SetSkillToast(GameObject skillToast, Transform skillToastRoot)
|
|
{
|
|
this.cacheSkillToast = skillToast;
|
|
this.skillToastRoot = skillToastRoot;
|
|
}
|
|
|
|
public BattleControlBoxCollider GetSkillBoxCollider()
|
|
{
|
|
if(isClear)
|
|
{
|
|
return null;
|
|
}
|
|
if (boxColliderList.Count > 0)
|
|
{
|
|
var box = boxColliderList[boxColliderList.Count - 1];
|
|
boxColliderList.RemoveAt(boxColliderList.Count - 1);
|
|
box.gameObject.SetActive(true);
|
|
box.IsRecycle = false;
|
|
return box;
|
|
}
|
|
else
|
|
{
|
|
var gameObject = new GameObject(BattleConst.BATTLE_BOX_COLLIDER_NAME);
|
|
gameObject.transform.SetParent(sceneNode);
|
|
var box = gameObject.AddComponent<BattleControlBoxCollider>();
|
|
box.IsRecycle = false;
|
|
box.SetColliderEnabled(false);
|
|
return box;
|
|
}
|
|
}
|
|
|
|
public void RecycleSkillBoxCollider(BattleControlBoxCollider box)
|
|
{
|
|
if(isClear)
|
|
{
|
|
GameObject.Destroy(box.gameObject);
|
|
return;
|
|
}
|
|
box.uniqueId = GetColliderUniqueId();
|
|
box.IsRecycle = true;
|
|
boxColliderList.Add(box);
|
|
box.gameObject.SetActive(false);
|
|
}
|
|
|
|
public BattleControlSphereCollider GetSkillSphereCollider()
|
|
{
|
|
if(isClear)
|
|
{
|
|
return null;
|
|
}
|
|
if (sphereColliderList.Count > 0)
|
|
{
|
|
var sphere = sphereColliderList[sphereColliderList.Count - 1];
|
|
sphereColliderList.RemoveAt(sphereColliderList.Count - 1);
|
|
sphere.gameObject.SetActive(true);
|
|
sphere.IsRecycle = false;
|
|
return sphere;
|
|
}
|
|
else
|
|
{
|
|
var gameObject = new GameObject(BattleConst.BATTLE_SPHERE_COLLIDER_NAME);
|
|
gameObject.transform.SetParent(sceneNode);
|
|
var sphere = gameObject.AddComponent<BattleControlSphereCollider>();
|
|
sphere.IsRecycle = false;
|
|
sphere.SetColliderEnabled(false);
|
|
return sphere;
|
|
}
|
|
}
|
|
|
|
public void RecycleSkillSphereCollider(BattleControlSphereCollider sphere)
|
|
{
|
|
if(isClear)
|
|
{
|
|
GameObject.Destroy(sphere.gameObject);
|
|
return;
|
|
}
|
|
sphere.uniqueId = GetColliderUniqueId();
|
|
sphere.IsRecycle = true;
|
|
sphereColliderList.Add(sphere);
|
|
sphere.gameObject.SetActive(false);
|
|
}
|
|
|
|
public BattleContinuousTarget GetContinuousTarge()
|
|
{
|
|
if(isClear)
|
|
{
|
|
return null;
|
|
}
|
|
if (continuousTargeList.Count > 0)
|
|
{
|
|
var target = continuousTargeList[continuousTargeList.Count - 1];
|
|
continuousTargeList.RemoveAt(continuousTargeList.Count - 1);
|
|
return target;
|
|
}
|
|
else
|
|
{
|
|
var target = new BattleContinuousTarget();
|
|
return target;
|
|
}
|
|
}
|
|
|
|
public void RecycleContinuousTarge(BattleContinuousTarget target)
|
|
{
|
|
if(isClear)
|
|
{
|
|
target.Unit = null;
|
|
return;
|
|
}
|
|
continuousTargeList.Add(target);
|
|
}
|
|
|
|
public BattleControlColliderContainer GetColliderContainer()
|
|
{
|
|
if(isClear)
|
|
{
|
|
return null;
|
|
}
|
|
if (colliderContainerList.Count > 0)
|
|
{
|
|
var container = colliderContainerList[colliderContainerList.Count - 1];
|
|
colliderContainerList.RemoveAt(colliderContainerList.Count - 1);
|
|
container.IsRecycle = false;
|
|
return container;
|
|
}
|
|
else
|
|
{
|
|
var container = new BattleControlColliderContainer();
|
|
container.IsRecycle = false;
|
|
return container;
|
|
}
|
|
}
|
|
|
|
public void RecycleColliderContainer(BattleControlColliderContainer container)
|
|
{
|
|
if(isClear)
|
|
{
|
|
return;
|
|
}
|
|
container.IsRecycle = true;
|
|
colliderContainerList.Add(container);
|
|
}
|
|
|
|
public BattleControlSphereBullet GetSphereBullet()
|
|
{
|
|
if(isClear)
|
|
{
|
|
return null;
|
|
}
|
|
if (sphereBulletList.Count > 0)
|
|
{
|
|
var bullet = sphereBulletList[sphereBulletList.Count - 1];
|
|
sphereBulletList.RemoveAt(sphereBulletList.Count - 1);
|
|
bullet.gameObject.SetActive(true);
|
|
bullet.IsRecycle = false;
|
|
return bullet;
|
|
}
|
|
else
|
|
{
|
|
var gameObject = new GameObject(BattleConst.BATTLE_SPHERE_BULLET_NAME);
|
|
gameObject.transform.SetParent(sceneNode);
|
|
var bullet = gameObject.AddComponent<BattleControlSphereBullet>();
|
|
bullet.IsRecycle = false;
|
|
bullet.SetColliderEnabled(false);
|
|
return bullet;
|
|
}
|
|
}
|
|
|
|
public void RecycleSphereBullet(BattleControlSphereBullet bullet)
|
|
{
|
|
if(isClear)
|
|
{
|
|
GameObject.Destroy(bullet.gameObject);
|
|
return;
|
|
}
|
|
bullet.IsRecycle = true;
|
|
sphereBulletList.Add(bullet);
|
|
bullet.gameObject.SetActive(false);
|
|
}
|
|
|
|
public BattleControlBoxBullet GetBoxBullet()
|
|
{
|
|
if(isClear)
|
|
{
|
|
return null;
|
|
}
|
|
if (boxBulletList.Count > 0)
|
|
{
|
|
var bullet = boxBulletList[boxBulletList.Count - 1];
|
|
boxBulletList.RemoveAt(boxBulletList.Count - 1);
|
|
bullet.gameObject.SetActive(true);
|
|
bullet.IsRecycle = false;
|
|
return bullet;
|
|
}
|
|
else
|
|
{
|
|
var gameObject = new GameObject(BattleConst.BATTLE_BOX_BULLET_NAME);
|
|
gameObject.transform.SetParent(sceneNode);
|
|
var bullet = gameObject.AddComponent<BattleControlBoxBullet>();
|
|
bullet.IsRecycle = false;
|
|
bullet.SetColliderEnabled(false);
|
|
return bullet;
|
|
}
|
|
}
|
|
|
|
public void RecycleBoxBullet(BattleControlBoxBullet bullet)
|
|
{
|
|
if(isClear)
|
|
{
|
|
GameObject.Destroy(bullet.gameObject);
|
|
return;
|
|
}
|
|
bullet.IsRecycle = true;
|
|
boxBulletList.Add(bullet);
|
|
bullet.gameObject.SetActive(false);
|
|
}
|
|
|
|
public BattleEffectNumber GetEffectText(int colorType)
|
|
{
|
|
if(isClear)
|
|
{
|
|
return null;
|
|
}
|
|
if (colorType == 1)
|
|
{
|
|
if (effectNumberRedList.Count > 0)
|
|
{
|
|
var cachedComp = effectNumberRedList[effectNumberRedList.Count - 1];
|
|
effectNumberRedList.RemoveAt(effectNumberRedList.Count - 1);
|
|
cachedComp.SetEnabled(true);
|
|
return cachedComp;
|
|
}
|
|
var obj = GameObject.Instantiate(cacheEffectTextRed, numberRoot, false);
|
|
var comp = obj.GetComponent<BattleEffectNumber>();
|
|
comp.ColorType = colorType;
|
|
allEffectNumberList.Add(comp);
|
|
return comp;
|
|
}
|
|
else if (colorType == 2)
|
|
{
|
|
if (effectNumberYellowList.Count > 0)
|
|
{
|
|
var cachedComp = effectNumberYellowList[effectNumberYellowList.Count - 1];
|
|
effectNumberYellowList.RemoveAt(effectNumberYellowList.Count - 1);
|
|
cachedComp.SetEnabled(true);
|
|
return cachedComp;
|
|
}
|
|
var obj = GameObject.Instantiate(cacheEffectTextYellow, numberRoot, false);
|
|
var comp = obj.GetComponent<BattleEffectNumber>();
|
|
comp.ColorType = colorType;
|
|
allEffectNumberList.Add(comp);
|
|
return comp;
|
|
}
|
|
else if (colorType == 3)
|
|
{
|
|
if (effectNumberGreenList.Count > 0)
|
|
{
|
|
var cachedComp = effectNumberGreenList[effectNumberGreenList.Count - 1];
|
|
effectNumberGreenList.RemoveAt(effectNumberGreenList.Count - 1);
|
|
cachedComp.SetEnabled(true);
|
|
return cachedComp;
|
|
}
|
|
var obj = GameObject.Instantiate(cacheEffectTextGreen, numberRoot, false);
|
|
var comp = obj.GetComponent<BattleEffectNumber>();
|
|
comp.ColorType = colorType;
|
|
allEffectNumberList.Add(comp);
|
|
return comp;
|
|
}
|
|
else
|
|
{
|
|
if (effectNumberList.Count > 0)
|
|
{
|
|
var cachedComp = effectNumberList[effectNumberList.Count - 1];
|
|
effectNumberList.RemoveAt(effectNumberList.Count - 1);
|
|
cachedComp.SetEnabled(true);
|
|
return cachedComp;
|
|
}
|
|
var obj = GameObject.Instantiate(cacheEffectText, numberRoot, false);
|
|
var comp = obj.GetComponent<BattleEffectNumber>();
|
|
comp.ColorType = 0;
|
|
allEffectNumberList.Add(comp);
|
|
return comp;
|
|
}
|
|
}
|
|
|
|
public void PutBackEffectText(BattleEffectNumber comp, int colorType)
|
|
{
|
|
if(isClear)
|
|
{
|
|
GameObject.Destroy(comp.gameObject);
|
|
return;
|
|
}
|
|
comp.transform.localScale = Vector3.zero;
|
|
comp.SetEnabled(false);
|
|
if (colorType == 1)
|
|
{
|
|
effectNumberRedList.Add(comp);
|
|
}
|
|
else if (colorType == 2)
|
|
{
|
|
effectNumberYellowList.Add(comp);
|
|
}
|
|
else if (colorType == 3)
|
|
{
|
|
effectNumberGreenList.Add(comp);
|
|
}
|
|
else
|
|
{
|
|
effectNumberList.Add(comp);
|
|
}
|
|
}
|
|
|
|
public BattleHpBar GetHpBar(int side)
|
|
{
|
|
if(isClear)
|
|
{
|
|
return null;
|
|
}
|
|
if (side == 2)
|
|
{
|
|
if (hpBarDefList.Count > 0)
|
|
{
|
|
var cachedComp = hpBarDefList[hpBarDefList.Count - 1];
|
|
hpBarDefList.RemoveAt(hpBarDefList.Count - 1);
|
|
cachedComp.enabled = true;
|
|
return cachedComp;
|
|
}
|
|
var obj = GameObject.Instantiate(cacheHpDef, hpRoot, false);
|
|
var comp = obj.GetComponent<BattleHpBar>();
|
|
return comp;
|
|
}
|
|
else
|
|
{
|
|
if (hpBarAtkList.Count > 0)
|
|
{
|
|
var cachedComp = hpBarAtkList[hpBarAtkList.Count - 1];
|
|
hpBarAtkList.RemoveAt(hpBarAtkList.Count - 1);
|
|
cachedComp.enabled = true;
|
|
return cachedComp;
|
|
}
|
|
var obj = GameObject.Instantiate(cacheHpAtk, hpRoot, false);
|
|
var comp = obj.GetComponent<BattleHpBar>();
|
|
return comp;
|
|
}
|
|
}
|
|
|
|
public void PutBackHpBar(BattleHpBar comp, int side)
|
|
{
|
|
if(isClear)
|
|
{
|
|
GameObject.Destroy(comp.gameObject);
|
|
return;
|
|
}
|
|
comp.transform.localScale = Vector3.zero;
|
|
comp.enabled = false;
|
|
if (side == 2)
|
|
{
|
|
hpBarDefList.Add(comp);
|
|
}
|
|
else
|
|
{
|
|
hpBarAtkList.Add(comp);
|
|
}
|
|
}
|
|
|
|
public BattleSkillToast GetSkillToast()
|
|
{
|
|
if(isClear)
|
|
{
|
|
return null;
|
|
}
|
|
if (skillToastList.Count > 0)
|
|
{
|
|
var cachedComp = skillToastList[skillToastList.Count - 1];
|
|
skillToastList.RemoveAt(skillToastList.Count - 1);
|
|
cachedComp.enabled = true;
|
|
return cachedComp;
|
|
}
|
|
var obj = GameObject.Instantiate(cacheSkillToast, skillToastRoot, false);
|
|
var comp = obj.GetComponent<BattleSkillToast>();
|
|
allSkillToastList.Add(comp);
|
|
return comp;
|
|
}
|
|
|
|
public void PutBackSkillToast(BattleSkillToast comp)
|
|
{
|
|
if(isClear)
|
|
{
|
|
GameObject.Destroy(comp.gameObject);
|
|
return;
|
|
}
|
|
comp.transform.localScale = Vector3.zero;
|
|
comp.SetEnabled(false);
|
|
skillToastList.Add(comp);
|
|
|
|
BFMain.Instance.BattleMgr.RemoveSkillToastSet(comp);
|
|
}
|
|
|
|
public static int GetColliderUniqueId()
|
|
{
|
|
return colliderUniqueId ++;
|
|
}
|
|
|
|
public void Pause()
|
|
{
|
|
if (!ReferenceEquals(allEffectNumberList, null))
|
|
{
|
|
int count = allEffectNumberList.Count;
|
|
for(int i = 0; i < count; i++)
|
|
{
|
|
allEffectNumberList[i].SetPause();
|
|
}
|
|
}
|
|
if (!ReferenceEquals(allSkillToastList, null))
|
|
{
|
|
int count = allSkillToastList.Count;
|
|
for(int i = 0; i < count; i++)
|
|
{
|
|
allSkillToastList[i].SetPause();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Resume()
|
|
{
|
|
if (!ReferenceEquals(allEffectNumberList, null))
|
|
{
|
|
int count = allEffectNumberList.Count;
|
|
for(int i = 0; i < count; i++)
|
|
{
|
|
allEffectNumberList[i].SetResume();
|
|
}
|
|
}
|
|
if (!ReferenceEquals(allSkillToastList, null))
|
|
{
|
|
int count = allSkillToastList.Count;
|
|
for(int i = 0; i < count; i++)
|
|
{
|
|
allSkillToastList[i].SetResume();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
isClear = true;
|
|
if (!ReferenceEquals(boxColliderList, null))
|
|
{
|
|
boxColliderList.Clear();
|
|
}
|
|
if (!ReferenceEquals(sphereColliderList, null))
|
|
{
|
|
sphereColliderList.Clear();
|
|
}
|
|
if (!ReferenceEquals(boxBulletList, null))
|
|
{
|
|
boxBulletList.Clear();
|
|
}
|
|
if (!ReferenceEquals(sphereBulletList, null))
|
|
{
|
|
sphereBulletList.Clear();
|
|
}
|
|
if (!ReferenceEquals(continuousTargeList, null))
|
|
{
|
|
continuousTargeList.Clear();
|
|
}
|
|
if (!ReferenceEquals(colliderContainerList, null))
|
|
{
|
|
colliderContainerList.Clear();
|
|
}
|
|
if (!ReferenceEquals(effectNumberList, null))
|
|
{
|
|
effectNumberList.Clear();
|
|
}
|
|
if (!ReferenceEquals(effectNumberGreenList, null))
|
|
{
|
|
effectNumberGreenList.Clear();
|
|
}
|
|
if (!ReferenceEquals(effectNumberRedList, null))
|
|
{
|
|
effectNumberRedList.Clear();
|
|
}
|
|
if (!ReferenceEquals(effectNumberYellowList, null))
|
|
{
|
|
effectNumberYellowList.Clear();
|
|
}
|
|
if (!ReferenceEquals(allEffectNumberList, null))
|
|
{
|
|
int count = allEffectNumberList.Count;
|
|
for(int i = 0; i < count; i++)
|
|
{
|
|
GameObject.Destroy(allEffectNumberList[i].gameObject);
|
|
}
|
|
allEffectNumberList.Clear();
|
|
}
|
|
if (!ReferenceEquals(allSkillToastList, null))
|
|
{
|
|
int count = allSkillToastList.Count;
|
|
for(int i = 0; i < count; i++)
|
|
{
|
|
GameObject.Destroy(allSkillToastList[i].gameObject);
|
|
}
|
|
allSkillToastList.Clear();
|
|
}
|
|
if (!ReferenceEquals(hpBarAtkList, null))
|
|
{
|
|
hpBarAtkList.Clear();
|
|
}
|
|
if (!ReferenceEquals(hpBarDefList, null))
|
|
{
|
|
hpBarDefList.Clear();
|
|
}
|
|
if (!ReferenceEquals(skillToastList, null))
|
|
{
|
|
skillToastList.Clear();
|
|
}
|
|
if (poolNode != null)
|
|
{
|
|
GameObject.Destroy(poolNode);
|
|
poolNode = null;
|
|
}
|
|
sceneNode = null;
|
|
}
|
|
}
|
|
}
|