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.

55 lines
1.7 KiB

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UltraCombos;
using UnityEngine;
using UnityEngine.EventSystems;
public class FlakeSpawner : MonoBehaviour
{
// Start is called before the first frame update
public Rect roiFilterSrc;
public Rect roiFilterDst;
public GameObject prefab;
public DShowClip[] clips;
void Update()
{
if (EventSystem.current == null || EventSystem.current.currentInputModule == null)
return;
BaseInput input = EventSystem.current.currentInputModule.input;
if (input.GetMouseButton(0))
{
TrySpawn(input.mousePosition);
}
for (int i = 0; i < input.touchCount; i++)
{
Touch t = input.GetTouch(i);
TrySpawn(t.position);
}
}
List<RaycastResult> raycastResults = new List<RaycastResult>();
void TrySpawn(Vector2 position)
{
position = Rect.PointToNormalized(roiFilterSrc, position);
position = Rect.NormalizedToPoint(roiFilterDst, position);
PointerEventData data = new PointerEventData(EventSystem.current);
data.position = position;
raycastResults.Clear();
EventSystem.current.RaycastAll(data, raycastResults);
bool found = raycastResults.Select(r => r.gameObject.layer == LayerMask.NameToLayer("Flake")).Any(b => b);
if (found)
return;
GameObject obj = Instantiate(prefab, transform.parent);
(obj.transform as RectTransform).anchoredPosition = position;
obj.GetComponent<DShowPooledMoviePlayer>().VideoAsset = clips[Random.Range(0, clips.Length)];
obj.SetActive(true);
}
}