Muchas cosas

This commit is contained in:
Gerard Gascón 2023-02-27 20:45:11 +01:00
parent b4e11ac33f
commit 9c92dc678e
76 changed files with 15307 additions and 2021 deletions

219
Assets/Scripts/Blit.cs Normal file
View file

@ -0,0 +1,219 @@
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
/*
* Blit Renderer Feature https://github.com/Cyanilux/URP_BlitRenderFeature
* ------------------------------------------------------------------------------------------------------------------------
* Based on the Blit from the UniversalRenderingExamples
* https://github.com/Unity-Technologies/UniversalRenderingExamples/tree/master/Assets/Scripts/Runtime/RenderPasses
*
* Extended to allow for :
* - Specific access to selecting a source and destination (via current camera's color / texture id / render texture object
* - (Pre-2021.2/v12) Automatic switching to using _AfterPostProcessTexture for After Rendering event, in order to correctly handle the blit after post processing is applied
* - Setting a _InverseView matrix (cameraToWorldMatrix), for shaders that might need it to handle calculations from screen space to world.
* e.g. Reconstruct world pos from depth : https://www.cyanilux.com/tutorials/depth/#blit-perspective
* - (2020.2/v10 +) Enabling generation of DepthNormals (_CameraNormalsTexture)
* This will only include shaders who have a DepthNormals pass (mostly Lit Shaders / Graphs)
(workaround for Unlit Shaders / Graphs: https://gist.github.com/Cyanilux/be5a796cf6ddb20f20a586b94be93f2b)
* ------------------------------------------------------------------------------------------------------------------------
* @Cyanilux
*/
namespace Cyan {
/*
CreateAssetMenu here allows creating the ScriptableObject without being attached to a Renderer Asset
Can then Enqueue the pass manually via https://gist.github.com/Cyanilux/8fb3353529887e4184159841b8cad208
as a workaround for 2D Renderer not supporting features (prior to 2021.2). Uncomment if needed.
*/
// [CreateAssetMenu(menuName = "Cyan/Blit")]
public class Blit : ScriptableRendererFeature {
public class BlitPass : ScriptableRenderPass {
public Material blitMaterial = null;
public FilterMode filterMode { get; set; }
private BlitSettings settings;
private RenderTargetIdentifier source { get; set; }
private RenderTargetIdentifier destination { get; set; }
RenderTargetHandle m_TemporaryColorTexture;
RenderTargetHandle m_DestinationTexture;
string m_ProfilerTag;
#if !UNITY_2020_2_OR_NEWER // v8
private ScriptableRenderer renderer;
#endif
public BlitPass(RenderPassEvent renderPassEvent, BlitSettings settings, string tag) {
this.renderPassEvent = renderPassEvent;
this.settings = settings;
blitMaterial = settings.blitMaterial;
m_ProfilerTag = tag;
m_TemporaryColorTexture.Init("_TemporaryColorTexture");
if (settings.dstType == Target.TextureID) {
m_DestinationTexture.Init(settings.dstTextureId);
}
}
public void Setup(ScriptableRenderer renderer) {
#if UNITY_2020_2_OR_NEWER // v10+
if (settings.requireDepthNormals)
ConfigureInput(ScriptableRenderPassInput.Normal);
#else // v8
this.renderer = renderer;
#endif
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) {
CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);
RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;
opaqueDesc.depthBufferBits = 0;
// Set Source / Destination
#if UNITY_2020_2_OR_NEWER // v10+
var renderer = renderingData.cameraData.renderer;
#else // v8
// For older versions, cameraData.renderer is internal so can't be accessed. Will pass it through from AddRenderPasses instead
var renderer = this.renderer;
#endif
// note : Seems this has to be done in here rather than in AddRenderPasses to work correctly in 2021.2+
if (settings.srcType == Target.CameraColor) {
source = renderer.cameraColorTarget;
} else if (settings.srcType == Target.TextureID) {
source = new RenderTargetIdentifier(settings.srcTextureId);
} else if (settings.srcType == Target.RenderTextureObject) {
source = new RenderTargetIdentifier(settings.srcTextureObject);
}
if (settings.dstType == Target.CameraColor) {
destination = renderer.cameraColorTarget;
} else if (settings.dstType == Target.TextureID) {
destination = new RenderTargetIdentifier(settings.dstTextureId);
} else if (settings.dstType == Target.RenderTextureObject) {
destination = new RenderTargetIdentifier(settings.dstTextureObject);
}
if (settings.setInverseViewMatrix) {
Shader.SetGlobalMatrix("_InverseView", renderingData.cameraData.camera.cameraToWorldMatrix);
}
if (settings.dstType == Target.TextureID) {
if (settings.overrideGraphicsFormat) {
opaqueDesc.graphicsFormat = settings.graphicsFormat;
}
cmd.GetTemporaryRT(m_DestinationTexture.id, opaqueDesc, filterMode);
}
//Debug.Log($"src = {source}, dst = {destination} ");
// Can't read and write to same color target, use a TemporaryRT
if (source == destination || (settings.srcType == settings.dstType && settings.srcType == Target.CameraColor)) {
cmd.GetTemporaryRT(m_TemporaryColorTexture.id, opaqueDesc, filterMode);
Blit(cmd, source, m_TemporaryColorTexture.Identifier(), blitMaterial, settings.blitMaterialPassIndex);
Blit(cmd, m_TemporaryColorTexture.Identifier(), destination);
} else {
Blit(cmd, source, destination, blitMaterial, settings.blitMaterialPassIndex);
}
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void FrameCleanup(CommandBuffer cmd) {
if (settings.dstType == Target.TextureID) {
cmd.ReleaseTemporaryRT(m_DestinationTexture.id);
}
if (source == destination || (settings.srcType == settings.dstType && settings.srcType == Target.CameraColor)) {
cmd.ReleaseTemporaryRT(m_TemporaryColorTexture.id);
}
}
}
[System.Serializable]
public class BlitSettings {
public RenderPassEvent Event = RenderPassEvent.AfterRenderingOpaques;
public Material blitMaterial = null;
public int blitMaterialPassIndex = 0;
public bool setInverseViewMatrix = false;
public bool requireDepthNormals = false;
public Target srcType = Target.CameraColor;
public string srcTextureId = "_CameraColorTexture";
public RenderTexture srcTextureObject;
public Target dstType = Target.CameraColor;
public string dstTextureId = "_BlitPassTexture";
public RenderTexture dstTextureObject;
public bool overrideGraphicsFormat = false;
public UnityEngine.Experimental.Rendering.GraphicsFormat graphicsFormat;
}
public enum Target {
CameraColor,
TextureID,
RenderTextureObject
}
public BlitSettings settings = new BlitSettings();
public BlitPass blitPass;
public override void Create() {
var passIndex = settings.blitMaterial != null ? settings.blitMaterial.passCount - 1 : 1;
settings.blitMaterialPassIndex = Mathf.Clamp(settings.blitMaterialPassIndex, -1, passIndex);
blitPass = new BlitPass(settings.Event, settings, name);
#if !UNITY_2021_2_OR_NEWER
if (settings.Event == RenderPassEvent.AfterRenderingPostProcessing) {
Debug.LogWarning("Note that the \"After Rendering Post Processing\"'s Color target doesn't seem to work? (or might work, but doesn't contain the post processing) :( -- Use \"After Rendering\" instead!");
}
#endif
if (settings.graphicsFormat == UnityEngine.Experimental.Rendering.GraphicsFormat.None) {
settings.graphicsFormat = SystemInfo.GetGraphicsFormat(UnityEngine.Experimental.Rendering.DefaultFormat.LDR);
}
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) {
if (settings.blitMaterial == null) {
Debug.LogWarningFormat("Missing Blit Material. {0} blit pass will not execute. Check for missing reference in the assigned renderer.", GetType().Name);
return;
}
#if !UNITY_2021_2_OR_NEWER
// AfterRenderingPostProcessing event is fixed in 2021.2+ so this workaround is no longer required
if (settings.Event == RenderPassEvent.AfterRenderingPostProcessing) {
} else if (settings.Event == RenderPassEvent.AfterRendering && renderingData.postProcessingEnabled) {
// If event is AfterRendering, and src/dst is using CameraColor, switch to _AfterPostProcessTexture instead.
if (settings.srcType == Target.CameraColor) {
settings.srcType = Target.TextureID;
settings.srcTextureId = "_AfterPostProcessTexture";
}
if (settings.dstType == Target.CameraColor) {
settings.dstType = Target.TextureID;
settings.dstTextureId = "_AfterPostProcessTexture";
}
} else {
// If src/dst is using _AfterPostProcessTexture, switch back to CameraColor
if (settings.srcType == Target.TextureID && settings.srcTextureId == "_AfterPostProcessTexture") {
settings.srcType = Target.CameraColor;
settings.srcTextureId = "";
}
if (settings.dstType == Target.TextureID && settings.dstTextureId == "_AfterPostProcessTexture") {
settings.dstType = Target.CameraColor;
settings.dstTextureId = "";
}
}
#endif
blitPass.Setup(renderer);
renderer.EnqueuePass(blitPass);
}
}
}

