added some stuff

This commit is contained in:
Wong Sui Bin 2023-01-24 21:51:46 +08:00
parent 9b69003715
commit 3dbf2f9010
520 changed files with 176780 additions and 2 deletions

View file

@ -0,0 +1,296 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Lemon.GenericLib.VFX {
public class CameraController : MonoBehaviour
{
public static CameraController instanceCC;
[SerializeField] Camera cam;
[SerializeField] Transform player;
[SerializeField] float shootshakeDuration = 0.2f;
private Vector2 originalPosition;
Vector3 target, mousePos, refVel, shkeOffset;
float cameraDist = 2.5f;
float smoothTime = 0.2f;
[SerializeField] float shootShakeMagnitude = 2;
Vector3 shootShakeDirection = Vector3.zero;
float shootShakeTimeEnd = 0;
bool shootshake = false;
[SerializeField] float shakePower;
[SerializeField] float smallShakeMultiplier;
[SerializeField] Vector2 screenshakeOffset = Vector2.zero;
//private Game_Manager gameManager;
//singleton pattern
private void Awake()
{
if (instanceCC == null)
{
instanceCC = this;
}
if (instanceCC != this)
{
Destroy(gameObject);
}
}
public void SetPlayer(Transform playerTransform)
{
player = playerTransform;
}
// Start is called before the first frame update
void Start()
{
//cb = GetComponent<CinemachineBrain>();
//gameManager = Game_Manager.instanceGM;
cam = Camera.main;
originalPosition = transform.position;
//player = FindObjectOfType<PlayerController>()?.transform;
screenshakeOffset = Vector2.zero;
//gameManager.ChangeGameStateEvent += HandleGameStateChanges;
}
////not working currently for some reason
//private void HandleGameStateChanges(object sender, Game_Manager.ChangeGameStateArgs e)
//{
// //Debug.Log("finding player");
// if (e.newState == Game_Manager.GameState.gameplay) {
// Invoke("FindPlayer", 0.01f);
// }
//}
void FindPlayer()
{
Debug.Log("finding player");
//player = FindObjectOfType<PlayerController>()?.transform;
}
Vector3 shootShakeOffset = Vector3.zero;
// Update is called once per frame
void Update()
{
Vector3 destinationPos = originalPosition;
//Vector3 destinationPos = transform.position;
//if (player != null)
//{
// mousePos = GetMousePos();
// target = UpdateTargetPos();
// Vector3 tempPos;
// tempPos = Vector3.SmoothDamp(transform.position, target, ref refVel, smoothTime);
// transform.position = tempPos;
// //mouse distance thing
// Vector2 playerPos = Vector3.zero;
// destinationPos = Vector2.Lerp(originalPosition, playerPos, 0.2f);
// Vector2 MousePos = cam.ScreenToWorldPoint(Input.mousePosition);
// Vector3 mouseDistance = MousePos - playerPos;
// mouseDistance = Vector3.Lerp(Vector3.zero, mouseDistance, 0.05f);
// mouseDistance.z = 0;
if (!shootshake || Time.time >= shootShakeTimeEnd)
{
shootshake = false;
//Debug.Log("not shaking");
shootShakeOffset = Vector3.Lerp(shootShakeOffset, Vector3.zero, 15 * Time.deltaTime);
}
else
{
//Debug.Log(" shaking");
shootShakeOffset = Vector3.Lerp(shootShakeOffset, shootShakeDirection * shootShakeMagnitude, 15 * Time.deltaTime);
}
destinationPos.z = -10;
transform.position = destinationPos + (Vector3)screenshakeOffset + shootShakeOffset;
//}
//else
//{
// destinationPos = Vector2.Lerp(transform.position, originalPosition, 0.2f);
// destinationPos.z = -10;
// transform.position = destinationPos + (Vector3)screenshakeOffset;
//}
}
public Vector3 UpdateTargetPos()
{
Vector3 mouseOffset = mousePos * cameraDist;
Vector3 ret = player.position + mouseOffset;
ret.z = -10;
return ret;
}
public Vector3 GetMousePos()
{
Vector2 ret = cam.ScreenToViewportPoint(Input.mousePosition);
ret *= 2;
ret -= Vector2.one;
float max = 0.9f;
if (Mathf.Abs(ret.x) > max || Mathf.Abs(ret.y) > max)
{
ret = ret.normalized;
}
return ret;
}
public void ApplyShootShake(float duration, Vector3 direction)
{
shootshake = true;
shootShakeDirection = direction;
//yield return new WaitForSeconds(duration);
shootShakeTimeEnd = Time.time + duration;
}
public void ApplyShootShake(float angle, float power)
{
shootshake = true;
shootShakeDirection = (new Vector3((float)Mathf.Cos(angle * Mathf.Deg2Rad), (float)Mathf.Sin(angle * Mathf.Deg2Rad))).normalized;
//yield return new WaitForSeconds(duration);
shootShakeTimeEnd = Time.time + shootshakeDuration;
}
public void ApplyShootShake(float angle)
{
shootshake = true;
shootShakeDirection = (new Vector3((float)Mathf.Cos(angle * Mathf.Deg2Rad), (float)Mathf.Sin(angle * Mathf.Deg2Rad))).normalized;
//yield return new WaitForSeconds(duration);
shootShakeTimeEnd = Time.time + shootshakeDuration;
}
public void ApplyShootShake(Vector3 direction)
{
shootshake = true;
shootShakeDirection = direction;
//yield return new WaitForSeconds(duration);
shootShakeTimeEnd = Time.time + shootshakeDuration;
}
public void ApplyScreenShake(float duration = 0.1f, bool isSmall = false)
{
StopCoroutine("Screenshake");
StartCoroutine(Screenshake(duration, isSmall));
}
public void ApplyScreenShake(float duration, float newShakePower, bool isSmall = false)
{
//cb.enabled = false;
StopCoroutine("Screenshake");
StartCoroutine(Screenshake(duration, newShakePower, isSmall));
}
IEnumerator Screenshake(float duration, bool isSmall = false)
{
screenshakeOffset = Vector2.zero;
//originalPosition = transform.position;
//cb.enabled = false;
//Debug.Log("shake " + cb.enabled);
float currentShakePower = shakePower;
if (isSmall) currentShakePower *= smallShakeMultiplier;
float shakeFadeTime = currentShakePower / duration;
while (duration > 0)
{
float xOffset = Random.Range(-1f, 1f) * currentShakePower;
float yOffset = Random.Range(-1f, 1f) * currentShakePower;
screenshakeOffset.x = xOffset;
screenshakeOffset.y = yOffset;
duration -= Time.deltaTime;
currentShakePower = Mathf.MoveTowards(shakePower, 0f, shakeFadeTime * Time.deltaTime);
yield return null;
}
screenshakeOffset = Vector2.zero;
// cb.enabled = true;
}
IEnumerator Screenshake(float duration, float thisShakePower, bool isSmall = false)
{
screenshakeOffset = Vector2.zero;
float currentShakePower = thisShakePower;
if (isSmall) currentShakePower *= smallShakeMultiplier;
float shakeFadeTime = currentShakePower / duration;
while (duration > 0)
{
float xOffset = Random.Range(-1f, 1f) * currentShakePower;
float yOffset = Random.Range(-1f, 1f) * currentShakePower;
screenshakeOffset.x = xOffset;
screenshakeOffset.y = yOffset;
duration -= Time.deltaTime;
currentShakePower = Mathf.MoveTowards(shakePower, 0f, shakeFadeTime * Time.deltaTime);
yield return null;
}
screenshakeOffset = Vector2.zero;
}
public void HitPause(float duration = 0.05f)
{
Time.timeScale = 1;
StopCoroutine("HitPauseRoutine");
StartCoroutine(HitPauseRoutine(duration));
}
IEnumerator HitPauseRoutine(float duration)
{
// Debug.LogError("FUCK");
Time.timeScale = 0;
yield return new WaitForSecondsRealtime(duration);
Time.timeScale = 1;
}
}
}

