架构大更
This commit is contained in:
@@ -3,6 +3,7 @@ using System;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -17,27 +18,27 @@ namespace Kamgam.UGUIParticles
|
||||
public const string AssetLink = "https://assetstore.unity.com/packages/slug/274456";
|
||||
|
||||
public static string _assetRootPathDefault = "Assets/Kamgam/UGUIParticles/";
|
||||
|
||||
public static string ExamplePath = AssetRootPath + "Examples/UGUIParticlesDemo.unity";
|
||||
|
||||
public static string AssetRootPath
|
||||
{
|
||||
get
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (System.IO.File.Exists(_assetRootPathDefault))
|
||||
{
|
||||
return _assetRootPathDefault;
|
||||
}
|
||||
if (File.Exists(_assetRootPathDefault)) return _assetRootPathDefault;
|
||||
|
||||
// The the tool was moved then search for the installer script and derive the root
|
||||
// path from there. Used Assets/ as ultimate fallback.
|
||||
string finalPath = "Assets/";
|
||||
string assetRootPathRelative = _assetRootPathDefault.Replace("Assets/", "");
|
||||
var finalPath = "Assets/";
|
||||
var assetRootPathRelative = _assetRootPathDefault.Replace("Assets/", "");
|
||||
var installerGUIDS = AssetDatabase.FindAssets("t:Script Installer");
|
||||
foreach (var guid in installerGUIDS)
|
||||
{
|
||||
var path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
if (path.Contains(assetRootPathRelative))
|
||||
{
|
||||
int index = path.IndexOf(assetRootPathRelative);
|
||||
var index = path.IndexOf(assetRootPathRelative);
|
||||
return path.Substring(0, index) + assetRootPathRelative;
|
||||
}
|
||||
}
|
||||
@@ -49,32 +50,6 @@ namespace Kamgam.UGUIParticles
|
||||
}
|
||||
}
|
||||
|
||||
public static string ExamplePath = AssetRootPath + "Examples/UGUIParticlesDemo.unity";
|
||||
|
||||
public static Version GetVersion() => new Version(Version);
|
||||
|
||||
[UnityEditor.Callbacks.DidReloadScripts(998001)]
|
||||
public static void InstallIfNeeded()
|
||||
{
|
||||
bool versionChanged = VersionHelper.UpgradeVersion(GetVersion, out Version oldVersion, out Version newVersion);
|
||||
if (versionChanged)
|
||||
{
|
||||
if (versionChanged)
|
||||
{
|
||||
Debug.Log(AssetName + " version changed from " + oldVersion + " to " + newVersion);
|
||||
|
||||
if (AddDefineSymbol())
|
||||
{
|
||||
CrossCompileCallbacks.RegisterCallback(showWelcomeMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
showWelcomeMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int callbackOrder => 0;
|
||||
|
||||
public void OnActiveBuildTargetChanged(BuildTarget previousTarget, BuildTarget newTarget)
|
||||
@@ -83,6 +58,27 @@ namespace Kamgam.UGUIParticles
|
||||
AddDefineSymbol();
|
||||
}
|
||||
|
||||
public static Version GetVersion()
|
||||
{
|
||||
return new Version(Version);
|
||||
}
|
||||
|
||||
[DidReloadScripts(998001)]
|
||||
public static void InstallIfNeeded()
|
||||
{
|
||||
var versionChanged = VersionHelper.UpgradeVersion(GetVersion, out var oldVersion, out var newVersion);
|
||||
if (versionChanged)
|
||||
if (versionChanged)
|
||||
{
|
||||
Debug.Log(AssetName + " version changed from " + oldVersion + " to " + newVersion);
|
||||
|
||||
if (AddDefineSymbol())
|
||||
CrossCompileCallbacks.RegisterCallback(showWelcomeMessage);
|
||||
else
|
||||
showWelcomeMessage();
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Tools/" + AssetName + "/Debug/Add Defines", priority = 501)]
|
||||
private static void AddDefineSymbolMenu()
|
||||
{
|
||||
@@ -91,9 +87,9 @@ namespace Kamgam.UGUIParticles
|
||||
|
||||
private static bool AddDefineSymbol()
|
||||
{
|
||||
bool didChange = false;
|
||||
var didChange = false;
|
||||
|
||||
foreach (BuildTargetGroup targetGroup in System.Enum.GetValues(typeof(BuildTargetGroup)))
|
||||
foreach (BuildTargetGroup targetGroup in Enum.GetValues(typeof(BuildTargetGroup)))
|
||||
{
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
if (targetGroup == BuildTargetGroup.Unknown || targetGroup == BuildTargetGroup.GameCoreScarlett)
|
||||
@@ -103,7 +99,8 @@ namespace Kamgam.UGUIParticles
|
||||
try
|
||||
{
|
||||
#if UNITY_2023_1_OR_NEWER
|
||||
string currentDefineSymbols = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(targetGroup));
|
||||
var currentDefineSymbols =
|
||||
PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(targetGroup));
|
||||
#else
|
||||
string currentDefineSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup);
|
||||
#endif
|
||||
@@ -112,7 +109,8 @@ namespace Kamgam.UGUIParticles
|
||||
continue;
|
||||
|
||||
#if UNITY_2023_1_OR_NEWER
|
||||
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(targetGroup), currentDefineSymbols + ";" + Define);
|
||||
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(targetGroup),
|
||||
currentDefineSymbols + ";" + Define);
|
||||
#else
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, currentDefineSymbols + ";" + Define);
|
||||
#endif
|
||||
@@ -132,7 +130,7 @@ namespace Kamgam.UGUIParticles
|
||||
[MenuItem("Tools/" + AssetName + "/Debug/Remove Defines", priority = 502)]
|
||||
private static void RemoveDefineSymbol()
|
||||
{
|
||||
foreach (BuildTargetGroup targetGroup in System.Enum.GetValues(typeof(BuildTargetGroup)))
|
||||
foreach (BuildTargetGroup targetGroup in Enum.GetValues(typeof(BuildTargetGroup)))
|
||||
{
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
if (targetGroup == BuildTargetGroup.Unknown || targetGroup == BuildTargetGroup.GameCoreScarlett)
|
||||
@@ -142,7 +140,8 @@ namespace Kamgam.UGUIParticles
|
||||
try
|
||||
{
|
||||
#if UNITY_2023_1_OR_NEWER
|
||||
string currentDefineSymbols = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(targetGroup));
|
||||
var currentDefineSymbols =
|
||||
PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(targetGroup));
|
||||
#else
|
||||
string currentDefineSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup);
|
||||
#endif
|
||||
@@ -151,7 +150,8 @@ namespace Kamgam.UGUIParticles
|
||||
{
|
||||
currentDefineSymbols = currentDefineSymbols.Replace(";" + Define, "");
|
||||
#if UNITY_2023_1_OR_NEWER
|
||||
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(targetGroup), currentDefineSymbols);
|
||||
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(targetGroup),
|
||||
currentDefineSymbols);
|
||||
#else
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, currentDefineSymbols);
|
||||
#endif
|
||||
@@ -162,20 +162,19 @@ namespace Kamgam.UGUIParticles
|
||||
{
|
||||
// There are many obsolete defines in the enum, skip them silently.
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void showWelcomeMessage()
|
||||
private static void showWelcomeMessage()
|
||||
{
|
||||
bool openExample = EditorUtility.DisplayDialog(
|
||||
AssetName,
|
||||
"Thank you for choosing " + AssetName + ".\n\n" +
|
||||
"Please start by reading the manual.\n\n" +
|
||||
"If you can find the time I would appreciate your feedback in the form of a review.\n\n" +
|
||||
"I have prepared some examples for you.",
|
||||
"Open Example", "Open manual (web)"
|
||||
);
|
||||
var openExample = EditorUtility.DisplayDialog(
|
||||
AssetName,
|
||||
"Thank you for choosing " + AssetName + ".\n\n" +
|
||||
"Please start by reading the manual.\n\n" +
|
||||
"If you can find the time I would appreciate your feedback in the form of a review.\n\n" +
|
||||
"I have prepared some examples for you.",
|
||||
"Open Example", "Open manual (web)"
|
||||
);
|
||||
|
||||
if (openExample)
|
||||
OpenExample();
|
||||
@@ -193,7 +192,7 @@ namespace Kamgam.UGUIParticles
|
||||
[MenuItem("Tools/" + AssetName + "/Open Example Scene", priority = 103)]
|
||||
public static void OpenExample()
|
||||
{
|
||||
EditorApplication.delayCall += () =>
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
var scene = AssetDatabase.LoadAssetAtPath<SceneAsset>(ExamplePath);
|
||||
EditorGUIUtility.PingObject(scene);
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Kamgam.UGUIParticles
|
||||
{
|
||||
public partial class ParticleSystemForImage // .Attractor
|
||||
{
|
||||
[System.NonSerialized]
|
||||
protected ParticleSystemForceField _particleSystemForceField;
|
||||
private RectTransform _attractorRect;
|
||||
|
||||
[NonSerialized] protected ParticleSystemForceField _particleSystemForceField;
|
||||
|
||||
public ParticleSystemForceField ParticleSystemForceField
|
||||
{
|
||||
get
|
||||
@@ -16,9 +17,8 @@ namespace Kamgam.UGUIParticles
|
||||
return null;
|
||||
|
||||
if (_particleSystemForceField == null)
|
||||
{
|
||||
_particleSystemForceField = ParticleSystem.gameObject.GetComponentInChildren<ParticleSystemForceField>(includeInactive: true);
|
||||
}
|
||||
_particleSystemForceField =
|
||||
ParticleSystem.gameObject.GetComponentInChildren<ParticleSystemForceField>(true);
|
||||
|
||||
return _particleSystemForceField;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ namespace Kamgam.UGUIParticles
|
||||
return;
|
||||
|
||||
// Find or create force field
|
||||
var forceField = ParticleSystem.gameObject.GetComponentInChildren<ParticleSystemForceField>(includeInactive: true);
|
||||
var forceField = ParticleSystem.gameObject.GetComponentInChildren<ParticleSystemForceField>(true);
|
||||
|
||||
var forces = ParticleSystem.externalForces;
|
||||
forces.enabled = true;
|
||||
@@ -62,6 +62,7 @@ namespace Kamgam.UGUIParticles
|
||||
forceField.multiplyDragByParticleSize = false;
|
||||
go.SetActive(true);
|
||||
}
|
||||
|
||||
if (forces.influenceCount > 0)
|
||||
forces.SetInfluence(0, forceField);
|
||||
else
|
||||
@@ -80,19 +81,16 @@ namespace Kamgam.UGUIParticles
|
||||
var forces = ParticleSystem.externalForces;
|
||||
forces.enabled = false;
|
||||
|
||||
var forceField = ParticleSystem.gameObject.GetComponentInChildren<ParticleSystemForceField>(includeInactive: true);
|
||||
if (forceField != null)
|
||||
{
|
||||
forceField.gameObject.SetActive(false);
|
||||
}
|
||||
var forceField = ParticleSystem.gameObject.GetComponentInChildren<ParticleSystemForceField>(true);
|
||||
if (forceField != null) forceField.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
RectTransform _attractorRect;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="originRelativeToBottomLeft">The origin of the particles relative to the bottom left of the ParticleImage rect.</param>
|
||||
/// <param name="originRelativeToBottomLeft">
|
||||
/// The origin of the particles relative to the bottom left of the ParticleImage
|
||||
/// rect.
|
||||
/// </param>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
public void UpdateAttractorPosition(Vector3 originRelativeToBottomLeft, float width, float height)
|
||||
@@ -102,12 +100,11 @@ namespace Kamgam.UGUIParticles
|
||||
DisableAttractor();
|
||||
return;
|
||||
}
|
||||
else if(UseAttractor && Attractor && !ParticleSystemForceField.gameObject.activeSelf)
|
||||
{
|
||||
EnableAttractor();
|
||||
}
|
||||
|
||||
if (!UseAttractor || ParticleImage == null || ParticleSystem == null || ParticleSystemForceField == null || Attractor == null)
|
||||
if (UseAttractor && Attractor && !ParticleSystemForceField.gameObject.activeSelf) EnableAttractor();
|
||||
|
||||
if (!UseAttractor || ParticleImage == null || ParticleSystem == null || ParticleSystemForceField == null ||
|
||||
Attractor == null)
|
||||
return;
|
||||
|
||||
if (_attractorRect != Attractor)
|
||||
@@ -120,24 +117,23 @@ namespace Kamgam.UGUIParticles
|
||||
|
||||
Vector3 attractorDeltaToBottomLeft;
|
||||
if (_attractorRect != null)
|
||||
{
|
||||
attractorDeltaToBottomLeft = ParticleImage.WorldSpaceToUISpace(_attractorRect.TransformPoint(_attractorRect.rect.center), worldPosFromRect: true, ParticleImage.RectTransform, ParticleImage.GetRenderMode());
|
||||
}
|
||||
attractorDeltaToBottomLeft = ParticleImage.WorldSpaceToUISpace(
|
||||
_attractorRect.TransformPoint(_attractorRect.rect.center), true, ParticleImage.RectTransform,
|
||||
ParticleImage.GetRenderMode());
|
||||
else
|
||||
{
|
||||
attractorDeltaToBottomLeft = ParticleImage.WorldSpaceToUISpace(Attractor, ParticleImage.RectTransform, ParticleImage.GetRenderMode());
|
||||
}
|
||||
attractorDeltaToBottomLeft = ParticleImage.WorldSpaceToUISpace(Attractor, ParticleImage.RectTransform,
|
||||
ParticleImage.GetRenderMode());
|
||||
|
||||
Vector3 pixelsPerUnitScaled = new Vector3(
|
||||
var pixelsPerUnitScaled = new Vector3(
|
||||
PixelsPerUnit * ParticleImage.transform.lossyScale.x,
|
||||
PixelsPerUnit * ParticleImage.transform.lossyScale.y,
|
||||
PixelsPerUnit * ParticleImage.transform.lossyScale.z
|
||||
);
|
||||
Vector3 deltaInWorldSpace = (attractorDeltaToBottomLeft - originRelativeToBottomLeft);
|
||||
var deltaInWorldSpace = attractorDeltaToBottomLeft - originRelativeToBottomLeft;
|
||||
deltaInWorldSpace.x /= pixelsPerUnitScaled.x;
|
||||
deltaInWorldSpace.y /= pixelsPerUnitScaled.y;
|
||||
deltaInWorldSpace.z /= pixelsPerUnitScaled.z;
|
||||
ParticleSystemForceField.gameObject.transform.localPosition = deltaInWorldSpace;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditorInternal;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
#endif
|
||||
|
||||
namespace Kamgam.UGUIParticles
|
||||
@@ -11,7 +12,195 @@ namespace Kamgam.UGUIParticles
|
||||
[RequireComponent(typeof(ParticleSystem))]
|
||||
public partial class ParticleSystemForImage : MonoBehaviour
|
||||
{
|
||||
public static Vector3 DefaultPosition = new Vector3(0f, 0f, -1000f);
|
||||
public static Vector3 DefaultPosition = new(0f, 0f, -1000f);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Should the particle system start playing whenever it is shown?
|
||||
/// </summary>
|
||||
public bool PlayOnEnable = true;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip(
|
||||
"Defines the size conversion factor from particle system units to UI reference pixels (pixels refer to the reference resolution in the CanvasScaler component).")]
|
||||
protected int _pixelsPerUnit = 50;
|
||||
|
||||
[SerializeField] protected Texture _texture;
|
||||
|
||||
[Header("Origin")]
|
||||
[SerializeField]
|
||||
[ShowIfAttribute("OriginTransform", null, ShowIfAttribute.DisablingType.ReadOnly)]
|
||||
public ParticlesOrigin _origin = ParticlesOrigin.Center;
|
||||
|
||||
[Tooltip("Specify a Transfrom or a RectTransfrom to use as the origin of particles.\n" +
|
||||
"If an origin transform is used then the value of 'Origin' is ignored. The origin will be at the center of the transform.")]
|
||||
public Transform OriginTransform;
|
||||
|
||||
[Space(4)]
|
||||
[SerializeField]
|
||||
[Tooltip(
|
||||
"The position is a delta value that is added to the origin position. It is always based on the ParticleImage RectTransform.")]
|
||||
protected float _positionX;
|
||||
|
||||
[SerializeField] protected ParticlesLengthUnit _positionXUnit = ParticlesLengthUnit.Percent;
|
||||
|
||||
[Space(4)]
|
||||
[SerializeField]
|
||||
[Tooltip(
|
||||
"The position is a delta value that is added to the origin position. It is always based on the ParticleImage RectTransform.")]
|
||||
protected float _positionY;
|
||||
|
||||
[SerializeField] protected ParticlesLengthUnit _positionYUnit = ParticlesLengthUnit.Percent;
|
||||
|
||||
[Space(4)]
|
||||
[Header("Emitter")]
|
||||
[SerializeField]
|
||||
[Tooltip(
|
||||
"Whether the shape of the particle emitter should be based on the ParticleImage rect transform or the particle system shape module.")]
|
||||
protected ParticlesEmitterShape _emitterShape = ParticlesEmitterShape.System;
|
||||
|
||||
[Header("Attractor")] [SerializeField] protected bool _useAttractor;
|
||||
|
||||
public Transform Attractor;
|
||||
|
||||
protected ParticlesEmitterShape? _lastKnownEmitterShape;
|
||||
protected ParticleSystemShapeType? _lastKnownEmitterShapeType;
|
||||
|
||||
protected ParticleImage _particleImage;
|
||||
|
||||
protected ParticleSystem _particleSystem;
|
||||
|
||||
public int PixelsPerUnit
|
||||
{
|
||||
get => _pixelsPerUnit;
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _pixelsPerUnit)
|
||||
{
|
||||
_pixelsPerUnit = value;
|
||||
ParticleImage?.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Texture Texture
|
||||
{
|
||||
get => _texture;
|
||||
set
|
||||
{
|
||||
_texture = value;
|
||||
updateTexture();
|
||||
}
|
||||
}
|
||||
|
||||
public Material Material
|
||||
{
|
||||
get => ParticleImage.material;
|
||||
set => ParticleImage.material = value;
|
||||
}
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get => ParticleImage.color;
|
||||
set => ParticleImage.color = value;
|
||||
}
|
||||
|
||||
public ParticlesOrigin Origin
|
||||
{
|
||||
get => _origin;
|
||||
set
|
||||
{
|
||||
if (_origin == value)
|
||||
return;
|
||||
|
||||
_origin = value;
|
||||
ParticleImage?.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
|
||||
public float PositionX
|
||||
{
|
||||
get => _positionX;
|
||||
set => _positionX = value;
|
||||
}
|
||||
|
||||
public ParticlesLengthUnit PositionXUnit
|
||||
{
|
||||
get => _positionXUnit;
|
||||
set => _positionXUnit = value;
|
||||
}
|
||||
|
||||
public float PositionY
|
||||
{
|
||||
get => _positionY;
|
||||
set => _positionY = value;
|
||||
}
|
||||
|
||||
public ParticlesLengthUnit PositionYUnit
|
||||
{
|
||||
get => _positionYUnit;
|
||||
set => _positionYUnit = value;
|
||||
}
|
||||
|
||||
public ParticlesEmitterShape EmitterShape
|
||||
{
|
||||
get => _emitterShape;
|
||||
|
||||
set
|
||||
{
|
||||
if (_emitterShape == value)
|
||||
return;
|
||||
|
||||
_emitterShape = value;
|
||||
UpdateEmitterShape(_emitterShape);
|
||||
}
|
||||
}
|
||||
|
||||
public bool UseAttractor
|
||||
{
|
||||
get => _useAttractor;
|
||||
set
|
||||
{
|
||||
if (value != _useAttractor)
|
||||
{
|
||||
_useAttractor = value;
|
||||
OnUseAttractorChanged(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ParticleImage ParticleImage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_particleImage == null) _particleImage = GetComponentInParent<ParticleImage>();
|
||||
return _particleImage;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsPlaying => ParticleSystem.isPlaying;
|
||||
|
||||
public ParticleSystem ParticleSystem
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_particleSystem == null && this != null) _particleSystem = GetComponent<ParticleSystem>();
|
||||
return _particleSystem;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnValidate()
|
||||
{
|
||||
if (ParticleImage != null)
|
||||
{
|
||||
updateTexture();
|
||||
UpdateEmitterShape(EmitterShape);
|
||||
ParticleImage.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public static ParticleSystemForImage CreateParticleSystemForImage(ParticleImage image)
|
||||
{
|
||||
@@ -46,11 +235,11 @@ namespace Kamgam.UGUIParticles
|
||||
go.SetActive(true); // Will trigger OnEable()
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.SetDirty(go);
|
||||
EditorUtility.SetDirty(go);
|
||||
#endif
|
||||
Logger.Log("Particle System created.");
|
||||
}
|
||||
catch (System.Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
if (go != null)
|
||||
Utils.SmartDestroy(go);
|
||||
@@ -60,201 +249,15 @@ namespace Kamgam.UGUIParticles
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// Move component up (fail silently)
|
||||
if (system != null)
|
||||
{
|
||||
EditorApplication.delayCall += () => UnityEditorInternal.ComponentUtility.MoveComponentUp(system);
|
||||
}
|
||||
if (system != null) EditorApplication.delayCall += () => ComponentUtility.MoveComponentUp(system);
|
||||
|
||||
// Auto Play
|
||||
if (system != null)
|
||||
{
|
||||
ParticleImageEditor.StartPlaying(system.ParticleImage);
|
||||
}
|
||||
if (system != null) ParticleImageEditor.StartPlaying(system.ParticleImage);
|
||||
#endif
|
||||
|
||||
return system;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Should the particle system start playing whenever it is shown?
|
||||
/// </summary>
|
||||
public bool PlayOnEnable = true;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Defines the size conversion factor from particle system units to UI reference pixels (pixels refer to the reference resolution in the CanvasScaler component).")]
|
||||
protected int _pixelsPerUnit = 50;
|
||||
public int PixelsPerUnit
|
||||
{
|
||||
get => _pixelsPerUnit;
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _pixelsPerUnit)
|
||||
{
|
||||
_pixelsPerUnit = value;
|
||||
ParticleImage?.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
protected Texture _texture;
|
||||
public Texture Texture
|
||||
{
|
||||
get => _texture;
|
||||
set
|
||||
{
|
||||
_texture = value;
|
||||
updateTexture();
|
||||
}
|
||||
}
|
||||
|
||||
public Material Material
|
||||
{
|
||||
get => ParticleImage.material;
|
||||
set
|
||||
{
|
||||
ParticleImage.material = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Color Color
|
||||
{
|
||||
get => ParticleImage.color;
|
||||
set
|
||||
{
|
||||
ParticleImage.color = value;
|
||||
}
|
||||
}
|
||||
|
||||
[Header("Origin")]
|
||||
|
||||
[SerializeField]
|
||||
[ShowIfAttribute("OriginTransform", null, ShowIfAttribute.DisablingType.ReadOnly)]
|
||||
public ParticlesOrigin _origin = ParticlesOrigin.Center;
|
||||
public ParticlesOrigin Origin
|
||||
{
|
||||
get => _origin;
|
||||
set
|
||||
{
|
||||
if (_origin == value)
|
||||
return;
|
||||
|
||||
_origin = value;
|
||||
ParticleImage?.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
|
||||
[Tooltip("Specify a Transfrom or a RectTransfrom to use as the origin of particles.\n" +
|
||||
"If an origin transform is used then the value of 'Origin' is ignored. The origin will be at the center of the transform.")]
|
||||
public Transform OriginTransform;
|
||||
|
||||
[Space(4)]
|
||||
[SerializeField]
|
||||
[Tooltip("The position is a delta value that is added to the origin position. It is always based on the ParticleImage RectTransform.")]
|
||||
protected float _positionX = 0f;
|
||||
public float PositionX
|
||||
{
|
||||
get => _positionX;
|
||||
set
|
||||
{
|
||||
_positionX = value;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
protected ParticlesLengthUnit _positionXUnit = ParticlesLengthUnit.Percent;
|
||||
public ParticlesLengthUnit PositionXUnit
|
||||
{
|
||||
get => _positionXUnit;
|
||||
set
|
||||
{
|
||||
_positionXUnit = value;
|
||||
}
|
||||
}
|
||||
|
||||
[Space(4)]
|
||||
[SerializeField]
|
||||
[Tooltip("The position is a delta value that is added to the origin position. It is always based on the ParticleImage RectTransform.")]
|
||||
protected float _positionY = 0f;
|
||||
public float PositionY
|
||||
{
|
||||
get => _positionY;
|
||||
set
|
||||
{
|
||||
_positionY = value;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
protected ParticlesLengthUnit _positionYUnit = ParticlesLengthUnit.Percent;
|
||||
public ParticlesLengthUnit PositionYUnit
|
||||
{
|
||||
get => _positionYUnit;
|
||||
set
|
||||
{
|
||||
_positionYUnit = value;
|
||||
}
|
||||
}
|
||||
[Space(4)]
|
||||
|
||||
[Header("Emitter")]
|
||||
[SerializeField]
|
||||
[Tooltip("Whether the shape of the particle emitter should be based on the ParticleImage rect transform or the particle system shape module.")]
|
||||
protected ParticlesEmitterShape _emitterShape = ParticlesEmitterShape.System;
|
||||
public ParticlesEmitterShape EmitterShape
|
||||
{
|
||||
get
|
||||
{
|
||||
return _emitterShape;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_emitterShape == value)
|
||||
return;
|
||||
|
||||
_emitterShape = value;
|
||||
UpdateEmitterShape(_emitterShape);
|
||||
}
|
||||
}
|
||||
|
||||
[Header("Attractor")]
|
||||
|
||||
[SerializeField]
|
||||
protected bool _useAttractor = false;
|
||||
public bool UseAttractor
|
||||
{
|
||||
get => _useAttractor;
|
||||
set
|
||||
{
|
||||
if (value != _useAttractor)
|
||||
{
|
||||
_useAttractor = value;
|
||||
OnUseAttractorChanged(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Transform Attractor;
|
||||
|
||||
protected ParticleImage _particleImage;
|
||||
public ParticleImage ParticleImage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_particleImage == null)
|
||||
{
|
||||
_particleImage = this.GetComponentInParent<ParticleImage>();
|
||||
}
|
||||
return _particleImage;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsPlaying => ParticleSystem.isPlaying;
|
||||
|
||||
public void Play()
|
||||
{
|
||||
ParticleSystem.Play();
|
||||
@@ -262,10 +265,7 @@ namespace Kamgam.UGUIParticles
|
||||
|
||||
protected void updateTexture()
|
||||
{
|
||||
if (ParticleImage != null)
|
||||
{
|
||||
ParticleImage.canvasRenderer.SetTexture(_texture);
|
||||
}
|
||||
if (ParticleImage != null) ParticleImage.canvasRenderer.SetTexture(_texture);
|
||||
}
|
||||
|
||||
public void Pause(bool withChildren = true)
|
||||
@@ -273,24 +273,12 @@ namespace Kamgam.UGUIParticles
|
||||
ParticleSystem.Pause(withChildren);
|
||||
}
|
||||
|
||||
public void Stop(bool withChildren = true, ParticleSystemStopBehavior stopBehaviour = ParticleSystemStopBehavior.StopEmitting)
|
||||
public void Stop(bool withChildren = true,
|
||||
ParticleSystemStopBehavior stopBehaviour = ParticleSystemStopBehavior.StopEmitting)
|
||||
{
|
||||
ParticleSystem.Stop(withChildren, stopBehaviour);
|
||||
}
|
||||
|
||||
protected ParticleSystem _particleSystem;
|
||||
public ParticleSystem ParticleSystem
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_particleSystem == null && this != null)
|
||||
{
|
||||
_particleSystem = this.GetComponent<ParticleSystem>();
|
||||
}
|
||||
return _particleSystem;
|
||||
}
|
||||
}
|
||||
|
||||
public void InitializeAfterCreation(ParticleImage image)
|
||||
{
|
||||
// Disable renderer, we don't need it.
|
||||
@@ -340,31 +328,28 @@ namespace Kamgam.UGUIParticles
|
||||
transform.parent = null;
|
||||
}
|
||||
|
||||
static bool isEditing()
|
||||
private static bool isEditing()
|
||||
{
|
||||
#if !UNITY_EDITOR
|
||||
return false;
|
||||
#else
|
||||
return !UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode;
|
||||
return !EditorApplication.isPlayingOrWillChangePlaymode;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
static bool isInPrefabStage()
|
||||
private static bool isInPrefabStage()
|
||||
{
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
return UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage() != null;
|
||||
return PrefabStageUtility.GetCurrentPrefabStage() != null;
|
||||
#else
|
||||
return UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage() != null;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
protected ParticlesEmitterShape? _lastKnownEmitterShape = null;
|
||||
protected ParticleSystemShapeType? _lastKnownEmitterShapeType = null;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// The last emitter shape is cached and it only updates if the shape has changed or if forseRefresh is set to true.
|
||||
/// The last emitter shape is cached and it only updates if the shape has changed or if forseRefresh is set to true.
|
||||
/// </summary>
|
||||
/// <param name="shape"></param>
|
||||
/// <param name="forceRefresh"></param>
|
||||
@@ -374,7 +359,7 @@ namespace Kamgam.UGUIParticles
|
||||
return;
|
||||
|
||||
var shapeModule = ParticleSystem.shape;
|
||||
bool changed = !_lastKnownEmitterShape.HasValue || shape != _lastKnownEmitterShape.Value;
|
||||
var changed = !_lastKnownEmitterShape.HasValue || shape != _lastKnownEmitterShape.Value;
|
||||
_lastKnownEmitterShape = shape;
|
||||
|
||||
if (changed || forceRefresh)
|
||||
@@ -390,7 +375,7 @@ namespace Kamgam.UGUIParticles
|
||||
ParticleImage.Width / ParticleImage.PixelsPerUnit,
|
||||
ParticleImage.Height / ParticleImage.PixelsPerUnit,
|
||||
1.01f); // The 1.01f is used as a flag for none-user-created rect shape.
|
||||
// If the z scale is 1.01f it is assumed to have been set by this code.
|
||||
// If the z scale is 1.01f it is assumed to have been set by this code.
|
||||
|
||||
break;
|
||||
|
||||
@@ -398,7 +383,8 @@ namespace Kamgam.UGUIParticles
|
||||
default:
|
||||
// Only reset if there is a known value and it has not been changed by the user.
|
||||
// Check for 1.01 flag to determine if set by user.
|
||||
if (shapeModule.shapeType != ParticleSystemShapeType.Rectangle || !Mathf.Approximately(shapeModule.scale.z, 1.01f))
|
||||
if (shapeModule.shapeType != ParticleSystemShapeType.Rectangle ||
|
||||
!Mathf.Approximately(shapeModule.scale.z, 1.01f))
|
||||
_lastKnownEmitterShapeType = null; // Reset if user changed it
|
||||
if (_lastKnownEmitterShapeType.HasValue)
|
||||
{
|
||||
@@ -408,21 +394,10 @@ namespace Kamgam.UGUIParticles
|
||||
shapeModule.shapeType = _lastKnownEmitterShapeType.Value;
|
||||
shapeModule.scale = Vector3.one;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnValidate()
|
||||
{
|
||||
if (ParticleImage != null)
|
||||
{
|
||||
updateTexture();
|
||||
UpdateEmitterShape(EmitterShape);
|
||||
ParticleImage.MarkDirtyRepaint();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "Kamgam.UGUIParticles",
|
||||
"rootNamespace": "",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
"name": "Kamgam.UGUIParticles",
|
||||
"rootNamespace": "",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
Reference in New Issue
Block a user