Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
T
tuseGameColor
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shujianhe
tuseGameColor
Commits
5f8903dc
Commit
5f8903dc
authored
Aug 20, 2023
by
Ever
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新保存文件
parent
c219757b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
36 deletions
+96
-36
mainGameView.cs
Assets/scripts/common/mainGameView.cs
+63
-5
SaveManager.cs
Assets/scripts/utils/SaveManager.cs
+33
-31
No files found.
Assets/scripts/common/mainGameView.cs
View file @
5f8903dc
...
...
@@ -16,6 +16,11 @@ using UnityEngine.Windows;
using
Input
=
UnityEngine
.
Input
;
using
System.Runtime.Serialization.Formatters.Binary
;
using
UnityEngine.Rendering
;
using
System.Security.Policy
;
using
UnityEngine.Networking
;
using
Directory
=
System
.
IO
.
Directory
;
using
static
UnityEditor
.
Progress
;
using
File
=
System
.
IO
.
File
;
public
class
mainGameView
:
MonoBehaviour
//大图的处理、具体的玩法
{
...
...
@@ -1722,21 +1727,74 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法
item
.
localRotation
=
Quaternion
.
Euler
(
0
,
0
,
0
);
item
.
localScale
=
Vector3
.
one
;
EventDispatcher
.
Dispatch
(
EventName
.
Event
.
Event_LoadingChange
);
//开始初始化
string
path
=
Application
.
persistentDataPath
+
$"/MyPic/cc2D9Z2w9k0evqUiCQ/"
;
if
(
Directory
.
Exists
(
path
))
{
StartCoroutine
(
LoadPic
(
path
,
"cc2D9Z2w9k0evqUiCQ"
,
item
));
return
;
}
var
png
=
Resources
.
Load
<
Texture2D
>(
"cc2D9Z2w9k0evqUiCQ/png"
);
var
jpg_texture
=
Resources
.
Load
<
Texture2D
>(
"cc2D9Z2w9k0evqUiCQ/jpg"
);
var
jpg
=
Sprite
.
Create
(
jpg_texture
,
new
Rect
(
0
,
0
,
jpg_texture
.
width
,
jpg_texture
.
height
),
new
Vector2
(
0.5f
,
0.5f
));
var
jsondata
=
getdata
();
var
jsondata
=
getdata
(
"cc2D9Z2w9k0evqUiCQ"
);
EventDispatcher
.
Dispatch
(
EventName
.
Event
.
Event_LoadingChange
);
//开始初始化
item
.
GetComponent
<
GameMgr
>().
Init
(
"cc2D9Z2w9k0evqUiCQ"
,
png
,
jpg
,
jsondata
);
}
IEnumerator
LoadPic
(
string
dirpath
,
string
name
,
Transform
item
)
{
Texture2D
png
=
null
;
Sprite
jpg
=
null
;
string
pngpath
=
dirpath
+
$"
{
name
}
.png"
;
UnityWebRequest
request
;
if
(
File
.
Exists
(
pngpath
))
{
request
=
UnityWebRequestTexture
.
GetTexture
(
pngpath
);
yield
return
request
.
SendWebRequest
();
if
(
request
.
isDone
)
{
png
=
DownloadHandlerTexture
.
GetContent
(
request
);
}
}
else
{
png
=
Resources
.
Load
<
Texture2D
>(
"cc2D9Z2w9k0evqUiCQ/png"
);
}
string
jpgpath
=
dirpath
+
$"
{
name
}
.jpg"
;
if
(
File
.
Exists
(
jpgpath
))
{
request
=
UnityWebRequestTexture
.
GetTexture
(
jpgpath
);
yield
return
request
.
SendWebRequest
();
if
(
request
.
isDone
)
{
var
jpg_texture
=
DownloadHandlerTexture
.
GetContent
(
request
);
jpg
=
Sprite
.
Create
(
jpg_texture
,
new
Rect
(
0
,
0
,
jpg_texture
.
width
,
jpg_texture
.
height
),
new
Vector2
(
0.5f
,
0.5f
));
}
}
else
{
var
jpg_texture
=
Resources
.
Load
<
Texture2D
>(
"cc2D9Z2w9k0evqUiCQ/jpg"
);
jpg
=
Sprite
.
Create
(
jpg_texture
,
new
Rect
(
0
,
0
,
jpg_texture
.
width
,
jpg_texture
.
height
),
new
Vector2
(
0.5f
,
0.5f
));
}
private
ResJsonData
getdata
()
var
jsondata
=
getdata
(
"cc2D9Z2w9k0evqUiCQ"
);
item
.
GetComponent
<
GameMgr
>().
Init
(
"cc2D9Z2w9k0evqUiCQ"
,
png
,
jpg
,
jsondata
);
}
private
ResJsonData
getdata
(
string
name
)
{
string
path
=
$"
{
Application
.
dataPath
}
/Resources/cc2D9Z2w9k0evqUiCQ/cc2D9Z2w9k0evqUiCQ.bin"
;
string
path
;
//= $"{Application.dataPath}/Resources/cc2D9Z2w9k0evqUiCQ/cc2D9Z2w9k0evqUiCQ.bin";
path
=
Application
.
persistentDataPath
+
$"/MyPic/
{
name
}
/
{
name
}
.bin"
;
if
(!
File
.
Exists
(
path
))
{
path
=
$"
{
Application
.
dataPath
}
/Resources/cc2D9Z2w9k0evqUiCQ/cc2D9Z2w9k0evqUiCQ.bin"
;
}
FileStream
readFs
=
new
FileStream
(
path
,
FileMode
.
Open
);
BinaryFormatter
readBf
=
new
BinaryFormatter
();
ResJsonData
rjd
=
(
ResJsonData
)
readBf
.
Deserialize
(
readFs
);
...
...
Assets/scripts/utils/SaveManager.cs
View file @
5f8903dc
...
...
@@ -16,7 +16,7 @@ public class SaveManager : MonoBehaviour
{
get
{
return
Application
.
dataPath
+
$"/Resources/cc2D9Z2w9k0evqUiCQ/"
;
//暂时先用这里的
return
Application
.
persistentDataPath
+
"/MyPic/"
;
//Application.
dataPath+$"/Resources/cc2D9Z2w9k0evqUiCQ/"; //暂时先用这里的
}
set
{
savepath
=
value
;
}
}
...
...
@@ -24,16 +24,25 @@ public class SaveManager : MonoBehaviour
{
instance
=
this
;
}
private
void
Start
()
{
if
(!
Directory
.
Exists
(
SavePath
))
{
Directory
.
CreateDirectory
(
SavePath
);
}
}
public
void
SaveRes
(
string
key
,
ResJsonData
data
,
Texture2D
png
)
{
SavePng
(
key
,
png
);
SaveBin
(
key
,
data
);
}
public
void
SaveBin
(
string
pngname
,
ResJsonData
data
)
public
void
SaveBin
(
string
key
,
ResJsonData
data
)
{
string
json
=
JsonUtility
.
ToJson
(
data
);
SaveBin
(
pngname
,
json
);
SaveBin
(
key
,
json
);
}
/// <summary>
...
...
@@ -41,10 +50,11 @@ public class SaveManager : MonoBehaviour
/// </summary>
/// <param name="path"></param>
/// <param name="json"></param>
public
void
SaveBin
(
string
pngname
,
string
json
)
public
void
SaveBin
(
string
key
,
string
json
)
{
FileStream
fs
=
new
FileStream
(
SavePath
+
$"
{
name
}
.bin"
,
FileMode
.
Create
,
FileAccess
.
Write
);
CreateDirectory
(
SavePath
+
$"
{
key
}
"
);
string
path
=
SavePath
+
$"
{
key
}
/
{
key
}
.bin"
;
FileStream
fs
=
new
FileStream
(
path
,
FileMode
.
Create
,
FileAccess
.
Write
);
BinaryFormatter
saveBf
=
new
BinaryFormatter
();
saveBf
.
Serialize
(
fs
,
json
);
fs
.
Close
();
...
...
@@ -55,43 +65,35 @@ public class SaveManager : MonoBehaviour
/// </summary>
/// <param name="path"></param>
/// <param name="png"></param>
public
void
SavePng
(
Texture2D
png
)
public
void
SavePng
(
string
key
,
Texture2D
png
)
{
//var colors = png.GetPixels();
//for (int i = 0; i < png.width; i+=2)
//{
// for (int j = 0; j < png.height; j+=2)
// {
// png.SetPixel(i, j, new Color(1, 1, 1, 1));
// }
//}
//png.Apply();
CreateDirectory
(
SavePath
+
$"
{
key
}
"
);
string
path
=
SavePath
+
$"
{
key
}
/
{
key
}
.png"
;
byte
[]
dataBytes
=
png
.
EncodeToPNG
();
FileStream
fs
=
File
.
Open
(
SavePath
+
$"
{
png
.
name
}
.png"
,
FileMode
.
OpenOrCreate
);
FileStream
fs
=
File
.
Open
(
path
,
FileMode
.
OpenOrCreate
);
fs
.
Write
(
dataBytes
,
0
,
dataBytes
.
Length
);
fs
.
Flush
();
fs
.
Close
();
}
public
void
SaveJPG
(
Texture2D
png
)
public
void
SaveJPG
(
string
key
,
Texture2D
png
)
{
//var colors = png.GetPixels();
//for (int i = 0; i < png.width; i+=2)
//{
// for (int j = 0; j < png.height; j+=2)
// {
// png.SetPixel(i, j, new Color(1, 1, 1, 1));
// }
//}
//png.Apply();
string
path
=
SavePath
+
$"
{
key
}
/
{
key
}
.jpg"
;
CreateDirectory
(
SavePath
+
$"
{
key
}
"
);
byte
[]
dataBytes
=
png
.
EncodeToPNG
();
FileStream
fs
=
File
.
Open
(
SavePath
+
$"
{
png
.
name
}
.jpg"
,
FileMode
.
OpenOrCreate
);
FileStream
fs
=
File
.
Open
(
path
,
FileMode
.
OpenOrCreate
);
fs
.
Write
(
dataBytes
,
0
,
dataBytes
.
Length
);
fs
.
Flush
();
fs
.
Close
();
}
private
void
CreateDirectory
(
string
dirpath
)
{
if
(!
Directory
.
Exists
(
dirpath
))
{
Directory
.
CreateDirectory
(
dirpath
);
}
}
}
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