View file

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

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 567bcdbc30b48f04b8ca65b4b274f08e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GhostController : MonoBehaviour {
[SerializeField] float speed;
[SerializeField] Transform player;
Rigidbody2D _rb2d;
// Start is called before the first frame update
void Awake() {
_rb2d = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate() {
_rb2d.position = Vector2.MoveTowards(_rb2d.position, player.position, Time.deltaTime * speed);
}
}

View file

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

View file

@ -7,6 +7,7 @@ using UnityEngine.Events;
[System.Serializable]
public enum OrbTypes {
None,
Blue,
Red,
InvertedControls,
@ -20,8 +21,9 @@ public enum OrbTypes {
public class GameManager : MonoBehaviour {
[SerializeField] GenericDictionary<OrbTypes, UnityEvent> orbEffects;
[SerializeField] OrbTypes currentType;
[SerializeField] GenericDictionary<OrbTypes, UnityEvent> orbStartEffects;
[SerializeField] GenericDictionary<OrbTypes, UnityEvent> orbEndEffects;
[SerializeField] OrbTypes currentType = OrbTypes.None;
// Start is called before the first frame update
void Start(){
@ -33,8 +35,16 @@ public class GameManager : MonoBehaviour {
}
[Space, SerializeField] OrbTypes forceEventChangeType = OrbTypes.None;
[ButtonMethod]
void ForceEventChange() {
if (!Application.isPlaying) return;
ChangeEventCall(forceEventChangeType);
}
void ChangeEventCall(OrbTypes type) {
if(currentType != OrbTypes.None) orbEndEffects[currentType].Invoke();
currentType = type;
orbEffects[currentType].Invoke();
if(type != OrbTypes.None) orbStartEffects[currentType].Invoke();
}
}

View file

@ -1,6 +1,9 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Cinemachine;
using MyBox;
using SimpleTools.Cinemachine;
using UnityEngine;
using UnityEngine.Serialization;
@ -8,6 +11,7 @@ public class PlayerController : MonoBehaviour {
[Header("Stats")]
[SerializeField] float speed = 50f;
float _currentSpeed;
[SerializeField, Range(0f, .5f)] float acceleration = .1f;
[SerializeField, Range(0f, .5f)] float flipSmooth = .1f;
[SerializeField] float jumpForce = 10f;
@ -31,11 +35,37 @@ public class PlayerController : MonoBehaviour {
[SerializeField, Range(0f, .5f)] float jumpBuffer;
float _jumpBuffer;
[Header("Camera")]
[SerializeField, OverrideLabel("vCam")] CinemachineVirtualCamera vCam;
Transform _cameraTarget;
Animator _anim;
static readonly int Speed = Animator.StringToHash("Speed");
static readonly int Grounded = Animator.StringToHash("Grounded");
static readonly int Die = Animator.StringToHash("Die");
bool _dead;
void Awake() {
_rb2d = GetComponent<Rigidbody2D>();
_anim = GetComponent<Animator>();
_cameraTarget = new GameObject("Camera Target").transform;
vCam.m_Follow = _cameraTarget;
ResetSpeed();
}
void Update() {
Vector3 localScale;
if (_dead) {
localScale = transform.localScale;
localScale = new Vector3(Mathf.SmoothDamp(localScale.x, _facingDirection, ref _flipVelocity, flipSmooth),
localScale.y, localScale.z);
transform.localScale = localScale;
return;
}
_input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
_facingDirection = _input.x switch {
> 0f => 1,
@ -43,12 +73,13 @@ public class PlayerController : MonoBehaviour {
_ => _facingDirection
};
Vector3 localScale = transform.localScale;
localScale = transform.localScale;
localScale = new Vector3(Mathf.SmoothDamp(localScale.x, _facingDirection, ref _flipVelocity, flipSmooth),
localScale.y, localScale.z);
transform.localScale = localScale;
_isGrounded = Physics2D.OverlapBox(feetPos.position, new Vector2(feetWidth, feetHeight), 0f, groundMask);
_anim.SetBool(Grounded, _isGrounded);
if (_isGrounded && _rb2d.velocity.y <= 0f) _coyoteTime = coyoteTime;
if (Input.GetKeyDown(KeyCode.Space)) _jumpBuffer = jumpBuffer;
@ -59,7 +90,10 @@ public class PlayerController : MonoBehaviour {
}
void FixedUpdate() {
_rb2d.velocity = new Vector2(Mathf.SmoothDamp(_rb2d.velocity.x, _input.x * speed, ref _xVelocity, acceleration), _rb2d.velocity.y);
if (_dead) return;
_rb2d.velocity = new Vector2(Mathf.SmoothDamp(_rb2d.velocity.x, _input.x * _currentSpeed, ref _xVelocity, acceleration), _rb2d.velocity.y);
_anim.SetFloat(Speed, Mathf.Abs(_rb2d.velocity.x));
if (_coyoteTime > 0f && _jumpBuffer > 0f) {
_rb2d.velocity = new Vector2(_rb2d.velocity.x, 0f);
@ -73,8 +107,32 @@ public class PlayerController : MonoBehaviour {
}
}
void LateUpdate() {
if (_dead) return;
float yPos = _isGrounded && _rb2d.velocity.y <= 0f ? transform.position.y : _cameraTarget.position.y;
_cameraTarget.position = new Vector3(transform.position.x, yPos);
}
void OnDrawGizmosSelected() {
Gizmos.color = Color.red;
if (feetPos) Gizmos.DrawWireCube(feetPos.position, new Vector3(feetWidth, feetHeight));
}
void OnTriggerEnter2D(Collider2D col) {
if (col.CompareTag("Ghost")) {
_anim.SetTrigger(Die);
_dead = true;
ScreenShake.Shake(20f, .5f);
}
}
#region OrbPowerups
public void ResetSpeed() {
_currentSpeed = speed;
}
public void SetSpeed(float newSpeed) {
_currentSpeed = newSpeed;
}
#endregion
}

72
Assets/Scripts/Thunder.cs Normal file
View file

@ -0,0 +1,72 @@
using System.Collections;
using System.Collections.Generic;
using SimpleTools.Cinemachine;
using UnityEngine;
public class Thunder : MonoBehaviour{
[SerializeField] private Camera camera;
[SerializeField] private UnityEngine.Rendering.Universal.Light2D globalLight;
[SerializeField] private Color lightingColor;
[SerializeField] private AudioSource thunderSound;
[SerializeField] private float intervalTime = 5f;
private Color orgLightColor;
private Color orgCamBGColor;
private float orgIntensity;
private float timer;
// Start is called before the first frame update
void Start(){
orgLightColor = globalLight.color;
orgIntensity = globalLight.intensity;
orgCamBGColor = camera.backgroundColor;
timer = intervalTime;
}
// Update is called once per frame
void Update(){
timer -= Time.deltaTime;
if (timer <= 0){
LightningStrike();
timer = intervalTime + Random.Range(-intervalTime * 0.3f, intervalTime * 0.3f);
}
if (globalLight.intensity > orgIntensity){
globalLight.intensity -= Time.deltaTime * 2.5f;
camera.backgroundColor = Color.Lerp(camera.backgroundColor, orgCamBGColor, Mathf.PingPong(Time.time, 0.2f));
}else{
ResetLights();
}
}
private void LightningStrike(){
//ScreenshakeHandler.AddScreenShake(5, 5, 0.5f);
ScreenShake.Shake(5, .5f);
//thunderSound.pitch = Random.Range(0.5f, 1f);
//thunderSound.Play();
globalLight.color = lightingColor;
camera.backgroundColor = lightingColor;
globalLight.intensity = 1f;
//Invoke("MiniStrike", 0.05f);
Invoke("MiniStrike", 0.15f);
// Invoke("ResetLights", 2.25f);
}
private void MiniStrike(){
globalLight.color = lightingColor;
// camera.backgroundColor = lightingColor;
globalLight.intensity = .75f;
}
private void ResetLights(){
globalLight.color = orgLightColor;
camera.backgroundColor = orgCamBGColor;
globalLight.intensity = orgIntensity;
}
}

View file

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