Unity Shenanigans - Part 1

What I've done in the past weeks and months

These last months I've decided to learn more about Unity by trying to make some scenes with some level of procedurality.

Dialogues


First I started trying to make a dialogue box and interactions with the enviroment. I first tried managing every interaction on a separate thread, but I quickly discovered one can not interact with the Unity API from different threads. I ended up discovering about IEnumerators and yield return, allowing me to code very specific events, with just C#, that can be stopped mid-execution to wait for user input (Like closing a dialogue box!).

public class InteractionText1 : Interactable {

    override public string GetUIName() {return "Talk";}

    //Performs an action
    protected override IEnumerator Action() {
        PlayerController.EnablePlayerInteraction(false);

        List<DialogueElement> ds = new List<DialogueElement>();
        ds.Add(new DialogueElement(LOC.Get("1c_NPC1_Dial1_1"), "Nice NPC"));
        ds.Add(new DialogueElement(LOC.Get("1c_NPC1_Dial1_2"), "Nice NPC"));

        DialogueManager.StartDialogue(ds);

        //Wait for the dialogue to end and advance
        yield return WaitForCheck(DialogueManager.active, false);

        ds.Clear();
        ds.Add(new DialogueElement(LOC.Get("1c_NPC1_Dial1_3"), "Nice NPC"));

        DialogueManager.StartDialogue(ds);

        //Wait for the dialogue to end and advance
        yield return WaitForCheck(DialogueManager.active, false);

        PlayerController.EnablePlayerInteraction(true);
    }
}
An example of an Interaction, starting some dialogues and waiting
with yield return for the dialogue to indicate it has ended (active == false).

Shadergraph learning


Then I delved straight into Unity's Shadergraph functionality, which allows users to create shaders with graph-style programming. Starting with a sweet tutorial by Brackeys, I made a simple first water shader, and as I wanted a pixelated style, I forced the UV map to have a "resolution" of sorts, giving the final product a nice style.

A low-poly planet



With the new knowledge I had recieved from making the water shader, I made this little low-poly planet! It uses fake lighting with a pre-computed normal map to provide a pixelated toon shadow. This specific planet is from the mod Other Worlds I made for KSP, with some color modifications.

A pixelart dynamic sky



Then I decided to create a "surface" scene, with a very low poly model for it, based on a heightmap. To add more character to it, I added a sky, and not only that, a dynamic one. The sky's and sun's color changes depending on the time of day, and not only that, you can see other planets in the form of stars! These aren't fixed either. Unity takes a set of Keplerian parameters (A simple but very used way of defining orbits in science) and transforms them to Cartesian Coordinates (Normal 3D coordinates), and using transform matrix, place the planets in the sky. These planets are also not very far away (Float Point Precision Errors are scary), so they are, actually, all about the same distance from the center of the scene.

I'm extremly proud of this one, even though it has used a lot of my time (But look how cute it looks!)

More Random Stuff


A test scene to try out the positioning of planets in the sky. The big
sphere is the Sun.

Trying out rendering whole planets. In this case,
I used Kerbal Space Program's planets to test it.
(The tidal locking worked!)

Fake Fresnel reflecting the sun's light in the water

The surface of the test scene (Triplanar mapping everywhere).
The ground's detail can be found here, made by hhh316

What now

I'm still learning step by step how to use Unity, but I think I'm already doing very cool stuff. I might use this in future projects if it turns out very well.

I will post more about my Unity Shenanigans in the future.

Comments

Post a Comment

Popular posts from this blog

A world of sulphur and heat - Redesign of Kevari

A Lava planet - Redesign of Troni