Created
April 18, 2021 17:43
-
-
Save CryZe/7fefa5e80939129f04166ccfeb489de7 to your computer and use it in GitHub Desktop.
LiveSplit One in Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using LiveSplitCore; | |
| using System; | |
| using System.IO; | |
| public class LS : MonoBehaviour | |
| { | |
| Timer timer; | |
| Layout layout; | |
| LayoutState layoutState; | |
| SoftwareRenderer softwareRenderer; | |
| Texture2D texture; | |
| void Start() | |
| { | |
| var spriteRenderer = GetComponent<SpriteRenderer>(); | |
| texture = new Texture2D(300, 500); | |
| var sprite = Sprite.Create( | |
| texture, | |
| new Rect(0.0f, 0.0f, texture.width, texture.height), | |
| new Vector2(0.5f, 0.5f) | |
| ); | |
| spriteRenderer.sprite = sprite; | |
| string path = @"C:\the\path\to\the\splits.lss"; | |
| var run = Run.Parse(File.OpenRead(path), path, true).Unwrap(); | |
| timer = Timer.New(run); | |
| timer.Start(); | |
| layout = Layout.DefaultLayout(); | |
| layoutState = new LayoutState(); | |
| softwareRenderer = new SoftwareRenderer(); | |
| } | |
| void Update() | |
| { | |
| layout.UpdateState(layoutState, timer); | |
| var textureBytes = texture.GetRawTextureData<byte>(); | |
| unsafe | |
| { | |
| var ptr = (IntPtr)Unity.Collections.LowLevel.Unsafe.NativeArrayUnsafeUtility.GetUnsafePtr(textureBytes); | |
| softwareRenderer.Render(layoutState, ptr, 300, 500, 300, false); | |
| } | |
| texture.Apply(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment