Commit 2dac4321 authored by Ever's avatar Ever

更新代码

parent f6d1bad2
...@@ -21,7 +21,7 @@ TextureImporter: ...@@ -21,7 +21,7 @@ TextureImporter:
heightScale: 0.25 heightScale: 0.25
normalMapFilter: 0 normalMapFilter: 0
flipGreenChannel: 0 flipGreenChannel: 0
isReadable: 0 isReadable: 1
streamingMipmaps: 0 streamingMipmaps: 0
streamingMipmapsPriority: 0 streamingMipmapsPriority: 0
vTOnly: 0 vTOnly: 0
......
...@@ -419,7 +419,7 @@ public class mainGameOneImageView : mainGameView //回放上面,回放用的 ...@@ -419,7 +419,7 @@ public class mainGameOneImageView : mainGameView //回放上面,回放用的
height = gameidJsondata.height; height = gameidJsondata.height;
return true; return true;
} }
public override void loadFileInfo(string url, string localpath, int typeId) public override void loadFileInfo(string url, string localpath, int typeId,string key="")
{ {
if (typeId == 1 || typeId == 2) if (typeId == 1 || typeId == 2)
......
...@@ -585,11 +585,34 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法 ...@@ -585,11 +585,34 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法
} }
} }
public virtual void loadFileInfo(string url, string localpath, int typeId) public virtual void loadFileInfo(string url, string localpath, int typeId,string key="")
{ {
if (typeId == 1 || typeId == 2) if (typeId == 1 || typeId == 2)
{ {
//if (typeId == 1)
//{
// string pngpath = Application.persistentDataPath + $"/MyPic/{key}/{key}.png";
// if (!File.Exists(pngpath))
// {
// File.Move(localpath, pngpath);
// }
//}
//else
//{
// string jpgpath = Application.persistentDataPath + $"/MyPic/{key}/{key}.jpg";
// if (!File.Exists(jpgpath))
// {
// File.Move(localpath, jpgpath);
// }
//}
DownLoadFileinfos.Add(url);
EventDispatcher.Dispatch(EventName.Event.Event_LoadingChange); //加载完成
if (DownLoadFileinfos.Count >= 3)
{
StartGame();
}
return;
utilsTools.httpDOWNIMG(this, url, localpath, (string id, string url1, bool isSuccess, System.Object data) => utilsTools.httpDOWNIMG(this, url, localpath, (string id, string url1, bool isSuccess, System.Object data) =>
{ {
if (isSuccess == false) if (isSuccess == false)
...@@ -644,6 +667,21 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法 ...@@ -644,6 +667,21 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法
} }
else if (typeId == 3) else if (typeId == 3)
{ {
//string path = Application.persistentDataPath + $"/MyPic/{key}/{key}.json"; //这个以后改为、bin文件
//if (!File.Exists(path))
//{
// File.Move(localpath,path);
//}
EventDispatcher.Dispatch(EventName.Event.Event_LoadingChange);//加载完成
DownLoadFileinfos.Add(url);
if (DownLoadFileinfos.Count >= 3)
{
StartGame();
}
return;
utilsTools.httpDownText(this, url, localpath, (string id, string url1, bool isSuccess, System.Object data) => utilsTools.httpDownText(this, url, localpath, (string id, string url1, bool isSuccess, System.Object data) =>
{ {
if (isSuccess == false) if (isSuccess == false)
...@@ -775,13 +813,19 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法 ...@@ -775,13 +813,19 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法
//utilsTools.setGDataByKey("loadBinEnd", utilsTools.getTotalMillisecond()); //utilsTools.setGDataByKey("loadBinEnd", utilsTools.getTotalMillisecond());
//utilsTools.setGDataByKey("downJson", utilsTools.getTotalMillisecond()); //utilsTools.setGDataByKey("downJson", utilsTools.getTotalMillisecond());
EventDispatcher.Dispatch(EventName.Event.Event_LoadingChange); //开始加载文件 EventDispatcher.Dispatch(EventName.Event.Event_LoadingChange); //开始加载本地文件
string dicpath= Application.persistentDataPath + $"/MyPic/{gameUserInfo.id}";
if (!Directory.Exists(dicpath))
{
Directory.CreateDirectory(dicpath);
}
loadFileInfo(gameUserInfo.json, jsonPath, 3); loadFileInfo(gameUserInfo.json, jsonPath, 3, gameUserInfo.id);
//utilsTools.setGDataByKey("loadGaoQing", utilsTools.getTotalMillisecond()); //utilsTools.setGDataByKey("loadGaoQing", utilsTools.getTotalMillisecond());
loadFileInfo(gameUserInfo.img, linePath, 1); loadFileInfo(gameUserInfo.img, linePath, 1, gameUserInfo.id);
//utilsTools.setGDataByKey("loadJpg", utilsTools.getTotalMillisecond()); //utilsTools.setGDataByKey("loadJpg", utilsTools.getTotalMillisecond());
loadFileInfo(gameUserInfo.finishImg, colorPath, 2); loadFileInfo(gameUserInfo.finishImg, colorPath, 2, gameUserInfo.id);
return true; return true;
} }
public bool loadGameImgId() public bool loadGameImgId()
...@@ -1741,12 +1785,15 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法 ...@@ -1741,12 +1785,15 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法
var jsondata = getdata("cc2D9Z2w9k0evqUiCQ"); var jsondata = getdata("cc2D9Z2w9k0evqUiCQ");
item.GetComponent<GameMgr>().Init("cc2D9Z2w9k0evqUiCQ",png, jpg, jsondata); item.GetComponent<GameMgr>().Init("cc2D9Z2w9k0evqUiCQ",png, jpg, jsondata);
SaveManager.Instance.SaveRes("cc2D9Z2w9k0evqUiCQ", jsondata, png);
//SaveManager.Instance.SaveJPG("cc2D9Z2w9k0evqUiCQ", jpg_texture);
} }
IEnumerator LoadPic(string dirpath,string name,Transform item) IEnumerator LoadPic(string dirpath,string name,Transform item)
{ {
Texture2D png=null; Texture2D png=null;
Sprite jpg=null; Sprite jpg=null;
Texture2D jpg_texture = null;
string pngpath = dirpath+$"{name}.png"; string pngpath = dirpath+$"{name}.png";
UnityWebRequest request; UnityWebRequest request;
if (File.Exists(pngpath)) if (File.Exists(pngpath))
...@@ -1769,13 +1816,13 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法 ...@@ -1769,13 +1816,13 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法
yield return request.SendWebRequest(); yield return request.SendWebRequest();
if (request.isDone) if (request.isDone)
{ {
var jpg_texture = DownloadHandlerTexture.GetContent(request); 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)); jpg = Sprite.Create(jpg_texture, new Rect(0, 0, jpg_texture.width, jpg_texture.height), new Vector2(0.5f, 0.5f));
} }
} }
else else
{ {
var jpg_texture = Resources.Load<Texture2D>("cc2D9Z2w9k0evqUiCQ/jpg"); 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)); jpg = Sprite.Create(jpg_texture, new Rect(0, 0, jpg_texture.width, jpg_texture.height), new Vector2(0.5f, 0.5f));
} }
...@@ -1783,7 +1830,9 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法 ...@@ -1783,7 +1830,9 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法
var jsondata = getdata("cc2D9Z2w9k0evqUiCQ"); var jsondata = getdata("cc2D9Z2w9k0evqUiCQ");
item.GetComponent<GameMgr>().Init("cc2D9Z2w9k0evqUiCQ", png, jpg, jsondata); item.GetComponent<GameMgr>().Init("cc2D9Z2w9k0evqUiCQ", png, jpg, jsondata);
SaveManager.Instance.SaveRes("cc2D9Z2w9k0evqUiCQ", jsondata, png);
yield return new WaitForSeconds(0.5f);
SaveManager.Instance.SaveJPG("cc2D9Z2w9k0evqUiCQ", item.GetComponent<GameMgr>().md.jpg.texture);
} }
private ResJsonData getdata(string name) private ResJsonData getdata(string name)
...@@ -1797,6 +1846,7 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法 ...@@ -1797,6 +1846,7 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法
FileStream readFs = new FileStream(path, FileMode.Open); FileStream readFs = new FileStream(path, FileMode.Open);
BinaryFormatter readBf = new BinaryFormatter(); BinaryFormatter readBf = new BinaryFormatter();
ResJsonData rjd = (ResJsonData)readBf.Deserialize(readFs); ResJsonData rjd = (ResJsonData)readBf.Deserialize(readFs);
readFs.Close(); readFs.Close();
return rjd; return rjd;
......
...@@ -3,6 +3,7 @@ using System.Collections.Generic; ...@@ -3,6 +3,7 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using System.IO; using System.IO;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
using System.Net.NetworkInformation;
public class SaveManager : MonoBehaviour public class SaveManager : MonoBehaviour
{ {
...@@ -40,23 +41,27 @@ public class SaveManager : MonoBehaviour ...@@ -40,23 +41,27 @@ public class SaveManager : MonoBehaviour
public void SaveBin(string key,ResJsonData data) public void SaveBin(string key,ResJsonData data)
{ {
string json= JsonUtility.ToJson(data); StartCoroutine(SaveBing(key, data));
SaveBin(key,json);
} }
IEnumerator SaveBing(string key, ResJsonData data)
{
yield return null;
SaveBin_Ie(key, data);
}
/// <summary> /// <summary>
/// 保存bin文件 /// 保存bin文件
/// </summary> /// </summary>
/// <param name="path"></param> /// <param name="path"></param>
/// <param name="json"></param> /// <param name="json"></param>
public void SaveBin(string key, string json) public void SaveBin_Ie(string key, ResJsonData data)
{ {
CreateDirectory(SavePath + $"{key}"); CreateDirectory(SavePath + $"{key}");
string path = SavePath + $"{key}/{key}.bin"; string path = SavePath + $"{key}/{key}.bin";
FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write); FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
BinaryFormatter saveBf = new BinaryFormatter(); BinaryFormatter saveBf = new BinaryFormatter();
saveBf.Serialize(fs, json); saveBf.Serialize(fs, data);
fs.Close(); fs.Close();
} }
...@@ -69,26 +74,37 @@ public class SaveManager : MonoBehaviour ...@@ -69,26 +74,37 @@ public class SaveManager : MonoBehaviour
{ {
CreateDirectory(SavePath + $"{key}"); CreateDirectory(SavePath + $"{key}");
string path = SavePath + $"{key}/{key}.png"; string path = SavePath + $"{key}/{key}.png";
byte[] dataBytes = png.EncodeToPNG(); StartCoroutine(SavePic(path, png));
FileStream fs = File.Open(path, FileMode.OpenOrCreate); //byte[] dataBytes = png.EncodeToPNG();
fs.Write(dataBytes, 0, dataBytes.Length); //FileStream fs = File.Open(path, FileMode.OpenOrCreate);
fs.Flush(); //fs.Write(dataBytes, 0, dataBytes.Length);
fs.Close(); //fs.Flush();
//fs.Close();
} }
public void SaveJPG(string key, Texture2D png) public void SaveJPG(string key, Texture2D jpg)
{ {
string path = SavePath + $"{key}/{key}.jpg"; string path = SavePath + $"{key}/{key}.jpg";
CreateDirectory(SavePath + $"{key}"); CreateDirectory(SavePath + $"{key}");
byte[] dataBytes = png.EncodeToPNG(); StartCoroutine(SavePic(path, jpg));
//byte[] dataBytes = png.EncodeToPNG();
//FileStream fs = File.Open(path, FileMode.OpenOrCreate);
//fs.Write(dataBytes, 0, dataBytes.Length);
//fs.Flush();
//fs.Close();
}
IEnumerator SavePic(string path,Texture2D pic)
{
yield return null;
byte[] dataBytes = pic.EncodeToPNG();
FileStream fs = File.Open(path, FileMode.OpenOrCreate); FileStream fs = File.Open(path, FileMode.OpenOrCreate);
fs.Write(dataBytes, 0, dataBytes.Length); fs.Write(dataBytes, 0, dataBytes.Length);
fs.Flush(); fs.Flush();
fs.Close(); fs.Close();
} }
private void CreateDirectory(string dirpath) private void CreateDirectory(string dirpath)
{ {
if (!Directory.Exists(dirpath)) if (!Directory.Exists(dirpath))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment