added animation package and made small changes
This commit is contained in:
@@ -0,0 +1,539 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class DemoManager : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
public enum ParticleMode
|
||||
{
|
||||
looping,
|
||||
oneshot,
|
||||
}
|
||||
|
||||
public enum Level
|
||||
{
|
||||
none,
|
||||
basic,
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
public Transform cameraRotationTransform;
|
||||
public Transform cameraTranslationTransform;
|
||||
|
||||
public Vector3 cameraLookAtPosition = new Vector3(0.0f, 3.0f, 0.0f);
|
||||
|
||||
public MouseFollow mouse;
|
||||
|
||||
Vector3 targetCameraPosition;
|
||||
Vector3 targetCameraRotation;
|
||||
|
||||
Vector3 cameraPositionStart;
|
||||
Vector3 cameraRotationStart;
|
||||
|
||||
Vector2 input;
|
||||
|
||||
// Because Euler angles wrap around 360, I use
|
||||
// a separate value to store the full rotation.
|
||||
|
||||
Vector3 cameraRotation;
|
||||
|
||||
public float cameraMoveAmount = 2.0f;
|
||||
public float cameraRotateAmount = 2.0f;
|
||||
|
||||
public float cameraMoveSpeed = 12.0f;
|
||||
public float cameraRotationSpeed = 12.0f;
|
||||
|
||||
public Vector2 cameraAngleLimits = new Vector2(-8.0f, 60.0f);
|
||||
|
||||
public GameObject[] levels;
|
||||
public Level currentLevel = Level.basic;
|
||||
|
||||
public ParticleMode particleMode = ParticleMode.looping;
|
||||
|
||||
public bool advancedRendering = true;
|
||||
|
||||
public Toggle loopingParticleModeToggle;
|
||||
public Toggle oneshotParticleModeToggle;
|
||||
|
||||
public Toggle advancedRenderingToggle;
|
||||
|
||||
public Toggle mouseParticlesToggle;
|
||||
|
||||
Toggle[] levelToggles;
|
||||
public ToggleGroup levelTogglesContainer;
|
||||
|
||||
LoopingParticleSystemsManager loopingParticleSystems;
|
||||
OneshotParticleSystemsManager oneshotParticleSystems;
|
||||
|
||||
public GameObject ui;
|
||||
|
||||
public Text particleCountText;
|
||||
public Text currentParticleSystemText;
|
||||
|
||||
public Text particleSpawnInstructionText;
|
||||
|
||||
public Slider timeScaleSlider;
|
||||
public Text timeScaleSliderValueText;
|
||||
|
||||
public Camera mainCamera;
|
||||
|
||||
public MonoBehaviour[] mainCameraPostEffects;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
void Awake()
|
||||
{
|
||||
loopingParticleSystems = FindObjectOfType<LoopingParticleSystemsManager>();
|
||||
oneshotParticleSystems = FindObjectOfType<OneshotParticleSystemsManager>();
|
||||
|
||||
loopingParticleSystems.Init();
|
||||
oneshotParticleSystems.Init();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Start()
|
||||
{
|
||||
// ...
|
||||
|
||||
cameraPositionStart = cameraTranslationTransform.localPosition;
|
||||
cameraRotationStart = cameraRotationTransform.localEulerAngles;
|
||||
|
||||
ResetCameraTransformTargets();
|
||||
|
||||
// ...
|
||||
|
||||
switch (particleMode)
|
||||
{
|
||||
case ParticleMode.looping:
|
||||
{
|
||||
SetToLoopingParticleMode(true);
|
||||
|
||||
loopingParticleModeToggle.isOn = true;
|
||||
oneshotParticleModeToggle.isOn = false;
|
||||
|
||||
break;
|
||||
}
|
||||
case ParticleMode.oneshot:
|
||||
{
|
||||
SetToOneshotParticleMode(true);
|
||||
|
||||
loopingParticleModeToggle.isOn = false;
|
||||
oneshotParticleModeToggle.isOn = true;
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
print("Unknown case.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
SetAdvancedRendering(advancedRendering);
|
||||
advancedRenderingToggle.isOn = advancedRendering;
|
||||
|
||||
// ...
|
||||
|
||||
levelToggles =
|
||||
levelTogglesContainer.GetComponentsInChildren<Toggle>(true);
|
||||
|
||||
for (int i = 0; i < levels.Length; i++)
|
||||
{
|
||||
// Toggle's OnValueChanged handles
|
||||
// level state. No need to SetActive().
|
||||
|
||||
if (i == (int)currentLevel)
|
||||
{
|
||||
levels[i].SetActive(true);
|
||||
levelToggles[i].isOn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
levels[i].SetActive(false);
|
||||
levelToggles[i].isOn = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
UpdateCurrentParticleSystemNameText();
|
||||
timeScaleSlider.onValueChanged.AddListener(OnTimeScaleSliderValueChanged);
|
||||
|
||||
OnTimeScaleSliderValueChanged(timeScaleSlider.value);
|
||||
|
||||
mouseParticlesToggle.isOn = mouse.gameObject.activeSelf;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void OnTimeScaleSliderValueChanged(float value)
|
||||
{
|
||||
Time.timeScale = value;
|
||||
timeScaleSliderValueText.text = value.ToString("0.00");
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void SetToLoopingParticleMode(bool set)
|
||||
{
|
||||
if (set)
|
||||
{
|
||||
oneshotParticleSystems.Clear();
|
||||
|
||||
loopingParticleSystems.gameObject.SetActive(true);
|
||||
oneshotParticleSystems.gameObject.SetActive(false);
|
||||
|
||||
particleSpawnInstructionText.gameObject.SetActive(false);
|
||||
|
||||
particleMode = ParticleMode.looping;
|
||||
|
||||
UpdateCurrentParticleSystemNameText();
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void SetToOneshotParticleMode(bool set)
|
||||
{
|
||||
if (set)
|
||||
{
|
||||
loopingParticleSystems.gameObject.SetActive(false);
|
||||
oneshotParticleSystems.gameObject.SetActive(true);
|
||||
|
||||
particleSpawnInstructionText.gameObject.SetActive(true);
|
||||
|
||||
particleMode = ParticleMode.oneshot;
|
||||
|
||||
UpdateCurrentParticleSystemNameText();
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void SetLevel(Level level)
|
||||
{
|
||||
for (int i = 0; i < levels.Length; i++)
|
||||
{
|
||||
if (i == (int)level)
|
||||
{
|
||||
levels[i].SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
levels[i].SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
currentLevel = level;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void SetLevelFromToggle(Toggle toggle)
|
||||
{
|
||||
if (toggle.isOn)
|
||||
{
|
||||
SetLevel((Level)System.Array.IndexOf(levelToggles, toggle));
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void SetAdvancedRendering(bool value)
|
||||
{
|
||||
advancedRendering = value;
|
||||
mainCamera.allowHDR = value;
|
||||
|
||||
if (value)
|
||||
{
|
||||
//QualitySettings.SetQualityLevel(32, true);
|
||||
//mainCamera.renderingPath = RenderingPath.UsePlayerSettings;
|
||||
|
||||
//mouse.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
//QualitySettings.SetQualityLevel(0, true);
|
||||
//mainCamera.renderingPath = RenderingPath.VertexLit;
|
||||
|
||||
//mouse.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
for (int i = 0; i < mainCameraPostEffects.Length; i++)
|
||||
{
|
||||
if (mainCameraPostEffects[i])
|
||||
{
|
||||
mainCameraPostEffects[i].enabled = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void SetMouseParticlesRendering(bool value)
|
||||
{
|
||||
mouse.gameObject.SetActive(value);
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public static Vector3 DampVector3(Vector3 from, Vector3 to, float speed, float dt)
|
||||
{
|
||||
return Vector3.Lerp(from, to, 1.0f - Mathf.Exp(-speed * dt));
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
Vector3 cameraPositionSmoothDampVelocity;
|
||||
Vector3 cameraRotationSmoothDampVelocity;
|
||||
|
||||
void Update()
|
||||
{
|
||||
// ...
|
||||
|
||||
input.x = Input.GetAxis("Horizontal");
|
||||
input.y = Input.GetAxis("Vertical");
|
||||
|
||||
// Get targets.
|
||||
|
||||
if (Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
targetCameraPosition.z += input.y * cameraMoveAmount;
|
||||
targetCameraPosition.z = Mathf.Clamp(targetCameraPosition.z, -6.3f, -1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
targetCameraRotation.y += input.x * cameraRotateAmount;
|
||||
targetCameraRotation.x += input.y * cameraRotateAmount;
|
||||
|
||||
targetCameraRotation.x = Mathf.Clamp(targetCameraRotation.x, cameraAngleLimits.x, cameraAngleLimits.y);
|
||||
}
|
||||
|
||||
// Camera position.
|
||||
|
||||
cameraTranslationTransform.localPosition = Vector3.SmoothDamp(
|
||||
cameraTranslationTransform.localPosition, targetCameraPosition, ref cameraPositionSmoothDampVelocity, 1.0f / cameraMoveSpeed, Mathf.Infinity, Time.unscaledDeltaTime);
|
||||
|
||||
// Camera container rotation.
|
||||
|
||||
cameraRotation = Vector3.SmoothDamp(
|
||||
cameraRotation, targetCameraRotation, ref cameraRotationSmoothDampVelocity, 1.0f / cameraRotationSpeed, Mathf.Infinity, Time.unscaledDeltaTime);
|
||||
|
||||
cameraRotationTransform.localEulerAngles = cameraRotation;
|
||||
|
||||
// Look at origin.
|
||||
|
||||
cameraTranslationTransform.LookAt(cameraLookAtPosition);
|
||||
|
||||
// Scroll through systems.
|
||||
|
||||
if (Input.GetAxis("Mouse ScrollWheel") < 0)
|
||||
{
|
||||
Next();
|
||||
}
|
||||
else if (Input.GetAxis("Mouse ScrollWheel") > 0)
|
||||
{
|
||||
Previous();
|
||||
}
|
||||
|
||||
// Toggle UI.
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.U))
|
||||
{
|
||||
ui.SetActive(!ui.activeSelf);
|
||||
}
|
||||
|
||||
// Switch between one-shot and looping prefabs.
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.O))
|
||||
{
|
||||
if (particleMode == ParticleMode.looping)
|
||||
{
|
||||
SetToOneshotParticleMode(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetToLoopingParticleMode(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Cycle levels.
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.L))
|
||||
{
|
||||
SetLevel((Level)((int)(currentLevel + 1) % System.Enum.GetNames(typeof(Level)).Length));
|
||||
}
|
||||
|
||||
// Random prefab while holding key.
|
||||
|
||||
else if (Input.GetKey(KeyCode.R))
|
||||
{
|
||||
//if (particleMode == ParticleMode.oneshot)
|
||||
//{
|
||||
// oneshotParticleSystems.randomize();
|
||||
// updateCurrentParticleSystemNameText();
|
||||
|
||||
// // If also holding down, auto-spawn at random point.
|
||||
|
||||
// if (Input.GetKey(KeyCode.T))
|
||||
// {
|
||||
// //oneshotParticleSystems.instantiateParticlePrefabRandom();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
// Left-click to spawn once.
|
||||
// Right-click to continously spawn.
|
||||
|
||||
if (particleMode == ParticleMode.oneshot)
|
||||
{
|
||||
Vector3 mousePosition = Input.mousePosition;
|
||||
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
CameraShake cameraShake = FindObjectOfType<CameraShake>();
|
||||
|
||||
cameraShake.Add(0.2f, 5.0f, 0.2f, CameraShakeTarget.Position, CameraShakeAmplitudeCurve.FadeInOut25);
|
||||
cameraShake.Add(4.0f, 5.0f, 0.5f, CameraShakeTarget.Rotation, CameraShakeAmplitudeCurve.FadeInOut25);
|
||||
|
||||
oneshotParticleSystems.InstantiateParticlePrefab(mousePosition, mouse.distanceFromCamera);
|
||||
}
|
||||
if (Input.GetMouseButton(1))
|
||||
{
|
||||
oneshotParticleSystems.InstantiateParticlePrefab(mousePosition, mouse.distanceFromCamera);
|
||||
}
|
||||
}
|
||||
|
||||
// Reset.
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.R))
|
||||
{
|
||||
ResetCameraTransformTargets();
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
// Update particle count display.
|
||||
|
||||
particleCountText.text = "PARTICLE COUNT: ";
|
||||
|
||||
if (particleMode == ParticleMode.looping)
|
||||
{
|
||||
particleCountText.text += loopingParticleSystems.GetParticleCount().ToString();
|
||||
}
|
||||
else if (particleMode == ParticleMode.oneshot)
|
||||
{
|
||||
particleCountText.text += oneshotParticleSystems.GetParticleCount().ToString();
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void ResetCameraTransformTargets()
|
||||
{
|
||||
targetCameraPosition = cameraPositionStart;
|
||||
targetCameraRotation = cameraRotationStart;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void UpdateCurrentParticleSystemNameText()
|
||||
{
|
||||
if (particleMode == ParticleMode.looping)
|
||||
{
|
||||
currentParticleSystemText.text = loopingParticleSystems.GetCurrentPrefabName(true);
|
||||
}
|
||||
else if (particleMode == ParticleMode.oneshot)
|
||||
{
|
||||
currentParticleSystemText.text = oneshotParticleSystems.GetCurrentPrefabName(true);
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void Next()
|
||||
{
|
||||
if (particleMode == ParticleMode.looping)
|
||||
{
|
||||
loopingParticleSystems.Next();
|
||||
}
|
||||
else if (particleMode == ParticleMode.oneshot)
|
||||
{
|
||||
oneshotParticleSystems.Next();
|
||||
}
|
||||
|
||||
UpdateCurrentParticleSystemNameText();
|
||||
}
|
||||
|
||||
public void Previous()
|
||||
{
|
||||
if (particleMode == ParticleMode.looping)
|
||||
{
|
||||
loopingParticleSystems.Previous();
|
||||
}
|
||||
else if (particleMode == ParticleMode.oneshot)
|
||||
{
|
||||
oneshotParticleSystems.Previous();
|
||||
}
|
||||
|
||||
UpdateCurrentParticleSystemNameText();
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33d6fc44fae54d642925ba68dc57410f
|
||||
timeCreated: 1435559456
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,108 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class FPSDisplay : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
float timer;
|
||||
public float updateTime = 1.0f;
|
||||
|
||||
int frameCount;
|
||||
float fpsAccum;
|
||||
|
||||
// Display.
|
||||
|
||||
Text fpsText;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Start()
|
||||
{
|
||||
fpsText = GetComponent<Text>();
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Update()
|
||||
{
|
||||
frameCount++;
|
||||
timer += Time.deltaTime;
|
||||
|
||||
fpsAccum += 1.0f / Time.deltaTime;
|
||||
|
||||
if (timer >= updateTime)
|
||||
{
|
||||
timer = 0.0f;
|
||||
|
||||
int fps = Mathf.RoundToInt(fpsAccum / frameCount);
|
||||
|
||||
fpsText.text = "Average FPS: " + fps;
|
||||
|
||||
frameCount = 0;
|
||||
fpsAccum = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9f4f59ed613035409cd1a3760587dc0
|
||||
timeCreated: 1442945759
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,98 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class FPSTest : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
public int targetFPS1 = 60;
|
||||
public int targetFPS2 = 10;
|
||||
|
||||
int previousVSyncCount;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKey(KeyCode.Space))
|
||||
{
|
||||
Application.targetFrameRate = targetFPS2;
|
||||
|
||||
previousVSyncCount = QualitySettings.vSyncCount;
|
||||
QualitySettings.vSyncCount = 0;
|
||||
}
|
||||
else if (Input.GetKeyUp(KeyCode.Space))
|
||||
{
|
||||
Application.targetFrameRate = targetFPS1;
|
||||
QualitySettings.vSyncCount = previousVSyncCount;
|
||||
}
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29ec48b8d9f9b294eab9a7f660adcdc3
|
||||
timeCreated: 1458196122
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,123 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class LoopingParticleSystemsManager : ParticleManager
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
// ...
|
||||
|
||||
particlePrefabs[currentParticlePrefabIndex][0].gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public override void Next()
|
||||
{
|
||||
particlePrefabs[currentParticlePrefabIndex][0].gameObject.SetActive(false);
|
||||
|
||||
base.Next();
|
||||
particlePrefabs[currentParticlePrefabIndex][0].gameObject.SetActive(true);
|
||||
}
|
||||
public override void Previous()
|
||||
{
|
||||
particlePrefabs[currentParticlePrefabIndex][0].gameObject.SetActive(false);
|
||||
|
||||
base.Previous();
|
||||
particlePrefabs[currentParticlePrefabIndex][0].gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public override int GetParticleCount()
|
||||
{
|
||||
// Return particle count from active prefab.
|
||||
|
||||
int particleCount = 0;
|
||||
|
||||
ParticleSystem[] currentPrefab = particlePrefabs[currentParticlePrefabIndex];
|
||||
|
||||
for (int i = 0; i < currentPrefab.Length; i++)
|
||||
{
|
||||
particleCount += currentPrefab[i].particleCount;
|
||||
}
|
||||
|
||||
return particleCount;
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c510a03d7e25f949891cc966a3b4cda
|
||||
timeCreated: 1435559456
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,102 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class MouseFollow : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
public float speed = 8.0f;
|
||||
public float distanceFromCamera = 5.0f;
|
||||
|
||||
public bool ignoreTimeScale;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Update()
|
||||
{
|
||||
Vector3 mousePosition = Input.mousePosition;
|
||||
mousePosition.z = distanceFromCamera;
|
||||
|
||||
Vector3 mouseScreenToWorld = Camera.main.ScreenToWorldPoint(mousePosition);
|
||||
|
||||
float deltaTime = !ignoreTimeScale ? Time.deltaTime : Time.unscaledDeltaTime;
|
||||
Vector3 position = Vector3.Lerp(transform.position, mouseScreenToWorld, 1.0f - Mathf.Exp(-speed * deltaTime));
|
||||
|
||||
transform.position = position;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d060625387cf804ea2e5920cc7a829e
|
||||
timeCreated: 1459508605
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,106 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class MouseRotateCamera : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
public float maxRotation = 5.0f;
|
||||
public float speed = 2.0f;
|
||||
|
||||
public bool unscaledTime;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
Vector2 mousePosition = Input.mousePosition;
|
||||
|
||||
float screenHalfWidth = Screen.width / 2.0f;
|
||||
float screenHalfHeight = Screen.height / 2.0f;
|
||||
|
||||
float mouseNormalizedPositionHalfX = (mousePosition.x - screenHalfWidth) / screenHalfWidth;
|
||||
float mouseNormalizedPositionHalfY = (mousePosition.y - screenHalfHeight) / screenHalfHeight;
|
||||
|
||||
Vector3 localEulerAngles = transform.localEulerAngles;
|
||||
|
||||
localEulerAngles.y = mouseNormalizedPositionHalfX * -maxRotation;
|
||||
localEulerAngles.x = mouseNormalizedPositionHalfY * maxRotation;
|
||||
|
||||
float deltaTime = (!unscaledTime ? Time.deltaTime : Time.unscaledDeltaTime) * speed;
|
||||
|
||||
localEulerAngles.x = Mathf.LerpAngle(transform.localEulerAngles.x, localEulerAngles.x, deltaTime);
|
||||
localEulerAngles.y = Mathf.LerpAngle(transform.localEulerAngles.y, localEulerAngles.y, deltaTime);
|
||||
|
||||
transform.localEulerAngles = localEulerAngles;
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a459c580f4cd938498d2d9aa94d3a03b
|
||||
timeCreated: 1475038359
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,214 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class OneshotParticleSystemsManager : ParticleManager
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
public LayerMask mouseRaycastLayerMask = ~0;
|
||||
List<ParticleSystem[]> spawnedPrefabs;
|
||||
|
||||
// Don't allow spawning if true.
|
||||
// Used for button clicks vs. empty-space clicks.
|
||||
|
||||
public bool disableSpawn { get; set; }
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
// ...
|
||||
|
||||
disableSpawn = false;
|
||||
spawnedPrefabs = new List<ParticleSystem[]>();
|
||||
}
|
||||
|
||||
// Get rid of spawned systems when re-activated.
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
//clear();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
if (spawnedPrefabs != null)
|
||||
{
|
||||
for (int i = 0; i < spawnedPrefabs.Count; i++)
|
||||
{
|
||||
if (spawnedPrefabs[i][0])
|
||||
{
|
||||
Destroy(spawnedPrefabs[i][0].gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
spawnedPrefabs.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public void InstantiateParticlePrefab(Vector2 mousePosition, float maxDistance)
|
||||
{
|
||||
if (spawnedPrefabs != null)
|
||||
{
|
||||
if (!disableSpawn)
|
||||
{
|
||||
Vector3 position = mousePosition;
|
||||
|
||||
position.z = maxDistance;
|
||||
Vector3 worldMousePosition = Camera.main.ScreenToWorldPoint(position);
|
||||
|
||||
Vector3 directionToWorldMouse = worldMousePosition - Camera.main.transform.position;
|
||||
|
||||
RaycastHit rayHit;
|
||||
|
||||
// Start the raycast a little bit ahead of the camera because the camera starts right where a cube's edge is
|
||||
// and that causes the raycast to hit... spawning a prefab right at the camera position. It's fixed by moving the camera,
|
||||
// or I can just add this forward to prevent it from happening at all.
|
||||
|
||||
Physics.Raycast(Camera.main.transform.position + Camera.main.transform.forward * 0.01f, directionToWorldMouse, out rayHit, maxDistance);
|
||||
|
||||
Vector3 spawnPosition;
|
||||
|
||||
if (rayHit.collider)
|
||||
{
|
||||
spawnPosition = rayHit.point;
|
||||
}
|
||||
else
|
||||
{
|
||||
spawnPosition = worldMousePosition;
|
||||
}
|
||||
|
||||
ParticleSystem[] prefab = particlePrefabs[currentParticlePrefabIndex];
|
||||
ParticleSystem newParticlePrefab = Instantiate(prefab[0], spawnPosition, prefab[0].transform.rotation);
|
||||
|
||||
newParticlePrefab.gameObject.SetActive(true);
|
||||
|
||||
// Parent to spawner.
|
||||
|
||||
newParticlePrefab.transform.parent = transform;
|
||||
|
||||
spawnedPrefabs.Add(newParticlePrefab.GetComponentsInChildren<ParticleSystem>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
//public void instantiateParticlePrefabRandom()
|
||||
//{
|
||||
// if (!disableSpawn)
|
||||
// {
|
||||
// instantiateParticlePrefab(new Vector3(
|
||||
// Random.Range(0.0f, Screen.width), Random.Range(0.0f, Screen.height), 0.0f));
|
||||
// }
|
||||
//}
|
||||
|
||||
// ...
|
||||
|
||||
public void Randomize()
|
||||
{
|
||||
currentParticlePrefabIndex = Random.Range(0, particlePrefabs.Count);
|
||||
}
|
||||
|
||||
// Get particle count from all spawned.
|
||||
|
||||
public override int GetParticleCount()
|
||||
{
|
||||
int particleCount = 0;
|
||||
|
||||
if (spawnedPrefabs != null)
|
||||
{
|
||||
for (int i = 0; i < spawnedPrefabs.Count; i++)
|
||||
{
|
||||
if (spawnedPrefabs[i][0])
|
||||
{
|
||||
for (int j = 0; j < spawnedPrefabs[i].Length; j++)
|
||||
{
|
||||
particleCount += spawnedPrefabs[i][j].particleCount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
spawnedPrefabs.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return particleCount;
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b8e608e3ccbfe341885f855c07d6184
|
||||
timeCreated: 1435559456
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,206 @@
|
||||
|
||||
// =================================
|
||||
// Namespaces.
|
||||
// =================================
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
// =================================
|
||||
// Define namespace.
|
||||
// =================================
|
||||
|
||||
namespace MirzaBeig
|
||||
{
|
||||
|
||||
namespace ParticleSystems
|
||||
{
|
||||
|
||||
namespace Demos
|
||||
{
|
||||
|
||||
// =================================
|
||||
// Classes.
|
||||
// =================================
|
||||
|
||||
public class ParticleManager : MonoBehaviour
|
||||
{
|
||||
// =================================
|
||||
// Nested classes and structures.
|
||||
// =================================
|
||||
|
||||
|
||||
|
||||
// =================================
|
||||
// Variables.
|
||||
// =================================
|
||||
|
||||
protected List<ParticleSystem[]> particlePrefabs;
|
||||
|
||||
public int currentParticlePrefabIndex;
|
||||
|
||||
// Take only the part of the prefab name string after these many underscores.
|
||||
|
||||
public int prefabNameUnderscoreCountCutoff = 4;
|
||||
|
||||
// Since I may have prefabs as children I was using to set values.
|
||||
// But I don't want to disable/enable them each time I want to run
|
||||
// the build or change values. This will auto-disable all at start.
|
||||
|
||||
public bool disableChildrenAtStart = true;
|
||||
|
||||
// Already initialized?
|
||||
|
||||
bool initialized = false;
|
||||
|
||||
// =================================
|
||||
// Functions.
|
||||
// =================================
|
||||
|
||||
// ...
|
||||
|
||||
public void Init()
|
||||
{
|
||||
// Default.
|
||||
|
||||
//currentParticlePrefab = 0;
|
||||
|
||||
// Get all particles.
|
||||
|
||||
particlePrefabs = new List<ParticleSystem[]>();
|
||||
|
||||
int numChildren = transform.childCount;
|
||||
|
||||
for (int i = 0; i < numChildren; i++)
|
||||
{
|
||||
particlePrefabs.Add(transform.GetChild(i).GetComponentsInChildren<ParticleSystem>());
|
||||
}
|
||||
|
||||
// Disable all particle prefab object children.
|
||||
|
||||
if (disableChildrenAtStart)
|
||||
{
|
||||
for (int i = 0; i < particlePrefabs.Count; i++)
|
||||
{
|
||||
particlePrefabs[i][0].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
if (initialized)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public virtual void Next()
|
||||
{
|
||||
currentParticlePrefabIndex++;
|
||||
|
||||
if (currentParticlePrefabIndex > particlePrefabs.Count - 1)
|
||||
{
|
||||
currentParticlePrefabIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Previous()
|
||||
{
|
||||
currentParticlePrefabIndex--;
|
||||
|
||||
if (currentParticlePrefabIndex < 0)
|
||||
{
|
||||
currentParticlePrefabIndex = particlePrefabs.Count - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public string GetCurrentPrefabName(bool shorten = false)
|
||||
{
|
||||
// Save object name for clarity.
|
||||
|
||||
string particleSystemName = particlePrefabs[currentParticlePrefabIndex][0].name;
|
||||
|
||||
// Only take name from after the last underscore to the end.
|
||||
|
||||
if (shorten)
|
||||
{
|
||||
int lastIndexOfUnderscore = 0;
|
||||
|
||||
for (int i = 0; i < prefabNameUnderscoreCountCutoff; i++)
|
||||
{
|
||||
// -1 if not found, 0 to n otherwise. +1 to move position forward.
|
||||
|
||||
lastIndexOfUnderscore = particleSystemName.IndexOf("_", lastIndexOfUnderscore) + 1;
|
||||
|
||||
// Not found. -1 + 1 == 0.
|
||||
|
||||
if (lastIndexOfUnderscore == 0)
|
||||
{
|
||||
// "Error"... sort of.
|
||||
|
||||
print("Iteration of underscore not found.");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
particleSystemName = particleSystemName.Substring(lastIndexOfUnderscore, particleSystemName.Length - lastIndexOfUnderscore);
|
||||
}
|
||||
|
||||
// Return display text.
|
||||
|
||||
return "PARTICLE SYSTEM: #" + (currentParticlePrefabIndex + 1).ToString("00") +
|
||||
" / " + particlePrefabs.Count.ToString("00") + " (" + particleSystemName + ")";
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public virtual int GetParticleCount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End functions.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// End namespace.
|
||||
// =================================
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// =================================
|
||||
// --END-- //
|
||||
// =================================
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4151f3ce4d5482d4786330fc08faeda1
|
||||
timeCreated: 1435559456
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user