Skip to content

Commit

Permalink
add vfx
Browse files Browse the repository at this point in the history
  • Loading branch information
O-S-K committed Nov 28, 2024
1 parent 731c88f commit 460c112
Show file tree
Hide file tree
Showing 16 changed files with 324 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class MoveAlongPathEditorWindow : EditorWindow
public int indexPathSelect;


[MenuItem("OSK-Framework/Path Editor/Move Along Path Editor")]
[MenuItem("OSK-Framework/Tools/Path Editor/Move Along Path Editor")]
public static void ShowWindow()
{
GetWindow<MoveAlongPathEditorWindow>("Path Editor");
Expand Down
8 changes: 8 additions & 0 deletions Runtime/VFX.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions Runtime/VFX/BreathingVFX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using UnityEngine;
using static BreathingVFX;
using Random = UnityEngine.Random;

public class BreathingVFX : MonoBehaviour
{
public enum Asix
{
X, Y, Z
}

public Asix asix;
public float time = 5f;
public float mul = 0.1f;

float clock;

protected void Start()
{
clock = Random.Range(-5f, 5f);
}

protected void Update()
{
clock += Time.deltaTime * time;

switch (asix)
{
case Asix.X:
transform.localScale = new Vector3(1f + Mathf.Sin(clock) * mul, 1f, 1f);
break;
case Asix.Y:
transform.localScale = new Vector3(1, 1f + Mathf.Sin(clock) * mul, 1f);
break;
case Asix.Z:
transform.localScale = new Vector3(1, 1f, 1f + Mathf.Sin(clock) * mul);
break;
}
}
}
11 changes: 11 additions & 0 deletions Runtime/VFX/BreathingVFX.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions Runtime/VFX/DissolveControlVFX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using UnityEngine;
using UnityEngine.UI;

[ExecuteInEditMode]
public class DissolveControlVFX : MonoBehaviour
{
private Material dissolveMaterialInstance;

[Range(0f, 1f)]
public float dissolveValue = 0.0f;
public Texture texture; // Public texture to be set via Editor or scripts

void Start()
{
Renderer renderer = GetComponent<Renderer>();
SpriteRenderer spriteRenderer = GetComponent<SpriteRenderer>();
Image image = GetComponent<Image>();
RawImage rawImage = GetComponent<RawImage>();

if (renderer != null)
{
dissolveMaterialInstance = new Material(renderer.sharedMaterial);
renderer.material = dissolveMaterialInstance;
}
else if (spriteRenderer != null)
{
dissolveMaterialInstance = new Material(spriteRenderer.sharedMaterial);
spriteRenderer.material = dissolveMaterialInstance;
}
else if (image != null)
{
dissolveMaterialInstance = new Material(image.material);
image.material = dissolveMaterialInstance;
}
else if (rawImage != null)
{
dissolveMaterialInstance = new Material(rawImage.material);
rawImage.material = dissolveMaterialInstance;
}
else
{
Debug.LogWarning("DissolveControl: No compatible renderer found on the GameObject.", this);
}
}

void Update()
{
if (dissolveMaterialInstance != null)
{
dissolveMaterialInstance.SetFloat("_DissolveThreshold", dissolveValue);

// Check if the texture is not null and set it
if (texture != null)
{
dissolveMaterialInstance.SetTexture("_NoiseTex", texture);
}
}
}
}
11 changes: 11 additions & 0 deletions Runtime/VFX/DissolveControlVFX.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Runtime/VFX/FadeGlowVFX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using UnityEngine;

public class FadeGlowVFX : MonoBehaviour
{
public float speed = 0.2f;
public float from = 0f;
public float to = 1f;

public SpriteRenderer sr;

void Update()
{
var srColor = sr.color;
srColor.a = Remap(Mathf.Abs(Mathf.Sin(Time.time * speed)), -1f, 1f, from, to);
sr.color = srColor;
}

public static float Remap(float value, float from1, float to1, float from2, float to2)
{
return (value - from1) / (to1 - from1) * (to2 - from2) + from2;
}
}
11 changes: 11 additions & 0 deletions Runtime/VFX/FadeGlowVFX.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions Runtime/VFX/FlashVFX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections;
using UnityEngine;

namespace Animations
{
public class FlashVFX : MonoBehaviour
{
[SerializeField] private SpriteRenderer spriteRenderer;
[SerializeField] private Material flashMaterial;
[SerializeField] private float duration;

public float Duration => duration;

private Material originalMaterial;
private Coroutine flashRoutine;

[ContextMenu("Flash")]
public void Flash()
{
if (flashRoutine != null)
{
StopCoroutine(flashRoutine);
}
flashRoutine = StartCoroutine(FlashRoutine());
}

private void Start()
{
originalMaterial = spriteRenderer.material;
}

private IEnumerator FlashRoutine()
{
spriteRenderer.material = flashMaterial;
yield return new WaitForSeconds(duration);
spriteRenderer.material = originalMaterial;
flashRoutine = null;
}
}
}
11 changes: 11 additions & 0 deletions Runtime/VFX/FlashVFX.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions Runtime/VFX/MeanderVFX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using UnityEngine;

public class MeanderVFX : MonoBehaviour
{
public float pos = 0f;
public float angle = 5f;
public float speed = 2f;

private Quaternion startRotation;
private Vector3 startPosition;

float time;

void Start()
{
time = Random.Range(0f, 10f);
startRotation = transform.rotation;
startPosition = transform.localPosition;
}

void Update()
{
time += Time.deltaTime;

float angleChange = Mathf.Sin(time * speed) * angle;
Quaternion currentRotation = Quaternion.Euler(0f, 0f, angleChange);
transform.rotation = startRotation * currentRotation;

Vector3 newpos = new Vector3(Mathf.Sin(time * speed) * pos, 0, 0);
transform.localPosition = startPosition + newpos;
}
}
11 changes: 11 additions & 0 deletions Runtime/VFX/MeanderVFX.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Runtime/VFX/NoiseVFX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using UnityEngine;

public class NoiseVFX : MonoBehaviour
{
public float strength = 0.1f;
public float duration;
private float currentDuration;


private void Start()
{
currentDuration = duration;
}

void Update()
{
if (currentDuration <= 0)
{
currentDuration = duration;
transform.localPosition = Random.insideUnitCircle * strength;
}
currentDuration -= Time.deltaTime;
}
}
11 changes: 11 additions & 0 deletions Runtime/VFX/NoiseVFX.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Runtime/VFX/RestartIntervalVFX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using UnityEngine;

public class RestartIntervalVFX : MonoBehaviour
{
public float interval = 1f;
public bool isActivated = false;
public GameObject target;
private float clock = 0f;

private void Update()
{
clock += Time.deltaTime;

if (clock > interval)
{
clock = 0;
isActivated = !isActivated;
target.SetActive(isActivated);
}
}
}
11 changes: 11 additions & 0 deletions Runtime/VFX/RestartIntervalVFX.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 460c112

Please sign in to comment.