You've already forked ParticleEffectForUGUI
mirror of
https://github.com/mob-sakai/ParticleEffectForUGUI.git
synced 2026-05-14 20:20:06 +00:00
resharp
This commit is contained in:
@@ -1,25 +1,31 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace Coffee.UIExtensions.Demo
|
||||
{
|
||||
public class CopyItemOnStart : MonoBehaviour
|
||||
{
|
||||
public GameObject origin;
|
||||
public int count;
|
||||
[FormerlySerializedAs("origin")]
|
||||
[SerializeField]
|
||||
private GameObject m_Origin;
|
||||
|
||||
[FormerlySerializedAs("count")]
|
||||
[SerializeField]
|
||||
private int m_Count;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (!origin) return;
|
||||
origin.SetActive(false);
|
||||
if (!m_Origin) return;
|
||||
m_Origin.SetActive(false);
|
||||
|
||||
var parent = origin.transform.parent;
|
||||
for (var i = 0; i < count; i++)
|
||||
var parent = m_Origin.transform.parent;
|
||||
for (var i = 0; i < m_Count; i++)
|
||||
{
|
||||
var go = Instantiate(origin, parent, false);
|
||||
go.name = string.Format("{0} {1}", origin.name, i + 1);
|
||||
var go = Instantiate(m_Origin, parent, false);
|
||||
go.name = $"{m_Origin.name} {i + 1}";
|
||||
go.hideFlags = HideFlags.DontSave;
|
||||
go.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,31 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
public class UIElementDragger : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
||||
{
|
||||
public enum Target
|
||||
{
|
||||
Self,
|
||||
Parent,
|
||||
Custom,
|
||||
}
|
||||
[SerializeField]
|
||||
private Target m_Target;
|
||||
|
||||
private RectTransform rectTransform;
|
||||
private Canvas canvas;
|
||||
public Target m_Target;
|
||||
public Transform m_CustomTarget;
|
||||
public bool ex2;
|
||||
[SerializeField]
|
||||
private Transform m_CustomTarget;
|
||||
|
||||
[FormerlySerializedAs("ex2")]
|
||||
[SerializeField]
|
||||
private bool m_UseCanvasScale;
|
||||
|
||||
private Canvas _canvas;
|
||||
private RectTransform _rectTransform;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
rectTransform = GetComponent<RectTransform>();
|
||||
canvas = GetComponentInParent<Canvas>();
|
||||
_rectTransform = GetComponent<RectTransform>();
|
||||
_canvas = GetComponentInParent<Canvas>();
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
@@ -29,57 +35,59 @@ public class UIElementDragger : MonoBehaviour, IBeginDragHandler, IDragHandler,
|
||||
switch (m_Target)
|
||||
{
|
||||
case Target.Self:
|
||||
rectTransform.localPosition += delta;
|
||||
_rectTransform.localPosition += delta;
|
||||
break;
|
||||
case Target.Parent:
|
||||
rectTransform.parent.localPosition += delta;
|
||||
_rectTransform.parent.localPosition += delta;
|
||||
break;
|
||||
case Target.Custom:
|
||||
rectTransform.localPosition += delta;
|
||||
_rectTransform.localPosition += delta;
|
||||
if (m_CustomTarget)
|
||||
{
|
||||
if (ex2)
|
||||
delta.Scale(canvas.rootCanvas.transform.localScale);
|
||||
if (m_UseCanvasScale)
|
||||
{
|
||||
delta.Scale(_canvas.rootCanvas.transform.localScale);
|
||||
}
|
||||
|
||||
m_CustomTarget.localPosition += delta;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
private Vector2 GetLocalDelta(Vector2 evDelta)
|
||||
{
|
||||
switch (canvas.renderMode)
|
||||
switch (_canvas.renderMode)
|
||||
{
|
||||
case RenderMode.ScreenSpaceOverlay:
|
||||
{
|
||||
var zero = transform.InverseTransformPoint(Vector2.zero);
|
||||
var delta = transform.InverseTransformPoint(evDelta);
|
||||
return delta - zero;
|
||||
}
|
||||
{
|
||||
var zero = transform.InverseTransformPoint(Vector2.zero);
|
||||
var delta = transform.InverseTransformPoint(evDelta);
|
||||
return delta - zero;
|
||||
}
|
||||
case RenderMode.ScreenSpaceCamera:
|
||||
{
|
||||
Vector2 zero, delta;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Vector2.zero, canvas.worldCamera, out zero);
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, evDelta, canvas.worldCamera, out delta);
|
||||
return delta - zero;
|
||||
}
|
||||
case RenderMode.WorldSpace:
|
||||
{
|
||||
Vector3 zero, delta;
|
||||
RectTransformUtility.ScreenPointToWorldPointInRectangle(rectTransform, Vector2.zero, canvas.worldCamera, out zero);
|
||||
RectTransformUtility.ScreenPointToWorldPointInRectangle(rectTransform, evDelta, canvas.worldCamera, out delta);
|
||||
return delta - zero;
|
||||
}
|
||||
{
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(_rectTransform, Vector2.zero,
|
||||
_canvas.worldCamera, out var zero);
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(_rectTransform, evDelta,
|
||||
_canvas.worldCamera, out var delta);
|
||||
return delta - zero;
|
||||
}
|
||||
default:
|
||||
throw new System.NotSupportedException();
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum Target
|
||||
{
|
||||
Self,
|
||||
Parent,
|
||||
Custom
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Coffee.UIExtensions.Demo
|
||||
{
|
||||
public class UIParticle_Demo : MonoBehaviour
|
||||
{
|
||||
public Canvas root;
|
||||
[FormerlySerializedAs("root")]
|
||||
[SerializeField]
|
||||
private Canvas m_RootCanvas;
|
||||
|
||||
private int _width;
|
||||
private int _height;
|
||||
private int _score;
|
||||
private int _width;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -24,11 +28,18 @@ namespace Coffee.UIExtensions.Demo
|
||||
case RuntimePlatform.WindowsPlayer:
|
||||
case RuntimePlatform.LinuxPlayer:
|
||||
if (Screen.width == _width && Screen.height == _height)
|
||||
{
|
||||
Screen.SetResolution(_height, _width, Screen.fullScreen);
|
||||
}
|
||||
else if (Screen.width == _height && Screen.height == _width)
|
||||
{
|
||||
Screen.SetResolution(Mathf.Min(_width, _height), Mathf.Min(_width, _height), Screen.fullScreen);
|
||||
}
|
||||
else
|
||||
{
|
||||
Screen.SetResolution(_width, _height, Screen.fullScreen);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -38,27 +49,31 @@ namespace Coffee.UIExtensions.Demo
|
||||
Screen.fullScreen = !Screen.fullScreen;
|
||||
}
|
||||
|
||||
public void EnableAnimations(bool enabled)
|
||||
public void EnableAnimations(bool flag)
|
||||
{
|
||||
foreach (var animator in FindObjectsOfType<Animator>())
|
||||
{
|
||||
animator.enabled = enabled;
|
||||
animator.enabled = flag;
|
||||
}
|
||||
}
|
||||
|
||||
public void UIParticle_MeshSharing(bool enabled)
|
||||
public void UIParticle_MeshSharing(bool flag)
|
||||
{
|
||||
foreach (var uip in root.GetComponentsInChildren<UIParticle>(true))
|
||||
foreach (var uip in m_RootCanvas.GetComponentsInChildren<UIParticle>(true))
|
||||
{
|
||||
uip.meshSharing = enabled ? UIParticle.MeshSharing.Auto : UIParticle.MeshSharing.None;
|
||||
uip.meshSharing = flag
|
||||
? UIParticle.MeshSharing.Auto
|
||||
: UIParticle.MeshSharing.None;
|
||||
}
|
||||
}
|
||||
|
||||
public void UIParticle_RandomGroup(bool enabled)
|
||||
public void UIParticle_RandomGroup(bool flag)
|
||||
{
|
||||
foreach (var uip in root.GetComponentsInChildren<UIParticle>(true))
|
||||
foreach (var uip in m_RootCanvas.GetComponentsInChildren<UIParticle>(true))
|
||||
{
|
||||
uip.groupMaxId = enabled ? 4 : 0;
|
||||
uip.groupMaxId = flag
|
||||
? 4
|
||||
: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,38 +85,40 @@ namespace Coffee.UIExtensions.Demo
|
||||
}
|
||||
}
|
||||
|
||||
public void ParticleSystem_WorldSpaseSimulation(bool enabled)
|
||||
public void ParticleSystem_WorldSpaseSimulation(bool flag)
|
||||
{
|
||||
foreach (var ps in FindObjectsOfType<ParticleSystem>())
|
||||
foreach (var p in FindObjectsOfType<ParticleSystem>())
|
||||
{
|
||||
var main = ps.main;
|
||||
main.simulationSpace = enabled ? ParticleSystemSimulationSpace.World : ParticleSystemSimulationSpace.Local;
|
||||
var main = p.main;
|
||||
main.simulationSpace = flag
|
||||
? ParticleSystemSimulationSpace.World
|
||||
: ParticleSystemSimulationSpace.Local;
|
||||
}
|
||||
}
|
||||
|
||||
public void ParticleSystem_WorldSpaseSimulation(ParticleSystem particleSystem)
|
||||
public void ParticleSystem_WorldSpaseSimulation(ParticleSystem ps)
|
||||
{
|
||||
foreach (var ps in particleSystem.GetComponentsInChildren<ParticleSystem>())
|
||||
foreach (var p in ps.GetComponentsInChildren<ParticleSystem>())
|
||||
{
|
||||
var main = ps.main;
|
||||
var main = p.main;
|
||||
main.simulationSpace = ParticleSystemSimulationSpace.World;
|
||||
ps.Clear();
|
||||
p.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void ParticleSystem_LocalSpaseSimulation(ParticleSystem particleSystem)
|
||||
public void ParticleSystem_LocalSpaseSimulation(ParticleSystem ps)
|
||||
{
|
||||
foreach (var ps in particleSystem.GetComponentsInChildren<ParticleSystem>())
|
||||
foreach (var p in ps.GetComponentsInChildren<ParticleSystem>())
|
||||
{
|
||||
var main = ps.main;
|
||||
var main = p.main;
|
||||
main.simulationSpace = ParticleSystemSimulationSpace.Local;
|
||||
ps.Clear();
|
||||
p.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void ParticleSystem_Emit(ParticleSystem particleSystem)
|
||||
public void ParticleSystem_Emit(ParticleSystem ps)
|
||||
{
|
||||
particleSystem.Emit(5);
|
||||
ps.Emit(5);
|
||||
}
|
||||
|
||||
public void ParticleSystem_SetScale(float scale)
|
||||
@@ -127,41 +144,37 @@ namespace Coffee.UIExtensions.Demo
|
||||
attractor.movement = UIParticleAttractor.Movement.Sphere;
|
||||
}
|
||||
|
||||
int score = 0;
|
||||
public void UIParticleAttractor_OnAttract(Text scoreText)
|
||||
{
|
||||
score++;
|
||||
scoreText.text = score.ToString();
|
||||
_score++;
|
||||
scoreText.text = _score.ToString();
|
||||
scoreText.GetComponent<Animator>().Play(0);
|
||||
}
|
||||
|
||||
public void Canvas_WorldSpace(bool flag)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
var canvas = FindObjectOfType<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceCamera;
|
||||
canvas.renderMode = RenderMode.WorldSpace;
|
||||
canvas.transform.rotation = Quaternion.Euler(new Vector3(0, 10, 0));
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
public void Canvas_CameraSpace(bool flag)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
var canvas = FindObjectOfType<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceCamera;
|
||||
}
|
||||
if (!flag) return;
|
||||
|
||||
var canvas = FindObjectOfType<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceCamera;
|
||||
}
|
||||
|
||||
public void Canvas_Overlay(bool flag)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
var canvas = FindObjectOfType<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
}
|
||||
if (!flag) return;
|
||||
|
||||
var canvas = FindObjectOfType<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,37 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace Coffee.UIExtensions.Demo
|
||||
{
|
||||
public class UIParticle_Demo_UIParticleController : MonoBehaviour
|
||||
{
|
||||
public Transform root;
|
||||
[FormerlySerializedAs("root")]
|
||||
[SerializeField]
|
||||
private Transform m_RootTransform;
|
||||
|
||||
public void UIParticle_MeshSharing(bool enabled)
|
||||
public void UIParticle_MeshSharing(bool flag)
|
||||
{
|
||||
foreach (var uip in root.GetComponentsInChildren<UIParticle>(true))
|
||||
foreach (var uip in m_RootTransform.GetComponentsInChildren<UIParticle>(true))
|
||||
{
|
||||
uip.meshSharing = enabled ? UIParticle.MeshSharing.Auto : UIParticle.MeshSharing.None;
|
||||
uip.meshSharing = flag
|
||||
? UIParticle.MeshSharing.Auto
|
||||
: UIParticle.MeshSharing.None;
|
||||
}
|
||||
}
|
||||
|
||||
public void UIParticle_RandomGroup(bool enabled)
|
||||
public void UIParticle_RandomGroup(bool flag)
|
||||
{
|
||||
foreach (var uip in root.GetComponentsInChildren<UIParticle>(true))
|
||||
foreach (var uip in m_RootTransform.GetComponentsInChildren<UIParticle>(true))
|
||||
{
|
||||
uip.groupMaxId = enabled ? 4 : 0;
|
||||
uip.groupMaxId = flag
|
||||
? 4
|
||||
: 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void UIParticle_Scale(float scale)
|
||||
{
|
||||
foreach (var uip in root.GetComponentsInChildren<UIParticle>(true))
|
||||
foreach (var uip in m_RootTransform.GetComponentsInChildren<UIParticle>(true))
|
||||
{
|
||||
uip.scale = scale;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user