bashfu-dev
bashfu-dev
~ Bash's Dev Blog ~
2 posts
I try to talk about programming here. And sometimes that programming relates to game development.
Don't wanna be here? Send us removal request.
bashfu-dev ยท 7 years ago
Photo
Tumblr media
GIF of the 'game' in action
Inspired by In the Snowy Winter's Wake I wanted to figure out how I could do something like this myself, since I'm a gamedev n00b.I thought it woud be fun to just have an understanding of how something like this could work in Unity.
I've heard of raycasting many times through my Google dives, so I figured that would be what I was looking for. I started with a simple class that could hold the information I'd use in drawing the UI.
public class AreaInfo : MonoBehaviour { public Color backgroundColor; public Color textColor; public string mainText; }
And then finally, I needed a class to sit on the camer and grab the data from the areas and send it to my UI.This is where raycasting came in.
public class DataGrabbyThing : MonoBehaviour { public RectTransform panel; public Text text; void FixedUpdate () { RaycastHit hit; Vector3 dir = transform.TransformDirection(Vector3.forward); if (Physics.Raycast(transform.position, dir, out hit)) { AreaInfo info = hit.transform.GetComponent<areainfo>(); panel.GetComponent<image>().color = info.backgroundColor; text.color = info.textColor; text.text = info.mainText; } } }
It's so simple, but I learned about the basics of casting a ray, used GetComponent for the first time ever, and created my first ever UI.
All in all, I'm beginning my journey of learning Unity Engine.
1 note ยท View note
bashfu-dev ยท 7 years ago
Text
Creating a Music Ticker for My Live Stream
I stream a lot on Mixer, Microsoft's Twitch competitor, and I listen to a lot of music when I stream, especially because I usually stream programming stuff.
I'm a YouTube Red subscriber (I want to support channels, even if they're demonetized) and that gives me access to the Google Play Music library, which is really cool.
I've been using this service for upwards of a year at this point, and for that entire time, I've used Google Play Music Desktop Player, an electron-based desktop client for the music service.
For a while now, this application has offered a websocket API to pull information about your current application state, such as how far into a song you are, what song is playing, so on.
A few weeks ago, I wrote a ticker that could share information from this API on my stream in JavaScript. It writes to a text file can then be imported into OBS or XSplit.
However, I'm currently working on moving away from writing EVERYTHING with JavaScript/Node so I decided to recreate the project in Python, a language I've always admired, but never used extensively (check out my only other Python project, MeIRL Bot.)
I used the websockets library for this one, as well as Python 3's asyncio to handle most of the big stuff.
Learning asyncio's form of async/await was kind of a nice experience, and semi-familiar.
I did end up hitting a small bump in the road when I used a different websocket library which had its own asyncio loop, making it impossible to run my own loop as well.
I have two asyncio tasks that I register, one that connects to the local ws server and waits for incoming messages, and another that runs every x seconds to check if any changes have occurred on the socket server (such as song changes, or pausing the music.)
I also had a blast learning about the @property and @x.setter decorators which assisted in the actual checking for changes. When I set a change in the Ticker class, the setter allows me to do more than just change the value of the prop, such as also setting the private __changed property to True so I can track that.
But that's enough talking, here's the code.
If you have any questions, you can ask
0 notes