View file

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

View file

@ -0,0 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Lemon.GenericLib.VFX {
public class ConstantRotation : MonoBehaviour
{
public Vector3 rotationVector;
private void FixedUpdate()
{
transform.Rotate(rotationVector * Time.deltaTime);
}
}
}

View file

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

View file

@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Lemon.GenericLib.VFX
{
public class FixedRotation : MonoBehaviour
{
// Update is called once per frame
void Update()
{
transform.rotation = Quaternion.identity;
}
}
}

View file

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

View file

@ -0,0 +1,65 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//TODO: make this object pool compatible
namespace Lemon.GenericLib.VFX
{
public class GhostManager : MonoBehaviour
{
public float ghostInterval = 0.1f;
public float ghostLifeTime = 0.5f;
private float currentInterval = 0;
public GameObject ghost;
public bool createGhost = false;
public bool recolourGhost;
public Color ghostColor;
private SpriteRenderer sr;
// Start is called before the first frame update
void Start()
{
sr = GetComponent<SpriteRenderer>();
currentInterval = 0;
}
// Update is called once per frame
void Update()
{
if (currentInterval >= ghostInterval)
{
if (!createGhost) return;
GameObject currentGhost = Instantiate(ghost, transform.position, transform.rotation);
currentGhost.transform.localScale = transform.localScale;
currentGhost.GetComponent<SpriteRenderer>().sprite = sr.sprite;
if (recolourGhost)
{
currentGhost.GetComponent<SpriteRenderer>().color = ghostColor;
}
Destroy(currentGhost, ghostLifeTime);
currentInterval = 0;
}
else
{
currentInterval += Time.deltaTime;
}
}
public void CreateGhostTemp(float time)
{
StartCoroutine(CreateGhostTempRoutine(time));
}
IEnumerator CreateGhostTempRoutine(float time)
{
createGhost = true;
yield return new WaitForSeconds(time);
createGhost = false;
}
}
}

View file

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

View file

@ -0,0 +1,77 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
//use lean tween next time
namespace Lemon.GenericLib.VFX
{
public class Popup_Text : MonoBehaviour
{
TextMeshPro PopupText;
public string text;
public float lifetime = 2;
public float startSpeed;
public float speed;
private float targetSpeed;
private float size;
private float targetSize;
public Transform parent;
// Start is called before the first frame update
void Start()
{
PopupText = GetComponent<TextMeshPro>();
PopupText.text = text;
targetSpeed = startSpeed;
size = 0;
targetSize = 1;
StartCoroutine(LifeTime());
parent = transform.parent;
}
// Update is called once per frame
void Update()
{
transform.localPosition += Vector3.up * targetSpeed * Time.deltaTime;
transform.localScale = new Vector3(transform.localScale.x, size);
targetSpeed = Mathf.Lerp(targetSpeed, speed, 5 * Time.deltaTime);
size = Mathf.Lerp(size, targetSize, 20 * Time.deltaTime);
if (parent != null)
{
if (parent.localRotation.y != 0)
{
transform.localRotation = Quaternion.Euler(0, parent.rotation.y - 180, 0);
}
else
{
transform.localRotation = Quaternion.Euler(0, 0, 0);
}
}
}
public void SetText(string text)
{
this.text = text;
PopupText.text = this.text;
}
IEnumerator LifeTime()
{
yield return new WaitForSeconds(lifetime);
targetSize = 0;
Destroy(gameObject, 0.25f);
}
}
}

View file

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

View file

