Commit 8caa1b6a authored by JiangWanZhi's avatar JiangWanZhi

同步代码

parent 675314e6
......@@ -173,30 +173,34 @@ public class GameMgr : MonoBehaviour
}
public void RePlay()
{
rePlayList = md.json.step;
md.RePlay();
rePlayIndex = 0;
}
public int rePlayIndex = -1;
public List<int> rePlayList = new List<int>();
public float maxTime = 1;
public float curTime = 0;
public void Play()
{
if (rePlayIndex == -1)
if (rePlayList.Count == 0)
{
return;
}
for (int i = 0; i < md.json.roomDatas.Count; i++)
curTime += Time.deltaTime;
if (curTime >= maxTime)
{
if (md.json.roomDatas[i].id == md.json.step[rePlayIndex])
curTime -= maxTime;
for (int i = 0; i < md.json.roomDatas.Count; i++)
{
Vector2 v = new Vector2(md.json.roomDatas[i].px, md.json.roomDatas[i].py);
md.OnClickPos(v);
rePlayIndex++;
if (rePlayIndex >= md.json.step.Count)
if (md.json.roomDatas[i].id == rePlayList[0])
{
rePlayIndex = -1;
Debug.Log("进入:" + rePlayList[0] + "_rePlayList.Count=" + rePlayList.Count);
Vector2 v = new Vector2(md.json.roomDatas[i].px, md.json.roomDatas[i].py);
Debug.Log("模拟点击:" + v);
md.OnClickPos(v);
rePlayList.RemoveAt(0);
break;
}
break;
}
}
}
......
......@@ -26,6 +26,7 @@ public class MainData : MonoBehaviour
public void Init(string _key, Texture2D _png, Sprite _jpg, ResJsonData _json)
{
ChooseGroup();
key = _key;
png = _png;
jpg = _jpg;
......@@ -111,8 +112,13 @@ public class MainData : MonoBehaviour
return false;
}
public void ChooseGroup(int id)
public void ChooseGroup(int id = -1)
{
if (id == -1)
{
curGroupId = id;
GameMgr.Ins.giMgr.CircleAll();
}
Debug.Log("选中组:" + id);
if (curGroupId == id)
{
......@@ -203,6 +209,7 @@ public class MainData : MonoBehaviour
json.roomGroupsData[i].roomIds.AddRange(json.roomGroupsData[i].roomIdsOver);
json.roomGroupsData[i].roomIdsOver.Clear();
}
json.step = new List<int>();
Color[] c = png.GetPixels();
for (int i = 0; i < c.Length; i++)
{
......@@ -213,5 +220,8 @@ public class MainData : MonoBehaviour
}
png.SetPixels(c);
png.Apply();
ChooseGroup();
GameMgr.Ins.tiMgr.Init(json, png);
GameMgr.Ins.tiMgr.SizeChange(transform.parent.localScale.x);
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -32,6 +32,7 @@ public static class EventName
public const string Event_GroupListCreate = "Event_GroupListCreate";//加载组的数量
public const string Event_GropuItemChange = "Event_GropuItemChange";//某个组的进度改变
public const string Event_GroupItemClick = "Event_GroupItemClick";//点击某一个组
public const string Event_ChoiseGroupByPic = "Event_ChoiseGroupByPic"; //图片区域长按选择某一个组
public const string Event_AllGroupOver = "Event_AllGroupOver";//游戏结束,全部组都涂完了
......
......@@ -42,7 +42,30 @@ public class GroupListManager : MonoBehaviour
{
EventDispatcher.RegisterEvent(EventName.Event.Event_GroupListCreate, CreateGroup, flag);
EventDispatcher.RegisterEvent(EventName.Event.Event_GropuItemChange, GroupItemChange, flag);
EventDispatcher.RegisterEvent(EventName.Event.Event_ChoiseGroupByPic, Event_ChoiseGroupByPic, flag);
}
public int idd=5;
private void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
EventDispatcher.Dispatch(EventName.Event.Event_ChoiseGroupByPic, idd);
}
}
private void Event_ChoiseGroupByPic(object[] values) //图片区域长按选择一个组
{
int Gid = (int)values[0];
var item = AllItem.FirstOrDefault((a) => a.GID == Gid);
float childsize = item.GetComponent<RectTransform>().sizeDelta.x;
if (item != null)
{
float targetpos = childsize * item.index - scrollview.flexibleWidth;
//Content.transform.DOLocalMoveX();
}
}
public void ChangeTipTitleState(bool flag)
{
TipTitle.SetActive(flag);
......@@ -254,4 +277,9 @@ public class GroupListManager : MonoBehaviour
{
GameMgr.Ins.Clear();
}
public void Test_Btn_RePlay()
{
GameMgr.Ins.RePlay();
}
}
......@@ -1796,8 +1796,10 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法
Texture2D jpg_texture = null;
string pngpath = dirpath+$"{name}.png";
UnityWebRequest request;
bool localflag = false;
if (File.Exists(pngpath))
{
localflag = true;
request = UnityWebRequestTexture.GetTexture(pngpath);
yield return request.SendWebRequest();
if (request.isDone)
......@@ -1823,18 +1825,46 @@ public class mainGameView : MonoBehaviour //大图的处理、具体的玩法
else
{
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));
}
var jsondata = getdata("cc2D9Z2w9k0evqUiCQ");
item.GetComponent<GameMgr>().Init("cc2D9Z2w9k0evqUiCQ", png, jpg, jsondata);
if (localflag) //加载本地的到这里就回去了,下面是第一次
{
item.GetComponent<GameMgr>().Init("cc2D9Z2w9k0evqUiCQ", png, jpg, jsondata);
yield break;
}
SaveManager.Instance.SaveRes("cc2D9Z2w9k0evqUiCQ", jsondata, png);
yield return new WaitForSeconds(0.5f);
SaveManager.Instance.SaveJPG("cc2D9Z2w9k0evqUiCQ", item.GetComponent<GameMgr>().md.jpg.texture);
while (!SaveManager.Instance.IsSaveOver)
{
yield return null;
}
request = UnityWebRequestTexture.GetTexture(pngpath);
yield return request.SendWebRequest();
if (request.isDone)
{
png = DownloadHandlerTexture.GetContent(request);
}
request = UnityWebRequestTexture.GetTexture(jpgpath);
yield return request.SendWebRequest();
if (request.isDone)
{
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));
}
jsondata = getdata("cc2D9Z2w9k0evqUiCQ");
item.GetComponent<GameMgr>().Init("cc2D9Z2w9k0evqUiCQ", png, jpg, jsondata);
}
private ResJsonData getdata(string name)
{
string path;//= $"{Application.dataPath}/Resources/cc2D9Z2w9k0evqUiCQ/cc2D9Z2w9k0evqUiCQ.bin";
......
......@@ -21,6 +21,17 @@ public class SaveManager : MonoBehaviour
}
set { savepath = value; }
}
//是否保存结束
public bool IsSaveOver
{
get
{
return savefiles.Count == 0;
}
}
private List<string> savefiles= new List<string>();
private void Awake()
{
instance = this;
......@@ -41,6 +52,7 @@ public class SaveManager : MonoBehaviour
public void SaveBin(string key,ResJsonData data)
{
savefiles.Add(key);
StartCoroutine(SaveBing(key, data));
}
......@@ -49,6 +61,8 @@ public class SaveManager : MonoBehaviour
yield return null;
SaveBin_Ie(key, data);
if (savefiles.Count > 0)
savefiles.RemoveAt(0);
}
/// <summary>
/// 保存bin文件
......@@ -72,27 +86,19 @@ public class SaveManager : MonoBehaviour
/// <param name="png"></param>
public void SavePng(string key, Texture2D png)
{
savefiles.Add(key);
CreateDirectory(SavePath + $"{key}");
string path = SavePath + $"{key}/{key}.png";
StartCoroutine(SavePic(path, png));
//byte[] dataBytes = png.EncodeToPNG();
//FileStream fs = File.Open(path, FileMode.OpenOrCreate);
//fs.Write(dataBytes, 0, dataBytes.Length);
//fs.Flush();
//fs.Close();
}
public void SaveJPG(string key, Texture2D jpg)
{
savefiles.Add(key);
string path = SavePath + $"{key}/{key}.jpg";
CreateDirectory(SavePath + $"{key}");
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)
......@@ -103,6 +109,8 @@ public class SaveManager : MonoBehaviour
fs.Write(dataBytes, 0, dataBytes.Length);
fs.Flush();
fs.Close();
if(savefiles.Count>0)
savefiles.RemoveAt(0);
}
private void CreateDirectory(string 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