跳转至

Module 1: Game Engine + Objects

Coverage

Git and GitHub

  • Branches and Forks
    • Learn how to manage branches and forks effectively.
    • To save a Unity project, you only need the following three folders:
      • Assets
      • Packages
      • ProjectSettings (These store project settings and are optional; you mainly need the Assets folder.)
    • Do not push or submit the following folders as they can be re-generated by the Unity Editor:
      • Library, Temp, Logs, obj, .vs.

Basic Unity Skills

  • Open and work with the Unity Editor.
  • Configure a 2D camera, including setting the world size.
  • Build your game for:
    • EXE format.
    • WebGL.
  • Host WebGL builds for public access.

User Interaction

  • Implement keyboard state polling for user input.

Unity Objects

  • Work with textures and create 2D sprite objects.
  • Attach scripts (MonoBehaviour components) to GameObjects.
  • Assign GameObjects to script variables in the Unity Editor.
  • Use the Transform component to modify object positions.

Unity Setup

Unity Installation

  • Download and install Unity 3D. Refer to Unity Installation Help.
  • Stick to the specified Unity version for the class; do not update versions during the course as this may cause project delays.

Online Tools


Working with Git and GitHub

  • Fork the provided repository to track changes.
  • Clone the forked repository to your local machine.
  • Navigate to the Unity project folder (1.BasicSimpleProject) and note:
    • Assets folder: Store all project resources here.
    • EXE folder: Contains build results (not for editing).

Folder Management

  • Before submission:
    • Remove unnecessary folders: Temp, Obj, Library, Logs, Builds.
    • Keep backup copies of your work to prevent accidental loss.

Observations in Unity Editor

  • When opening a project in Unity, folders such as Library, Logs, Temp are auto-generated. These improve startup performance but are not needed for saving or sharing your project.

Module 1: Examples and Exercises

Example 1: Basic Simple Project

Exploring the Scene

  • Open the ClassExample scene:
    • Navigate to the Project panel: AssetsScenesClassExample.
    • Ensure you are in 2D mode by selecting the 2D option in the top-left corner of the Scene window.

Key Editor Windows

  1. Scene: Interactive editor for designing levels.
  2. Hierarchy: Lists all objects in the scene.
  3. Inspector: Displays details of the selected object.
  4. Game: Preview what the player will see.
  5. Console: Displays error and status messages.

Camera Configuration

  • Initial Settings:
    • Position: (0, 0, -10)
    • Rotation: (0, 0, 0)
    • Projection: Orthographic
    • Size: 100 (half the vertical height of the visible world).
    • Clipping Planes: Near: 0.3, Far: 1000.

Textures and Sprite Objects

  • Drag images into the Assets folder to import textures.
  • Ensure the Texture Type is set to Sprite (2D and UI).
  • Create a 2D Sprite Object:
    • GameObject2D ObjectSprite.
    • Assign a texture to the SpriteRenderer component.

World Coordinates

  • The visible height and width of the world are determined by the camera's size and aspect ratio.

Example 2: Scripts and Keyboard Input

Adding Scripts

  • Add a script to a GameObject:
    • Use the Add Component button in the Inspector.
    • Drag a script file onto the Inspector window.

Programming Model

  • Unity follows the Entity-Component-System (ECS) architecture:
    • Entity: GameObject.
    • Component: Components like Camera, SpriteRenderer, or custom scripts.
    • System: Unity's execution protocol (e.g., calling Awake(), Start(), Update()).

Script Lifecycle

  1. Awake(): Called first for initialization.
  2. Start(): Called once after Awake().
  3. Update(): Called once per frame during gameplay.

Key Learnings

  1. Open a Unity Scene and configure 2D camera settings.
  2. Create and manipulate 2D sprite objects.
  3. Add and manage scripts in Unity using the ECS architecture.
  4. Distinguish between Editor Mode and Play Mode:
    • Changes made in Play Mode are not saved after exiting.

Final Notes

Debugging

Building Your Game

  • Build as:
  • Practice hosting your WebGL game for public access.

Self-Practice

  • Follow the instructions provided and practice in class.
  • After each step, compare with the instructor's demonstration.

Credits

All clipart used in this class are from the "Microsoft Office Free Clip Art Library."