AR视频direction文件相关调整
This commit is contained in:
1 parent
d876c20def
commit
17c2a44e40
62 files changed
+120845
-42066
No files matched your search
@@ -65,14 +65,14 @@ namespace Assets.Scripts.Apis
|
||||
/// <param name="sort">hot, distance</param>
|
||||
/// <param name="sortDire">asc</param>
|
||||
/// <returns></returns>
|
||||
public Task<JsonResult<List<MapRoute>>> GetList(int pageIndex, int pageSize, string name, string distance="", string hands="", bool is3D=false, string sort="", string sortDire = "", bool isFav = false,bool isMine = false,bool isRecent = false)
|
||||
public Task<JsonResult<List<MapRoute>>> GetList(int pageIndex, int pageSize, string name, string distance="", string hands="", bool is3D=false, string sort="", string sortDire = "", bool isFav = false,bool isMine = false,bool isRecent = false,bool isEnableAR = false)
|
||||
{
|
||||
string lngLat = "";
|
||||
if (sort.Equals("Near"))
|
||||
{
|
||||
lngLat = $"{App.longitude},{App.latitude}";
|
||||
}
|
||||
var url = $"Map/GetRoute?pageIndex={ pageIndex }&pageSize={ pageSize }&name={ name }&distance={ distance }&hands={ hands }&is3D={ is3D }&sort={ sort }&sortDire={ sortDire }&isFav={isFav}&lngLat={lngLat}&isMine={isMine}&isRecent={isRecent}";
|
||||
var url = $"Map/GetRoute?pageIndex={ pageIndex }&pageSize={ pageSize }&name={ name }&distance={ distance }&hands={ hands }&is3D={ is3D }&sort={ sort }&sortDire={ sortDire }&isFav={isFav}&lngLat={lngLat}&isMine={isMine}&isRecent={isRecent}&isEnableAR={isEnableAR}";
|
||||
|
||||
return GetAsync<JsonResult<List<MapRoute>>>(url);
|
||||
}
|
||||
|
||||
@@ -19,10 +19,13 @@ public class MainController : BaseScene
|
||||
{
|
||||
[SerializeField] GameObject root;
|
||||
private Text Version;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
Debug.Log("执行25");
|
||||
|
||||
MapUDPService.MessageListener = ListenerHandler;
|
||||
Version = this.transform.Find("GameObject").Find("Version").GetComponent<Text>();
|
||||
Version.text = "V" + App.AppVersion;
|
||||
DeviceCache.Init(PFConstants.DeviceCacheFolder);
|
||||
@@ -64,6 +67,16 @@ public class MainController : BaseScene
|
||||
//DOTween.KillAll();
|
||||
FinishMessage(sender);
|
||||
}
|
||||
private bool DataSorceChanged { get; set; }
|
||||
private void ListenerHandler(List<ReceiveMsgModel> message)
|
||||
{
|
||||
var msg = message.Where(c => c.RoomList != null && c.RoomList.Count > 0).FirstOrDefault();
|
||||
if (msg != null)
|
||||
{
|
||||
App.gameRoomDetail = msg.RoomList.FirstOrDefault();
|
||||
DataSorceChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
List<CanvasGroup> msgs;
|
||||
Vector3 msgLocation;
|
||||
@@ -318,7 +331,7 @@ public class MainController : BaseScene
|
||||
}
|
||||
if (App.MainSceneParam["Name"] == "NewRouteDetail" && App.currentArea != null)
|
||||
{
|
||||
UIManager.ShowNewRouteDetailPanel(App.currentArea.Id);
|
||||
UIManager.ShowNewRouteDetailPanel(App.currentArea.Id,App.currentArea.CoverImage);
|
||||
}
|
||||
if (App.MainSceneParam["Name"] == "UserInfoPanel")
|
||||
{
|
||||
@@ -364,7 +377,7 @@ public class MainController : BaseScene
|
||||
//UIManager.ShowBigMapPanel();
|
||||
//UIManager.ShowEarthPanel();
|
||||
}
|
||||
|
||||
ShowGameRoomInviteConfirm();
|
||||
UIManager.UpdateJoinCompetition();//查询当前我参加的赛事
|
||||
}
|
||||
|
||||
@@ -378,6 +391,12 @@ public class MainController : BaseScene
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (DataSorceChanged)
|
||||
{
|
||||
DataSorceChanged = false;
|
||||
UIManager.ShowGameRoomDetailPanel();
|
||||
return;
|
||||
}
|
||||
clearcachet -= Time.deltaTime;
|
||||
if (clearcachet <= 0)
|
||||
{
|
||||
@@ -517,6 +536,30 @@ public class MainController : BaseScene
|
||||
}
|
||||
}
|
||||
}
|
||||
//检查剪切板内容进入对战房间
|
||||
private void ShowGameRoomInviteConfirm()
|
||||
{
|
||||
var clipContent = Utils.GetClipboard();
|
||||
if (!string.IsNullOrEmpty(clipContent) && App.currentPageIsHome)
|
||||
{
|
||||
//GameRoom/{App.CurrentUser.Nickname}/{manager.GameRoom.Name}/{manager.GameRoom.RoomId}
|
||||
var code = EncrypHelper.Decrypt(clipContent);
|
||||
if (string.IsNullOrEmpty(code))
|
||||
return;
|
||||
var arr = code.Split('/');
|
||||
var userName = arr[1];
|
||||
var roomName = arr[2];
|
||||
var roomId = Convert.ToInt32(arr[3]);
|
||||
var content = $"{userName} {App.GetLocalString("invite you to join in")} {roomName} , {App.GetLocalString("are you accept the invitation?")}";
|
||||
UIManager.ShowConfirm(App.GetLocalString("Invitition"), content, () => {
|
||||
UIManager.CloseConfirm();
|
||||
App.Model = "GameRoom";
|
||||
MapUDPService.SendJoinGameRoom(roomId, App.CurrentUser.Id, UIManager.Now.GetDateTime().ToUniversalTime());
|
||||
MapUDPService.SendQueryGameRoomList(App.CurrentUser.Id, 0, 1, arr[3]);
|
||||
});
|
||||
Utils.CopyToClipboard("");
|
||||
}
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
EventQueueSystem.RemoveListener<LinkedMessageEvent>(LinkedMessageHandler);
|
||||
|
||||
@@ -142,6 +142,7 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
Cadence = item.Cadence,
|
||||
TotalTicks = item.TotalTicks,
|
||||
WeightKg = item.WeightKg,
|
||||
Sex = item.Sex,
|
||||
});
|
||||
}
|
||||
{
|
||||
@@ -161,7 +162,7 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
Headimage = item.HeadImage,
|
||||
CreateTime = DateTime.MaxValue,
|
||||
EndDistance = item.EndDistance,
|
||||
IsCompleted = item.IsCompleted
|
||||
IsCompleted = item.IsCompleted,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -292,6 +293,7 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
EndDistance = item.EndDistance,
|
||||
PreDistance = item.PreDistance,
|
||||
WeightKg = item.WeightKg,
|
||||
Sex = item.Sex,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,12 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
{
|
||||
public class GameModel : BaseCycling
|
||||
{
|
||||
/// <summary>
|
||||
/// 第一个到终点的时间
|
||||
/// </summary>
|
||||
public DateTime? FirstEndTime { get; private set; }
|
||||
public GameRoomModel GameRoom { get; private set; }
|
||||
|
||||
public GameModel(Route route,RouteResultParam param)
|
||||
: base(route, CyclingModel.Single)
|
||||
{
|
||||
@@ -30,6 +36,7 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
selectParam = param,
|
||||
RoomId = App.gameRoomDetail.RoomId,
|
||||
};
|
||||
GameRoom = App.gameRoomDetail;
|
||||
App.gameRoomDetail = null;
|
||||
if (param != null)
|
||||
{
|
||||
@@ -68,6 +75,7 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
EndDistance = item.EndDistance,
|
||||
PreDistance = item.PreDistance,
|
||||
WeightKg = item.WeightKg,
|
||||
Sex = item.Sex,
|
||||
FrameRate = item.FrameRate,
|
||||
});
|
||||
}
|
||||
@@ -75,5 +83,20 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
#endregion
|
||||
base.Run(targetData);
|
||||
}
|
||||
|
||||
protected override void BeforeRunAfterPakcData()
|
||||
{
|
||||
base.BeforeRunAfterPakcData();
|
||||
|
||||
var userList = MapUDPService.GetOnlineUsers(recorderData.CurrentRoute.RouteInstance.Id,recorderData.RoomId).Where(c=>c.IsSelf == false).OrderByDescending(u => u.Saved).ThenBy(d => d.CreateTime).ThenByDescending(d => d.EndDistance);
|
||||
if (userList.Any())
|
||||
{
|
||||
foreach (var item in userList)
|
||||
{
|
||||
if(!FirstEndTime.HasValue && item.IsCompleted)
|
||||
FirstEndTime = Now.AddMinutes(GameRoom.CloseTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,6 +91,7 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
EndDistance = item.EndDistance,
|
||||
PreDistance = item.PreDistance,
|
||||
WeightKg = item.WeightKg,
|
||||
Sex = item.Sex,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -80,6 +80,7 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
EndDistance = item.EndDistance,
|
||||
PreDistance = item.PreDistance,
|
||||
WeightKg = item.WeightKg,
|
||||
Sex = item.Sex,
|
||||
FrameRate = item.FrameRate,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Assets.Scenes.Ride.Scripts.Model.RiderModels
|
||||
public class OnlineRiderModel : BaseRider
|
||||
{
|
||||
public override RiderType riderType => RiderType.Online;
|
||||
|
||||
public int Sex { get; set; } = 0;
|
||||
public double PreDistance { get; set; } = 0;
|
||||
public double Speed { get; set; } = 0;
|
||||
public double WeightKg { get; set; } = 0;
|
||||
|
||||
@@ -8,6 +8,7 @@ using System;
|
||||
using ChartAndGraph;
|
||||
using DG.Tweening;
|
||||
using System.Collections;
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
@@ -61,7 +62,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
weight = App.CurrentUser.Weight;
|
||||
bicycleWeight = App.CurrentUser.BicycleWeight;
|
||||
//#if UNITY_EDITOR
|
||||
power = 300;
|
||||
power = 400;
|
||||
//#endif
|
||||
mainController.TrackResistance(currentSlope * App.RideSetting.Sensitivity / 100);
|
||||
}
|
||||
@@ -122,8 +123,25 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
mainController.SaveRealTime();
|
||||
}
|
||||
}
|
||||
HandleForGameRoom();
|
||||
}
|
||||
protected override void BeforeRun()
|
||||
|
||||
private bool gameRoomHandled { get; set; }
|
||||
private void HandleForGameRoom()
|
||||
{
|
||||
var model = mainController.cyclingController as GameModel;
|
||||
if (model != null && model.FirstEndTime.HasValue && !gameRoomHandled)
|
||||
{
|
||||
gameRoomHandled = true;
|
||||
var gap = model.FirstEndTime.Value - UIManager.Now.GetDateTime();
|
||||
var seconds = Math.Floor(gap.TotalSeconds);
|
||||
UIManager.ShowGameRoomCountDownPanel((int)seconds, () => {
|
||||
Upload();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected override void BeforeRun()
|
||||
{
|
||||
//if (mainController != null)
|
||||
//{
|
||||
@@ -157,7 +175,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
nextPosition.x -= 14f;
|
||||
nextPosition.y += 5f;
|
||||
//人物移动 停止条件 到中间且线未加载完
|
||||
if ( GetStart() && chartDataSourceScript.ReachMid(viewIndex) && !chartDataSourceScript.ReachEnd())
|
||||
if ( GetStart() && chartDataSourceScript.ReachMid(CurrentIndex) && !chartDataSourceScript.ReachEnd())
|
||||
{
|
||||
var currentDistance = CurrentDistance;
|
||||
var distance = Distance;
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
timer -= Time.deltaTime;
|
||||
|
||||
CreateHeadImage();
|
||||
|
||||
|
||||
while (timer <= 0)
|
||||
{
|
||||
try
|
||||
@@ -141,26 +141,35 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
}
|
||||
private bool animated = false;
|
||||
private float offset = 0;
|
||||
private Vector3 rotation = Vector3.zero;
|
||||
protected CustomRange currentRange { get; set; }
|
||||
//控制角色进行向左或向右
|
||||
protected virtual void Turn()
|
||||
{
|
||||
var currentFrame = GetCurrentFrame();
|
||||
var result = manager.mockDirection.Where(c => c.Start < currentFrame && c.End > currentFrame).FirstOrDefault();
|
||||
if (result != null)
|
||||
currentRange = manager.mockDirection.Where(c => c.Start < currentFrame && c.End > currentFrame).FirstOrDefault();
|
||||
if (currentRange != null)
|
||||
{
|
||||
bearing = result.Value;
|
||||
bearing = currentRange.RotationY;
|
||||
rotation.y = currentRange.RotationY;
|
||||
rotation.z = currentRange.RotationZ;
|
||||
}
|
||||
else
|
||||
{
|
||||
rotation.y = 0;
|
||||
rotation.z = 0;
|
||||
bearing = 0;
|
||||
}
|
||||
animator.SetFloat("bearing", bearing);
|
||||
|
||||
var headBack = ticks % 60 == 0 && speed > 0 && bearing == 0;
|
||||
var drink = ticks % 125 == 0 && speed > 0 && bearing == 0;
|
||||
|
||||
animator.SetFloat("bearing", bearing);
|
||||
animator.SetBool("headBack", headBack);
|
||||
animator.SetBool("drinking", drink);
|
||||
|
||||
var waiting = ratio == 0 ? 1 : 1 / ratio;
|
||||
//直角拐弯
|
||||
if (Math.Abs(bearing) > 30)
|
||||
{
|
||||
if (!animated)
|
||||
@@ -181,6 +190,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
}
|
||||
else
|
||||
{
|
||||
//直角拐弯回正
|
||||
if (offset != 0)
|
||||
{
|
||||
var cpoffset = offset;
|
||||
@@ -193,11 +203,31 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
};
|
||||
offset = 0;
|
||||
}
|
||||
//正常拐弯
|
||||
else
|
||||
{
|
||||
transform.DORotate(new Vector3(0, bearing, -bearing), waiting);
|
||||
transform.DORotate(rotation, 0.6f);
|
||||
}
|
||||
}
|
||||
}
|
||||
Vector3 current;
|
||||
Vector3 forward;
|
||||
//0-90 右转弯 -90-0左转弯
|
||||
protected virtual void TurnAround()
|
||||
{
|
||||
StartCoroutine(MoveTo());
|
||||
}
|
||||
|
||||
protected virtual IEnumerator MoveTo()
|
||||
{
|
||||
float t = 0;
|
||||
while (t < 1)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
Vector3 v = Vector3.Lerp(current, forward, t);
|
||||
current = v;
|
||||
transform.DORotate(v, 0);
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
}
|
||||
//计算人物当前属性
|
||||
@@ -269,6 +299,9 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
}
|
||||
if (manager.CurrentPlayer != null && manager.CurrentPlayer.UserId != UserId)
|
||||
return;
|
||||
|
||||
manager.Play(ratio);
|
||||
|
||||
if (ratio > 1)
|
||||
{
|
||||
ratio = Math.Min(ratio, 1.2f);
|
||||
@@ -283,8 +316,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
animator.speed = ratio;
|
||||
}
|
||||
manager.Play(ratio);
|
||||
|
||||
}
|
||||
|
||||
protected virtual void ComputeRecord() { }
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -84,7 +81,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
if (manager.CurrentPlayer == null || manager.CurrentPlayer.UserId != UserId)
|
||||
{
|
||||
var result = manager.mockDirection.Where(c => c.Start < currentFrame && c.End > currentFrame).FirstOrDefault();
|
||||
bearing = result?.Value ?? 0;
|
||||
bearing = result?.RotationY ?? 0;
|
||||
animator.SetFloat("bearing", bearing);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,14 +24,34 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
public class CustomRange
|
||||
{
|
||||
public int Start { get; set; }
|
||||
public int End { get; set; }
|
||||
public int Value { get; set; }
|
||||
public int Start { get; set; }//起始帧
|
||||
public int End { get; set; }//结束帧
|
||||
public int PositionX { get; set; }
|
||||
public int PositionY { get; set; }
|
||||
public int PositionZ { get; set; }
|
||||
public int RotationY { get; set; }
|
||||
public int RotationZ { get; set; }
|
||||
public int ShadowDirection { get; set; }
|
||||
|
||||
public static CustomRange Read(string s)
|
||||
{
|
||||
//243~573:-15,13,12
|
||||
var result = s.Split(':');
|
||||
var range = result[0].Split('~');
|
||||
var v = result[1].Split(',');
|
||||
CustomRange r = new CustomRange()
|
||||
{
|
||||
Start = Convert.ToInt32(range[0]),
|
||||
End = Convert.ToInt32(range[1]),
|
||||
RotationY = Convert.ToInt32(v[0]),
|
||||
RotationZ = Convert.ToInt32(v[1]),
|
||||
PositionX = Convert.ToInt32(v[2]),
|
||||
};
|
||||
return r;
|
||||
}
|
||||
}
|
||||
public class VideoGameManager : DeviceServiceMonoBase
|
||||
{
|
||||
[SerializeField]
|
||||
public VideoPlayer videoPlayer;
|
||||
public AbstractVideoPlayer CurrentPlayer { get; set; }
|
||||
private MapDataModel mapData { get; set; }
|
||||
private MediaPlayer mediaPlayer { get; set; }
|
||||
@@ -49,6 +69,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
public List<float> slots = new List<float>();
|
||||
GameObject infoPanel;
|
||||
GameObject OnlinePlayer;
|
||||
GameObject OnlinePlayer_NV;
|
||||
private bool isStop { get; set; }
|
||||
public enum ARMode
|
||||
{
|
||||
@@ -69,7 +90,8 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
recordId = Guid.NewGuid().ToString();
|
||||
MockDirection();
|
||||
infoPanel = Resources.Load<GameObject>("UI/Prefab/AR/VideoPlayerHead");
|
||||
OnlinePlayer = Resources.Load<GameObject>("UI/Prefab/OnlineVideoPlayer");
|
||||
OnlinePlayer = Resources.Load<GameObject>("UI/Prefab/AR/OnlineVideoPlayer");
|
||||
OnlinePlayer_NV = Resources.Load<GameObject>("UI/Prefab/AR/OnlineVideoPlayer_NV");
|
||||
StartCoroutine(Init());
|
||||
}
|
||||
void Start()
|
||||
@@ -152,7 +174,15 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
if (currentPlayer != null)
|
||||
{
|
||||
var onlineRider = currentPlayer as OnlineRiderModel;
|
||||
var obj = Instantiate(OnlinePlayer, transform);
|
||||
GameObject obj;
|
||||
if (onlineRider.Sex == 1)
|
||||
{
|
||||
obj = Instantiate(OnlinePlayer, transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = Instantiate(OnlinePlayer_NV, transform);
|
||||
}
|
||||
var online = obj.GetComponent<OnlineVideoPlayer>();
|
||||
online.SetPlayer(onlineRider.NickName, onlineRider.EndDistance-onlineRider.PreDistance, onlineRider.EndDistance, onlineRider.Cadence, onlineRider.HeartRate, onlineRider.TotalTicks, onlineRider.UserId, onlineRider.Power, onlineRider.EndDistance,onlineRider.FrameRate.Value);
|
||||
obj.transform.DOMoveX(0, 1);
|
||||
@@ -196,7 +226,15 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
var diff = item.EndDistance % mapData.TotalDistance - currentPlayerInfo.EndDistance % mapData.TotalDistance;
|
||||
if (Math.Abs(diff * 1000) <= 50)
|
||||
{
|
||||
var obj = Instantiate(OnlinePlayer, transform);
|
||||
GameObject obj;
|
||||
if (currentPlayerInfo.Sex == 1)
|
||||
{
|
||||
obj = Instantiate(OnlinePlayer, transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = Instantiate(OnlinePlayer_NV, transform);
|
||||
}
|
||||
var online = obj.GetComponent<OnlineVideoPlayer>();
|
||||
online.SetPlayer(onlineRider.NickName, onlineRider.EndDistance - onlineRider.PreDistance, onlineRider.EndDistance, item.Cadence, item.HeartRate, onlineRider.WeightKg, item.UserId, onlineRider.Power, currentPlayerInfo.EndDistance, onlineRider.FrameRate.Value);
|
||||
obj.transform.DOMoveX(slots[currentOnlineCount], 1);
|
||||
@@ -212,19 +250,28 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
_aRMode = aRMode;
|
||||
var uimanager = FindObjectOfType<VideoUIManager>();
|
||||
uimanager.SetCurrentMode(aRMode);
|
||||
if (_aRMode == ARMode.INSPECT)
|
||||
if (_aRMode != ARMode.INSPECT)
|
||||
{
|
||||
videoPlayer?.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
videoPlayer?.gameObject.SetActive(true);
|
||||
CurrentPlayer = videoPlayer;
|
||||
InitCurrentPlayer();
|
||||
ContinueAsync();
|
||||
}
|
||||
}
|
||||
//初始化人物模型
|
||||
public void InitCurrentPlayer()
|
||||
{
|
||||
GameObject videoPlayer;
|
||||
if (App.CurrentUser.Sex == 1)
|
||||
{
|
||||
videoPlayer = Instantiate(Resources.Load<GameObject>("UI/Prefab/AR/VidePlayer"),transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
videoPlayer = Instantiate(Resources.Load<GameObject>("UI/Prefab/AR/VidePlayer_NV"), transform);
|
||||
}
|
||||
CurrentPlayer = videoPlayer.GetComponent<VideoPlayer>();
|
||||
}
|
||||
|
||||
Vector3 origin = new Vector3(0, -1, 4);
|
||||
Vector3 origin = new Vector3(0, -1, 3);
|
||||
//切换人物
|
||||
public void ChangePlayer(int userId)
|
||||
{
|
||||
@@ -300,18 +347,13 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
private void MockDirection()
|
||||
{
|
||||
var text = Resources.Load<TextAsset>("UI/direction");
|
||||
var arr = text.text.Replace("\r\n", ",").Split(',');
|
||||
var arr = text.text.Replace("\r\n", " ").Split(' ');
|
||||
foreach (var item in arr)
|
||||
{
|
||||
if (string.IsNullOrEmpty(item))
|
||||
continue;
|
||||
var result = item.Split(':');
|
||||
var range = result[0].Split('~');
|
||||
mockDirection.Add(new CustomRange() {
|
||||
Start = Convert.ToInt32(range[0]),
|
||||
End = Convert.ToInt32(range[1]),
|
||||
Value = Convert.ToInt32(result[1]),
|
||||
});
|
||||
var c = CustomRange.Read(item);
|
||||
mockDirection.Add(c);
|
||||
}
|
||||
}
|
||||
//设置骑行模式
|
||||
@@ -521,5 +563,10 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
return new Vector2d(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
App.gameRoomDetail = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -234,6 +234,8 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
protected void Download(BaseEventData baseEvent)
|
||||
{
|
||||
var path = PFConstants.VideoFolder;
|
||||
var filepath = path + $"/{route.FileName}";
|
||||
StartCoroutine(Utils.DownloadVideo(route.FileName, route.Url
|
||||
, (p, req) =>
|
||||
{
|
||||
@@ -249,7 +251,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
else
|
||||
{
|
||||
slider.value = 100;
|
||||
manager.SetMedia(p);
|
||||
manager.SetMedia(filepath);
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
using DG.Tweening;
|
||||
using System;
|
||||
using System.Linq;
|
||||
@@ -44,14 +45,26 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
base.ComputeAnimator();
|
||||
}
|
||||
protected override void Turn()
|
||||
{
|
||||
base.Turn();
|
||||
if (currentRange != null)
|
||||
{
|
||||
transform.DOMoveX(currentRange.PositionX, 0.8f);
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.DOMoveX(1, 0.8f);
|
||||
}
|
||||
}
|
||||
protected override void ComputePlayer()
|
||||
{
|
||||
heartRate = manager.UpDateHeart();
|
||||
power = manager.UpdatePower();
|
||||
cadance = manager.UpdateCadence();
|
||||
//#if UNITY_EDITOR
|
||||
power = 350;
|
||||
cadance = 150;
|
||||
power = 100;
|
||||
cadance = 70;
|
||||
heartRate = 160;
|
||||
//#endif
|
||||
weight = App.CurrentUser.Weight;
|
||||
@@ -59,10 +72,27 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
wkg = Math.Round(power / weight, 2);
|
||||
var mainFrame = manager.GetCurrentFrame();
|
||||
var result = manager.mockDirection.Where(c => c.Start < mainFrame && c.End > mainFrame).FirstOrDefault();
|
||||
bearing = result?.Value ?? 0;
|
||||
bearing = result?.RotationY ?? 0;
|
||||
//发送阻力
|
||||
manager.TrackResistance(currentSlope);
|
||||
base.ComputePlayer();
|
||||
HandleForGameRoom();
|
||||
}
|
||||
private bool gameRoomHandled { get; set; }
|
||||
private void HandleForGameRoom()
|
||||
{
|
||||
var model = manager.cyclingController as GameModel;
|
||||
if (model != null && model.FirstEndTime.HasValue && !gameRoomHandled)
|
||||
{
|
||||
gameRoomHandled = true;
|
||||
var gap = model.FirstEndTime.Value - UIManager.Now.GetDateTime();
|
||||
var seconds = Math.Floor(gap.TotalSeconds);
|
||||
UIManager.ShowGameRoomCountDownPanel((int)seconds, () => {
|
||||
Upload();
|
||||
var uiManager = FindObjectOfType<VideoUIManager>();
|
||||
uiManager.ShowResultPanel();
|
||||
});
|
||||
}
|
||||
}
|
||||
//控制视频播放速度
|
||||
protected override void ComputeVideo()
|
||||
@@ -89,7 +119,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
_TotalClimb = totalClimb,
|
||||
_FrameRate = manager.GetCurrentFrame()
|
||||
};
|
||||
var preDistance = totalDistance >= mapData.TotalDistance ? targetData._Distance : targetData._Distance - distance;
|
||||
var preDistance = targetData._Distance - distance;//totalDistance >= mapData.TotalDistance ? targetData._Distance : targetData._Distance - distance;
|
||||
recorderData.PreDistance = Math.Round(preDistance, 6, MidpointRounding.AwayFromZero);
|
||||
recorderData.EndDistance = Math.Round(targetData._Distance, 6, MidpointRounding.AwayFromZero);
|
||||
recorderData.RiderDatas.Add(targetData);
|
||||
|
||||
@@ -216,6 +216,15 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
cameraImage.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowResultPanel()
|
||||
{
|
||||
resultPanel.SetActive(true);
|
||||
resultPanel.transform.SetAsLastSibling();
|
||||
var videoResultScript = resultPanel.GetComponent<VideoResultScript>();
|
||||
videoResultScript.InjectController(manager);
|
||||
videoResultScript.SetDataSource(manager.cyclingController.recorderData);
|
||||
}
|
||||
private void QuitClick(BaseEventData e)
|
||||
{
|
||||
if (manager._aRMode == VideoGameManager.ARMode.RIDE)
|
||||
|
||||
@@ -58,6 +58,7 @@ class GameRoomDownloadTask : MonoBehaviour
|
||||
{
|
||||
slider.gameObject.SetActive(false);
|
||||
gameObject.Destroy();
|
||||
Loom.DownLoadTaskList.Remove(FileName);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,24 +29,34 @@ class GameRoomPlayerPanel : MonoBehaviour
|
||||
|
||||
public bool NotUse { get; private set; }
|
||||
|
||||
public bool IsOwner { get; private set; }
|
||||
|
||||
private void Start()
|
||||
{
|
||||
var manager = FindObjectOfType<GameRoomDetailController>();
|
||||
var inviteBtn = inviteModal.transform.Find("InviteBtn").gameObject;
|
||||
UIManager.AddEvent(inviteBtn,EventTriggerType.PointerClick,(e)=> {
|
||||
Utils.CopyToClipboard($"GameRoom/{manager.GameRoom.RoomId}");
|
||||
var encryptCode = EncrypHelper.Encrypt($"GameRoom/{App.CurrentUser.Nickname}/{manager.GameRoom.Name}/{manager.GameRoom.RoomId}");
|
||||
Utils.CopyToClipboard(encryptCode);
|
||||
Utils.showToast(transform.parent.gameObject, App.GetLocalString("copy to clipboard successfully!"));
|
||||
});
|
||||
|
||||
UIManager.AddEvent(gameObject, EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
if (App.gameRoomDetail.UserId != App.CurrentUser.Id)
|
||||
return;
|
||||
kickModal.SetActive(true);
|
||||
});
|
||||
UIManager.AddEvent(cancelBtn, EventTriggerType.PointerExit, (e) =>
|
||||
UIManager.AddEvent(cancelBtn, EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
if (App.gameRoomDetail.UserId != App.CurrentUser.Id)
|
||||
return;
|
||||
kickModal.SetActive(false);
|
||||
});
|
||||
UIManager.AddEvent(kickBtn, EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
if (App.gameRoomDetail.UserId != App.CurrentUser.Id)
|
||||
return;
|
||||
MapUDPService.SendGameRoomKick(App.gameRoomDetail.RoomId, UserId, App.CurrentUser.Id);
|
||||
});
|
||||
}
|
||||
@@ -63,7 +73,7 @@ class GameRoomPlayerPanel : MonoBehaviour
|
||||
ftpTxt.text = ftp.ToString();
|
||||
me.SetActive(App.CurrentUser.Id == userId);
|
||||
owner.SetActive(isOwner);
|
||||
//Show ready
|
||||
IsOwner = isOwner;
|
||||
ready.SetActive(!isOwner && Status == 1);
|
||||
}
|
||||
|
||||
@@ -77,14 +87,10 @@ class GameRoomPlayerPanel : MonoBehaviour
|
||||
ftpTxt.text = ftp.ToString();
|
||||
me.SetActive(App.CurrentUser.Id == userId);
|
||||
owner.SetActive(isOwner);
|
||||
IsOwner = isOwner;
|
||||
ready.SetActive(!isOwner && Status == 1);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Ready()
|
||||
{
|
||||
ready.SetActive(true);
|
||||
|
||||
@@ -27,9 +27,10 @@ public class NewRouteItemController : MonoBehaviour
|
||||
GetComponent<Button>().onClick.RemoveAllListeners();
|
||||
GetComponent<Button>().onClick.AddListener(() =>
|
||||
{
|
||||
UIManager.ShowNewRouteDetailPanel(area.Id);
|
||||
UIManager.ShowNewRouteDetailPanel(area.Id,area.CoverImage);
|
||||
});
|
||||
StartCoroutine(displayImage(area, caches));
|
||||
Utils.DisplayImage(GetComponent<RawImage>(), area.CoverImage);
|
||||
//StartCoroutine(displayImage(area, caches));
|
||||
}
|
||||
|
||||
IEnumerator displayImage(MapRouteAreaItem area, Dictionary<string, Texture> caches = null)
|
||||
|
||||
@@ -42,7 +42,10 @@ public class GameRoomCountDownController : PFUIPanel
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
count.text = Seconds.ToString();
|
||||
else
|
||||
{
|
||||
count.text = Seconds.ToString();
|
||||
}
|
||||
Seconds--;
|
||||
timer += 1f;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,10 @@ public class GameRoomDetailController : PFUIPanel
|
||||
if (detail.RoomList != null)
|
||||
{
|
||||
GameRoom = detail.RoomList.Where(c => c.RoomId == GameRoom.RoomId).FirstOrDefault();
|
||||
DataSourceChanged = true;
|
||||
if (GameRoom != null)
|
||||
{
|
||||
DataSourceChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,11 +137,11 @@ public class GameRoomDetailController : PFUIPanel
|
||||
d3.SetActive(enable3d);
|
||||
ar.SetActive(GameRoom.EnableAR);
|
||||
|
||||
//DataSourceChanged = true;
|
||||
MapUDPService.SendQueryGameRoomList(App.CurrentUser.Id, 0, 1, GameRoom.RoomId.ToString());
|
||||
readyBtn.SetActive(true);
|
||||
cancelBtn.SetActive(false);
|
||||
startBtn.SetActive(false);
|
||||
var isOwner = GameRoom.UserId == App.CurrentUser.Id;
|
||||
readyBtn.SetActive(!isOwner);
|
||||
cancelBtn.SetActive(!isOwner);
|
||||
startBtn.SetActive(isOwner);
|
||||
|
||||
idText.text = GameRoom.RoomId.ToString().PadLeft(7, '0');
|
||||
roomName.text = GameRoom.Name;
|
||||
@@ -170,21 +173,21 @@ public class GameRoomDetailController : PFUIPanel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool isOwner { get; set; } = true;
|
||||
private void TcpHandler()
|
||||
{
|
||||
if (DataSourceChanged)
|
||||
{
|
||||
var playerList = FindObjectsOfType<GameRoomPlayerPanel>();
|
||||
var list = GameRoom.RoomPlayerList;
|
||||
//自己
|
||||
//自己是否是房主
|
||||
var mine = list.Where(c => c.UserId == App.CurrentUser.Id).FirstOrDefault();
|
||||
if (mine != null)
|
||||
if (mine != null && isOwner != mine.IsOwner)
|
||||
{
|
||||
//是否是房主
|
||||
var owner = mine.IsOwner;
|
||||
readyBtn.SetActive(!owner);
|
||||
startBtn.SetActive(owner);
|
||||
isOwner = mine.IsOwner;
|
||||
readyBtn.SetActive(!isOwner);
|
||||
startBtn.SetActive(isOwner);
|
||||
cancelBtn.SetActive(!isOwner);
|
||||
}
|
||||
//新增/更新
|
||||
foreach (var item in list)
|
||||
|
||||
@@ -30,7 +30,7 @@ public class GameRoomListController : PFUIPanel
|
||||
private Transform searchInput;
|
||||
|
||||
private string sort = "", sortDire = "";
|
||||
private bool isFav;
|
||||
private bool isEnableAR { get; set; }
|
||||
private int pageSize = 10;
|
||||
private string ftname = "";
|
||||
private string distance = "";
|
||||
@@ -276,6 +276,7 @@ public class GameRoomListController : PFUIPanel
|
||||
UIManager.ShowGameRoomDetailPanel();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitStep1()
|
||||
{
|
||||
sort = "Near";
|
||||
@@ -286,6 +287,7 @@ public class GameRoomListController : PFUIPanel
|
||||
scroll = transform.Find("MapList/Modal/Right/Scroll View").gameObject;
|
||||
if (scroll != null)
|
||||
{
|
||||
UIManager.RemoveEvent(scroll, UnityEngine.EventSystems.EventTriggerType.EndDrag);
|
||||
UIManager.AddEvent(scroll, UnityEngine.EventSystems.EventTriggerType.EndDrag, OnEndDrag);
|
||||
}
|
||||
|
||||
@@ -296,6 +298,7 @@ public class GameRoomListController : PFUIPanel
|
||||
distanceOptions.GetComponent<Dropdown>().value = 0;
|
||||
var dDropdown = distanceOptions.GetComponent<Dropdown>();
|
||||
dDropdown.options = MapFilterOptions.distances;
|
||||
dDropdown.onValueChanged.RemoveAllListeners();
|
||||
dDropdown.onValueChanged.AddListener(ChangeDistance);
|
||||
}
|
||||
|
||||
@@ -307,6 +310,7 @@ public class GameRoomListController : PFUIPanel
|
||||
var g = tdContainer.Find("Gou").gameObject;
|
||||
g.SetActive(false);
|
||||
is3d = false;
|
||||
UIManager.RemoveEvent(tdContainer.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick);
|
||||
UIManager.AddEvent(tdContainer.gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
var gou = tdContainer.Find("Gou").gameObject;
|
||||
@@ -321,13 +325,13 @@ public class GameRoomListController : PFUIPanel
|
||||
{
|
||||
var g = favContainer.Find("Gou").gameObject;
|
||||
g.SetActive(false);
|
||||
isFav = false;
|
||||
UIManager.AddEvent(favContainer.gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
var gou = favContainer.Find("Gou").gameObject;
|
||||
isEnableAR = false;
|
||||
UIManager.RemoveEvent(favContainer.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick);
|
||||
UIManager.AddEvent(favContainer.gameObject, EventTriggerType.PointerClick, (e)=> {
|
||||
var gou = e.selectedObject.transform.Find("Gou").gameObject;
|
||||
bool v = !gou.activeSelf;
|
||||
gou.SetActive(v);
|
||||
isFav = v;
|
||||
isEnableAR = v;
|
||||
Refresh();
|
||||
});
|
||||
}
|
||||
@@ -337,12 +341,13 @@ public class GameRoomListController : PFUIPanel
|
||||
{
|
||||
searchInput.GetComponent<InputField>().text = "";
|
||||
ftname = "";
|
||||
searchInput.GetComponent<InputField>().onEndEdit.RemoveAllListeners();
|
||||
searchInput.GetComponent<InputField>().onEndEdit.AddListener((s) =>
|
||||
{
|
||||
var t = searchInput.GetComponent<InputField>().text;
|
||||
ftname = t;
|
||||
});
|
||||
|
||||
UIManager.RemoveEvent(searchInput.Find("Button").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick);
|
||||
UIManager.AddEvent(searchInput.Find("Button").gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
onEndEdit();
|
||||
@@ -362,6 +367,7 @@ public class GameRoomListController : PFUIPanel
|
||||
ColorUtility.TryParseHtmlString("#23232D", out Color cc);
|
||||
image.color = cc;
|
||||
text.color = new Color(1, 1, 1, 1);
|
||||
UIManager.RemoveEvent(button.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick);
|
||||
UIManager.AddEvent(button.gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
ColorUtility.TryParseHtmlString("#23232D", out Color c1);
|
||||
@@ -391,6 +397,7 @@ public class GameRoomListController : PFUIPanel
|
||||
var drop = sorts.GetComponent<Dropdown>();
|
||||
drop.options = MapFilterOptions.sorts;
|
||||
drop.value = 0;
|
||||
drop.onValueChanged.RemoveAllListeners();
|
||||
drop.onValueChanged.AddListener((int index) =>
|
||||
{
|
||||
var text = drop.options[index].text;
|
||||
@@ -420,6 +427,7 @@ public class GameRoomListController : PFUIPanel
|
||||
if (sortDir)
|
||||
{
|
||||
var image = sortDir.Find("Image").GetComponent<Image>();
|
||||
UIManager.RemoveEvent(sortDir.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick);
|
||||
UIManager.AddEvent(sortDir.gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
if (image.sprite.name == "DOWN")
|
||||
@@ -454,22 +462,22 @@ public class GameRoomListController : PFUIPanel
|
||||
|
||||
right = transform.Find("MapList/Modal/Right").gameObject;
|
||||
right2 = transform.Find("MapList/Modal/Right2").gameObject;
|
||||
|
||||
UIManager.RemoveEvent(cancel, UnityEngine.EventSystems.EventTriggerType.PointerClick);
|
||||
UIManager.AddEvent(cancel, EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
MapList.SetActive(false);
|
||||
});
|
||||
|
||||
UIManager.RemoveEvent(next, UnityEngine.EventSystems.EventTriggerType.PointerClick);
|
||||
UIManager.AddEvent(next, EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
HandleStepBtn(next.name);
|
||||
});
|
||||
|
||||
UIManager.RemoveEvent(previous, UnityEngine.EventSystems.EventTriggerType.PointerClick);
|
||||
UIManager.AddEvent(previous, EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
HandleStepBtn(previous.name);
|
||||
});
|
||||
|
||||
UIManager.RemoveEvent(create, UnityEngine.EventSystems.EventTriggerType.PointerClick);
|
||||
UIManager.AddEvent(create, EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
MapUDPService.SendCreateGameRoom(RoomName, selectedRouteId, Roompwd, UIManager.Now.GetDateTime(), CloseTime, Members, Map.AverageGrade, (Map.TotalClimb ?? 0), Map.Distance, Map.Enable3D, Map.EnableAR, Map.Name, Map.FileName, Map.Url, Map.AltitudeGraph);
|
||||
@@ -506,12 +514,14 @@ public class GameRoomListController : PFUIPanel
|
||||
HandleFormInput();
|
||||
HandleCloseTimeBtnClick(0, "");
|
||||
HandleMembersBtnClick(0, "");
|
||||
roomNameInputField.onValueChanged.RemoveAllListeners();
|
||||
//房间名
|
||||
roomNameInputField.onValueChanged.AddListener((e) => {
|
||||
RoomName = e;
|
||||
HandleFormInput();
|
||||
});
|
||||
//房间密码
|
||||
passwordInputField.onValueChanged.RemoveAllListeners();
|
||||
passwordInputField.onValueChanged.AddListener((e) => {
|
||||
Roompwd = e;
|
||||
HandleFormInput();
|
||||
@@ -537,12 +547,14 @@ public class GameRoomListController : PFUIPanel
|
||||
HandleCloseTimeBtnClick(60, btn60.name);
|
||||
});
|
||||
//小时
|
||||
hourInputField.onValueChanged.RemoveAllListeners();
|
||||
hourInputField.onValueChanged.AddListener((e) => {
|
||||
hours = Convert.ToInt32(e);
|
||||
CloseTime = hours * 60 + mins;
|
||||
HandleCloseTimeBtnClick(CloseTime, hourInputField.name);
|
||||
});
|
||||
//分钟
|
||||
minInputField.onValueChanged.RemoveAllListeners();
|
||||
minInputField.onValueChanged.AddListener((e) => {
|
||||
mins = Convert.ToInt32(e);
|
||||
CloseTime = hours * 60 + mins;
|
||||
@@ -829,7 +841,7 @@ public class GameRoomListController : PFUIPanel
|
||||
private async void GetList()
|
||||
{
|
||||
if (isEnd) return;
|
||||
var res = await ConfigHelper.mapApi.GetList(pageIndex, pageSize, ftname, distance, string.Join(",", hands), is3d, sort, sortDire);
|
||||
var res = await ConfigHelper.mapApi.GetList(pageIndex, pageSize, ftname, distance, string.Join(",", hands), is3d, sort, sortDire, isEnableAR:isEnableAR);
|
||||
if (res.result)
|
||||
{
|
||||
if (res.data.Count == 0)
|
||||
|
||||
@@ -131,10 +131,12 @@ public class HomeController : PFUIPanel
|
||||
private void GoGameRoom(BaseEventData e)
|
||||
{
|
||||
#if UNITY_STANDALONE_WIN
|
||||
OnExit(e);
|
||||
var pe = (PointerEventData)e;
|
||||
if (pe == null)
|
||||
return;
|
||||
var parent = pe.pointerEnter.transform.parent;
|
||||
UIManager.ShowGameRoomListPanel();
|
||||
OnExit(e);
|
||||
#endif
|
||||
}
|
||||
private void GoRide(BaseEventData e)
|
||||
|
||||
@@ -134,12 +134,12 @@ public class NewRouteDetailController : PFUIPanel
|
||||
MapRouteAreaDetail area;
|
||||
int pageIndex = 0, pageSize = 12;
|
||||
bool isEnd = false, startMouse = false;
|
||||
public async void Initial(int areaId)
|
||||
public async void Initial(int areaId,string coverImage)
|
||||
{
|
||||
isEnd = false;
|
||||
pageIndex = 0;
|
||||
var left = transform.Find("Container/Left");
|
||||
left.Find("Icon").GetComponent<RawImage>().texture = null;
|
||||
Utils.DisplayImageTempDict(transform.Find("Container/Left/Icon").GetComponent<RawImage>(), coverImage, caches , b =>{ });
|
||||
scroll.content.DestroyChildren();
|
||||
transform.Find("Container/Left/RideContainer/Text").GetComponent<Text>()
|
||||
.text = string.Empty;
|
||||
@@ -151,8 +151,6 @@ public class NewRouteDetailController : PFUIPanel
|
||||
.text = string.Empty;
|
||||
transform.Find("Container/Left/DescScroll/Viewport/Content/Desc").GetComponent<Text>()
|
||||
.text = string.Empty;
|
||||
|
||||
|
||||
await GetData(areaId);
|
||||
GetList();
|
||||
|
||||
|
||||
@@ -170,6 +170,8 @@ public class NewRouteOverviewController: PFUIPanel
|
||||
}
|
||||
group.SetParent(collectionContent);
|
||||
group.localScale = Vector3.one;
|
||||
//获取数据后需要重绘
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(collectionContent);
|
||||
}
|
||||
//for (int i = 0; i < 10; i++)
|
||||
//{
|
||||
@@ -182,8 +184,7 @@ public class NewRouteOverviewController: PFUIPanel
|
||||
// group.SetParent(collectionContent);
|
||||
// group.localScale = Vector3.one;
|
||||
//}
|
||||
//获取数据后需要重绘
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(collectionContent);
|
||||
|
||||
}
|
||||
void MoveBanner(bool right)
|
||||
{
|
||||
|
||||
@@ -101,6 +101,7 @@ public class UserInfoController : PFUIPanel
|
||||
// var result = await userApi.Login("15651831367", "123456", "");
|
||||
// App.CurrentUser = result.data;
|
||||
//}
|
||||
Utils.DisplayHead(infoPanel.Find("Avatar").GetComponent<RawImage>(), App.CurrentUser.WxHeadImg);
|
||||
var r = await ConfigHelper.userApi.GetSummary();
|
||||
if (r.result)
|
||||
{
|
||||
|
||||
@@ -250,7 +250,7 @@ public class ResultListController : PFUIPanel
|
||||
obj.GetComponent<RouteItem>().Initial(item.ToObject<RowerResultModel>(), index, transform,true);
|
||||
}
|
||||
//obj.SendMessage("Initial", );
|
||||
obj.transform.parent = content;
|
||||
obj.transform.SetParent(content);
|
||||
obj.transform.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -401,10 +401,10 @@ public class UIManager : MonoBehaviour
|
||||
return this.GetPanelInstance("NewRouteDetailPanel", ref this.mNewRouteDetailController);
|
||||
}
|
||||
}
|
||||
public static void ShowNewRouteDetailPanel(int areaId)
|
||||
public static void ShowNewRouteDetailPanel(int areaId,string coverImage)
|
||||
{
|
||||
UIManager.Show(UIManager.Instance.NewRouteDetailPanel, UIManager.Instance.MainPanel);
|
||||
UIManager.Instance.NewRouteDetailPanel.GetComponent<NewRouteDetailController>().Initial(areaId);
|
||||
UIManager.Instance.NewRouteDetailPanel.GetComponent<NewRouteDetailController>().Initial(areaId, coverImage);
|
||||
}
|
||||
#endregion
|
||||
private CountDownAnimation mCountDownAnimation;
|
||||
@@ -872,11 +872,15 @@ public class UIManager : MonoBehaviour
|
||||
public static void ShowGameRoomListPanel()
|
||||
{
|
||||
App.Model = "GameRoom";
|
||||
UIManager.Instance.MainPanel.GetComponent<Image>().sprite =
|
||||
Resources.Load<Sprite>("Images/GameRoom/RACE-BG");
|
||||
UIManager.Show(UIManager.Instance.GameRoomListPanel, UIManager.Instance.MainPanel);
|
||||
}
|
||||
public static void ShowGameRoomDetailPanel()
|
||||
{
|
||||
App.Model = "GameRoom";
|
||||
UIManager.Instance.MainPanel.GetComponent<Image>().sprite =
|
||||
Resources.Load<Sprite>("Images/GameRoom/RACE-BG");
|
||||
UIManager.Show(UIManager.Instance.GameRoomDetailPanel, UIManager.Instance.MainPanel);
|
||||
}
|
||||
//显示房间loading页面
|
||||
@@ -1086,6 +1090,13 @@ public class UIManager : MonoBehaviour
|
||||
if (et == null) return;
|
||||
et.triggers.RemoveAll(x => true);
|
||||
}
|
||||
|
||||
public static void RemoveEvent(GameObject gameObject, EventTriggerType eventTriggerType)
|
||||
{
|
||||
EventTrigger et = gameObject.GetComponent<EventTrigger>();
|
||||
if (et == null) return;
|
||||
et.triggers.RemoveAll(x => x.eventID == eventTriggerType);
|
||||
}
|
||||
public static void AddEvent(GameObject gameObject, EventTriggerType eventTriggerType, UnityAction<BaseEventData> call)
|
||||
{
|
||||
EventTrigger et = gameObject.GetComponent<EventTrigger>();
|
||||
|
||||
@@ -0,0 +1,601 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Davinci - A powerful, esay-to-use image downloading and caching library for Unity in Run-Time
|
||||
/// v 1.2
|
||||
/// Developed by ShamsDEV.com
|
||||
/// copyright (c) ShamsDEV.com All Rights Reserved.
|
||||
/// Licensed under the MIT License.
|
||||
/// https://github.com/shamsdev/davinci
|
||||
/// </summary>
|
||||
public class Davinci : MonoBehaviour
|
||||
{
|
||||
private static bool ENABLE_GLOBAL_LOGS = true;
|
||||
|
||||
private bool enableLog = false;
|
||||
private float fadeTime = 1;
|
||||
private bool cached = true;
|
||||
|
||||
private enum RendererType
|
||||
{
|
||||
none,
|
||||
uiImage,
|
||||
renderer
|
||||
}
|
||||
|
||||
private RendererType rendererType = RendererType.none;
|
||||
private GameObject targetObj;
|
||||
private string url = null;
|
||||
|
||||
private Texture2D loadingPlaceholder, errorPlaceholder;
|
||||
|
||||
private UnityAction onStartAction,
|
||||
onDownloadedAction,
|
||||
OnLoadedAction,
|
||||
onEndAction;
|
||||
|
||||
private UnityAction<int> onDownloadProgressChange;
|
||||
private UnityAction<string> onErrorAction;
|
||||
|
||||
private static Dictionary<string, Davinci> underProcessDavincies
|
||||
= new Dictionary<string, Davinci>();
|
||||
|
||||
private string uniqueHash;
|
||||
private int progress;
|
||||
|
||||
private bool success = false;
|
||||
|
||||
static string filePath = Application.persistentDataPath + "/" +
|
||||
"davinci" + "/";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get instance of davinci class
|
||||
/// </summary>
|
||||
public static Davinci get()
|
||||
{
|
||||
return new GameObject("Davinci").AddComponent<Davinci>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set image url for download.
|
||||
/// </summary>
|
||||
/// <param name="url">Image Url</param>
|
||||
/// <returns></returns>
|
||||
public Davinci load(string url)
|
||||
{
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] Url set : " + url);
|
||||
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set fading animation time.
|
||||
/// </summary>
|
||||
/// <param name="fadeTime">Fade animation time. Set 0 for disable fading.</param>
|
||||
/// <returns></returns>
|
||||
public Davinci setFadeTime(float fadeTime)
|
||||
{
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] Fading time set : " + fadeTime);
|
||||
|
||||
this.fadeTime = fadeTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set target Image component.
|
||||
/// </summary>
|
||||
/// <param name="image">target Unity UI image component</param>
|
||||
/// <returns></returns>
|
||||
public Davinci into(MaskableGraphic image)
|
||||
{
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] Target as UIImage set : " + image);
|
||||
|
||||
rendererType = RendererType.uiImage;
|
||||
this.targetObj = image.gameObject;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set target Renderer component.
|
||||
/// </summary>
|
||||
/// <param name="renderer">target renderer component</param>
|
||||
/// <returns></returns>
|
||||
public Davinci into(Renderer renderer)
|
||||
{
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] Target as Renderer set : " + renderer);
|
||||
|
||||
rendererType = RendererType.renderer;
|
||||
this.targetObj = renderer.gameObject;
|
||||
return this;
|
||||
}
|
||||
|
||||
#region Actions
|
||||
public Davinci withStartAction(UnityAction action)
|
||||
{
|
||||
this.onStartAction = action;
|
||||
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] On start action set : " + action);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Davinci withDownloadedAction(UnityAction action)
|
||||
{
|
||||
this.onDownloadedAction = action;
|
||||
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] On downloaded action set : " + action);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Davinci withDownloadProgressChangedAction(UnityAction<int> action)
|
||||
{
|
||||
this.onDownloadProgressChange = action;
|
||||
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] On download progress changed action set : " + action);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Davinci withLoadedAction(UnityAction action)
|
||||
{
|
||||
this.OnLoadedAction = action;
|
||||
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] On loaded action set : " + action);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Davinci withErrorAction(UnityAction<string> action)
|
||||
{
|
||||
this.onErrorAction = action;
|
||||
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] On error action set : " + action);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Davinci withEndAction(UnityAction action)
|
||||
{
|
||||
this.onEndAction = action;
|
||||
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] On end action set : " + action);
|
||||
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Show or hide logs in console.
|
||||
/// </summary>
|
||||
/// <param name="enable">'true' for show logs in console.</param>
|
||||
/// <returns></returns>
|
||||
public Davinci setEnableLog(bool enableLog)
|
||||
{
|
||||
this.enableLog = enableLog;
|
||||
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] Logging enabled : " + enableLog);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the sprite of image when davinci is downloading and loading image
|
||||
/// </summary>
|
||||
/// <param name="loadingPlaceholder">loading texture</param>
|
||||
/// <returns></returns>
|
||||
public Davinci setLoadingPlaceholder(Texture2D loadingPlaceholder)
|
||||
{
|
||||
this.loadingPlaceholder = loadingPlaceholder;
|
||||
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] Loading placeholder has been set.");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set image sprite when some error occurred during downloading or loading image
|
||||
/// </summary>
|
||||
/// <param name="errorPlaceholder">error texture</param>
|
||||
/// <returns></returns>
|
||||
public Davinci setErrorPlaceholder(Texture2D errorPlaceholder)
|
||||
{
|
||||
this.errorPlaceholder = errorPlaceholder;
|
||||
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] Error placeholder has been set.");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable cache
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Davinci setCached(bool cached)
|
||||
{
|
||||
this.cached = cached;
|
||||
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] Cache enabled : " + cached);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start davinci process.
|
||||
/// </summary>
|
||||
public void start()
|
||||
{
|
||||
if (url == null)
|
||||
{
|
||||
error("Url has not been set. Use 'load' funtion to set image url.");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Uri uri = new Uri(url);
|
||||
this.url = uri.AbsoluteUri;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error("Url is not correct.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (rendererType == RendererType.none || targetObj == null)
|
||||
{
|
||||
error("Target has not been set. Use 'into' function to set target component.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] Start Working.");
|
||||
|
||||
if (loadingPlaceholder != null)
|
||||
SetLoadingImage();
|
||||
|
||||
if (onStartAction != null)
|
||||
onStartAction.Invoke();
|
||||
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
|
||||
uniqueHash = CreateMD5(url);
|
||||
|
||||
if (underProcessDavincies.ContainsKey(uniqueHash))
|
||||
{
|
||||
Davinci sameProcess = underProcessDavincies[uniqueHash];
|
||||
sameProcess.onDownloadedAction += () =>
|
||||
{
|
||||
if (onDownloadedAction != null)
|
||||
onDownloadedAction.Invoke();
|
||||
|
||||
loadSpriteToImage();
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
if (File.Exists(filePath + uniqueHash))
|
||||
{
|
||||
if (onDownloadedAction != null)
|
||||
onDownloadedAction.Invoke();
|
||||
|
||||
loadSpriteToImage();
|
||||
}
|
||||
else
|
||||
{
|
||||
underProcessDavincies.Add(uniqueHash, this);
|
||||
StopAllCoroutines();
|
||||
StartCoroutine("Downloader");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator Downloader()
|
||||
{
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] Download started.");
|
||||
|
||||
var www = new WWW(url);
|
||||
|
||||
while (!www.isDone)
|
||||
{
|
||||
if (www.error != null)
|
||||
{
|
||||
error("Error while downloading the image : " + www.error);
|
||||
yield break;
|
||||
}
|
||||
|
||||
progress = Mathf.FloorToInt(www.progress * 100);
|
||||
if (onDownloadProgressChange != null)
|
||||
onDownloadProgressChange.Invoke(progress);
|
||||
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] Downloading progress : " + progress + "%");
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (www.error == null)
|
||||
File.WriteAllBytes(filePath + uniqueHash, www.bytes);
|
||||
|
||||
www.Dispose();
|
||||
www = null;
|
||||
|
||||
if (onDownloadedAction != null)
|
||||
onDownloadedAction.Invoke();
|
||||
|
||||
loadSpriteToImage();
|
||||
|
||||
underProcessDavincies.Remove(uniqueHash);
|
||||
}
|
||||
|
||||
private void loadSpriteToImage()
|
||||
{
|
||||
progress = 100;
|
||||
if (onDownloadProgressChange != null)
|
||||
onDownloadProgressChange.Invoke(progress);
|
||||
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] Downloading progress : " + progress + "%");
|
||||
|
||||
if (!File.Exists(filePath + uniqueHash))
|
||||
{
|
||||
error("Loading image file has been failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(ImageLoader());
|
||||
}
|
||||
|
||||
private void SetLoadingImage()
|
||||
{
|
||||
switch (rendererType)
|
||||
{
|
||||
case RendererType.renderer:
|
||||
Renderer renderer = targetObj.GetComponent<Renderer>();
|
||||
renderer.material.mainTexture = loadingPlaceholder;
|
||||
break;
|
||||
|
||||
case RendererType.uiImage:
|
||||
Image image = targetObj.GetComponent<Image>();
|
||||
Sprite sprite = Sprite.Create(loadingPlaceholder,
|
||||
new Rect(0, 0, loadingPlaceholder.width, loadingPlaceholder.height),
|
||||
new Vector2(0.5f, 0.5f));
|
||||
image.sprite = sprite;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private IEnumerator ImageLoader(Texture2D texture = null)
|
||||
{
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] Start loading image.");
|
||||
|
||||
if (texture == null)
|
||||
{
|
||||
byte[] fileData;
|
||||
fileData = File.ReadAllBytes(filePath + uniqueHash);
|
||||
texture = new Texture2D(2, 2);
|
||||
//ImageConversion.LoadImage(texture, fileData);
|
||||
texture.LoadImage(fileData); //..this will auto-resize the texture dimensions.
|
||||
}
|
||||
|
||||
Color color;
|
||||
|
||||
if (targetObj != null)
|
||||
switch (rendererType)
|
||||
{
|
||||
case RendererType.renderer:
|
||||
Renderer renderer = targetObj.GetComponent<Renderer>();
|
||||
|
||||
if (renderer == null || renderer.material == null)
|
||||
break;
|
||||
|
||||
renderer.material.mainTexture = texture;
|
||||
float maxAlpha;
|
||||
|
||||
if (fadeTime > 0 && renderer.material.HasProperty("_Color"))
|
||||
{
|
||||
color = renderer.material.color;
|
||||
maxAlpha = color.a;
|
||||
|
||||
color.a = 0;
|
||||
|
||||
renderer.material.color = color;
|
||||
float time = Time.time;
|
||||
while (color.a < maxAlpha)
|
||||
{
|
||||
color.a = Mathf.Lerp(0, maxAlpha, (Time.time - time) / fadeTime);
|
||||
|
||||
if (renderer != null)
|
||||
renderer.material.color = color;
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case RendererType.uiImage:
|
||||
|
||||
MaskableGraphic image = null;
|
||||
if (targetObj.GetComponent<RawImage>())
|
||||
{
|
||||
image = targetObj.GetComponent<RawImage>();
|
||||
targetObj.GetComponent<RawImage>().texture = texture;
|
||||
}
|
||||
else if (targetObj.GetComponent<Image>())
|
||||
{
|
||||
image = targetObj.GetComponent<Image>();
|
||||
Sprite sprite = Sprite.Create(texture,
|
||||
new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
|
||||
targetObj.GetComponent<Image>().sprite = sprite;
|
||||
}
|
||||
|
||||
if (image == null)
|
||||
break;
|
||||
|
||||
color = image.color;
|
||||
maxAlpha = color.a;
|
||||
|
||||
if (fadeTime > 0)
|
||||
{
|
||||
color.a = 0;
|
||||
image.color = color;
|
||||
|
||||
float time = Time.time;
|
||||
while (color.a < maxAlpha)
|
||||
{
|
||||
color.a = Mathf.Lerp(0, maxAlpha, (Time.time - time) / fadeTime);
|
||||
|
||||
if (image != null)
|
||||
image.color = color;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (OnLoadedAction != null)
|
||||
OnLoadedAction.Invoke();
|
||||
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] Image has been loaded.");
|
||||
|
||||
success = true;
|
||||
finish();
|
||||
}
|
||||
|
||||
public static string CreateMD5(string input)
|
||||
{
|
||||
// Use input string to calculate MD5 hash
|
||||
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
|
||||
{
|
||||
byte[] inputBytes = Encoding.ASCII.GetBytes(input);
|
||||
byte[] hashBytes = md5.ComputeHash(inputBytes);
|
||||
|
||||
// Convert the byte array to hexadecimal string
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < hashBytes.Length; i++)
|
||||
{
|
||||
sb.Append(hashBytes[i].ToString("X2"));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private void error(string message)
|
||||
{
|
||||
success = false;
|
||||
|
||||
if (enableLog)
|
||||
Debug.LogError("[Davinci] Error : " + message);
|
||||
|
||||
if (onErrorAction != null)
|
||||
onErrorAction.Invoke(message);
|
||||
|
||||
if (errorPlaceholder != null)
|
||||
StartCoroutine(ImageLoader(errorPlaceholder));
|
||||
else finish();
|
||||
}
|
||||
|
||||
private void finish()
|
||||
{
|
||||
if (enableLog)
|
||||
Debug.Log("[Davinci] Operation has been finished.");
|
||||
|
||||
if (!cached)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(filePath + uniqueHash);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (enableLog)
|
||||
Debug.LogError($"[Davinci] Error while removing cached file: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
if (onEndAction != null)
|
||||
onEndAction.Invoke();
|
||||
|
||||
Invoke("destroyer", 0.5f);
|
||||
}
|
||||
|
||||
private void destroyer()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Clear a certain cached file with its url
|
||||
/// </summary>
|
||||
/// <param name="url">Cached file url.</param>
|
||||
/// <returns></returns>
|
||||
public static void ClearCache(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(filePath + CreateMD5(url));
|
||||
|
||||
if (ENABLE_GLOBAL_LOGS)
|
||||
Debug.Log($"[Davinci] Cached file has been cleared: {url}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ENABLE_GLOBAL_LOGS)
|
||||
Debug.LogError($"[Davinci] Error while removing cached file: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear all davinci cached files
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static void ClearAllCachedFiles()
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(filePath, true);
|
||||
|
||||
if (ENABLE_GLOBAL_LOGS)
|
||||
Debug.Log("[Davinci] All Davinci cached files has been cleared.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ENABLE_GLOBAL_LOGS)
|
||||
Debug.LogError($"[Davinci] Error while removing cached file: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9b77a5c7e324f6499d232d9e031ae96
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
|
||||
|
||||
public class EncrypHelper
|
||||
{
|
||||
/// <summary>
|
||||
///静态无参构造
|
||||
/// </summary>
|
||||
static EncrypHelper()
|
||||
{
|
||||
//默认的密钥
|
||||
SecretKey = "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用SHA256加密字符串
|
||||
/// </summary>
|
||||
/// <param name="Source"></param>
|
||||
/// <returns></returns>
|
||||
public static string EncrypToSHA(string Source)
|
||||
{
|
||||
SHA256Managed sha256 = new SHA256Managed();
|
||||
byte[] s = UTF8Encoding.UTF8.GetBytes(Source);
|
||||
byte[] t = sha256.ComputeHash(s);
|
||||
return Convert.ToBase64String(t);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 缺省的密钥
|
||||
/// </summary>
|
||||
public static readonly string SecretKey;
|
||||
|
||||
/// <summary>
|
||||
/// 使用缺省密钥字符串加密string
|
||||
/// </summary>
|
||||
/// <param name="original">明文</param>
|
||||
/// <returns>密文</returns>
|
||||
public static string Encrypt(string original)
|
||||
{
|
||||
return Encrypt(original, SecretKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用缺省密钥字符串解密string
|
||||
/// </summary>
|
||||
/// <param name="original">密文</param>
|
||||
/// <returns>明文</returns>
|
||||
public static string Decrypt(string original)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Decrypt(original, SecretKey, System.Text.Encoding.Default);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用给定密钥字符串加密string
|
||||
/// </summary>
|
||||
/// <param name="original">原始文字</param>
|
||||
/// <param name="key">密钥</param>
|
||||
/// <returns>密文</returns>
|
||||
public static string Encrypt(string original, string key)
|
||||
{
|
||||
byte[] buff = System.Text.Encoding.Default.GetBytes(original);
|
||||
byte[] kb = System.Text.Encoding.Default.GetBytes(key);
|
||||
return Convert.ToBase64String(Encrypt(buff, kb));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用给定密钥字符串解密string
|
||||
/// </summary>
|
||||
/// <param name="original">密文</param>
|
||||
/// <param name="key">密钥</param>
|
||||
/// <returns>明文</returns>
|
||||
public static string Decrypt(string original, string key)
|
||||
{
|
||||
return Decrypt(original, key, System.Text.Encoding.Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用给定密钥字符串解密string,返回指定编码方式明文
|
||||
/// </summary>
|
||||
/// <param name="encrypted">密文</param>
|
||||
/// <param name="key">密钥</param>
|
||||
/// <param name="encoding">字符编码方案</param>
|
||||
/// <returns>明文</returns>
|
||||
public static string Decrypt(string encrypted, string key, Encoding encoding)
|
||||
{
|
||||
byte[] buff = Convert.FromBase64String(encrypted);
|
||||
byte[] kb = System.Text.Encoding.Default.GetBytes(key);
|
||||
return encoding.GetString(Decrypt(buff, kb));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成MD5摘要
|
||||
/// </summary>
|
||||
/// <param name="original">数据源</param>
|
||||
/// <returns>摘要</returns>
|
||||
public static byte[] MakeMd5(byte[] original)
|
||||
{
|
||||
|
||||
MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
|
||||
byte[] keyhash = hashmd5.ComputeHash(original);
|
||||
hashmd5 = null;
|
||||
return keyhash;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用给定密钥加密
|
||||
/// </summary>
|
||||
/// <param name="original">明文</param>
|
||||
/// <param name="key">密钥</param>
|
||||
/// <returns>密文</returns>
|
||||
public static byte[] Encrypt(byte[] original, byte[] key)
|
||||
{
|
||||
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
|
||||
des.Key = MakeMd5(key);
|
||||
des.Mode = CipherMode.ECB;
|
||||
return des.CreateEncryptor().TransformFinalBlock(original, 0, original.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用给定密钥解密数据
|
||||
/// </summary>
|
||||
/// <param name="encrypted">密文</param>
|
||||
/// <param name="key">密钥</param>
|
||||
/// <returns>明文</returns>
|
||||
public static byte[] Decrypt(byte[] encrypted, byte[] key)
|
||||
{
|
||||
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
|
||||
des.Key = MakeMd5(key);
|
||||
des.Mode = CipherMode.ECB;
|
||||
return des.CreateDecryptor().TransformFinalBlock(encrypted, 0, encrypted.Length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a9ee2af5e9deb0c47b98031e6d4ec657
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -359,10 +359,13 @@ namespace Assets.Scripts
|
||||
}
|
||||
public static Dictionary<string, Texture> propTextureCache = new Dictionary<string, Texture>();
|
||||
public delegate Coroutine StartCoroutine(IEnumerator routine);
|
||||
public static void DisplayImage(MaskableGraphic img, string url, bool cache = false,Dictionary<string,Texture> caches = null)
|
||||
public static void DisplayImage(MaskableGraphic img, string url, bool cache = true,Dictionary<string,Texture> caches = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
return;
|
||||
|
||||
Davinci.get().load(url).setCached(cache).into(img).setFadeTime(0).start();
|
||||
return;
|
||||
//可以考虑缓存到硬盘里
|
||||
//Texture2D tex = null;
|
||||
//byte[] fileData;
|
||||
@@ -407,6 +410,8 @@ namespace Assets.Scripts
|
||||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
return;
|
||||
Davinci.get().load(url).setCached(true).into(img).setFadeTime(0).start();
|
||||
return;
|
||||
if (caches!=null)
|
||||
{
|
||||
if (caches.ContainsKey(url))
|
||||
@@ -494,14 +499,11 @@ namespace Assets.Scripts
|
||||
}
|
||||
else
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
var fs = File.Create(filepath);
|
||||
fs.Write(request.downloadHandler.data, 0, request.downloadHandler.data.Length);
|
||||
fs.Close();
|
||||
fs.Dispose();
|
||||
fs = null;
|
||||
});
|
||||
var fs = File.Create(filepath);
|
||||
fs.Write(request.downloadHandler.data, 0, request.downloadHandler.data.Length);
|
||||
fs.Close();
|
||||
fs.Dispose();
|
||||
request.Dispose();
|
||||
}
|
||||
}
|
||||
if (onCompleted != null)
|
||||
|
||||
Reference in new issue
Block a user