Skip to content

Commit

Permalink
Add a VFX Skin Property for Randomization
Browse files Browse the repository at this point in the history
  • Loading branch information
Noisysundae committed Mar 23, 2022
1 parent d59fca1 commit b01946e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Refer to the [Releases](https://github.com/Noisysundae/techmania-ns/releases) se

### New Features

* Sprite Sheet Property: `randomOrientationSeed`
* VFX Skins Only
* If Set, Randomly Rotates and Flips Each VFX Sprite Layer Instance
* Possible Values: Any Positive Integer
* If the same number is shared between different layers, they will be rotated / flipped by the same amount.
* Default Value: -1 (Not Randomized)
* Sprite Sheet Property: `directionTracking`
* Note Skins Only
* Possible Values: `"none"`, `"mirror"`, and `"rotate"`
Expand Down
2 changes: 1 addition & 1 deletion TECHMANIA/Assets/Scripts/Components/Game Scene/BaseBga.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static void Forward(string guid = "")
{
hash += b;
}
rand = new Random(hash);
rand = new Random(hash + (int) System.DateTime.Now.Ticks);
currentIndex = rand.Next(length);
break;
case PlaybackMode.Random:
Expand Down
28 changes: 27 additions & 1 deletion TECHMANIA/Assets/Scripts/Components/Game Scene/VFXDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using UnityEngine;
using UnityEngine.UI;

using Random = System.Random;

// This would be called VFXRenderer, but apparently
// "Script 'VFXRenderer' has the same name as built-in Unity component."
//
Expand All @@ -18,10 +20,33 @@ public class VFXDrawer : MonoBehaviour
private Image image;
private float startTime;

// For random orientation seed reference
private static int baseRandomSeed;

private void ModifyTransform (Transform transform,
SpriteSheet spriteSheet,
Vector3 position)
{
if (spriteSheet.randomOrientationSeed >= 0)
{
Random rand = new Random(
baseRandomSeed
+ spriteSheet.randomOrientationSeed
+ (int) position.x * 1000
+ (int) position.y * 1000);
transform.Rotate(0, 0, (float) rand.Next());

float flipX = rand.Next() % 2 == 0 ? -1f: 1f;
float flipY = rand.Next() % 2 == 0 ? -1f: 1f;
transform.localScale.Scale(new Vector3(flipX, flipY, 1f));
}
transform.position = position;
}

public void Initialize(Vector3 position,
SpriteSheet spriteSheet, bool loop)
{
transform.position = position;
ModifyTransform(transform, spriteSheet, position);
this.spriteSheet = spriteSheet;
this.loop = loop;
if (spriteSheet.additiveShader)
Expand All @@ -36,6 +61,7 @@ void Start()
rect = GetComponent<RectTransform>();
image = GetComponent<Image>();
startTime = Game.Time;
baseRandomSeed = (int) System.DateTime.Now.Ticks;

if (spriteSheet.sprites == null ||
spriteSheet.sprites.Count == 0)
Expand Down
6 changes: 4 additions & 2 deletions TECHMANIA/Assets/Scripts/Serializable/Skin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public static class DirectionTracking
public const string Mirror = "mirror";
public const string Rotate = "rotate";
}
public string directionTracking = null; // Note skin, non-trails only
public string directionTracking; // Note skin, non-trails only
public int randomOrientationSeed; // VFX skin

[NonSerialized] // Loaded at runtime
public Texture2D texture;
Expand All @@ -46,7 +47,8 @@ public SpriteSheet()
speed = 1f;
additiveShader = false;

// directionTracking = DirectionTracking.None;
directionTracking = null;
randomOrientationSeed = -1;
}

// Call after loading texture.
Expand Down

0 comments on commit b01946e

Please sign in to comment.