Lab 5 - Project Setup
Watch the lab Video
This lab consists of two parts:
- setting up git version control and
- creating an event-based structure that you can use in your project.
You don't submit anything this week. Instead, you should set up your project with your teammates.
Setting up a git repository:
- Create a repository for your team, you can use: Bitbucket or GitLab or GitHub.
- Enable Visible Meta files in Edit->Project Settings->Editor.
- Optional Scroll through the list of packages in Window->Package Manager and remove the ones you don't need. (you can later add them back)
- Create a local git repository from your project folder.
- Add appropriate git ignore file an example.
- Make sure that you DO NOT add *.meta files in your git ignore file. (meta files have to be in the repository. Otherwise, your changes will start disappearing).
- Commit and Push your initial code.
- Double-check that each asset file in your project has a corresponding metafile in your repository.
If you want to learn the basics of using Git version control, watch this video in Youtube: https://youtu.be/2sjqTHE0zok
Setting up the project structure
During the lab, you should create an individual sample project for practicing.
You could use the following asset packs for this practicing task:
Practicing tasks:
- Set up a currency system using events
- Create classes UI, Player, Coin and Events.
- Make the player movable and destroy the coin on a collision.
- Create a UI canvas with money text, try to use Text Mesh Pro for that.
- Make the Events class static (it doesn't inherit MonoBehavior)
- Create following events for changing and requesting the money
- public static event Action<int> OnChangeMoney;
- public static void ChangeMoney(int amount) => OnChangeMoney?.Invoke(amount);
- public static event Func<int> OnRequestMoney;
- public static int RequestMoney() => OnRequestMoney?.Invoke() ?? 0;
- Create "ChangeMoney(int amount)" method for your UI canvas. Bind it to the corresponding event in awake: Events.OnChangeMoney += ChangeMoney;
- Unbind the event in the OnDestroy method.
- Set the score when the money event is triggered.
- Store the money amount in player class. Bind both ChangeMoney and RequestMoney events in player script.
- Increase money amount when the coin is collected.
- Create a Store where the player can buy items.
- Create classes Shop, ItemData, ItemPresenter (These classes implement a Model-View-Controller pattern)
- ItemData should extend ScriptableObject class and contain following fields ItemType (enum), Name, Price, Sprite.
- Add an attribute [CreateAssetMenu(menuName ="Game/Item")] to this class.
- Create a Data folder and add a few items there.
- Add a public list of items to your shop script.
- Add 2 shopkeepers (with shop script) to your scene and fill their item lists.
- Create a world space UI with a panel and parent it to the shop.
- Add horizontal layout group to the panel and a button with equipment sprite in it. Give ItemPresenter class to the button and make a prefab out of it.
- Add SetData(ItemData data) method to the ItemPresenter;
- In the shop awake method, clear the list of items and initialize new ones according to the list of items.
- Bind the onClick method in the button and destory the item when pressed. Try to do it through the script this time.
- Listen OnMoneyChange event in itemPresenter and make the button inactive when the player doesn't have enough money. Also, change the money amount when buying an item.
Submission
You don't have to submit anything in this lab. Instead, spend the time to set up your own game architecture with your teammates.