indieaiden
New Member
Coding? I don't know her
Posts: 3
|
Post by indieaiden on Feb 7, 2022 16:20:34 GMT
Hi! My name is Aiden. I've been following this tutorial back and forth since 2020. I've learned a lot as a programmer, but I want to continue with this project. It has helped me to start programming seriously, but I've encountered some problems when I wanted to implement something new. So I'm starting this thread to put my advancements, keep track of everything and, eventually, help you out.
Things to do: - Save/Load the current state of the game
- Implement a loading state before loading maps or whatever
- Configure 2D animations and sprites instead of the blobbies
- Create scenes with characters and movement
- Change the static sprites in the UI to variable emotions
- Make the player able to explore the map
- Make a conversation pool to trigger from
Implementing:
- Revisit and finish the tutorial and take notes
Things done: - Board Creator changes to make it easier to work with ✓
- Make a colorTweener to fade text ✓
- Make the intro system
- Connect the conversations with DB
Any contribution or idea about how to's are welcome. Let's go!
|
|
indieaiden
New Member
Coding? I don't know her
Posts: 3
|
Post by indieaiden on Feb 7, 2022 16:33:16 GMT
First thing I did was to update the BoardCreator to work with the keyboard.
So at the BoardCreatorInspector class, I added some Event trackers after all the if situation we had there.
BoardCreatorInspector.cs
if (GUILayout.Button("Load")) current.Load(); if (GUI.changed) current.UpdateMarker (); // New things here ---> if (GUILayout.Button("Crear Base")) current.CreateBase();
Event e = Event.current; switch (e.type) { case EventType.KeyDown: { switch (Event.current.keyCode) { case KeyCode.LeftArrow: current.pos = current.pos + new Point(-1, 0); break; case KeyCode.RightArrow: current.pos = current.pos + new Point(1, 0); break; case KeyCode.UpArrow: current.pos = current.pos + new Point(0, 1); break; case KeyCode.DownArrow: current.pos = current.pos + new Point(0, -1); break; ///////////// Grow and such case KeyCode.J: current.Grow(); current.UpdateMarker (); break; case KeyCode.K: current.Shrink(); current.UpdateMarker (); break; } current.UpdateMarker(); break; } } I did this so you can move with the arrows and then grow and shrink with J and K keys, respectively. It's important to note that the focus has to be in the Inspector. But besides that, it's a lot easier to work with.
Hope it helps!
|
|
indieaiden
New Member
Coding? I don't know her
Posts: 3
|
Post by indieaiden on Feb 7, 2022 16:51:32 GMT
Next thing I wanted to do was some kind of introduction to the player. In my head, some text had to appear in the middle of the screen. I had some implementation already with the Conversation class and such, but I wanted to be able to make that cool transition with the Tweeners. If you can do it with the movement, why not with some text? So, as I'm using TextMeshPro, I made a class called TextMeshProAnimationExtension.cs following the theme of the tutorial.
TextMeshProAnimationExtension
using System.Collections; using System; using UnityEngine; using TMPro;
public static class TextMeshProAnimationExtension { public static Tweener ChangeColor (this TextMeshProUGUI t, Color32 change) { return ChangeColor(t, change, Tweener.DefaultDuration); } public static Tweener ChangeColor (this TextMeshProUGUI t, Color32 change, float duration) { return ChangeColor(t, change, duration, Tweener.DefaultEquation); } public static Tweener ChangeColor (this TextMeshProUGUI t, Color32 change, float duration, Func<float, float, float, float> equation) { ColorTweener tweener = t.gameObject.AddComponent<ColorTweener> (); //Vector 4 vs Color necesito cambiarlo Color coloraux;
tweener.startTweenValue = t.color; coloraux = change; tweener.endTweenValue = coloraux; tweener.duration = duration; tweener.equation = equation; tweener.Play (); return tweener; } }
Then I needed something to inherit from Tweener. I made a Vector4Tweener, so I could alter the alpha value of the text.
Vector4Tweener.cs
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Vector4Tweener : Tweener { public Vector4 startTweenValue; public Vector4 endTweenValue; public Vector4 currentTweenValue { get; private set; }
protected override void OnUpdate () { currentTweenValue = (endTweenValue - startTweenValue) * currentValue + startTweenValue; base.OnUpdate (); } }
And lastly, I needed to update the transparency of the text over time, so I made the ColorTweener.cs class.
ColorTweener.cs
using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro;
public class ColorTweener : Vector4Tweener { TextMeshProUGUI textmeshPro;
void Awake () { textmeshPro = gameObject.GetComponent<TextMeshProUGUI>(); }
protected override void OnUpdate () { base.OnUpdate(); textmeshPro.color = currentTweenValue; } }
And that's it! When I call MovePanel in ConversationController.cs, and it makes the transition and such, I make this:
ConversationController.cs (...)
if (pos == ShowCenter) { text = obj.gameObject.GetComponentInChildren<TextMeshProUGUI>(); text.color = new Color32(255,255,255,0); obj.panel.SetPosition(pos,false); transition = text.ChangeColor(new Color32(255,255,255,255), 1f, EasingEquations.EaseOutQuad); } if (pos == HideCenter) { text = obj.gameObject.GetComponentInChildren<TextMeshProUGUI>(); transition = text.ChangeColor(new Color32(255,255,255,0), .1f, EasingEquations.EaseOutQuad); // transition.completedEvent += obj.panel.SetPosition(pos, false); }; (...)
To call the new Tweener and make the text appear and dissappear. Hope it helps!
|
|
|
Post by Admin on Feb 7, 2022 23:14:41 GMT
Thanks for sharing your improvements. I am really glad every time I know I have helped or inspired someone to work through the project and continue to develop it!
|
|
|
Post by thomasf on Apr 18, 2022 16:52:14 GMT
Hey Aiden, I tested your code for moving the cursor in the unity editor inspector window and it's awesome. While I tried to implement it, I ran in a few issues, I wanted to share: 1.) Admin : As far as I learned the convention for public properties is to start with an uppercase letter. The convention is not followed in the tutorial blogpost, nor in the git. If you could confirm it'd be awesome, a sI am not that great with conventions - but also my IDE was screaming name convention violation. so this means in the script Tile.cs
'public vector 3 center...'should be
public Vector3 Center { get { return new Vector3(pos.x, height * stepHeight, pos.y); }}
we can use a lambda expression for the block constructor, and also have current uppercase BoardCreatorInspector.cs
public BoardCreator Current => (BoardCreator)target;
2.) Aiden, I think you forgot to mention that we should make Point pos in the BoardCreator.cs to public, in order to access it in the inspector script
public Point pos;
However after thinking about it I also thought to introduce a public property like this would do the trick and be more elegant so I changed 'pos' back to a serialized field and went with this solution instead:
BoardCreator.cs
[SerializeField] Point pos;
public Point Pos { get { return pos; } set { pos = value; } }
3.) Aiden: I also think we generally can remove the UpdateMarker(); function from the Keycode.J and Keycode.K switch cases, just updating it a single time outside the switch statement
After the minor changes in the Board Creator and Tile script my full BoardCreatorInspector.cs script currently looks like this (just a lil bit cleaned up):
using UnityEditor; using UnityEngine;
[CustomEditor(typeof(BoardCreator))] public class BoardCreatorInspector : Editor { public BoardCreator Current => (BoardCreator)target;
public override void OnInspectorGUI() { DrawDefaultInspector(); if (GUILayout.Button("Clear")) Current.Clear(); if (GUILayout.Button("Grow")) Current.Grow(); if (GUILayout.Button("Shrink")) Current.Shrink(); if (GUILayout.Button("Grow Area")) Current.GrowArea(); if (GUILayout.Button("Shrink Area")) Current.ShrinkArea(); if (GUILayout.Button("Save")) Current.Save(); if (GUILayout.Button("Load")) Current.Load(); if (GUI.changed) Current.UpdateMarker();
Event e = Event.current; switch (e.type) { case EventType.KeyDown: { switch (Event.current.keyCode) { case KeyCode.LeftArrow: Current.Pos = Current.Pos + new Point(-1, 0); break; case KeyCode.RightArrow: Current.Pos = Current.Pos + new Point(1, 0); break; case KeyCode.UpArrow: Current.Pos = Current.Pos + new Point(0, 1); break; case KeyCode.DownArrow: Current.Pos = Current.Pos + new Point(0, -1); break; case KeyCode.J: Current.Grow(); break; case KeyCode.K: Current.Shrink(); break; } Current.UpdateMarker(); break; } } } }
|
|
|
Post by Admin on Apr 19, 2022 12:58:11 GMT
You are correct that the convention for Properties is to begin with upper case letters (PascalCase). It wont surprise me to find if I have missed several conventions, especially now, as I mostly spend time in other languages like Swift. Thanks for catching it.
|
|