格子划分正常
This commit is contained in:
@@ -3,9 +3,14 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.Remoting.Metadata.W3cXsd2001;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.UI;
|
||||
using static MapManager;
|
||||
|
||||
public partial class MapManager : MonoBehaviour
|
||||
@@ -18,8 +23,8 @@ public partial class MapManager : MonoBehaviour
|
||||
return false;
|
||||
}
|
||||
|
||||
string path = string.Empty;
|
||||
|
||||
string path = string.Empty;
|
||||
|
||||
path = PathUtil.GetXmlPath(_curOpenMapId, "Obs");
|
||||
|
||||
if (!File.Exists(path))
|
||||
@@ -50,14 +55,14 @@ public partial class MapManager : MonoBehaviour
|
||||
|
||||
//0,0,1,0;0,1,1,1;0,2,1,2;
|
||||
string[] values = strData.Split(';');
|
||||
if(values.Length != cellCount)
|
||||
if (values.Length != cellCount)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>");
|
||||
return false;
|
||||
}
|
||||
|
||||
cellsNode = new CellNode[cellCount];
|
||||
for (int i=0; i<cellCount; i++)
|
||||
for (int i = 0; i < cellCount; i++)
|
||||
{
|
||||
string[] strCell = values[i].Split(',');
|
||||
|
||||
@@ -78,4 +83,56 @@ public partial class MapManager : MonoBehaviour
|
||||
|
||||
return true;
|
||||
}
|
||||
public void LoadMapSprite()
|
||||
{
|
||||
//map<61><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
|
||||
GameObject map = new GameObject("map");
|
||||
int mapRownum = 11;
|
||||
int mapColumn = 14;
|
||||
//ƽ<><C6BD>;
|
||||
float jpgscenew = 512f / 100;
|
||||
|
||||
for (int row = 0; row < mapRownum; row++)
|
||||
{
|
||||
for (int col = 0; col < mapColumn; col++)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>v1000_r1_c1.jpg
|
||||
string filename = $"v{1000}_r{row + 1}_c{col + 1}";
|
||||
string spPath = PathUtil.GetMapTexure(1000, filename, "jpg");
|
||||
GameObject obj = new GameObject(filename);
|
||||
obj.transform.SetParent(map.transform);
|
||||
SpriteRenderer sr = obj.AddComponent<SpriteRenderer>();
|
||||
float x = col * jpgscenew;
|
||||
float y = (mapRownum - row - 1) * jpgscenew;
|
||||
obj.transform.position = new Vector2(x, y);
|
||||
StartCoroutine(LoadSpriteT(spPath, obj,sr));
|
||||
// ֱ<><D6B1>ʹ<EFBFBD><CAB9>ԭʼ<D4AD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Sprite
|
||||
//sr.sprite = Sprite.Create(asset, new Rect(0, 0, asset.width, asset.height), Vector2.zero, 100f);
|
||||
//float x = col * jpgscenew;
|
||||
//float y = (mapRownum - row - 1) * jpgscenew;
|
||||
//obj.transform.position = new Vector2(x, y);
|
||||
//Debug.Log($"Tile {filename} placed at ({x}, {y})");
|
||||
}
|
||||
}
|
||||
MapManager.Instance.ReseCamera(jpgscenew * mapColumn, jpgscenew * mapRownum);
|
||||
MapManager.Instance.GenerateMap(jpgscenew * mapColumn, jpgscenew * mapRownum, 0.48f, 0.32f);
|
||||
}
|
||||
IEnumerator LoadSpriteT(string spName, GameObject go, SpriteRenderer sprite)
|
||||
{
|
||||
using (UnityWebRequest req = UnityWebRequestTexture.GetTexture(spName))
|
||||
{
|
||||
yield return req.SendWebRequest();
|
||||
if (req.result == UnityWebRequest.Result.Success)
|
||||
{
|
||||
Texture2D tt = DownloadHandlerTexture.GetContent(req);
|
||||
if (tt == null)
|
||||
yield break;
|
||||
sprite.sprite = Sprite.Create(tt, new Rect(0, 0, tt.width, tt.height), Vector2.zero, 100f);
|
||||
}
|
||||
else
|
||||
{
|
||||
UIWindow.Instance.ShowMessage(req.error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user