@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Lemon.GenericLib.VFX
{
//this only works for sprite objects
public class SineWaveHover : MonoBehaviour
{
[SerializeField] float effectSpeed = 1;
[SerializeField] float effectMultiplier = 1;
[SerializeField] public float effectOffset = 1;
float yPos;
Vector3 originalPos;
private void Start()
{
originalPos = transform.localPosition;
}
// Update is called once per frame
void Update()
{
yPos = Mathf.Sin((Time.time + effectOffset) * effectSpeed) * effectMultiplier;
transform.localPosition = originalPos + new Vector3(0, yPos, 0);
}
}
}

View file

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

View file

@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Lemon.GenericLib.VFX
{
//need to be further developed
public class SpriteFlicker : MonoBehaviour
{
private SpriteRenderer sr;
// Start is called before the first frame update
void Start()
{
sr = GetComponent<SpriteRenderer>();
}
public void FlickerSprite(float duration, int intervals)
{
StopCoroutine("FlickerSpriteRoutine");
StartCoroutine(FlickerSpriteRoutine(duration, intervals));
}
IEnumerator FlickerSpriteRoutine(float duration, int intervals)
{
for (int i = 0; i < intervals; i++)
{
if (i > 0)
{
//if (i == 1) Camera_Controller.instanceCC.ApplyScreenShake(0.05f);
if (sr.maskInteraction == SpriteMaskInteraction.None)
{
sr.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
}
else
{
sr.maskInteraction = SpriteMaskInteraction.None;
}
}
yield return new WaitForSeconds(duration / intervals);
}
sr.maskInteraction = SpriteMaskInteraction.None;
}
public void StopFlicker()
{
StopCoroutine("FlickerSpriteRoutine");
sr.maskInteraction = SpriteMaskInteraction.None;
}
}
}

View file

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

View file

@ -0,0 +1,59 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace Lemon.GenericLib.VFX
{
public class SpriteFrameSetter : MonoBehaviour
{
private SpriteRenderer sr;
[SerializeField] private SpriteFrame[] spriteFrames;
private void Start()
{
sr = GetComponent<SpriteRenderer>();
}
public void SetFrame(string spriteName)
{
foreach (var item in spriteFrames)
{
if (item.spriteName == spriteName)
{
sr.sprite = item.sprite;
return;
}
}
Debug.LogError("Sprite frame requiested is not available.\nPlease check the spelling error");
}
public void SetFrame(int index)
{
if (index >= 0 && index < spriteFrames.Length)
{
sr.sprite = spriteFrames[index].sprite;
return;
}
Debug.LogError($"Sprite frame requiested {index} is not available.\nPlease check the spelling error");
}
[Serializable]
private class SpriteFrame
{
public string spriteName;
public Sprite sprite;
}
}
}

View file

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

View file

@ -0,0 +1,46 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Lemon.GenericLib.VFX
{
public class SpriteVibration : MonoBehaviour
{
[SerializeField] Vector2 vibrationRange;
private Vector2 originalPos;
private bool isVibrating = false;
// Start is called before the first frame update
void Start()
{
originalPos = transform.localPosition;
StartCoroutine(Viberate());
}
IEnumerator Viberate()
{
while (true)
{
if (isVibrating)
transform.localPosition = originalPos + new Vector2(Random.Range(-vibrationRange.x, vibrationRange.x), Random.Range(-vibrationRange.y, vibrationRange.y));
//else transform.localPosition = originalPos;
yield return null;
}
}
public void SetVibration(bool value) {
isVibrating = value;
if (!isVibrating) transform.localPosition = originalPos;
}
public void SetTempVibration(float duration) {
StartCoroutine(SetTempVibrationRoutine(duration));
}
IEnumerator SetTempVibrationRoutine(float duration) {
SetVibration(true);
yield return new WaitForSeconds(duration);
SetVibration(false);
}
}
}

View file

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

View file

