Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
Z
ZeusHub_Unity
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
潘梓豪
ZeusHub_Unity
Commits
8c887e2b
Commit
8c887e2b
authored
May 05, 2023
by
潘梓豪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新脚本
parent
b35694ca
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
10660 additions
and
25 deletions
+10660
-25
ProductioRowData.cs
Assets/Scripts/Model/ProductioRowData.cs
+1
-1
Production.cs
Assets/Scripts/Model/Production.cs
+52
-14
AliyunOSSDownLoad.cs
Assets/Scripts/unit/AliyunOSSDownLoad.cs
+221
-0
AliyunOSSDownLoad.cs.meta
Assets/Scripts/unit/AliyunOSSDownLoad.cs.meta
+11
-0
DownloadUntily.cs
Assets/Scripts/unit/DownloadUntily.cs
+2
-5
MainThreadDispatcher.cs
Assets/Scripts/unit/MainThreadDispatcher.cs
+73
-0
MainThreadDispatcher.cs.meta
Assets/Scripts/unit/MainThreadDispatcher.cs.meta
+11
-0
UnityMainThreadDispatcher.cs
Assets/Scripts/unit/UnityMainThreadDispatcher.cs
+44
-0
UnityMainThreadDispatcher.cs.meta
Assets/Scripts/unit/UnityMainThreadDispatcher.cs.meta
+11
-0
MyScene.unity
Assets/_Scenes/MyScene.unity
+10231
-4
产品.prefab
Assets/_预设/产品.prefab
+2
-1
log.txt
Log/log.txt
+1
-0
No files found.
Assets/Scripts/Model/ProductioRowData.cs
View file @
8c887e2b
...
...
@@ -92,7 +92,7 @@ public class ProductioRowData : MonoBehaviour
production
.
OnReceiveMsg
=
OnReceiveMsg
;
production
.
OnReceiveMsg
.
AddListener
(
production
.
_onReceiveMsg
);
production
.
downloadUntily
=
new
DownloadUntily
();
production
.
aliyunOSSDownLoad
=
new
AliyunOSS
.
AliyunOSSDownLoad
();
if
(
type
==
1
)
{
production
.
set_btn
(
true
);
...
...
Assets/Scripts/Model/Production.cs
View file @
8c887e2b
...
...
@@ -7,6 +7,7 @@ using UnityEngine.Networking;
using
LitJson
;
using
System.Text
;
using
System
;
using
AliyunOSS
;
public
class
Production
:
MonoBehaviour
{
...
...
@@ -33,18 +34,53 @@ public class Production : MonoBehaviour
public
DownloadUntily
downloadUntily
;
public
AliyunOSSDownLoad
aliyunOSSDownLoad
;
public
GameObject
progress_side
;
public
Image
preset_image
;
public
float
fill_data
=
0
;
[
Header
(
"收到服务器信息事件"
)]
public
ReceiveMsgEvent
<
object
,
string
>
OnReceiveMsg
;
public
delegate
void
UpdateUIText
(
float
progress
);
public
UpdateUIText
updateUIText
;
public
void
Start
()
{
updateUIText
=
new
UpdateUIText
(
UpdateText
);
//this.OnReceiveMsg.AddListener(_onReceiveMsg);
}
void
LateUpdate
()
{
StartCoroutine
(
update_progress
());
}
public
IEnumerator
update_progress
()
{
if
(
progress_side
.
active
)
{
preset_image
.
fillAmount
=
fill_data
;
if
(
fill_data
==
1f
)
{
fill_data
=
0
;
progress_side
.
SetActive
(
false
);
}
}
else
{
if
(
fill_data
>
0
&&
fill_data
<
1
)
{
progress_side
.
SetActive
(
true
);
}
}
yield
return
new
WaitForSeconds
(
1f
);
}
//启动按钮
public
void
startProgress
()
...
...
@@ -52,7 +88,6 @@ public class Production : MonoBehaviour
string
json
=
"{\"productionid\":"
+
id
+
",\"code\":"
+
RobotCode
.
getMNum
()+
"}"
;
//请求校验,获取注册机码
StartCoroutine
(
request_post
(
Setting
.
IP
+
"/zeus/zeushub/getRobotCode?"
+
"productionid="
+
id
+
"&code="
+
RobotCode
.
getMNum
(),
json
,
1
));
}
...
...
@@ -70,7 +105,8 @@ public class Production : MonoBehaviour
}*/
if
(
url
!=
null
&&
!
url
.
Equals
(
""
))
{
StartCoroutine
(
downloadUntily
.
DownOss
(
url
,
id
,
appname
,
this
));
//StartCoroutine(aliyunOSSDownLoad.DownLoad(url, id, appname, this));
aliyunOSSDownLoad
.
DownLoad
(
url
,
id
,
appname
,
this
);
}
}
...
...
@@ -91,13 +127,9 @@ public class Production : MonoBehaviour
{
if
(
jd
[
"id"
].
ToString
().
Equals
(
id
))
{
if
(!
progress_side
.
active
)
{
progress_side
.
SetActive
(
true
);
}
else
{
float
present
=
float
.
Parse
(
jd
[
"jiedi"
].
ToString
())
/
100f
;
Debug
.
Log
(
jd
[
"id"
]);
Debug
.
Log
(
jd
[
"jiedi"
]);
float
present
=
float
.
Parse
(
jd
[
"jiedi"
].
ToString
());
preset_image
.
fillAmount
=
present
;
if
(
present
==
1f
)
{
...
...
@@ -105,7 +137,6 @@ public class Production : MonoBehaviour
progress_side
.
SetActive
(
false
);
}
}
}
}
else
if
(
parameter
.
Equals
(
"savepath"
))
{
if
(
jd
.
ContainsKey
(
"productionid"
)
&&
jd
[
"productionid"
].
Equals
(
id
))
...
...
@@ -217,6 +248,11 @@ public class Production : MonoBehaviour
}
}
void
UpdateText
(
float
progress
)
{
fill_data
=
progress
;
}
public
void
set_btn
(
bool
flag
)
{
foreach
(
Button
item
in
button
)
...
...
@@ -225,4 +261,6 @@ public class Production : MonoBehaviour
}
}
}
Assets/Scripts/unit/AliyunOSSDownLoad.cs
0 → 100644
View file @
8c887e2b
using
System
;
using
System.Threading
;
using
Aliyun.OSS
;
using
Aliyun.OSS.Common
;
using
System.IO
;
using
System.Collections
;
using
UnityEngine
;
using
LitJson
;
using
System.IO.Compression
;
using
System.Text.RegularExpressions
;
using
System.Text
;
using
System.Threading.Tasks
;
using
UnityEditor.Events
;
namespace
AliyunOSS
{
public
class
AliyunOSSDownLoad
{
// 创建OssClient实例。
static
OssClient
client
=
new
OssClient
(
Setting
.
endpoint
,
Setting
.
accessKeyId
,
Setting
.
accessKeySecret
);
private
bool
isdown
=
false
;
private
string
id
;
private
string
url
;
delegate
void
UpdateUIText
(
Production
production
,
JsonData
js_data
);
public
void
DownLoad
(
string
downloadingUrl
,
string
id
,
string
appname
,
Production
production
)
{
if
(!
isdown
)
{
JsonData
js_data
=
new
JsonData
();
this
.
id
=
id
;
if
(!
Directory
.
Exists
(
"D://DownloadDemo"
))
{
Directory
.
CreateDirectory
(
"D://DownloadDemo"
);
}
downloadingUrl
=
Uri
.
UnescapeDataString
(
downloadingUrl
);
// 填写Object完整路径,完整路径中不能包含Bucket名称,例如exampledir/exampleobject.txt。
var
objectName
=
downloadingUrl
.
Substring
(
downloadingUrl
.
LastIndexOf
(
"/"
)
+
1
);
// 填写本地文件的完整路径,例如D:\\localpath\\examplefile.txt。
var
downloadFilename
=
"D://DownloadDemo/"
+
objectName
;
Debug
.
Log
(
downloadingUrl
);
if
(
downloadingUrl
.
IndexOf
(
"https://"
)
<
0
)
{
js_data
[
"msg"
]
=
"下载路径不合法,请联系管理员"
;
production
.
OnReceiveMsg
.
Invoke
(
js_data
,
"msg"
);
isdown
=
false
;
}
else
{
if
(!
Directory
.
Exists
(
"D://DownloadDemo/"
+
downloadFilename
.
Substring
(
downloadFilename
.
LastIndexOf
(
"/"
)
+
1
,
downloadFilename
.
LastIndexOf
(
"."
)
-
(
downloadFilename
.
Substring
(
0
,
downloadFilename
.
LastIndexOf
(
"/"
)
+
1
).
Length
))
+
"/"
))
PutObjectWithProcessByThread
(
objectName
,
downloadFilename
,
js_data
,
production
,
isdown
,
id
,
appname
);
}
}
}
private
void
PutObjectWithProcessByThread
(
string
fullFilePath
,
string
downloadFilename
,
JsonData
js_data
,
Production
production
,
bool
isdown
,
string
id
,
string
appname
)
{
isdown
=
true
;
Thread
thread
=
null
;
thread
=
new
Thread
(()=>{
try
{
float
TotalByte
=
0
;
var
len
=
0
;
var
getObjectRequest
=
new
GetObjectRequest
(
Setting
.
bucketName
,
fullFilePath
);
UpdateUIText
updateUIText
=
new
UpdateUIText
(
UpdateText
);
//下载进度
getObjectRequest
.
StreamTransferProgress
+=
(
obg
,
args
)
=>
{
float
putProcess
=
(
args
.
TransferredBytes
*
100
/
args
.
TotalBytes
);
TotalByte
+=
putProcess
;
float
present
=
putProcess
/
100f
;
production
.
updateUIText
.
BeginInvoke
(
present
,
null
,
null
);
/*production.preset_image.fillAmount = present;
if (present == 1f)
{
production.preset_image.fillAmount = 0;
production.progress_side.SetActive(false);
}
if (putProcess >= 1)
{
getObjectRequest.StreamTransferProgress = null;
}*/
};
// 下载文件到流。OssObject包含了文件的各种信息,如文件所在的存储空间、文件名、元信息以及一个输入流。
var
obj
=
client
.
GetObject
(
getObjectRequest
);
using
(
var
requestStream
=
obj
.
Content
)
{
byte
[]
buf
=
new
byte
[
1024
];
var
fs
=
File
.
Open
(
downloadFilename
,
FileMode
.
OpenOrCreate
);
// 通过输入流将文件的内容读取到文件或者内存中。
while
((
len
=
requestStream
.
Read
(
buf
,
0
,
1024
))
!=
0
)
{
fs
.
Write
(
buf
,
0
,
len
);
}
fs
.
Close
();
//解压
//ZipFile.ExtractToDirectory(downloadFilename, "D://DownloadDemo/");
Debug
.
Log
(
"解压前:"
+
downloadFilename
.
Substring
(
downloadFilename
.
LastIndexOf
(
'/'
)
+
1
,
downloadFilename
.
LastIndexOf
(
'.'
)
-
downloadFilename
.
LastIndexOf
(
'/'
)
-
1
));
UnZip
(
downloadFilename
,
"D://DownloadDemo/"
,
downloadFilename
.
Substring
(
downloadFilename
.
LastIndexOf
(
'/'
)
+
1
,
downloadFilename
.
LastIndexOf
(
'.'
)
-
downloadFilename
.
LastIndexOf
(
'/'
)
-
1
));
//删除文件
File
.
Delete
(
downloadFilename
);
//string json = "{\"code\":\"" + RobotCode.getMNum() + "\",\"productionid\":\"" + id + "\"}";
js_data
=
new
JsonData
();
js_data
[
"apppath"
]
=
"D://DownloadDemo/"
+
downloadFilename
.
Substring
(
downloadFilename
.
LastIndexOf
(
"/"
)
+
1
,
downloadFilename
.
LastIndexOf
(
"."
)
-
(
downloadFilename
.
Substring
(
0
,
downloadFilename
.
LastIndexOf
(
"/"
)
+
1
).
Length
))
+
"/"
+
appname
;
js_data
[
"productionid"
]
=
id
;
js_data
[
"code"
]
=
RobotCode
.
getMNum
();
//保存
//production.OnReceiveMsg.Invoke(js_data, "savepath");
updateUIText
.
BeginInvoke
(
production
,
js_data
,
null
,
null
);
isdown
=
false
;
//browser.CallFunction("msg", "D://DownloadDemo/" + downloadFilename.Substring(downloadFilename.LastIndexOf("/") + 1, downloadFilename.LastIndexOf(".") - (downloadFilename.Substring(0, downloadFilename.LastIndexOf("/") + 1).Length)) + "/" + appname, id, 1);
}
}
catch
(
OssException
e
)
{
Console
.
WriteLine
(
"下载错误:"
+
e
);
}
catch
(
Exception
e
)
{
Console
.
WriteLine
(
"下载错误:"
+
e
);
}
finally
{
thread
.
Abort
();
}
});
thread
.
Start
();
}
// 定义一个函数,用于在UI线程中更新UI元素
void
UpdateText
(
Production
production
,
JsonData
js_data
)
{
production
.
OnReceiveMsg
.
Invoke
(
js_data
,
"sendProcess"
);
}
/// <summary>
/// 解压zip文件,并覆盖保存到指定的目标路径文件下
/// </summary>
/// <param name="zipFilePath">将要解压缩的zip文件的路径</param>
/// <param name="unZipDir">解压后将zip中的文件存储到磁盘的目标路径</param>
/// <returns></returns>
public
static
bool
UnZip
(
string
zipFilePath
,
string
unZipDir
,
string
directoryName
)
{
bool
result
;
try
{
unZipDir
=
unZipDir
.
EndsWith
(
@"\"
)
?
unZipDir
:
unZipDir
+
@"\"
;
var
directoryinfo
=
new
DirectoryInfo
(
unZipDir
);
if
(!
directoryinfo
.
Exists
)
directoryinfo
.
Create
();
var
fileinfo
=
new
FileInfo
(
zipFilePath
);
if
(!
fileinfo
.
Exists
)
return
false
;
using
(
var
zipToOpen
=
new
FileStream
(
zipFilePath
,
FileMode
.
Open
,
FileAccess
.
ReadWrite
,
FileShare
.
Read
))
{
using
(
var
archive
=
new
ZipArchive
(
zipToOpen
,
ZipArchiveMode
.
Read
))
{
foreach
(
var
zipArchiveEntry
in
archive
.
Entries
)
{
if
(!
zipArchiveEntry
.
FullName
.
EndsWith
(
"/"
))
{
//中文出现乱码问题,截取中文段部分后把自定义的directoryName,拼接到前面
var
entryFilePath
=
directoryName
+
'/'
+
Regex
.
Replace
(
zipArchiveEntry
.
FullName
.
Substring
(
zipArchiveEntry
.
FullName
.
IndexOf
(
'/'
)
+
1
).
Replace
(
"/"
,
@"\"
),
@"^\\*"
,
""
);
// Debug.Log("zipArchiveEntry.FullName=" +zipArchiveEntry.FullName);
// Debug.Log("entryFilePath=" + entryFilePath);
var
filePath
=
Encoding
.
UTF8
.
GetString
(
Encoding
.
UTF8
.
GetBytes
(
directoryinfo
+
entryFilePath
));
var
content
=
new
byte
[
zipArchiveEntry
.
Length
];
zipArchiveEntry
.
Open
().
Read
(
content
,
0
,
content
.
Length
);
var
greatFolder
=
Directory
.
GetParent
(
filePath
);
if
(!
greatFolder
.
Exists
)
greatFolder
.
Create
();
File
.
WriteAllBytes
(
filePath
,
content
);
}
}
}
}
result
=
true
;
}
catch
(
Exception
e
)
{
Debug
.
Log
(
e
);
result
=
false
;
}
return
result
;
}
}
}
Assets/Scripts/unit/AliyunOSSDownLoad.cs.meta
0 → 100644
View file @
8c887e2b
fileFormatVersion: 2
guid: 8ed2a6b6c6d1e41468fe154e67c95f4a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/unit/DownloadUntily.cs
View file @
8c887e2b
...
...
@@ -233,9 +233,6 @@ public class DownloadUntily
//browser.CallFunction("msg", "已存在项目", null, 2);
}
}
}
...
...
Assets/Scripts/unit/MainThreadDispatcher.cs
0 → 100644
View file @
8c887e2b
using
System
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Threading
;
using
UnityEngine
;
public
class
MainThreadDispatcher
:
MonoBehaviour
{
private
static
MainThreadDispatcher
instance
;
private
static
readonly
Queue
<
Action
>
actions
=
new
Queue
<
Action
>();
private
static
readonly
object
lockObject
=
new
object
();
public
static
MainThreadDispatcher
Instance
{
get
{
if
(
instance
==
null
)
{
instance
=
FindObjectOfType
<
MainThreadDispatcher
>();
if
(
instance
==
null
)
{
var
go
=
new
GameObject
(
"MainThreadDispatcher"
);
instance
=
go
.
AddComponent
<
MainThreadDispatcher
>();
}
}
return
instance
;
}
}
private
void
Awake
()
{
DontDestroyOnLoad
(
gameObject
);
}
private
void
Update
()
{
lock
(
lockObject
)
{
while
(
actions
.
Count
>
0
)
{
actions
.
Dequeue
().
Invoke
();
}
}
}
public
void
Enqueue
(
Action
action
)
{
lock
(
lockObject
)
{
actions
.
Enqueue
(
action
);
}
}
public
void
Enqueue
(
IEnumerator
coroutine
)
{
lock
(
lockObject
)
{
actions
.
Enqueue
(()
=>
StartCoroutine
(
coroutine
));
}
}
public
static
void
RunOnMainThread
(
Action
action
)
{
Instance
.
Enqueue
(
action
);
}
public
static
void
RunOnMainThread
(
IEnumerator
coroutine
)
{
Instance
.
Enqueue
(
coroutine
);
}
}
Assets/Scripts/unit/MainThreadDispatcher.cs.meta
0 → 100644
View file @
8c887e2b
fileFormatVersion: 2
guid: 0218216871585ca4e8d439729945037e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/unit/UnityMainThreadDispatcher.cs
0 → 100644
View file @
8c887e2b
using
System.Collections.Generic
;
using
UnityEngine
;
using
UnityEngine.Events
;
public
class
UnityMainThreadDispatcher
:
MonoBehaviour
{
private
static
UnityMainThreadDispatcher
instance
;
private
readonly
Queue
<
System
.
Action
>
queue
=
new
Queue
<
System
.
Action
>();
public
UnityEvent
UpdateEvent
=
new
UnityEvent
();
public
static
UnityMainThreadDispatcher
Instance
()
{
if
(!
instance
)
{
instance
=
FindObjectOfType
<
UnityMainThreadDispatcher
>();
if
(!
instance
)
{
var
obj
=
new
GameObject
(
"UnityMainThreadDispatcher"
);
instance
=
obj
.
AddComponent
<
UnityMainThreadDispatcher
>();
}
}
return
instance
;
}
private
void
Update
()
{
lock
(
queue
)
{
while
(
queue
.
Count
>
0
)
{
queue
.
Dequeue
().
Invoke
();
}
}
}
public
void
Enqueue
(
System
.
Action
action
)
{
lock
(
queue
)
{
queue
.
Enqueue
(
action
);
}
}
}
Assets/Scripts/unit/UnityMainThreadDispatcher.cs.meta
0 → 100644
View file @
8c887e2b
fileFormatVersion: 2
guid: f54d8078cfe456741b214573c98c0eef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/_Scenes/MyScene.unity
View file @
8c887e2b
This source diff could not be displayed because it is too large. You can
view the blob
instead.
Assets/_预设/产品.prefab
View file @
8c887e2b
...
...
@@ -994,7 +994,7 @@ RectTransform:
m_LocalEulerAnglesHint
:
{
x
:
0
,
y
:
0
,
z
:
0
}
m_AnchorMin
:
{
x
:
0
,
y
:
1
}
m_AnchorMax
:
{
x
:
0
,
y
:
1
}
m_AnchoredPosition
:
{
x
:
460.5
,
y
:
-501.08337
}
m_AnchoredPosition
:
{
x
:
547.5
,
y
:
-594.8571
}
m_SizeDelta
:
{
x
:
500
,
y
:
25
}
m_Pivot
:
{
x
:
0.5
,
y
:
0.5
}
---
!u!222
&6928409732293149083
...
...
@@ -1557,6 +1557,7 @@ MonoBehaviour:
manager
:
{
fileID
:
0
}
progress_side
:
{
fileID
:
5184067287142128276
}
preset_image
:
{
fileID
:
8565227069874954852
}
fill_data
:
0
---
!u!114
&2801718033762222592
MonoBehaviour
:
m_ObjectHideFlags
:
0
...
...
Log/log.txt
View file @
8c887e2b
...
...
@@ -7191,3 +7191,4 @@
2023/4/4 11:28:57 api:http://8.134.114.12:11011/zeus/zeushub/getRobotCode?productionid=12877&code=54bce43eff19b4720e1f58fe HTTP/1.1 502 Bad Gateway
2023/4/7 16:10:13 api:http://8.134.114.12:11011/oauth/token Cannot connect to destination host
2023/4/10 14:04:19 api:http://8.134.114.12:11011/oauth/token Cannot connect to destination host
2023/5/4 8:33:07 api:http://8.134.114.12:11011/oauth/token Cannot connect to destination host
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment