105 lines
2.8 KiB
C#
105 lines
2.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Timers;
|
|
using Chars;
|
|
using Data;
|
|
using UnityEngine;
|
|
// using GoogleMobileAds.Api;
|
|
using HexFiled;
|
|
using Random = UnityEngine.Random;
|
|
using Units;
|
|
using UnityEngine.UI;
|
|
|
|
public class AdsMob : MonoBehaviour
|
|
{
|
|
// private string _revardUnitId = "ca-app-pub-3940256099942544/5224354917";
|
|
// private RewardedAd _ad;
|
|
// private AdRequest _request;
|
|
private UnitInfo _player;
|
|
private UnitFactory _factory;
|
|
[SerializeField] private Button button;
|
|
[SerializeField] private GameObject canvas;
|
|
|
|
private void OnEnable()
|
|
{
|
|
// _ad = new RewardedAd(_revardUnitId);
|
|
// _request = new AdRequest.Builder().Build();
|
|
// _ad.LoadAd(_request);
|
|
// _ad.OnUserEarnedReward += HandleUser;
|
|
button.onClick.AddListener(Spawn) ;
|
|
canvas.SetActive(false);
|
|
//
|
|
}
|
|
// private void Start() {
|
|
// ShowAd();
|
|
// }
|
|
|
|
// private void HandleUser(object sender, Reward reward)
|
|
// {
|
|
//
|
|
// _player.Spawn(HexManager.CellByColor[UnitColor.GREY][Random.Range(0, HexManager.CellByColor[UnitColor.GREY].Count - 1)].coordinates);
|
|
// canvas.SetActive(false);
|
|
//
|
|
// }
|
|
|
|
private void Spawn()
|
|
{
|
|
var player = _player;
|
|
player.spawnPos =
|
|
HexManager.CellByColor[UnitColor.GREY][Random.Range(0, HexManager.CellByColor[UnitColor.GREY].Count - 1)]
|
|
.coordinates;
|
|
|
|
_factory.Spawn(player);
|
|
|
|
canvas.SetActive(false);
|
|
Time.timeScale = 1f;
|
|
}
|
|
|
|
// public void ShowAd()
|
|
// {
|
|
// //_player = player;
|
|
// if (_ad.IsLoaded())
|
|
// {
|
|
// _ad.Show();
|
|
// }
|
|
// }
|
|
|
|
public void ShowCanvas(UnitInfo player, UnitFactory factory)
|
|
{
|
|
_factory = factory;
|
|
_player = player;
|
|
Time.timeScale = 0f;
|
|
canvas.SetActive(true);
|
|
}
|
|
|
|
public void Respawn(GameObject player)
|
|
{
|
|
List<HexCell> cells = new List<HexCell>();
|
|
cells.AddRange(HexManager.CellByColor[UnitColor.GREY]);
|
|
// for (int i = 0; i < cells.Count; i++)
|
|
// {
|
|
|
|
// }
|
|
foreach (var cell in cells)
|
|
{
|
|
if(cell.Color == UnitColor.GREY)
|
|
{
|
|
var randomCell = Random.Range(0, cells.Count);
|
|
Vector3 respawnPosition = cells[randomCell].transform.position;
|
|
//cells[randomCell].Color = UnitColor.YELLOW;
|
|
player = FindObjectOfType<ExtraLife>().gameObject;
|
|
|
|
player.transform.position = respawnPosition;
|
|
if(player.transform.position == respawnPosition)
|
|
{
|
|
//cell.Color = UnitColor.YELLOW;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// private void OnDisable() {
|
|
// _ad.OnUserEarnedReward -= HandleUser;
|
|
// }
|
|
}
|