@ -0,0 +1,213 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Lemon.GenericLib.VFX
{
//to do: build linear lerping that can change duration
public class SquashAndStretch : MonoBehaviour
{
[SerializeField] private Vector3 squashSize;
[SerializeField] private Vector3 stretchSize;
[SerializeField] private float transformRate = 10;
[SerializeField] private bool useRealative;
[SerializeField] private bool forceSnap = false;
[SerializeField] private Vector3 snapingMargin = new Vector3(0.001f, 0.001f, 0.001f);
public enum SquashMode { lerp, linear, addition }
[SerializeField] SquashMode squashMode;
[SerializeField] float linearLerpDuration;
//if useRealative is enabled the squash size will be the ratio of the original size
//rather than the exact size it's self
private Vector3 originalSize;
private Vector3 targetSize;
private float timeElapsed = 0;
private Vector3 startSize;
// Start is called before the first frame update
void Start()
{
originalSize = transform.localScale;
targetSize = originalSize;
startSize = originalSize;
}
Vector3 vectorToLerp = Vector3.zero;
// Update is called once per frame
void FixedUpdate()
{
//squash and stretch
//if (transform.localScale != targetSize) {
if (squashMode == SquashMode.lerp)
{
transform.localScale = Vector3.Lerp(transform.localScale, targetSize, transformRate * Time.deltaTime);
//Debug.Log("squashing " + targetSize);
if (forceSnap)
{
if (targetSize.x - transform.localScale.x <= snapingMargin.x && targetSize.y - transform.localScale.y <= snapingMargin.y && targetSize.z - transform.localScale.z <= snapingMargin.z)
{
transform.localScale = targetSize;
}
}
}
else if (squashMode == SquashMode.linear)
{
if (timeElapsed < linearLerpDuration)
{
transform.localScale = Vector3.Lerp(startSize, targetSize, timeElapsed / linearLerpDuration);
timeElapsed += Time.deltaTime;
}
else
{
if (forceSnap) transform.localScale = targetSize;
}
}
else if (squashMode == SquashMode.addition)
{
vectorToLerp.x = (transform.localScale.x - targetSize.x) * transformRate * Time.deltaTime;
vectorToLerp.y = (transform.localScale.y - targetSize.y) * transformRate * Time.deltaTime;
vectorToLerp.z = (transform.localScale.z - targetSize.z) * transformRate * Time.deltaTime;
transform.localScale += vectorToLerp;
vectorToLerp = transform.localScale;
if (vectorToLerp.x >= targetSize.x || vectorToLerp.x <= targetSize.x)
{
vectorToLerp.x = targetSize.x;
}
if (vectorToLerp.y >= targetSize.y || vectorToLerp.y <= targetSize.y)
{
vectorToLerp.y = targetSize.y;
}
if (vectorToLerp.z >= targetSize.z || vectorToLerp.z <= targetSize.z)
{
vectorToLerp.z = targetSize.z;
}
transform.localScale = vectorToLerp;
}
//}
}
public void ChnageOriginalSize(Vector3 newSize)
{
originalSize = newSize;
}
public void SetToSquash()
{
if (useRealative)
{
targetSize = new Vector3(originalSize.x * squashSize.x, originalSize.y * squashSize.y, originalSize.z * squashSize.z);
}
else
{
targetSize = squashSize;
}
//if (squashMode == SquashMode.linear || squashMode == SquashMode.addition) {
// timeElapsed = 0;
// startSize = transform.localScale;
//}
}
//returns to original size once it is done
public void SetToSquash(float duration)
{
StartCoroutine(SquashTimer(duration));
}
public void SetToStretch()
{
if (useRealative)
{
targetSize = new Vector3(originalSize.x * stretchSize.x, originalSize.y * stretchSize.y, originalSize.z * stretchSize.z);
}
else
{
targetSize = stretchSize;
}
if (squashMode == SquashMode.linear || squashMode == SquashMode.addition)
{
timeElapsed = 0;
startSize = transform.localScale;
}
}
//returns to original size once it is done
public void SetToStretch(float duration)
{
StartCoroutine(StretchTimer(duration));
}
public void customSquish(Vector3 newSize, bool useRealitive = false)
{
if (useRealitive)
{
targetSize = new Vector3(originalSize.x * newSize.x, originalSize.y * newSize.y, originalSize.z * newSize.z);
}
else
{
//Debug.Log("set target size " + targetSize);
targetSize = newSize;
}
if (squashMode == SquashMode.linear || squashMode == SquashMode.addition)
{
timeElapsed = 0;
startSize = transform.localScale;
}
}
//returns to original size once it is done
public void customSquish(Vector3 newSize, float duration, bool useRealitive = false)
{
StartCoroutine(SquishTimer(newSize, duration, useRealitive));
}
//resets back to the original size
public void ResetScale()
{
targetSize = originalSize;
}
//couroutine used
IEnumerator SquashTimer(float duration)
{
SetToSquash();
yield return new WaitForSeconds(duration);
ResetScale();
}
IEnumerator StretchTimer(float duration)
{
SetToStretch();
yield return new WaitForSeconds(duration);
ResetScale();
}
IEnumerator SquishTimer(Vector3 newSize, float duration, bool useRealitive)
{
customSquish(newSize, useRealitive);
yield return new WaitForSeconds(duration);
ResetScale();
}
}
}

