ParticleEffectForUGUI/Samples~/Demo/Scripts/UIParticle_Demo.cs

181 lines
5.3 KiB
C#
Raw Normal View History

2022-06-09 00:50:36 +08:00
using UnityEngine;
2023-08-17 08:43:02 +08:00
using UnityEngine.Serialization;
2022-06-09 00:50:36 +08:00
using UnityEngine.UI;
namespace Coffee.UIExtensions.Demo
{
public class UIParticle_Demo : MonoBehaviour
{
2023-08-17 08:43:02 +08:00
[FormerlySerializedAs("root")]
[SerializeField]
private Canvas m_RootCanvas;
2022-06-09 00:50:36 +08:00
private int _height;
2023-08-17 08:43:02 +08:00
private int _score;
private int _width;
2022-06-09 00:50:36 +08:00
private void Start()
{
_width = Screen.width;
_height = Screen.height;
}
public void ResizeScreen()
{
switch (Application.platform)
{
case RuntimePlatform.OSXPlayer:
case RuntimePlatform.WindowsPlayer:
case RuntimePlatform.LinuxPlayer:
if (Screen.width == _width && Screen.height == _height)
2023-08-17 08:43:02 +08:00
{
2022-06-09 00:50:36 +08:00
Screen.SetResolution(_height, _width, Screen.fullScreen);
2023-08-17 08:43:02 +08:00
}
2022-06-09 00:50:36 +08:00
else if (Screen.width == _height && Screen.height == _width)
2023-08-17 08:43:02 +08:00
{
2022-06-09 00:50:36 +08:00
Screen.SetResolution(Mathf.Min(_width, _height), Mathf.Min(_width, _height), Screen.fullScreen);
2023-08-17 08:43:02 +08:00
}
2022-06-09 00:50:36 +08:00
else
2023-08-17 08:43:02 +08:00
{
2022-06-09 00:50:36 +08:00
Screen.SetResolution(_width, _height, Screen.fullScreen);
2023-08-17 08:43:02 +08:00
}
2022-06-09 00:50:36 +08:00
break;
}
}
public void FullScreen()
{
Screen.fullScreen = !Screen.fullScreen;
}
2023-08-17 08:43:02 +08:00
public void EnableAnimations(bool flag)
2022-06-09 00:50:36 +08:00
{
foreach (var animator in FindObjectsOfType<Animator>())
{
2023-08-17 08:43:02 +08:00
animator.enabled = flag;
2022-06-09 00:50:36 +08:00
}
}
2023-08-17 08:43:02 +08:00
public void UIParticle_MeshSharing(bool flag)
2022-06-09 00:50:36 +08:00
{
2023-08-17 08:43:02 +08:00
foreach (var uip in m_RootCanvas.GetComponentsInChildren<UIParticle>(true))
2022-06-09 00:50:36 +08:00
{
2023-08-17 08:43:02 +08:00
uip.meshSharing = flag
? UIParticle.MeshSharing.Auto
: UIParticle.MeshSharing.None;
2022-06-09 00:50:36 +08:00
}
}
2023-08-17 08:43:02 +08:00
public void UIParticle_RandomGroup(bool flag)
2022-06-09 00:50:36 +08:00
{
2023-08-17 08:43:02 +08:00
foreach (var uip in m_RootCanvas.GetComponentsInChildren<UIParticle>(true))
2022-06-09 00:50:36 +08:00
{
2023-08-17 08:43:02 +08:00
uip.groupMaxId = flag
? 4
: 0;
2022-06-09 00:50:36 +08:00
}
}
public void UIParticle_Scale(float scale)
{
foreach (var uip in FindObjectsOfType<UIParticle>())
{
uip.scale = scale;
}
}
2023-08-17 08:43:02 +08:00
public void ParticleSystem_WorldSpaseSimulation(bool flag)
2022-06-09 00:50:36 +08:00
{
2023-08-17 08:43:02 +08:00
foreach (var p in FindObjectsOfType<ParticleSystem>())
2022-06-09 00:50:36 +08:00
{
2023-08-17 08:43:02 +08:00
var main = p.main;
main.simulationSpace = flag
? ParticleSystemSimulationSpace.World
: ParticleSystemSimulationSpace.Local;
2022-06-09 00:50:36 +08:00
}
}
2023-08-17 08:43:02 +08:00
public void ParticleSystem_WorldSpaseSimulation(ParticleSystem ps)
2022-06-09 00:50:36 +08:00
{
2023-08-17 08:43:02 +08:00
foreach (var p in ps.GetComponentsInChildren<ParticleSystem>())
2022-06-09 00:50:36 +08:00
{
2023-08-17 08:43:02 +08:00
var main = p.main;
2022-06-09 00:50:36 +08:00
main.simulationSpace = ParticleSystemSimulationSpace.World;
2023-08-17 08:43:02 +08:00
p.Clear();
2022-06-09 00:50:36 +08:00
}
}
2023-08-17 08:43:02 +08:00
public void ParticleSystem_LocalSpaseSimulation(ParticleSystem ps)
2022-06-09 00:50:36 +08:00
{
2023-08-17 08:43:02 +08:00
foreach (var p in ps.GetComponentsInChildren<ParticleSystem>())
2022-06-09 00:50:36 +08:00
{
2023-08-17 08:43:02 +08:00
var main = p.main;
2022-06-09 00:50:36 +08:00
main.simulationSpace = ParticleSystemSimulationSpace.Local;
2023-08-17 08:43:02 +08:00
p.Clear();
2022-06-09 00:50:36 +08:00
}
}
2023-08-17 08:43:02 +08:00
public void ParticleSystem_Emit(ParticleSystem ps)
2022-06-09 00:50:36 +08:00
{
2023-08-17 08:43:02 +08:00
ps.Emit(5);
2022-06-09 00:50:36 +08:00
}
public void ParticleSystem_SetScale(float scale)
{
foreach (var ps in FindObjectsOfType<ParticleSystem>())
{
ps.transform.localScale = new Vector3(scale, scale, scale);
}
}
public void UIParticleAttractor_Linear(UIParticleAttractor attractor)
{
attractor.movement = UIParticleAttractor.Movement.Linear;
}
public void UIParticleAttractor_Smooth(UIParticleAttractor attractor)
{
attractor.movement = UIParticleAttractor.Movement.Smooth;
}
public void UIParticleAttractor_Sphere(UIParticleAttractor attractor)
{
attractor.movement = UIParticleAttractor.Movement.Sphere;
}
public void UIParticleAttractor_OnAttract(Text scoreText)
{
2023-08-17 08:43:02 +08:00
_score++;
scoreText.text = _score.ToString();
2022-06-09 00:50:36 +08:00
scoreText.GetComponent<Animator>().Play(0);
}
public void Canvas_WorldSpace(bool flag)
{
2023-08-17 08:43:02 +08:00
if (!flag) return;
var canvas = FindObjectOfType<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceCamera;
canvas.renderMode = RenderMode.WorldSpace;
canvas.transform.rotation = Quaternion.Euler(new Vector3(0, 10, 0));
2022-06-09 00:50:36 +08:00
}
public void Canvas_CameraSpace(bool flag)
{
2023-08-17 08:43:02 +08:00
if (!flag) return;
var canvas = FindObjectOfType<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceCamera;
2022-06-09 00:50:36 +08:00
}
public void Canvas_Overlay(bool flag)
{
2023-08-17 08:43:02 +08:00
if (!flag) return;
var canvas = FindObjectOfType<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
2022-06-09 00:50:36 +08:00
}
}
}