跳转至

Module 4 Camera manipulations, and multiple views

Coverage

Unity specific skills you will need, practice, and demonstrate include:

·         Working with camera viewport

·         Changing scenes

·         Information persisting across scenes

·         Sprite sheet (Atlas)

Concepts you will explore and understand include

·         More about the lerp function

·         Camera views and the game world,

·         Soft and hard movement of the camera: lerp and shake

  1. Basic Camera Controls:  

  2. Run Behavior:

  3. N: Move camera by (x, y) values (from the X/Y slider bars)

  4. M: Move camera to (x, y) values (to where Dye is located)
  5. H: Zoom with respect to the center (zoom factor slider bar)
  6. J: Zoom with respect to Dye (zoom factor slider bar)

  7. Scene setup:

  8. MainCamera:

  9. Has CameraSupport

  10. UI-Canvas:

  11. X/Y/Zoom: sliders (all connected to UserControlLogic)

  12. TheWorld: has UserControlLogic

  13. Background: Z=1 (larger than hero and egg)

  14. Hero and Egg

  15. UserControlLogic: central object that receives and parses user input

  16. Connection to UI sliders and other game objects

  17. Transmits user input to game objects to cause changes

  18. Camera folder/

  19. CameraSupport: seen this before, new function: ClampToWorldBound()

  20. CameraSupport_Manipulate: manipulates the connected camera

  21. MoveBy, Moveto, Zoom(towards center), ZoomTowards(point), PushCameaByPos()

  22. Testing:

  23. HeroControl (on the Hero)

  24. CollideWorldBound code

  25. PushCamera

  26. EggBehavior

  27. ClamAtWorldBound (always inside)

  28. Unity How to:

  29. Slicing Sprite Sheet (Atlas)

  30. Import Sprite Sheet (Type: Sprite (2D and UI))

  31. Select the Sprite
  32. Sprite Mode èMultiple
  33. Invoke the Sprite Editor, Click on Slice è Apply

  34. You may have to install the Sprite Editor using PackageManager

  35. Search for “2D Sprite” to install under “Unity Registry”

  36. Empty GameObject on TheWorld: UserControlLogic

  37. For organization

  38. Learned:

  39. Camera manipulation: simple changes to camera’s transform object (position, and orthographicSize)

  40. Note: the partial class to separate implementation into logical units

  41. Depth layering:

  42. Background with Z=1 (behind Hero and Egg)

  43. Unity: slicing of a sprite sheet

  44. Taking a closer look at Lerp

  45. Run BehaviorZ to see Lerp

  46. Try type Z-repeatedly!

  47. Increase to twice current size and tries to Lerp back gradually

  48. If continue to increase size before lerping to original size, net growth in size
  49. This can be easily avoided in HeroControl (how? e.g., ignore z-key when LerpIsActive())

  50. Examine: TimedLerp class

  51. Perform lerp for a fixed duration

  52. Rate is in units of second (easier to think about?)
  53. Rate and Duration are sliders in the UI-Canvas

  54. Look at HeroControl

  55. BeginLerp() to begin

  56. do not need to always SetLerpParms(), if you know the values

  57. LerpIsActive() to receive proper lerp results

  58. Learned:

  59. TimedLerp:

  60. Pretty handy class in general?

  61. This is is NOT a MonoBehavior!

  62. Note on testing: separate and trivial test environment, test all aspects

  63. More respectful camera manipulation:

  64. Run Behavior: same as previous examples, but notice the damping effect!

  65. N: Move camera by (x, y) values (from the X/Y slider bars)

  66. M: Move camera to (x, y) values (to where Dye is located)
  67. H: Zoom with respect to the center (zoom factor slider bar)
  68. J: Zoom with respect to Dye (zoom factor slider bar)

  69. CameraSupport:

  70. Position Lerp

  71. Size Lerp
  72. Update() function must check,

  73. If Lerps are going, must set accordingly

  74. Learned:

  75. One simple example of using the TimeLerp function (in lerping the camera position and size)

  76. Shaking … for the camera and more

  77. Run Behavior: same as previous examples, added key control

  78. X: To shake the camera (boss is coming!)

  79. Utility/ShakePosition (in Utility)

  80. Sampling on a DampedHarmonic function

  81. Number of cycles
  82. Length of shake duration

  83. CameraSupport_Manipulate:

  84. SetShakeParameters

  85. UpdateShake()

  86. When done, will return the original position

  87. Learned:

  88. Describe behavior and search functions learn, appropriately sample functions

  89. More advanced camera behaviors:

  90. Parallax, following: look for existing solutions (try to avoid implementing solutions that are already out there).

  91. Viewport and Hero Cam:

  92. Run Behavior: same as previous examples

  93. with a small cam focusing on the hero

  94. Small cam: Create a new Camera

  95. Projection: Orthographic

  96. Depth: > 0 (Main Camera is -1, the bigger the number, the more front)
  97. Check out the Viewport setting

  98. CameraSupport:

  99. SetViewportMinPos(x, y)

  100. SetViewportSize(w, h)

  101. UserControlLogic: testing

  102. Sliders connected to the HeroCam

  103. Change the small view viewport settings

  104. HeroControl:

  105. Changing the CamPosition of small view

  106. Questions:

  107. What does it mean to zoom in the small view?

  108. What does the orthographicsSize of Small view mean?

  109. Learned:

  110. What is a viewport and its settings

  111. How to work with the Unity viewport

  112. New Scene and Game State that persists over scenes

  113. Run Behavior: same as previous examples

  114. Perform some hero lerp and camera shakes (see the text echo)

  115. L key to load new scene: notice lerp and shake info persisted across scenes

  116. Unity details:

  117. Using UnityEngine.SceneManagementhttps://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html

  118. MUST:

  119. FileàBuild Settings

  120. Make sure all levels to be loaded are in the Scenes In Build

  121. Level Persistency: Singleton Pattern

  122. GameState class

  123. Print from UserControlLogic

  124. NewLevel level

  125. Simply echo, value persisted levels!

  126. Organization:

  127. Level-Specific folders

  128. Level-specific behavior: NewLevelGameManager

  129. Level-ClassExample

  130. HeroControl, EggBehavior, and UserControlLogic

  131. Move Camera into Utilities

  132. Learned:

  133. All game objects are erased when a new scene is loaded

  134. Must take special care (e.g., Singleton pattern) to create and maintain info across scenes
  135. Unity how to: create/load scene

  136. Take a look at:

  137. DontDestroyOnLoad()

  138. https://learn.unity.com/tutorial/implement-data-persistence-between-scenes