View file

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

View file

@ -0,0 +1,60 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Lemon.GenericLib.Generics;
namespace Lemon.GenericLib.VFX
{
public class SquashTimer : MonoBehaviour
{
[SerializeField] float interval = 1.5f;
[SerializeField] SquashAndStretch sns;
public bool interupt = false;
TickCounter tick = new TickCounter();
private bool isSquash = false;
// Start is called before the first frame update
void Start()
{
tick.addAction(SquashingCycle);
}
// Update is called once per frame
void Update()
{
tick.AdvanceTick();
}
void SquashingCycle()
{
if (isSquash)
{
if (!interupt) sns.SetToSquash();
isSquash = false;
}
else
{
if (!interupt) sns.SetToStretch();
isSquash = true;
}
}
public void InteruptTimer(float duration)
{
StartCoroutine(InteruptTimerCooutine(duration));
}
IEnumerator InteruptTimerCooutine(float duration)
{
interupt = true;
yield return new WaitForSeconds(duration);
interupt = false;
}
}
}

View file

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

View file

@ -0,0 +1,69 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
//namespace Lemon.GenericLib.VFX
//{
public class VFX_Manager : MonoBehaviour
{
public static VFX_Manager insatnceVFXM;
private void Awake()
{
if (insatnceVFXM == null)
{
insatnceVFXM = this;
}
if (insatnceVFXM != this)
{
Destroy(gameObject);
}
}
[SerializeField] vfxData[] allVFXData;
private Dictionary<string, vfxData> vfxDictionary;
[Serializable]
struct vfxData
{
public string vfxName;
public GameObject vfxObject;
public bool shouldKill;
public float lifeTime;
}
private void Start()
{
vfxDictionary = new Dictionary<string, vfxData>();
foreach (var item in allVFXData)
{
vfxDictionary.Add(item.vfxName, item);
}
}
public GameObject spawnVFX(string vfxname, Vector3 position)
{
if (vfxDictionary.ContainsKey(vfxname))
{
GameObject newVFX = Instantiate(vfxDictionary[vfxname].vfxObject, position, Quaternion.identity);
if (vfxDictionary[vfxname].shouldKill)
{
Destroy(newVFX, vfxDictionary[vfxname].lifeTime);
}
return newVFX;
}
else
{
Debug.LogError($"vfx with name {vfxname} does not exist.\nPlease check if the spelling is correct.");
return null;
}
}
}
//}

View file

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