You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
2.8 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FlakePosition : MonoBehaviour
{
public static FlakePosition Instance;
[AutoUI] public bool View;
[AutoUI] public Vector2 Position1;
[AutoUI] public Vector2 Position2;
[AutoUI] public Vector2 Position3;
[AutoUI] public Vector2 Position4;
[AutoUI] public Vector2 Position5;
[AutoUI] public Vector2 Position6;
[AutoUI] public bool enableFlake1;
[AutoUI] public bool enableFlake2;
[AutoUI] public bool enableFlake3;
[AutoUI] public bool enableFlake4;
[AutoUI] public bool enableFlake5;
[AutoUI] public bool enableFlake6;
[AutoUI] public bool enableFlakeLogo;
public SnowFlakeBehaviour flake1;
public SnowFlakeBehaviour flake2;
public SnowFlakeBehaviour flake3;
public SnowFlakeBehaviour flake4;
public SnowFlakeBehaviour flake5;
public SnowFlakeBehaviour flake6;
public SnowFlakeBehaviour flakeLogo;
private RawImage[] imgs;
[SerializeField] private List<int> PositionSeed = new List<int>();
// Start is called before the first frame update
void Awake()
{
Instance = this;
imgs = GetComponentsInChildren<RawImage>();
for (int seed = 1;seed <= 6; seed++)
PositionSeed.Add(seed);
}
void Start()
{
flake1.SetActive(enableFlake1);
flake2.SetActive(enableFlake2);
flake3.SetActive(enableFlake3);
flake4.SetActive(enableFlake4);
flake5.SetActive(enableFlake5);
flake6.SetActive(enableFlake6);
flakeLogo.SetActive(enableFlakeLogo);
}
// Update is called once per frame
void Update()
{
if ((Time.frameCount & 0x19) == 0)
{
SetImgEnable(View);
}
}
public void SetImgEnable(bool view)
{
for(int i = 0;i<imgs.Length;i++)
{
imgs[i].enabled = view;
imgs[i].rectTransform.anchoredPosition = GetPos(i + 1);
}
}
public int Take(out Vector2 pos)
{
var random = Random.Range(0, PositionSeed.Count);
var seed = PositionSeed[random];
Debug.Log(seed);
pos = GetPos(seed);
PositionSeed.RemoveAt(random);
return seed;
}
public void Put(int seed)
{
PositionSeed.Add(seed);
}
public Vector2 GetPos(int seed)
{
switch(seed)
{
case 1:
return Position1;
case 2:
return Position2;
case 3:
return Position3;
case 4:
return Position4;
case 5:
return Position5;
case 6:
return Position6;
}
return Vector2.zero;
}
}