Added explosions

This commit is contained in:
2026-01-23 00:01:04 +00:00
parent e79ff061a7
commit e5996382e8
75 changed files with 34537 additions and 1 deletions

View File

@@ -0,0 +1,33 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
namespace MirzaBeig.CinematicExplosionsFree
{
public class CustomImpulse : MonoBehaviour
{
CinemachineImpulseSource source;
void Start()
{
}
void OnEnable()
{
if (!source)
{
source = GetComponent<CinemachineImpulseSource>();
}
source.GenerateImpulse();
}
void Update()
{
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1fe0fb05fe5135c44bdc9ec77f6ec6f4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,193 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Rendering;
using TMPro;
namespace MirzaBeig.CinematicExplosionsFree
{
public class DemoController : MonoBehaviour
{
public enum Scene
{
Day,
Night,
}
Camera camera;
List<ParticleSystem> particleSystems;
public Transform particleSystemsContainer;
[Space]
public Button buttonPrefab;
public VerticalLayoutGroup buttonContainer;
[Space]
public Scene currentScene = Scene.Day;
ReflectionProbe[] reflectionProbes;
[Space]
public GameObject environment;
[Space]
public int targetFrameRate = 60;
void Start()
{
// Set scene.
camera = Camera.main;
Application.targetFrameRate = targetFrameRate;
// Find all reflection probes.
reflectionProbes = FindObjectsByType<ReflectionProbe>(
FindObjectsInactive.Exclude, FindObjectsSortMode.None);
switch (currentScene)
{
case Scene.Day:
{
SetDay();
break;
}
case Scene.Night:
{
SetNight();
break;
}
default:
{
throw new System.Exception("Unknown case.");
}
}
// Assume all top-level children of container are particle systems.
// Instantiate as many buttons as prefabs and link them.
//particleSystems = new List<ParticleSystem> ();
for (int i = 0; i < particleSystemsContainer.childCount; i++)
{
Transform childTransform = particleSystemsContainer.GetChild(i);
// Exclude inactive.
if (!childTransform.gameObject.activeSelf)
{
continue;
}
ParticleSystem particleSystem = childTransform.GetComponent<ParticleSystem>();
Button button = Instantiate(buttonPrefab, buttonContainer.transform);
button.GetComponentInChildren<TextMeshProUGUI>().text = particleSystem.name;
button.onClick.AddListener(() => childTransform.gameObject.SetActive(false));
button.onClick.AddListener(() => childTransform.gameObject.SetActive(true));
//particleSystems.Add(particleSystem);
childTransform.gameObject.SetActive(false);
}
}
void UpdateReflections()
{
for (int i = 0; i < reflectionProbes.Length; i++)
{
reflectionProbes[i].RenderProbe();
}
}
void SetReflectionClearFlags(ReflectionProbeClearFlags clearFlags)
{
for (int i = 0; i < reflectionProbes.Length; i++)
{
reflectionProbes[i].clearFlags = clearFlags;
}
}
// Set scene.
public void SetNight()
{
currentScene = Scene.Night;
camera.clearFlags = CameraClearFlags.SolidColor;
RenderSettings.ambientIntensity = 0.8f;
RenderSettings.reflectionIntensity = 0.5f;
RenderSettings.sun.intensity = 0.0f;
SetReflectionClearFlags(ReflectionProbeClearFlags.SolidColor);
UpdateReflections();
}
public void SetDay()
{
currentScene = Scene.Day;
camera.clearFlags = CameraClearFlags.Skybox;
RenderSettings.ambientIntensity = 1.0f;
RenderSettings.reflectionIntensity = 1.0f;
RenderSettings.sun.intensity = 1.0f;
SetReflectionClearFlags(ReflectionProbeClearFlags.Skybox);
UpdateReflections();
}
public void SetEnvironmentActive(bool active)
{
environment.SetActive(active);
UpdateReflections();
}
void Update()
{
// Toggle scenes.
if (Input.GetKeyDown(KeyCode.F))
{
switch (currentScene)
{
case Scene.Day:
{
SetNight();
break;
}
case Scene.Night:
{
SetDay();
break;
}
default:
{
throw new System.Exception("Unknown case.");
}
}
}
// Toggle environment.
if (Input.GetKeyDown(KeyCode.G))
{
SetEnvironmentActive(!environment.activeSelf);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7333b97e7ab39584b8d6a8a56a95131a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,109 @@
using UnityEngine;
using TMPro;
using System;
namespace MirzaBeig.CinematicExplosionsFree
{
[ExecuteAlways]
public class FPSDisplay : MonoBehaviour
{
public float fps { get; private set; } // Frames per second (interval average).
public float frameMS { get; private set; } // Milliseconds per frame (interval average).
GUIStyle style = new GUIStyle();
public int size = 16;
[Space]
public Vector2 position = new Vector2(16.0f, 16.0f);
public enum Alignment { Left, Right }
public Alignment alignment = Alignment.Left;
[Space]
public Color colour = Color.green;
[Space]
public float updateInterval = 0.5f;
float elapsedIntervalTime;
int intervalFrameCount;
[Space]
[Tooltip("Optional. Will render using GUI if not assigned.")]
public TextMeshProUGUI textMesh;
// Get average FPS and frame delta (ms) for current interval (so far, if called early).
public float GetIntervalFPS()
{
// 1 / time.unscaledDeltaTime for same-frame results.
// Same as above, but uses accumulated frameCount and deltaTime.
return intervalFrameCount / elapsedIntervalTime;
}
public float GetIntervalFrameMS()
{
// Calculate average frame delta during interval (time / frames).
// Same as Time.unscaledDeltaTime * 1000.0f, using accumulation.
return (elapsedIntervalTime * 1000.0f) / intervalFrameCount;
}
void Update()
{
intervalFrameCount++;
elapsedIntervalTime += Time.unscaledDeltaTime;
if (elapsedIntervalTime >= updateInterval)
{
fps = GetIntervalFPS();
frameMS = GetIntervalFrameMS();
fps = (float)Math.Round(fps, 2);
frameMS = (float)Math.Round(frameMS, 2);
intervalFrameCount = 0;
elapsedIntervalTime = 0.0f;
}
if (textMesh)
{
textMesh.text = GetFPSText();
}
else
{
style.fontSize = size;
style.fontStyle = FontStyle.Bold;
style.normal.textColor = colour;
}
}
string GetFPSText()
{
return $"FPS: {fps:.00} ({frameMS:.00} ms)";
}
void OnGUI()
{
string fpsText = GetFPSText();
if (!textMesh)
{
float x = position.x;
if (alignment == Alignment.Right)
{
x = Screen.width - x - style.CalcSize(new GUIContent(fpsText)).x;
}
GUI.Label(new Rect(x, position.y, 200, 100), fpsText, style);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c190d4d8f55efbe489702c2650969646
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
using UnityEngine;
using TMPro;
using System;
namespace MirzaBeig.CinematicExplosionsFree
{
[ExecuteAlways]
public class FPSTest : MonoBehaviour
{
public Vector2 size = new Vector2(128.0f, 64.0f);
public Vector2 position = new Vector2(16.0f, 64.0f);
[Space]
public float spacing = 72;
[Space]
public int[] fpsButtons = new int[] { 0, 10, 30, 45, 60, 90, 120 };
void Start()
{
}
void OnGUI()
{
float positionY = position.y;
for (int i = 0; i < fpsButtons.Length; i++)
{
int fps = fpsButtons[i];
if (GUI.Button(new Rect(position.x, positionY, size.x, size.y), $"FPS: {fps}"))
{
Application.targetFrameRate = fps;
}
positionY += spacing;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d9274bb3e13e3724b9dedbbc8c7937be
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: