powerfun-unity/Assets/Scripts/UI/Prefab/Activity/ActivityAdController.cs

97 lines
3.1 KiB
C#
Raw Normal View History

2022-02-16 18:22:27 +08:00
using Assets.Scripts;
2022-08-24 18:43:43 +08:00
using Assets.Scripts.Apis.Models;
using System;
2022-02-16 18:22:27 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2022-08-24 18:43:43 +08:00
using UnityEngine.SceneManagement;
using UnityEngine.UI;
2022-02-16 18:22:27 +08:00
public class ActivityAdController : PFUIPanel
{
Dictionary<string, Texture> caches;
2022-08-24 18:43:43 +08:00
private int activityType = 0;//0:内置网页 1骑行 2:赛事
private int routeId = 0;
private int competitionId = 0;
2022-02-16 18:22:27 +08:00
protected override void Awake()
{
caches = new Dictionary<string, Texture>();
2022-02-16 18:22:27 +08:00
UIManager.AddEvent(transform.Find("Exit").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
Close();
if (App.adQueue.Count > 0)
{
Invoke("ShowSelf", 0.5f);
}
2022-02-16 18:22:27 +08:00
});
UIManager.AddEvent(transform.Find("Image").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, async b =>
2022-02-16 18:22:27 +08:00
{
Close();
2022-08-24 18:43:43 +08:00
if (activityType == 1)
{
App.RouteIdParam = routeId;
var routeRes = ConfigHelper.mapApi.GetById(routeId);
if (routeRes.result)
{
if (routeRes.data.EnableAR)
{
SceneManager.LoadScene("VideoPlay");
}
else
{
SceneManager.LoadScene("Ride");
}
}
return;
}
2022-02-16 18:22:27 +08:00
//可以传参
//UIManager.ShowActivityPanel(url);
await ConfigHelper.activityApi.JoinActivity(id);
2022-02-16 18:22:27 +08:00
if (string.IsNullOrEmpty(App.CurrentUser.Contact) || string.IsNullOrEmpty(App.CurrentUser.ContactPhone) || string.IsNullOrEmpty(App.CurrentUser.ContactAddress))
{
UIManager.ShowAddressPanel();
}
else
{
UIManager.ShowActivityPanel(url);
}
});
//UIManager.AddEvent(transform.Find("LightUpChina/BtnRule").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
//{
// Application.OpenURL("https://www.baidu.com/");
//});
}
private void ShowSelf()
{
var ad = App.adQueue.Dequeue();
2022-08-24 18:43:43 +08:00
ad.Url = ad.Url + $"?Token={App.CurrentUser.cookie}";
UIManager.ShowActivityAdPanel(ad);
}
2022-02-16 18:22:27 +08:00
string image = null, url = null;
int id = 0;
2022-08-24 18:43:43 +08:00
public void Initial(ActivityModel activity)
2022-02-16 18:22:27 +08:00
{
2022-08-24 18:43:43 +08:00
this.id = activity.Id;
this.image = activity.DetailUrl;
var ri = transform.Find("Image").GetComponent<RawImage>();
Utils.DisplayImageTempDict(ri, image, caches);
2022-02-16 18:22:27 +08:00
App.ActivityUrl = url;
2022-08-24 18:43:43 +08:00
this.url = activity.Url;
this.activityType = activity.ActivityType;
this.routeId = activity.RouteId;
this.competitionId = activity.CompetitionId;
2022-02-16 18:22:27 +08:00
}
// Update is called once per frame
void Update()
{
}
protected override void OnDestroy()
{
caches = null;
Resources.UnloadUnusedAssets();
}
2022-02-16 18:22:27 +08:00
}