Sample project to showcase the use of UI Toolkit for Runtime based on the Unity Royale project.
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

68 行
1.6 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace UnityRoyale
{
public class CPUOpponent : MonoBehaviour
{
public DeckData aiDeck;
public UnityAction<CardData, Vector3, Placeable.Faction> OnCardUsed;
private bool act = false;
private Coroutine actingCoroutine;
public float opponentLoopTime = 5f;
public void LoadDeck()
{
DeckLoader newDeckLoaderComp = gameObject.AddComponent<DeckLoader>();
newDeckLoaderComp.OnDeckLoaded += DeckLoaded;
newDeckLoaderComp.LoadDeck(aiDeck);
}
//...
private void DeckLoaded()
{
Debug.Log("AI deck loaded");
//StartActing();
}
public void StartActing()
{
Invoke("Bridge", 0f);
}
private void Bridge()
{
act = true;
actingCoroutine = StartCoroutine(CreateRandomCards());
}
public void StopActing()
{
act = false;
StopCoroutine(actingCoroutine);
}
//TODO: create a proper AI
private IEnumerator CreateRandomCards()
{
yield return new WaitForSeconds(3f);
while(act)
{
if(OnCardUsed != null)
{
Vector3 newPos = new Vector3(Random.Range(-5f, 5f), 0f, Random.Range(3f, 8.5f));
OnCardUsed(aiDeck.GetNextCardFromDeck(), newPos, Placeable.Faction.Opponent);
}
yield return new WaitForSeconds(opponentLoopTime);
}
}
}
}