This repository was archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathCheckResourceState.cs
More file actions
130 lines (112 loc) · 3.19 KB
/
Copy pathCheckResourceState.cs
File metadata and controls
130 lines (112 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//-----------------------------------------------------------------------
// <copyright>
// Copyright (c) 2018 wanderer. All rights reserved.
// </copyright>
// <describe> #检查资源状态# </describe>
// <email> dutifulwanderer@gmail.com </email>
// <time> #2018年7月8日 13点20分# </time>
//-----------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
namespace Wanderer.GameFramework
{
[FSM()]
public class CheckResourceState : FSMState<GameStateContext>
{
#region 属性
//更新标记
private bool _updateFlag = false;
#endregion
#region 重写函数
public override void OnInit(FSM<GameStateContext> fsm)
{
base.OnInit(fsm);
}
public override void OnEnter(FSM<GameStateContext> fsm)
{
_updateFlag = false;
base.OnEnter(fsm);
//检查资源版本信息
var version = GameMode.Resource.Version;
version.CheckUpdate((needUpdate)=> {
if (needUpdate)
{
version.UpdateResource(OnResourceUpdateCallback,OnDownloadComplete, OnDownloadError);
}
_updateFlag = !needUpdate;
});
}
public override void OnExit(FSM<GameStateContext> fsm)
{
base.OnExit(fsm);
}
public override void OnUpdate(FSM<GameStateContext> fsm)
{
base.OnUpdate(fsm);
if (_updateFlag)
{
// 切换到加载界面
ChangeState<LoadResourceState>(fsm);
}
}
#endregion
#region 事件回调
/// <summary>
/// 资源下载的回调
/// </summary>
/// <param name="result">是否报错</param>
/// <param name="progress">当前进度 0.0-1.0</param>
/// <param name="speed">下载速度 KB/s</param>
/// <param name="size">文件大小 KB</param>
/// 下载回调[进度(0-1),大小(KB),速度(KB/S),剩余时间(s)]
private void OnResourceUpdateCallback(float progress, double size,double speed, float remainingTime)
{
}
/// <summary>
/// 资源下载完成
/// </summary>
private void OnDownloadComplete()
{
_updateFlag = true;
}
/// <summary>
/// 下载错误
/// </summary>
/// <param name="localPath"></param>
/// <param name="error"></param>
private void OnDownloadError(string localPath,string error)
{
Log.Warning($"资源下载失败,网络错误!! {localPath} {error}");
}
#endregion
#region 内部函数
////获取文件
//private string[] GetFiles(string path)
//{
// List<string> files = new List<string>();
// files.AddRange(Directory.GetFiles(path));
// foreach (var item in Directory.GetDirectories(path))
// {
// files.AddRange(GetFiles(item));
// }
// return files.ToArray();
//}
////移动物体
//private void MoveFiles(string srcPath, string dstPath)
//{
// string[] files = GetFiles(srcPath);
// foreach (var item in files)
// {
// string targetPath = item.Replace(srcPath, dstPath);
// string dirPath = Path.GetDirectoryName(targetPath);
// if (!Directory.Exists(dirPath))
// Directory.CreateDirectory(dirPath);
// File.Copy(item, targetPath, true);
// }
//}
#endregion
}
}