using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class MovedMass : MonoBehaviour
{
Texture2D back, t;
public float speed = 5;
List<Diamond>[] massDiamond;
float dSize;
struct Diamond
{
public Vector3 pos;
public int num;
}
void Start()
{
Camera.main.orthographic = true;
StartCoroutine(loadTexture());
Vector2Int size = new Vector2Int(Screen.width, Screen.height);
Vector2Int halfSize = size / 2;
back = new Texture2D(size.x, size.y);
for (int iy = 0; iy < size.y; iy++)
for (int ix = 0; ix < size.x; ix++)
back.SetPixel(ix, iy, Color.Lerp(Color.red, Color.yellow, Mathf.Sqrt((ix - halfSize.x) * (ix - halfSize.x) + (iy - halfSize.y) * (iy - halfSize.y)) / 1000));
back.Apply();
dSize = Screen.height / 10;
int wCount = Screen.width / (int)(dSize * 0.7f);
int hCount = Screen.height / (int)dSize;
massDiamond = new List<Diamond>[hCount];
for (int iy = 0; iy < hCount; iy++)
{
massDiamond[iy] = new List<Diamond>();
for (int ix = 0; ix < wCount; ix++)
{
Diamond d = new Diamond();
d.num = Random.Range(0, 9);
d.pos = new Vector3(ix * -dSize * 2, iy * dSize);
massDiamond[iy].Add(d);
}
}
}
void Update()
{
for (int iy = 0; iy < massDiamond.Length; iy++)
for (int ix = 0; ix < massDiamond[0].Count; ix++)
{
Diamond d = massDiamond[iy][ix];
if(d.pos.x<Screen.width - ix * dSize)
{
Vector3 t = d.pos;
t.x += speed;
d.pos = t;
massDiamond[iy][ix] = d;
}
}
}
private void OnGUI()
{
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), back);
for (int iy = 0; iy < massDiamond.Length; iy++)
for (int ix = 0; ix < massDiamond[0].Count; ix++)
{
Vector3 pos = massDiamond[iy][ix].pos;
int n = massDiamond[iy][ix].num;
GUI.DrawTextureWithTexCoords(new Rect(pos, new Vector2(dSize,dSize)), t, new Rect((n - (n / 4 * 4)) * 0.25f, (2 - n / 4) * 0.33f, .25f, .33f));
}
}
IEnumerator loadTexture()
{
UnityWebRequest request = UnityWebRequestTexture.GetTexture("https://opengameart.org/sites/default/files/gem-7soul1_1.png");
yield return request.SendWebRequest();
if (!request.isHttpError || request.isNetworkError)
t = DownloadHandlerTexture.GetContent(request);
t.alphaIsTransparency = true;
t.filterMode = FilterMode.Point;
}
}