Patterns
Monobehavior
- to perceive it is
Component
Singleton
- Uniqueness guaranteed
Managers
- Managers.cs
- if there is not
Managers
Object, make new one - this new
Managers
Object stay during play -
it links other Manager objects with each Managers
- InputManager.cs
-
If there is key input during play, receive key input
-
ResourceManager.cs
-
Instantiate
can make GameObject -
Destroy
can remove GameObject -
Load
can load GameObject - to use
Resources.Load
, there should be Resources folder
Controller
- PlayerController.cs
-
Quaternion.Slerp
can change direction
Collision
Gravity
- Player
- Add
Rigidbody
and checkUse Gravity
- Add
Capsule Collider
-
Is Kinematic
can ignore all physical laws in Unity - Plane
- Add
Mesh Collider
Collider and Trigger
- Collider
- There is
Rigidbody
on me (Is Kinematic : Off) - There is
Collider
on me (Is Trigger : Off) - There is
Collider
on other (Is Trigger : Off)
- Trigger
- There are
Collider
on me and other - There is
Rigidbody
on one - There is
Is Trigger
on one
Raycasting
- shoot a raser and detect object
-
TransformDirection
can change player’s direction to world direction -
RaycastHit
can save all objects that is hitted by player’s raser -
Physics.RaycastAll
can shoot a raser and detect objects - if you want to detect only one object, use
Physics.Raycast
Projection
-
Local ↔ World ↔ Viewport ↔ Screen
-
Screen
- Pixel standard
- Viewport
- Pixel ratio standard
- Camera
- You can change view range in
Clipping Planes
-
Near
can change where the camera range start -
Far
can change where the camera range end
- You can change view range in
Camera Raycasting
- camera can shoot raser and detect object
LayerMask
- you can set layers(also you can se Tags)
- from layers, you can define whether to detect object(s) or not
Camera
Follow Player
- if camera is in player’s hierarchy, camera will follow palyer
-
but the rotation is also changed, this is really messy for user
- Scripts\Utils\Define.cs
- CameraController.cs
- KeyInput and Camera transform is crushed by their update time.
LateUpdate
can delay Camera transform updating time. So Camera transform is excuted after player’s move
Click Moving
-
by clicking map, player can move to destination.
-
Scripts\Utils\Define.cs
- InputManager.cs
-
Left Mouse Click is 0 and Right Mouse Click is 1
-
PlayerController.cs
-
magnitude
returns length of vector -
hit.point
returns impact point in world space where the ray hit the collider
Camera Position
-
if player is hidden by wall, camera position will be change
-
CameraController.cs
Animation
WAIT & RUN
- Animation Controller
-
Animation Controller
can make animation - customize Animation
- Add controller in Animator
-
- PlayerController.cs
Animation Blending
- player can move sequencialy, not suddenly
- Blend Tree
- blend sevral animations
-
Threshold
sets blend values - when the value comes closer to threshold value, the animation will be excuted
- PlayerController.cs
State Pattern
- manage Player state
-
from this section, we don’t use keyboard KeyInput
- PlayerController.cs
State Machine
- you can set your animation in GUI
- PlayerController.cs
- Ordring animations
- you can order animations in
Transitions
section
- you can order animations in
- Conditioning
- you can make condition in animations
KeyFrame Animation
-
you can make KeyFrame Animation
-
Animation Tool
- Click object
- Add all Transform Properties
- change position at 60 sec and 120 sec
- keyframe recording mode
Animation Event
- Animation Event
- Add Animation Event
- Scripts\CubeEventTest.cs
- in added animation event, change function
- change
unitychan_RUN00_F
- Add Event
- PlayerController.cs
send reference value
- change
unitychan_RUN00_F
- change string
- PlayerController.cs
UI
Pivot
- it is central point of UI object
- object rotate round pivot when rotation is changed
Anchor
- set ratio and size of object when screen size is changed
UI Anomatification
Object Detection
- Detect Objects
- change object name
- Utils\Util.cs
- Scripts\UI\UI_Button.cs
Base UI
- Create Base UI
- use prefab
- Delete in Hierarchy
- first, delete
UI_Button
in prefeb - drag
UI_Button
in Hierarchy to prefab - delete
UI_Button
in Hierarchy - this step is to change
UI_Button
prefeb
- first, delete
- UI_Button.cs
- Script\UI\UI_Base.cs
- PlayerController.cs
Event Handler
- Drag Image
- add
UI_Button
in Hierarchy - add
ItemIcon
Image inUI_Button
- add
- PlayerController.cs
- Script\UI\UI_EventHandler.cs
- add this component in
ItemIcon
Image
- add this component in
- UI_Button.cs
UI Event
- Add Script Component
- by code, add script component in each game object atomatically
- UI_Base.cs
- Define.cs
- Util.cs
- UI_EventHandler.cs
- UI_Button.cs
- Extension.cs
- extense function
UI Manager
Create Popup
- Popup UI
- create Popup in code
- organize folder
- Create
Popup
folder in Prefabs\UI and Scripts\UI - Dreate
Scene
folder in Prefabs\UI and Scripts\UI - Move
UI_Button
to Prefabs\UI\Popup and Scripts\UI\Popup
- Create
- Scripts\UI\Popup\UI_Popup.cs
- Managers\UIManagers.cs
- use stack to manage popup
- UI_Button.cs
- Managers.cs
- PlayerController.cs
Popup ordering
- Popup Order
- Popup Ordering is essential when showing and closing popup
- Popup Blocker is essential if there is several Popups behind
- UIManager.cs
- UI_Popup.cs
- Scripts\UI\UI_Scene.cs
- PlayerController.cs
- UI_Button.cs
- Blocker
- Blocker blocks behind popup moving
- Create Image and set size to cover whole UI_Button
- set alpha value of color to 0
- set Hierarchy like below
Inventory
Panel
- Before starting, you should delete
UI_Button
in Hierarchy -
and change PlayerController.cs
- PlayerController.cs
- Asset Store
- search
Unity Samples : UI
- import only
Textures and Sprites
- search
- and down load
2D Sprite
in [window]-[Package Manager]
Binding
- Inventory Panel
- Create Pannel and Change Canvas name to
UI_Inven
- and use
UIPanel
in [Textures and Sprite]-[Rounded UI] to Panel
- Create Pannel and Change Canvas name to
- create Panel in Panel and change name to
UI_Inven_Item
- create Image in
UI_Inven_Item
- use
icon1
in [Textures and Sprite]-[Decoration] to Image
- Add
Grid Layout Group
in Panel
- prefab
UI_Inven_Item
and Duplicate this - prefab
UI_Inven
- Change Prefab
- in
UI_Inven
prefab, change panel name toGridPanel
- in
- in
UI_Inven_Item
prefab, change image name toItemIcon
- create Text and change name to
ItemNameText
- Scripts\UI\Scene\UI_Inven.cs
- PlayerController.cs
- UI_Base.cs
- Making Init in here is better
- UI_Popup.cs
- UI_Scene.cs
- Scripts\UI\Scene\UI_Inven_Item.cs
- Add Component
- in
UI_Inven
prefab, add ComponenetUI_Inven.cs
- in
UI_Inven_Item
prefab, add ComponentUI_Inven_Item.cs
- in
Fix Codes
- folder organization
- move
UI_Inven_Item
prefab and script
- move
- ResourceManager.cs
- it removes “(Clone)” string when creating new object by prefab
- UIManager.cs
- UI_Base.cs
-
and change all
AddUIEvent
toBindEvent
in the project -
Extension.cs
Scene
organize Scenes
- PlayerController.cs
- Scripts\Scenes\BaseScene.cs
- Scripts\Scenes\GameScene.cs
- Scripts\Scenes\LoginScene.cs
- Define.cs
- Game
- save
SampleScene
toGame
- Create Empty GameObject and change name to
@Scene
- Add
GameScene.cs
Componenet to@Scene
- save
- prefab EventSystem in Prefabs\UI
- Remove EventSystem object in Hierarchy
- Login
- Create New Scene and save name to
Login
- Create Empty GameObject and change name to
@Scene
- Add
LoginScene.cs
Componenet to@Scene
- Create New Scene and save name to
Changing Scenes
- Build Settings
- [Files]-[Build Settings]
- You can add Scene by Drag in Asset
-
it is for just setting, dont’ click build button, just exit this window
-
Scripts\Managers\SceneManagerEx.cs
- Managers.cs
- LoginScene.cs
- scene will change when you press Q
Sound
Sound ingredients
- Audio Source
- Player
- Audio Clip
- Sound file
- Audio Listener
- audience
Sound Manager
- move sound clips
- Create [Sounds] folder
- if player meet box, then sounds will play
- Add Sound Source Component
- Delete Cube Two
- Add Sound Source Component on Cube One
- check
Is Trigger
on Cube One - and Audio Listner is already in Main Camera, so you don’t have to add Audio Listner
- if you want, you can add Aduio Listner on player
- Scripts\Managers\SoundManager.cs
- Managers.cs
- Define.cs
- TestSound.cs
Memory Optimization
- Managers.cs
- InputManager.cs
- UIManager.cs
- SceneManagerEX.cs
- LoginScene.cs
3D Sound
- make 3D Sound on Cube One
- change Spatial Blend to 1. This mean this Sound Source is 3D Sound.
- change min and max distance
- for Next chapter, you need to remove TestSounc.cs and Sound Source Component on Cube One
Pool
- Pooling
- If there is so much object in game, it will make some trouble when loading.
- to decrese this overloading, pool manager will work
- pool manager loads object before they are activate setting non-activate
- when the are needed in game, pool manager will switch their status to activate from non-activate
Pool Manager
- Manager.cs
- Scripts\Managers\Poolable.cs
- Scripts\Managers\PoolManager.cs
- ResourceManager.cs
Test
- GameScene.cs
- LoginScene.cs
- Test
- create new prefab for player
- remove player in hierarchy
- add player in CameraController component
Coroutine
- can Save/Restore status of function
- stop a work spending so much time
- stop/restore function when you want
return
- yield retun object
- return type what you want(even class)
- yield return null
- pass this tic
- yield return break;
- stop this coroutine
Test
- GameScene.cs
Data
- JSON
- Normally, data is managed by json files
- Assets\Resources\Data\StatData.json
Data Manager
- Data Manager
- control the json files of data
- Managers.cs
- Scripts\Managers\DataManager.cs
Test
- GameScene.cs