added animation package and made small changes

This commit is contained in:
Lorenzo
2022-12-06 17:46:58 +01:00
parent 564ec183d7
commit 3f3323449f
3440 changed files with 12815908 additions and 344 deletions

View File

@@ -0,0 +1,363 @@
// =================================
// Namespaces.
// =================================
using UnityEngine;
using UnityEditor;
using System.Linq;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
// =================================
// Define namespace.
// =================================
namespace MirzaBeig
{
namespace EditorExtensions
{
namespace Utilities
{
// =================================
// Classes.
// =================================
//[CustomEditor(typeof(ParticlePrefab))]
//[CustomEditor(typeof(Transform))]
//[CustomEditor(typeof(ParticleSystem))]
//[CanEditMultipleObjects]
public class ParticleScalerEditorWindow : EditorWindow
{
// =================================
// Nested classes and structures.
// =================================
// ...
// =================================
// Variables.
// =================================
// Scale to apply.
float customScale = 1.0f;
// Also scale transform local position?
bool scaleTransformLocalPosition = true;
// Button sizes.
float scalePresetButtonHeight = 25.0f;
float modulePresetButtonHeight = 25.0f;
float applyCustomScaleButtonHeight = 35.0f;
// Playback.
ParticlePlayback particlePlayback = new ParticlePlayback();
// Selected objects in editor and all the particle systems components.
List<GameObject> selectedGameObjectsWithParticleSystems = new List<GameObject>();
// Particle systems and their scale values.
// I also keep last frame's particle systems because I update
// the list of particle systems on update. So clearing particles
// inside the systems may not do anything as the particles are
// updated and the list set to a length of zero before OnSelectionChange.
List<ParticleSystem> particleSystems = new List<ParticleSystem>();
List<ParticleSystem> particleSystemsFromLastFrame = new List<ParticleSystem>();
// For labeling and tooltips.
GUIContent guiContentLabel;
// =================================
// Functions.
// =================================
// ...
[MenuItem("Window/Mirza Beig/Particle Scaler")]
static void showEditor()
{
ParticleScalerEditorWindow window =
EditorWindow.GetWindow<ParticleScalerEditorWindow>(false, "Mirza Beig - Particle Scaler");
// Static init.
// ...
// Invoke non-static init.
window.initialize();
// Do a first check.
window.OnSelectionChange();
}
// Initialize.
void initialize()
{
}
// ...
void OnSelectionChange()
{
// Clear if set to clear on selection change.
if (particlePlayback.clearParticlesOnSelectionChange)
{
ParticleEditorUtility.clearParticles(particleSystems);
ParticleEditorUtility.clearParticles(particleSystemsFromLastFrame);
particlePlayback.repaintEditorCameraWindows();
}
// Pause all selected particles.
else if (!Application.isPlaying)
{
particlePlayback.pause(particleSystems);
}
// (Re-)verify current list of particles.
ParticleEditorUtility.getSelectedParticleSystems(ref particleSystems, ref selectedGameObjectsWithParticleSystems);
}
// ...
void applyScaleToAll(float scale)
{
Undo.RecordObjects(particleSystems.ToArray().Select(x => x.transform).ToArray(), "Scale Transform(s)");
saveUndo();
for (int i = 0; i < particleSystems.Count; i++)
{
particleSystems[i].scale(scale, scaleTransformLocalPosition);
particlePlayback.loopback(particleSystems[i]);
}
}
// ...
void saveUndo()
{
Undo.RecordObjects(particleSystems.ToArray(), "Scale Particle System(s)");
}
// ...
void setScalingModeForAll(ParticleSystemScalingMode mode)
{
saveUndo();
for (int i = 0; i < particleSystems.Count; i++)
{
ParticleSystem.MainModule m = particleSystems[i].main;
m.scalingMode = mode;
}
}
// ...
void OnGUI()
{
// Get windows.
particlePlayback.updateEditorCameraWindowReferences();
// Looks nicer.
EditorGUILayout.Separator();
// Scale settings.
EditorGUILayout.LabelField("- Scale Settings:", EditorStyles.boldLabel);
EditorGUILayout.Separator();
// Extension options.
guiContentLabel = new GUIContent("Scale Transform Position", "Scale local position in Transform component.");
scaleTransformLocalPosition = EditorGUILayout.Toggle(guiContentLabel, scaleTransformLocalPosition);
EditorGUILayout.Separator();
guiContentLabel = new GUIContent("Custom Scale", "ParticleSystem component scale factor.");
customScale = EditorGUILayout.Slider(guiContentLabel, customScale, 0.5f, 2.0f);
EditorGUILayout.Separator();
// Button to apply custom scale.
guiContentLabel = new GUIContent("Apply Custom Scale",
"Apply custom scaling factor to all ParticleSystem components in select GameObjects.");
if (GUILayout.Button(guiContentLabel, GUILayout.Height(applyCustomScaleButtonHeight)))
{
applyScaleToAll(customScale);
}
//EditorGUILayout.Separator();
GUI.enabled = particleSystems.Count != 0;
// Buttons for quick-apply scale factor presets.
EditorGUILayout.BeginHorizontal();
{
guiContentLabel = new GUIContent("Scale x0.5",
"Apply a preset scale factor of x0.5.");
if (GUILayout.Button(guiContentLabel, GUILayout.Height(scalePresetButtonHeight)))
{
applyScaleToAll(0.5f);
}
guiContentLabel = new GUIContent("Scale x0.75",
"Apply a preset scale factor of x0.75.");
if (GUILayout.Button(guiContentLabel, GUILayout.Height(scalePresetButtonHeight)))
{
applyScaleToAll(0.75f);
}
guiContentLabel = new GUIContent("Scale x1.5",
"Apply a preset scale factor of x1.5.");
if (GUILayout.Button(guiContentLabel, GUILayout.Height(scalePresetButtonHeight)))
{
applyScaleToAll(1.5f);
}
guiContentLabel = new GUIContent("Scale x2.0",
"Apply a preset scale factor of x2.0.");
if (GUILayout.Button(guiContentLabel, GUILayout.Height(scalePresetButtonHeight)))
{
applyScaleToAll(2.0f);
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Separator();
GUI.enabled = true;
EditorGUILayout.Separator();
// Module settings.
EditorGUILayout.LabelField("- Scale Mode Settings:", EditorStyles.boldLabel);
EditorGUILayout.Separator();
// Buttons for quick-apply scale factor presets.
EditorGUILayout.BeginHorizontal();
{
guiContentLabel = new GUIContent("Hierarchy",
"Change all particle systems to use \"Hierarchy\" as the scaling mode.");
if (GUILayout.Button(guiContentLabel, GUILayout.Height(modulePresetButtonHeight)))
{
setScalingModeForAll(ParticleSystemScalingMode.Hierarchy);
}
guiContentLabel = new GUIContent("Local",
"Change all particle systems to use \"Local\" as the scaling mode.");
if (GUILayout.Button(guiContentLabel, GUILayout.Height(modulePresetButtonHeight)))
{
setScalingModeForAll(ParticleSystemScalingMode.Local);
}
guiContentLabel = new GUIContent("Shape",
"Change all particle systems to use \"Shape\" as the scaling mode.");
if (GUILayout.Button(guiContentLabel, GUILayout.Height(modulePresetButtonHeight)))
{
setScalingModeForAll(ParticleSystemScalingMode.Shape);
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Separator();
// Playback settings.
particlePlayback.GUIPlaybackSettings(particleSystems);
EditorGUILayout.Separator();
// Selected objects.
particlePlayback.GUIParticleSelection(selectedGameObjectsWithParticleSystems);
}
// ...
void OnInspectorUpdate()
{
Repaint();
}
// ...
void Update()
{
// (Re-)verify current list of particles.
particleSystemsFromLastFrame =
new List<ParticleSystem>(particleSystems);
ParticleEditorUtility.getSelectedParticleSystems(
ref particleSystems, ref selectedGameObjectsWithParticleSystems);
particlePlayback.update(particleSystems);
}
// ...
void OnFocus()
{
// (Re-)verify current list of particles.
ParticleEditorUtility.getSelectedParticleSystems(
ref particleSystems, ref selectedGameObjectsWithParticleSystems);
}
// =================================
// End functions.
// =================================
}
// =================================
// End namespace.
// =================================
}
}
}
// =================================
// --END-- //
// =================================

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f98acd6c3adc2064d93476e8979298af
timeCreated: 1435598983
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,139 @@
// =================================
// Namespaces.
// =================================
using UnityEngine;
using UnityEditor;
// =================================
// Define namespace.
// =================================
namespace MirzaBeig
{
namespace EditorExtensions
{
namespace Utilities
{
// =================================
// Classes.
// =================================
public static class ParticleScalerExtensions
{
// =================================
// Nested classes and structures.
// =================================
// ...
// =================================
// Variables.
// =================================
// ...
// =================================
// Functions.
// =================================
// Scales against self.
public static void scale(this ParticleSystem particleSystem, float scale, bool scaleTransformLocalPosition)
{
// Transform.
if (scaleTransformLocalPosition)
{
particleSystem.transform.localPosition *= scale;
}
// Particle system.
ParticleSystem.MainModule main = particleSystem.main;
ParticleSystem.ShapeModule shape = particleSystem.shape;
ParticleSystem.VelocityOverLifetimeModule velocityOverLifetime = particleSystem.velocityOverLifetime;
ParticleSystem.LimitVelocityOverLifetimeModule limitVelocityOverLifetime = particleSystem.limitVelocityOverLifetime;
ParticleSystem.ForceOverLifetimeModule forceOverLifetime = particleSystem.forceOverLifetime;
ParticleSystem.MinMaxCurve mmCurve;
// Main.
mmCurve = main.startSpeed;
mmCurve.constantMin *= scale;
mmCurve.constantMax *= scale;
main.startSpeed = mmCurve;
mmCurve = main.startSize;
mmCurve.constantMin *= scale;
mmCurve.constantMax *= scale;
main.startSize = mmCurve;
// Shape.
shape.radius *= scale;
shape.scale *= scale;
shape.angle *= scale;
shape.randomDirectionAmount *= scale;
shape.sphericalDirectionAmount *= scale;
shape.normalOffset *= scale;
// Velocity over lifetime.
mmCurve = velocityOverLifetime.x;
mmCurve.constantMin *= scale;
mmCurve.constantMax *= scale;
velocityOverLifetime.x = mmCurve;
mmCurve = velocityOverLifetime.y;
mmCurve.constantMin *= scale;
mmCurve.constantMax *= scale;
velocityOverLifetime.y = mmCurve;
mmCurve = velocityOverLifetime.z;
mmCurve.constantMin *= scale;
mmCurve.constantMax *= scale;
velocityOverLifetime.z = mmCurve;
// Force over lifetime.
mmCurve = forceOverLifetime.x;
mmCurve.constantMin *= scale;
mmCurve.constantMax *= scale;
forceOverLifetime.x = mmCurve;
mmCurve = forceOverLifetime.y;
mmCurve.constantMin *= scale;
mmCurve.constantMax *= scale;
forceOverLifetime.y = mmCurve;
mmCurve = forceOverLifetime.z;
mmCurve.constantMin *= scale;
mmCurve.constantMax *= scale;
forceOverLifetime.z = mmCurve;
}
// =================================
// End functions.
// =================================
}
// =================================
// End namespace.
// =================================
}
}
}
// =================================
// --END-- //
// =================================

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 81e31f01d3baf154cbdef373f3613618
timeCreated: 1435598983
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: