HeavenStudioPlus/Assets/Scripts/Common/SuperScroll.cs
Rapandrasmus 864655096b Space Soccer Improvements (#382)
* SupahScrollSetUp

* Scrolls now, with issues, also added a flames animation

* Started implementing new multiple space kickers

* bg recolor space soccer

* Recolorable dots!

* we circular motitating n shit

* ReAdded Enter and exit stuff

* I despise unexplainable bugs

* The balls are so buggy 😱

* Trying to fix someting

* Fixed Scroll Stutter

* Fixed a whiff bug

* Updated sounds and added ease event for space kickers

* Fixed some bugs

* Changed some names

* new option for quiz show random presses

* Board meeting bug fixes

* Testing Curve stuff

* Converted all code to use new curves, need to fix all issues

* Playing around with keypoint values, will probably expose them so someone else can mess with them

* curves be like

* Fixed stuff

* BALLS FIXED

* Fixed clappy trio stuff

* Added player move event

* Almost fixed, just need to fix wonkiness with high kick toe

* Fixed da bug

* Board meeting and quiz show tweaks

* Fix for board meeting and enter/exit presets for space soccer

* Stop ball added

* Updated how scroll works
2023-04-26 12:43:35 +00:00

68 lines
No EOL
1.8 KiB
C#

using UnityEngine;
namespace HeavenStudio.Common
{
public class SuperScroll : MonoBehaviour
{
#region Private
[SerializeField] private Material _shader;
[SerializeField]
private Renderer _renderer;
[SerializeField]
private Sprite _sprite;
#endregion
#region Public
public float NormalizedX = 0.0f;
public float NormalizedY = 0.0f;
public Vector2 Normalized { get { return new Vector2(NormalizedX, NormalizedY); } set { NormalizedX = value.x; NormalizedY = value.y; } }
public float TileX = 1.0f;
public float TileY = 1.0f;
public Vector2 Tile { get { return new Vector2(TileX, TileY); } set { TileX = value.x; TileY = value.y; } }
public Material Material => _renderer.material;
#endregion
#region MonoBehaviour
private void Start()
{
_renderer.material = _shader;
var spriteRect = _sprite.rect;
var tex = CropTexture(_sprite.texture, new Rect(spriteRect.x, spriteRect.y, spriteRect.width, spriteRect .height));
tex.wrapMode = TextureWrapMode.Repeat;
Material.mainTexture = tex;
}
public void LateUpdate()
{
_renderer.material.mainTextureScale = Tile;
_renderer.material.mainTextureOffset = new Vector2(NormalizedX, -NormalizedY) * Tile;
}
#endregion
#region Custom
private Texture2D CropTexture(Texture2D original, Rect rect)
{
var colors = original.GetPixels((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
var newTex = new Texture2D((int)rect.width, (int)rect.height);
newTex.SetPixels(colors);
newTex.Apply();
return newTex;
}
#endregion
}
}