|
|
|
@ -1,6 +1,8 @@ |
|
|
|
using Cinemachine; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using UnityEngine; |
|
|
|
|
|
|
|
public class WeaponManager : Singleton<WeaponManager> |
|
|
|
@ -30,6 +32,8 @@ public class WeaponManager : Singleton<WeaponManager> |
|
|
|
private void Start() |
|
|
|
{ |
|
|
|
DontDestroyOnLoad(this.gameObject); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void Update() |
|
|
|
@ -146,4 +150,155 @@ public class WeaponManager : Singleton<WeaponManager> |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public GameObject getRandomWeaponNodeForPlayer() |
|
|
|
{ |
|
|
|
GameObject gem = Instantiate(Resources.Load<GameObject>(Name.WeaponNode.PrefabPath + Name.WeaponNode.PrefabName)); |
|
|
|
string condition = MathTool.GetRandomElements(Name.WeaponNodeCondition.PlayerConditionSet, 1).ElementAt(0); |
|
|
|
string conditionValue=""; |
|
|
|
string[] nodesMark=new string[4]; |
|
|
|
string[] nodesColor = new string[4]; |
|
|
|
string result = MathTool.GetRandomElements(Name.WeaponNodeFunction.PlayerResultSet, 1).ElementAt(0); |
|
|
|
string resultValue=""; |
|
|
|
switch (condition) |
|
|
|
{ |
|
|
|
case Name.WeaponNodeCondition.position: |
|
|
|
conditionValue= MathTool.GetRandomElements(new HashSet<string> {"0","1","2","3","4" }, 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeCondition.positionUnused: |
|
|
|
conditionValue = MathTool.GetRandomElements(new HashSet<string> { "0", "1", "2", "3", "4" }, 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeCondition.positionUsed: |
|
|
|
conditionValue = MathTool.GetRandomElements(new HashSet<string> { "0", "1", "2", "3", "4" }, 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeCondition.diffSettle: |
|
|
|
conditionValue=Name.none; |
|
|
|
break; |
|
|
|
case Name.WeaponNodeCondition.usedCard: |
|
|
|
conditionValue = MathTool.GetRandomElements(new HashSet<string> { "1", "2", "3", "4", "5" }, 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeCondition.threeColorDiffMoreThan: |
|
|
|
conditionValue = MathTool.GetRandomElements(new HashSet<string> { "3", "4", "5" }, 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeCondition.everyNumNodeConvert: |
|
|
|
conditionValue = MathTool.GetRandomElements(new HashSet<string> { "7", "8", "9" }, 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeCondition.bombbomb: |
|
|
|
conditionValue = Name.none; |
|
|
|
break; |
|
|
|
case Name.WeaponNodeCondition.node: |
|
|
|
conditionValue = Name.none; |
|
|
|
HashSet<string> nodesA = MathTool.GetRandomElements(new HashSet<string> { "1_0", "-1_0", "0_1", "0_-1", "-1_1", "-1_-1" }, 3); |
|
|
|
nodesA.Add("0_0"); |
|
|
|
nodesMark=nodesA.ToArray(); |
|
|
|
nodesColor = new string[4] { MathTool.GetRandomElements(new HashSet<string> { Name.Color.Red, Name.Color.Blue, Name.Color.Yellow }, 1).ElementAt(0) |
|
|
|
,MathTool.GetRandomElements(new HashSet<string> { Name.Color.Red, Name.Color.Blue, Name.Color.Yellow }, 1).ElementAt(0) |
|
|
|
,MathTool.GetRandomElements(new HashSet<string> { Name.Color.Red, Name.Color.Blue, Name.Color.Yellow }, 1).ElementAt(0) |
|
|
|
,MathTool.GetRandomElements(new HashSet<string> { Name.Color.Red, Name.Color.Blue, Name.Color.Yellow }, 1).ElementAt(0)}; |
|
|
|
break; |
|
|
|
case Name.WeaponNodeCondition.cardConditionPattern: |
|
|
|
conditionValue = Name.none; |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
sb.Append(MathTool.GetRandomElements(new HashSet<string> { Name.Color.Red, Name.Color.Blue, Name.Color.Yellow }, 1).ElementAt(0)) |
|
|
|
.Append(MathTool.GetRandomElements(new HashSet<string> { "<", ">" }, 1).ElementAt(0)) |
|
|
|
.Append(MathTool.GetRandomElements(new HashSet<string> { "5", "6", "7", "8", "9" }, 1).ElementAt(0)); |
|
|
|
condition =sb.ToString(); |
|
|
|
break; |
|
|
|
} |
|
|
|
switch (result) |
|
|
|
{ |
|
|
|
case Name.WeaponNodeFunction.addScore: |
|
|
|
resultValue = MathTool.GetRandomElements(MathTool.GenerateIntegerSet(7, 12), 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeFunction.mulScore: |
|
|
|
resultValue = MathTool.GetRandomElements(new HashSet<string> { "1", "2"}, 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeFunction.repetWeaponNode: |
|
|
|
resultValue = MathTool.GetRandomElements(new HashSet<string> { "0", "1", "2", "3", "4" }, 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeFunction.redNodeCount: |
|
|
|
resultValue = MathTool.GetRandomElements(MathTool.GenerateIntegerSet(3, 8), 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeFunction.blueNodeCount: |
|
|
|
resultValue = MathTool.GetRandomElements(MathTool.GenerateIntegerSet(3, 8), 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeFunction.yellowNodeCount: |
|
|
|
resultValue = MathTool.GetRandomElements(MathTool.GenerateIntegerSet(3, 8), 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeFunction.mostNodeCount: |
|
|
|
resultValue = MathTool.GetRandomElements(MathTool.GenerateIntegerSet(3, 8), 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeFunction.leastNodeCount: |
|
|
|
resultValue = MathTool.GetRandomElements(MathTool.GenerateIntegerSet(3, 8), 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeFunction.allNodeCount: |
|
|
|
resultValue = MathTool.GetRandomElements(MathTool.GenerateIntegerSet(2, 4), 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeFunction.drawCard: |
|
|
|
resultValue = MathTool.GetRandomElements(MathTool.GenerateIntegerSet(1, 4), 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeFunction.everyRedNodeAddScore: |
|
|
|
resultValue = MathTool.GetRandomElements(MathTool.GenerateIntegerSet(1, 3), 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeFunction.everyYellowNodeAddScore: |
|
|
|
resultValue = MathTool.GetRandomElements(MathTool.GenerateIntegerSet(1, 3), 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.WeaponNodeFunction.everyBlueNodeAddScore: |
|
|
|
resultValue = MathTool.GetRandomElements(MathTool.GenerateIntegerSet(1, 3), 1).ElementAt(0); |
|
|
|
break; |
|
|
|
case Name.NodeItem.Volcano: |
|
|
|
resultValue = MathTool.GetRandomElements(MathTool.GenerateIntegerSet(1, 2), 1).ElementAt(0); |
|
|
|
break; |
|
|
|
} |
|
|
|
WeaponNode weaponNode=gem.GetComponent<WeaponNode>(); |
|
|
|
weaponNode.result = result; |
|
|
|
weaponNode.resultValue = resultValue; |
|
|
|
weaponNode.condition = condition; |
|
|
|
weaponNode.conditionValue = conditionValue; |
|
|
|
weaponNode.nodesMark = nodesMark; |
|
|
|
weaponNode.nodesColor = nodesColor; |
|
|
|
return gem; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void loadEnemyWeaponNode(int position,GameObject weaponNode) |
|
|
|
{ |
|
|
|
|
|
|
|
Transform weaponSlot = enemyWeaponNodeList.GetChild(position); |
|
|
|
if (weaponSlot != null) |
|
|
|
{ |
|
|
|
ClearAllChildren(weaponSlot); |
|
|
|
weaponNode.transform.SetParent(weaponSlot.transform, true); |
|
|
|
weaponNode.transform.localPosition = Vector3.zero; |
|
|
|
weaponNode.transform.localRotation = Quaternion.identity; |
|
|
|
weaponNode.transform.localScale = Vector3.one; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void ClearAllChildren(Transform parent) |
|
|
|
{ |
|
|
|
// 创建临时列表存储子物体(避免在循环中修改集合)
|
|
|
|
List<GameObject> children = new List<GameObject>(); |
|
|
|
|
|
|
|
// 收集所有子物体
|
|
|
|
foreach (Transform child in parent) |
|
|
|
{ |
|
|
|
children.Add(child.gameObject); |
|
|
|
} |
|
|
|
|
|
|
|
// 删除所有子物体
|
|
|
|
foreach (GameObject child in children) |
|
|
|
{ |
|
|
|
// 根据环境选择销毁方式
|
|
|
|
if (Application.isPlaying) |
|
|
|
{ |
|
|
|
Destroy(child); |
|
|
|
} |
|
|
|
else // 编辑器模式下
|
|
|
|
{ |
|
|
|
DestroyImmediate(child); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|