public void PlayCollapseCutscene(Placeable.Faction f) { if (f == Placeable.Faction.Player) { redCastleCollapse.Play(); } else { blueCastleCollapse.Play(); } }
private void SetupPlaceable(GameObject go, PlaceableData pDataRef, Placeable.Faction pFaction) { switch (pDataRef.pType) { case Placeable.PlaceableType.Unit: { Unit uScript = go.GetComponent <Unit>(); uScript.Activate(pFaction, pDataRef); uScript.OnDealDamage += OnPlaceableDealtDamage; uScript.OnProjectileFired += OnProjectileFired; AddPlaceableToList(uScript); uiManager.AddHealthUI(uScript); break; } case Placeable.PlaceableType.Building: case Placeable.PlaceableType.Castle: { Building bScript = go.GetComponent <Building>(); bScript.Activate(pFaction, pDataRef); bScript.OnDealDamage += OnPlaceableDealtDamage; bScript.OnProjectileFired += OnProjectileFired; AddPlaceableToList(bScript); uiManager.AddHealthUI(bScript); if (pDataRef.pType == Placeable.PlaceableType.Castle) { bScript.OnDie += OnCastleDead; } navMesh.BuildNavMesh(); //rebake the navmesh break; } case Placeable.PlaceableType.Obstacle: { Obstacle oScript = go.GetComponent <Obstacle>(); oScript.Activate(pDataRef); navMesh.BuildNavMesh(); //rebake the navmesh break; } case Placeable.PlaceableType.Spell: { //TODO:spell break; } } go.GetComponent <Placeable>().OnDie += OnPlaceableDead; }
private List <ThinkingPlaceable> GetAttackList(Placeable.Faction f, Placeable.PlaceableTarget t) { switch (t) { case Placeable.PlaceableTarget.Both: return((f == Placeable.Faction.Player) ? allOpponents : allPlayers); case Placeable.PlaceableTarget.OnlyBuildings: return((f == Placeable.Faction.Player) ? opponentBuildings : playerBuildings); default: Debug.LogError("What faction is this?? Not Player nor Opponent"); return(null); } }
//setups all scripts and listeners on a Placeable GameObject private void SetupPlaceable(GameObject go, PlaceableData pDataRef, Placeable.Faction pFaction) { //Add the appropriate script switch (pDataRef.pType) { case Placeable.PlaceableType.Unit: Unit uScript = go.GetComponent <Unit>(); uScript.Activate(pFaction, pDataRef); //enables NavMeshAgent uScript.OnDealDamage += OnPlaceableDealtDamage; uScript.OnProjectileFired += OnProjectileFired; AddPlaceableToList(uScript); //add the Unit to the appropriate list UIManager.AddHealthUI(uScript); break; case Placeable.PlaceableType.Building: case Placeable.PlaceableType.Castle: Building bScript = go.GetComponent <Building>(); bScript.Activate(pFaction, pDataRef); bScript.OnDealDamage += OnPlaceableDealtDamage; bScript.OnProjectileFired += OnProjectileFired; AddPlaceableToList(bScript); //add the Building to the appropriate list UIManager.AddHealthUI(bScript); //special case for castles if (pDataRef.pType == Placeable.PlaceableType.Castle) { bScript.OnDie += OnCastleDead; } navMesh.BuildNavMesh(); //rebake the Navmesh break; case Placeable.PlaceableType.Obstacle: Obstacle oScript = go.GetComponent <Obstacle>(); oScript.Activate(pDataRef); navMesh.BuildNavMesh(); //rebake the Navmesh break; case Placeable.PlaceableType.Spell: //Spell sScript = newPlaceable.AddComponent<Spell>(); //sScript.Activate(pFaction, cardData.hitPoints); //TODO: activate the spell and… ? break; } go.GetComponent <Placeable>().OnDie += OnPlaceableDead; }
public void UseCard(CardData cardData, Vector3 position, Placeable.Faction pFaction) { for (int pNum = 0; pNum < cardData.placeablesData.Length; pNum++) { PlaceableData pDataRef = cardData.placeablesData[pNum]; Quaternion rot = (pFaction == Placeable.Faction.Player) ? Quaternion.identity : Quaternion.Euler(0f, 180f, 0f); //Prefab to spawn is the associatedPrefab if it's the Player faction, otherwise it's alternatePrefab. But if alternatePrefab is null, then first one is taken GameObject prefabToSpawn = (pFaction == Placeable.Faction.Player) ? pDataRef.associatedPrefab : ((pDataRef.alternatePrefab == null) ? pDataRef.associatedPrefab : pDataRef.alternatePrefab); GameObject newPlaceableGO = Instantiate <GameObject>(prefabToSpawn, position + cardData.relativeOffsets[pNum], rot); SetupPlaceable(newPlaceableGO, pDataRef, pFaction); appearEffectPool.UseParticles(position + cardData.relativeOffsets[pNum]); } updateAllPlaceables = true; //will force all AIBrains to update next time the Update loop is run }
public void UseCard(CardData cardData, Vector3 position, Placeable.Faction pFaction) { for (int pNum = 0; pNum < cardData.placeablesData.Length; pNum++) { PlaceableData pDataRef = cardData.placeablesData[pNum]; Quaternion rot = (pFaction == Placeable.Faction.Player) ? Quaternion.identity : Quaternion.Euler(0f, 180f, 0f); GameObject prefabToSpawn = (pFaction == Placeable.Faction.Player) ? pDataRef.associatedPrefab : ((pDataRef.alternatePrefab == null) ? pDataRef.associatedPrefab : pDataRef.alternatePrefab); GameObject newPlaceableGO = GameObject.Instantiate <GameObject>(prefabToSpawn, position + cardData.relativeOffsets[pNum], rot); SetupPlaceable(newPlaceableGO, pDataRef, pFaction); appearEffectPool.UseParticles(position + cardData.relativeOffsets[pNum]); } updateAllPlaceables = true; //更新AI下次的update loop }
private MyAIBaes FindNearestEnemy(Vector3 myPos, Placeable.Faction faction) { List <MyPlaceableView> units = (faction == Placeable.Faction.Player) ? his : mine; float x = float.MaxValue; MyAIBaes n = null; foreach (var unit in units) { var s = unit.GetComponent <MyAIBaes>(); if (s.state != AIState.Die) { var d = Vector3.Distance(unit.transform.position, myPos); if (d < x) { x = d; n = unit.GetComponent <MyAIBaes>(); } } } return(n); }
private void OnCastleDead(Placeable c) { loserFaction = c.faction; cinematicsManager.PlayCollapseCutscene(c.faction); c.OnDie -= OnCastleDead; gameOver = true; //stops the thinking loop //stop all the ThinkingPlaceables ThinkingPlaceable thkPl; for (int pN = 0; pN < allThinkingPlaceables.Count; pN++) { thkPl = allThinkingPlaceables[pN]; if (thkPl.state != ThinkingPlaceable.States.Dead) { thkPl.Stop(); thkPl.transform.LookAt(c.transform.position); UIManager.RemoveHealthUI(thkPl); } } CPUOpponent.StopActing(); }
public static async Task <List <MyPlaceableView> > CreatePlacable(MyCard data1, Transform parent, Vector3 Pos, Placeable.Faction faction) { List <MyPlaceableView> views = new List <MyPlaceableView>(); for (int i = 0; i < data1.placeablesIndices.Length; i++) { //取小兵ID var cardID = data1.placeablesIndices[i]; MyPlaceable placeable = null; for (int j = 0; j < MyPlaceableModel.instance.list.Count; j++) { //根据小兵ID找小兵 if (MyPlaceableModel.instance.list[j].id == cardID) { placeable = MyPlaceableModel.instance.list[j]; break; } } //取偏移 Vector3 offset = data1.relativeOffsets[i]; //实列小兵 //GameObject unitPrefad= Resources.Load<GameObject>((faction == Placeable.Faction.Player)? placeable.associatedPrefab: placeable.alternatePrefab); //var placeableInst = Instantiate(unitPrefad, parent, false); var ps = (faction == Placeable.Faction.Player) ? placeable.associatedPrefab : placeable.alternatePrefab; //异步实列小兵 GameObject placeableInst = await Addressables.InstantiateAsync(ps, parent, false).Task; //设置小兵偏移 placeableInst.transform.localPosition = offset; placeableInst.transform.position = Pos + offset; //赋值小兵数据 var p2 = placeable.Clone(); p2.faction = faction; placeableInst.GetComponent <MyPlaceableView>().data = p2; views.Add(placeableInst.GetComponent <MyPlaceableView>()); } return(views); }