| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 | using System;using System.Collections;using System.Collections.Generic;using UnityEngine;public class MapGenerator : MonoBehaviour{    public string nameHeard = "L";    public int x_Count = 0;    public int y_Count = 0;    public string ab_Name;    private List<GameObject> quadList = new List<GameObject>();    private bool isInit = false;    public void ShowMap()    {        if (!isInit)        {            StartCoroutine(CreatMap());        }        else        {            foreach (var mapQuad in quadList)            {                mapQuad.SetActive(true);            }        }    }    public void Hide()    {        foreach (var mapQuad in quadList)        {            mapQuad.SetActive(false);        }    }    private IEnumerator CreatMap()    {        WaitForSeconds wait = new WaitForSeconds(0.01f);        isInit = true;        for (int i = 0; i < x_Count; i++)        {            for (int j = 0; j < y_Count; j++)            {                GeneratorQuad(i, j, new Vector2(1, 1));            }            yield return wait;        }    }    private void GeneratorQuad(int _x, int _y, Vector2 _size)    {        string texName =$"{nameHeard}{_x}_{_y}";        GameObject tempQuad = new GameObject(texName);        MeshFilter meshFilter = tempQuad.AddComponent<MeshFilter>();        MeshRenderer meshRenderer = tempQuad.AddComponent<MeshRenderer>();        Material tempMat=new Material(Shader.Find("Unlit/Texture"));        meshRenderer.material = tempMat;        TextureLoadHelp._Instance.LoadTexFromUrl_AB(ab_Name,texName + ".jpg",tempMat);        Mesh mesh = new Mesh();        mesh.vertices = new Vector3[]        {            new Vector3(-_size.x / 2, -_size.y / 2, 0), // BL            new Vector3(-_size.x / 2, _size.y / 2, 0), // TL            new Vector3(_size.x / 2, _size.y / 2, 0), // TR            new Vector3(_size.x / 2, -_size.y / 2, 0), // BR        };        mesh.uv = new Vector2[]        {            new Vector2(0, 0), // BL            new Vector2(0, 1), // TL            new Vector2(1, 1), // TR            new Vector2(1, 0), // BR        };        mesh.triangles = new int[] { 0, 1, 2, 2, 3, 0 };        meshFilter.mesh = mesh;        tempQuad.transform.SetParent(this.transform);        tempQuad.transform.localScale = Vector3.one;        var x = (-x_Count * 0.5f) + (_y * _size.x) + 0.5f;        var y = (y_Count * 0.5f) - (_x * _size.y) - 0.5f;        tempQuad.transform.localPosition = new Vector3(x,y,0);        quadList.Add(tempQuad);    }}
 |