Building online tactical action games based on unity and csharp Xây dựng game hành động chiến thuật trực tuyến dựa trên Unity và CSharp
Introduction
Reasons for Choosing the Topic
Growing Market Demand for Tactical Action Games
The gaming industry is experiencing a significant surge in the popularity of tactical action games, especially those with online multiplayer features Gamers are attracted to these titles for their strategic complexity, emphasis on teamwork, and competitive gameplay This increasing market demand underscores the genre's appeal and the potential for profitability in developing such games.
Tactical action games captivate players for long durations due to their demand for strategic thinking The addition of online multiplayer features significantly enhances player engagement by fostering social interaction, competition, and community building This immersive experience not only makes gameplay more enjoyable but also improves player retention, as gamers are drawn back for the social and competitive elements.
Developing an online multiplayer game is a challenging yet rewarding technical task that requires careful consideration of various complexities By leveraging Unity's powerful networking features and C# scripting, developers can effectively create essential functionalities like real-time player interactions, matchmaking, and server-client communication These challenges not only enhance the development process but also encourage developers to broaden their skills and expertise, leading to a more enriching game development experience.
Creating an online tactical action game offers a valuable opportunity to enhance knowledge in game development, particularly in network programming and multiplayer design principles This experience allows developers to gain hands-on skills in synchronization, latency management, and scalability, which are crucial for delivering a smooth and enjoyable multiplayer experience Consequently, the development journey becomes both an educational and professionally rewarding endeavor.
The tactical action game genre provides significant opportunities for creativity and innovation, enabling developers to explore diverse gameplay mechanics, level designs, character classes, and progression systems This creative flexibility fosters the creation of distinctive and unforgettable gaming experiences that can thrive in a competitive market By capitalizing on these possibilities, developers can craft games that not only satisfy market needs but also challenge the limits of game design.
In summary, creating an online tactical action game with Unity and C# presents significant advantages, including access to a booming market and improved player engagement and retention The technical hurdles and opportunities for learning contribute to a rewarding development journey, while the creative flexibility fosters the production of distinctive and innovative gaming experiences.
Objectives of the Topic
Grasping the essential functions of Unity is vital for game programming As a robust game development platform, Unity provides an extensive array of tools and features that simplify the creation of intricate games By mastering these core functionalities, developers can leverage Unity to transform their game concepts into reality, establishing a solid foundation for any successful game development endeavor.
Creating a basic game product involves several key steps, starting with the conceptualization of the game idea This is followed by designing the game mechanics, graphics, and user interface, which serves as the foundation for development Next, developers implement the game's functionality through coding, often using programming languages like C# The process continues with testing and debugging to ensure a smooth, error-free experience Finally, the game undergoes polishing and optimization for performance before its public release.
System design is crucial in game development, necessitating careful analysis and planning It encompasses the organization of the game's architecture, the definition of interactions among various components, and the assurance that the system meets the game's demands An effective system design improves performance, scalability, and maintainability, facilitating the addition of new features and the resolution of issues.
Creating a comprehensive game product involves a blend of creativity, technical expertise, and meticulous planning Success in this field demands a solid grasp of game design principles, strong programming skills, and effective problem-solving abilities Developers enhance their capabilities through practical experience, allowing them to tackle common challenges and gain essential insights into game development This hands-on approach is crucial for crafting high-quality, engaging games that attract players and differentiate themselves in the competitive gaming landscape.
Limitation
The beta version of the game is currently experiencing various glitches and bugs, which may lead to connection issues when players attempt to join matches Additionally, some game functions, like opening or closing the game, may not operate correctly Furthermore, inadequate computer hardware can hinder performance and stability, affecting the overall gaming experience.
Thesis structure
The report is structured logically to ensure readers gain a comprehensive understanding of the project's knowledge, methods, and operations, and is divided into six main chapters for clarity.
This chapter provides an overview of the project, outlining its objectives, scope, and significance
● Chapter 2: Introduction to Unity Engine
This chapter introduces the Unity engine, explaining its fundamental functionalities and why it was chosen for this project
● Chapter 3: Photon and Basic Functions
This chapter covers Photon, a networking solution for Unity, detailing its basic functions and how it supports online multiplayer gameplay
● Chapter 4: PlayFab and how player database work?
This chapter discusses PlayFab, a backend platform for live games, and its integration into the project for managing player data and server-side operations
● Chapter 5: Tactical Online Game Analysis
This chapter analyzes the tactical online game genre, examining key elements such as game mechanics, player engagement strategies, and market trends
● Chapter 6: Test Cases and Results
This chapter presents the test cases used to evaluate the game, along with the results, highlighting any issues encountered and their resolutions
This chapter present conclusion and explain what this project achieved, what need to improve for further development.
Scope
This project focuses on creating an online tactical action game for PC using Unity and C# Players will engage in interactive shooting mechanics, enhancing the multiplayer experience The game will also offer basic character customization options, backed by a database for player profiles.
Furthermore, the project will integrate a login system connected to a server-side database.
Introduction of unity engine
Concept
Unity, developed by Unity Technologies, is a powerful game engine that enables the creation of video games for various platforms, including computers, consoles, and mobile devices Launched in 2005 at Apple's Worldwide Developers Conference, Unity now supports 27 platforms and offers robust capabilities for both 2D and 3D graphics Developers primarily use C# to code within Unity, allowing for the importation of sprites and the use of an advanced 2D world renderer for 2D games For 3D game development, Unity provides tools to adjust technical parameters such as textures and resolution, enhancing the overall gaming experience.
Basic Concepts in Unity
In game development, the root folder is essential as it contains all the necessary components for creating a game This folder is carefully organized to include models, resources, scripts, scenes, and other vital assets Each element within the root folder contributes significantly to the game's creation and functionality, highlighting its importance in the development process.
The root folder acts as a centralized repository for all game assets, including essential 3D models that define characters and objects for visual representation It also houses resources like textures, sounds, and animations that enhance the game's immersive experience Additionally, scripts written in languages such as C# control the behavior and interactions within the game environment Various scenes, representing different levels or environments, integrate these elements to provide a cohesive and interactive experience for players.
The Project serves as a comprehensive library that organizes all essential documents and files needed for game development, including assets, configuration files, metadata, and version control information By systematically structuring these elements, the Project enhances workflow efficiency for developers, supports collaboration among team members, and preserves the integrity of the game's architecture throughout the development process.
The root folder and the Project are essential components of game development, serving as the foundation for managing and organizing all necessary elements and documents to transform a game from concept to completion Recognizing the significance and functionality of these components is vital for developers aspiring to create high-quality, well-structured, and fully operational games.
Prefabs in Unity Game Development: Streamlining Reusability and Efficiency
Prefabs are essential in Unity game development, acting as crucial tools that streamline the creation and management of game objects This article highlights the importance of prefabs in improving reusability, ensuring consistency, and enhancing overall efficiency in game development workflows.
A prefab in Unity is a saved instance of a game object, carefully configured for reuse across various scenes This encapsulation includes the object's visual representation, scripts, and components, allowing developers to easily instantiate prefabs By promoting consistency and minimizing redundancy, prefabs streamline the development process in Unity projects.
Prefabs offer significant advantages in game development by enhancing reusability By transforming a game object into a prefab, developers can deploy it across multiple scenes and contexts, fostering versatility This approach not only helps maintain a consistent design language but also ensures uniform gameplay experiences throughout the entire game.
Prefabs greatly enhance productivity by simplifying development processes and reducing repetitive tasks Developers can easily instantiate prefabs through drag-and-drop or scripted methods, eliminating the need to recreate identical game objects This approach not only conserves valuable time but also lowers the likelihood of errors and inconsistencies that can occur with manual duplication.
Prefabs enhance the scalability and maintainability of Unity projects by acting as centralized templates for game objects This allows for quick iterations and updates during game development, as any changes made to a prefab automatically apply to all its instances throughout the project This feature ensures consistency and accelerates the iterative development process.
In summary, prefabs are essential components in Unity game development, providing numerous advantages such as improved reusability, consistency, and increased productivity By effectively utilizing prefabs, developers can optimize their workflows, accelerate development timelines, and create polished, cohesive, and engaging gaming experiences for players around the globe.
In game development, grasping the concept of entities is crucial for crafting engaging and dynamic virtual worlds This article highlights the importance of game objects in Unity, emphasizing their various roles and functionalities that enhance the overall gaming experience.
Entities in a game scene include all visible and invisible elements that enhance the interactive experience These range from physical objects like tables, chairs, and weapons to intangible elements such as sound sources, cameras, and lighting Each entity contributes uniquely to the game's atmosphere, gameplay mechanics, and overall immersion.
Game objects are essential components of Unity scenes, representing both tangible items and abstract entities within the game environment They create the structural foundation for the game's dynamics, allowing developers to instantiate, manipulate, and interact with them in real-time This versatility ensures a dynamic and engaging gaming experience for players.
Empty game objects in Unity, though lacking content, play a crucial role in the parent-child hierarchy system They act as organizational nodes and placeholders, helping to manage complex scene structures effectively By serving as parent objects to other game objects, they create hierarchical relationships that optimize development workflows and improve scene organization.
All game objects, regardless of whether they are filled or empty, have fundamental properties like position, rotation, and scale in the game world This spatial information allows developers to dynamically adjust game objects, modifying their location, orientation, and size to create desired gameplay effects and enhance visual appeal.
Basic Components of the Unity Editor
The game world window in Unity is an essential tool for developers, enabling them to visualize and manage all elements in the current scene This article explores the importance of the game world window, highlighting its vital functions in scene editing, object manipulation, and spatial organization within Unity's development environment.
Central to the game world window's functionality is its role as a comprehensive representation of the current scene, encompassing all elements—both visible and invisible—that constitute the virtual environment
Developers can enhance their understanding of a game's spatial layout, object hierarchy, and overall composition by utilizing visual overviews of the scene's contents This approach promotes efficient navigation and aids in comprehending the complexities of the game world.
The game world window is the main workspace for editing game objects within a scene, enabling developers to move, rotate, scale, and reposition these objects visually These editing actions are reflected in real-time, allowing developers to instantly observe and evaluate the visual impact of their modifications.
The game world window enables effective spatial organization and arrangement of game objects, allowing developers to intuitively rearrange items through drag-and-drop interactions This functionality helps establish hierarchical relationships and refine the layout, ultimately enhancing the aesthetics and gameplay dynamics Such spatial organization is crucial for promoting coherence, clarity, and navigability within the scene, thereby improving player immersion and engagement.
The game world window is a powerful workspace that enables developers to visualize, edit, and organize game elements effectively With its intuitive tools and real-time feedback, it enhances scene editing workflows, speeds up iteration cycles, and supports the realization of creative visions in Unity's development environment.
In summary, the game world window in Unity serves as a vital interface for developers to design and manipulate their game's virtual environments With its robust visualization features, user-friendly editing tools, and effective spatial organization, this window enables creators to build immersive gaming experiences that capture players' imaginations and create memorable moments.
The game window in Unity is the key interface that allows players to interact with the virtual environments crafted by developers This article highlights the importance of the game window, focusing on its function in showcasing the player's viewpoint and offering vital tools to enhance the gaming experience within Unity's development framework.
The game window serves as the player's primary viewport into the virtual world, enabling a dynamic and immersive experience Through the camera, it renders and displays objects within the scene, allowing players to interact with their environment, explore diverse settings, and engage with various gameplay mechanics.
The game window's toolbar features various options aimed at improving player experience and equipping developers with crucial tools for enhancing performance and functionality Players can adjust screen resolution, allowing them to customize their gaming experience to match their preferences and device specifications, ultimately optimizing both visual clarity and overall performance.
The toolbar offers essential statistics that deliver insights into performance metrics like frame rate, rendering time, and resource utilization These metrics enable developers to effectively monitor and optimize game performance, ensuring a smooth and responsive gameplay experience across diverse hardware configurations.
Incorporating gizmos into the game window significantly improves players' comprehension of the game world by offering visual cues and indicators for various objects and elements These gizmos assist players in navigating their surroundings, recognizing interactive components, and grasping spatial relationships, ultimately enhancing immersion and promoting intuitive gameplay experiences.
The toolbar gives developers the ability to toggle game components on and off, enhancing flexibility and control over the visibility and functionality of specific elements This functionality facilitates testing and debugging, allowing for fine-tuning of gameplay mechanics and optimization of performance, all while maintaining a seamless player experience.
The game window in Unity is an essential interface for players and developers, providing a glimpse into the virtual game world while offering vital tools for optimizing performance Its intuitive design and extensive features enhance player immersion, streamline gameplay, and enable developers to craft engaging and immersive gaming experiences within Unity's development environment.
The Hierarchy window in Unity is a crucial organizational tool that aids in managing and manipulating game objects within a scene This article explores the importance of the Hierarchy window, emphasizing its structured layout and essential function in enhancing scene organization and editing workflows in Unity's development environment.
The Hierarchy window is essential for organizing game objects into a tree structure that illustrates parent-child relationships, facilitating spatial organization and logical groupings within the scene This visual representation offers developers an intuitive framework to understand the scene's composition and hierarchy Additionally, the Hierarchy window dynamically updates to reflect any changes made to game objects, ensuring that additions, removals, or modifications are immediately visible This real-time feedback enhances efficiency and accuracy in scene editing, allowing developers to iterate quickly and make informed decisions about organization and composition.
Introduction of Photon
Photon is an advanced multiplayer game development framework created by Exit Games, enabling the effortless creation of online multiplayer experiences across various platforms This article offers a concise overview of Photon’s essential features and highlights its importance in academic discussions.
Photon's architecture is built on a strong networking framework designed for real-time communication and synchronization among players This infrastructure is optimized to reduce latency and provide high reliability, significantly improving the fluidity and responsiveness of multiplayer interactions.
Photon's standout characteristic is its exceptional scalability, enabling developers to seamlessly expand their multiplayer games from simple prototypes to large-scale, globally accessible experiences This capability is supported by Photon's cloud-based architecture, which intelligently allocates resources to adapt to varying player demand while ensuring optimal performance and stability.
Photon offers developers a robust suite of features designed to simplify multiplayer game development, including matchmaking, lobby management, integrated voice and text chat, strong player authentication, and effective data persistence solutions By handling the complexities of multiplayer networking, Photon allows developers to concentrate on creating captivating gameplay experiences.
In summary, Photon stands out as an essential resource in the field of multiplayer game development Its advanced networking capabilities, scalability, and extensive features make it a fundamental tool for both researchers and developers, facilitating the creation of innovative and engaging online multiplayer experiences across diverse platforms and genres.
Visual Studio and how to use it
Visual Studio is a powerful integrated development environment (IDE) developed by Microsoft, providing developers with a comprehensive set of tools for creating a wide range of applications, including web, mobile, desktop, cloud, and enterprise solutions.
Visual Studio provides developers with the ability to code in various programming languages, including C#, Visual Basic, C++, F#, and JavaScript It offers a wide range of features, from basic code editing to advanced tools for debugging, profiling, testing, and version control, all within a cohesive user interface.
Visual Studio enhances team collaboration through its suite of features, including live sharing and seamless integration with Azure DevOps, which simplifies project management and version control.
Visual Studio offers a vast ecosystem of extensions available in the Visual Studio Marketplace, allowing developers to customize their development environment to suit the unique needs of their projects.
Visual Studio is a powerful and versatile toolset that enables the efficient development of high-quality software solutions across various platforms and technologies.
2.6.2 How to link to Unity Engine
Integrating Visual Studio with the Unity game engine is essential for developers aiming to optimize their workflow and boost productivity in Unity project development This guide outlines a systematic approach to effectively establish this integration.
1 Visual Studio Installation: It is imperative to ensure that Visual Studio, preferably the Community edition for its accessibility, is appropriately installed on the system This step serves as the foundation for subsequent integration efforts
2 Unity Initialization: Upon launching the Unity editor, the user should proceed to open the desired Unity project within the interface This serves as the operational context for subsequent development endeavors
3 Designation of Default Script Editor: Within the Unity environment, navigating to the "Edit" menu, followed by "Preferences," and subsequently selecting "External Tools" facilitates the designation of Visual Studio as the default script editor This configuration ensures automatic routing of script- related activities to Visual Studio for seamless development
Figure 12 Setup an IDE tool for Unity Engine
4 Script Access Protocol: Double-clicking on any script file within the Unity
Editor triggers its automatic opening in Visual Studio, thereby enabling developers to swiftly access and modify script files within their Unity project
5 Direct Access from Unity: Alternatively, developers may opt to access
To open a script file in Visual Studio from the Unity interface, simply select the desired script in the Unity Project window and choose the "Open C# Project" option This process automatically launches Visual Studio, providing immediate access to the selected script for editing.
6 Coding and Debugging: Armed with Visual Studio, developers can leverage its robust features for code composition, editing, and debugging This capability empowers developers to iteratively refine and enhance their codebase with precision and efficiency
7 Compilation and Testing: Following modifications made within Visual
Developers are returning to the Unity environment for project compilation and testing due to its ability to automatically detect script changes and trigger recompilation This feature ensures that any adjustments made to the codebase are seamlessly synchronized with project execution, enhancing workflow efficiency.
Developers can enhance their development workflow and accelerate Unity project creation by systematically linking Visual Studio with the Unity game engine.
Introduction of Playfab
PlayFab is a robust backend platform tailored for the development and management of live games Since its acquisition by Microsoft in 2018, it has offered a diverse array of services that enable game developers to create and oversee their games with enhanced efficiency and effectiveness This article will explore its key features and functionalities.
● Player Accounts: Securely manage player identities and data across various platforms
● Player Data: Store and access player-specific data, such as game progress, inventory, and statistics
● Authentication: Support for multiple authentication methods including email, social media accounts, and custom IDs
● Real-Time Analytics: Monitor game performance and player behavior with real-time data insights
● Leaderboards and Statistics: Create and manage leaderboards, track player statistics, and maintain competitive environments
● Matchmaking: Facilitate multiplayer interactions with dynamic matchmaking services that pair players based on criteria such as skill level and latency
● Virtual Economy: Manage virtual currencies, items, and in-game purchases
● In-App Purchases: Integrate with various payment gateways to handle in-app transactions and subscriptions
● Promotions and Rewards: Create promotional campaigns, rewards, and loyalty programs to engage and retain players
● Cloud Script: Deploy and run custom game logic on the server side
● LiveOps: Update game content and configurations without the need for client updates, enabling A/B testing and dynamic content changes
● Push Notifications: Engage players with targeted messages and notifications
● Server Hosting: Scalable game server hosting to support multiplayer gameplay
● Party and Chat Services: Integrate social features like party systems and in- game chat
● Event Logging: Track in-game events to gather detailed insights into player behavior
● Data Export: Export data to external analytics tools for deeper analysis and reporting
● Scalability: Easily scale game services to accommodate a growing player base
● Efficiency: Focus on game development while PlayFab handles backend infrastructure
● Flexibility: Customize and extend services to fit specific game requirements
● Integration: Seamlessly integrate with other Microsoft services, such as Azure and Power BI, for enhanced capabilities
● Live Game Management: Continuously update and manage live games with real-time insights and dynamic content adjustments
● Player Engagement: Enhance player retention and engagement through personalized experiences, leaderboards, and social features
● Revenue Generation: Implement effective monetization strategies with robust in-game economy and payment integrations
1 Sign Up: Create a PlayFab account and set up a new game project on the PlayFab dashboard
2 SDK Integration: Integrate the PlayFab SDK into your game, available for various platforms and game engines such as Unity, Unreal Engine, and custom C++
3 Configure Services: Set up player management, game services, and economy features based on your game’s requirements
4 Deploy and Manage: Deploy your game and use PlayFab’s tools to monitor, update, and manage your live game
PlayFab offers a powerful and scalable platform for game developers, allowing them to concentrate on crafting captivating gaming experiences while utilizing advanced backend services to manage the complexities of game operations effectively.
How to apply model and make an animation
From step 1 to step 3 is download the model and extract model into asset folder
Acquiring and preparing 3D models for game development is a multi-step process essential for ensuring high-quality assets within the game environment This process includes extracting files from online sources and following a materialization procedure to enhance the functionality of the models.
To begin the process of game development, developers should source 3D models from reputable online repositories like Sketchfab, which is known for its extensive collection of high-quality models By browsing through Sketchfab's user-friendly platform, developers can select models that meet their project's aesthetic and functional needs, allowing for informed decision-making during the selection process.
After identifying the desired models, developers extract all relevant files, including the model and its textures This process entails downloading model files in compatible formats like OBJ or FBX, along with essential texture maps such as base color, metallic, and normal maps Ensuring the extraction of all necessary files is crucial for maintaining the model's visual fidelity and material properties during import into the game engine.
When a model lacks pre-existing materials, developers initiate the materialization process to create and apply suitable textures This involves extracting material information from the model and assigning textures that define surface properties, including color, reflectivity, and details Key texture maps, such as base color maps, dictate the model's coloration, while metallic and normal maps determine surface reflectivity and detailing.
Figure 14 A texture inspector for material model
From step 4 to step is creating an animation (in this report I will take how to create a shooting animation as an example)
The animation process begins with the selection of a prefab or a specific component of a prefab to be animated Prefabs act as reusable templates for game objects, enabling developers to efficiently manage and manipulate multiple instances of the same object By choosing a prefab or its component, developers lay the groundwork for creating animations that will influence the selected objects.
Figure 15 In this figure, there is no animations
Step 5: Creating an Animation and Organizing Files
Developers create animations by defining keyframes that outline the desired movements or transformations over time These animation files are usually saved with the "anim" extension and organized in a specific folder within the project directory, ensuring easy access and management within the Unity project.
To start the animation creation process in Unity, developers should activate the record mode in the animation editor This feature allows for modifications to selected objects, which are then recorded as keyframes in the animation timeline By enabling record mode, any changes made to the objects during the animation process are accurately captured and incorporated into the final animation.
Figure 16 This is an animation when turn on a record button
Step 7: Adding Keyframes (a write dot) and Adjusting Positions (a write horizontal) With record mode enabled, developers proceed to add keyframes at specific points along the animation timeline Keyframes serve as markers that define the state of the objects at various points in time, allowing for smooth transitions between different positions or rotations Developers can adjust the position, rotation, or other properties of the selected objects at each keyframe, refining the animation to achieve the desired visual effect
Step 8: Finalizing the Animation Once keyframes are added and positions adjusted, developers can turn off record mode and preview the animation by pressing the play button within Unity's animation editor This allows developers to observe how the objects move and interact over time, ensuring that the animation flows smoothly and effectively communicates the intended motion or behavior By fine- tuning keyframes and making adjustments as needed, developers can finalize the animation and integrate it seamlessly into the game environment
Figure 17 An overview of a saved heavy sniper shooting animation after turn off record
Conclusion
In summary, this chapter highlights the significance of Unity Hub as a vital tool for managing Unity projects With its user-friendly interface and extensive features, Unity Hub is accessible to both novice and seasoned developers It effectively streamlines workflows, manages various Unity versions, and organizes projects efficiently, making it an invaluable resource The development community widely adopts Unity Hub, contributing to a smoother and more productive development experience.
Photon and how Photon work ?
Setup
Setting up and integrating Photon networking into a Unity project requires several essential steps for effective multiplayer functionality This guide details the sequential process of establishing a Photon application and incorporating the Photon App ID into Unity, ensuring a smooth integration experience.
Step 1: Setting Up the Photon Application
To get started with a Photon application, visit the Photon website and create an account if you haven't already After logging into the Photon Dashboard, follow the prompts to create a new application Be sure to note the unique App ID provided, as this will be essential for integrating Photon networking into your Unity project.
Step 2: Integrating the Photon App ID into Unity
After obtaining the Photon App ID, developers integrate it into their Unity project by accessing the PhotonServerSettings, found under Assets > Photon Unity Networking In the PhotonServerSettings window, they paste the App ID into the AppIdRealtime field, ensuring proper communication between the Unity project and the designated Photon application.
Figure 18 The setup Photon SDK panel
How does Photon SDK work in Unity Hub ?
Photon SDK use case diagram :
Figure 19 An overview in Photon SDK work in Unity
Photon Unity Network utilizes Photon Cloud, a managed service that offers the backend infrastructure essential for multiplayer gaming It manages matchmaking, player connections, room management, and more
● Photon Server: A dedicated server responsible for handling game logic and player interactions It can be hosted either on-premises or in the cloud, based on the game's needs
● Photon Cloud: A cloud-based service that delivers the infrastructure for multiplayer games, eliminating the necessity for a dedicated server setup [8]
● Photon SDKs: SDKs available for various platforms, including Unity, which facilitate the integration of multiplayer features into games
Photon offers various matchmaking options to help players find and join games:
● Random Matchmaking: Players are automatically placed into available rooms
● Custom Matchmaking: Players can create or join rooms based on specific criteria, such as skill level or game mode
● Lobbies: Areas where players can wait before joining or creating a game room Photon supports multiple lobbies for different game types or regions
● Rooms: Instances of a game session where players are matched, which can be either public or private
Photon supports various networking models for multiplayer games:
● Client-Server Model: One player acts as the host (server), and other players connect as clients
● Dedicated Server Model: A separate server instance manages game logic and player interactions
● Peer-to-Peer Model: Players connect directly to each other without a central server [8]
Photon offers tools to synchronize game states across all clients:
● PhotonView: A component used to synchronize objects across the network
● RPC (Remote Procedure Calls): Allows functions to be called on other clients or the server
● Custom Properties: Enables storing and synchronizing custom data for rooms and players
Photon employs reliable networking protocols to ensure smooth gameplay:
● UDP (User Datagram Protocol): Utilized for fast and efficient data transfer
● TCP (Transmission Control Protocol): Used for reliable data transfer, ensuring all packets are received
Photon provides various tools and settings to optimize network performance:
● Lag Compensation: Techniques to reduce the perceived lag between players
● Network Culling: Optimization of which objects are synchronized based on player proximity
● Bandwidth Control: Management of data transfer rates to ensure a smooth experience
Photon Unity Network is deeply integrated with Unity, offering:
● Photon Unity Networking (PUN): A Unity-specific SDK that simplifies multiplayer game development
● Unity Editor Integration: Tools and components that integrate directly into the Unity Editor, facilitating the development and debugging of multiplayer games
Photon includes several security features to protect against cheating and unauthorized access:
● Authentication: Supports various authentication methods, such as OAuth, custom authentication, and PlayFab integration
● Data Encryption: Encrypts sensitive data transmitted over the network
● Since all users connect to the same servers, it's essential to have a system to differentiate between different players and games
● Each game or application is assigned a unique "AppId" in the Cloud, ensuring that players only interact with others using the same "AppId"
● Additionally, there is a "Game Version" identifier, which is a string that can be modified This versioning helps segregate players using older client versions from those with newer ones.
Testcase
How to test Expected result
Result Conclusi on Connecting to the game
Run the project in 2 devices then input a name in the project
(take damage and receive damage)
Pointing a player by a gun then use raycast to shoot
Player who receive damage is dropping health value
Player who receive damage is dropping health value
Move a player from this location to other location synchronize movement between two location synchroni ze movemen t between two location
4 Test movement after customized character
Move a player which player’s character from this location to other location synchronize movement between two location
Unable control player’s character, Gun not display
Problem in Photon SDK in my project
Figure 20 Test between two player
In the game depicted, two players interact: one controls a moving white capsule while the other wields a gun If the gun-wielding player shoots the capsule player, the latter will respawn Both players are connected via separate devices from different locations and internet providers However, if the customized character experiences lag and freezing during their connection, gameplay is hindered Notably, if PlayFab is removed, players can freely shoot and purchase weapons without restrictions.
Figure 21 Issue with customized character connecting to the game(issue lagging and can not move)
In the free version of our service, users may encounter occasional lag and disconnections from the Photon Cloud, often resulting in a "Time run out" message on the console when a connection fails To resolve this, players are advised to persistently attempt to reconnect until they successfully join a game Furthermore, integrating Playfab has introduced a complication where more than two players cannot control their characters when utilizing the Playfab SDK as the back-end.
Conclusion
In summary, this chapter has emphasized the Photon SDK as a robust solution for online multiplayer interactions Its user-friendly design and comprehensive documentation make it an ideal choice for beginners Both indie game developers and seasoned professionals value and favor the use of the Photon SDK for their projects.
Playfab and how player database work
Setup for unity engine
1,How to link playfab with unity
To create a PlayFab account, developers should visit the PlayFab website via the provided link Once there, they can choose to log in or create a new account New users will need to fill out required information, including their email address, username, and password, to set up their account.
After completing the account creation process, developers can log in to their new PlayFab account with the provided credentials Upon logging in, they will access the PlayFab dashboard, a centralized hub for managing game development aspects such as player accounts, analytics, and monetization features.
The PlayFab dashboard offers developers an all-in-one overview of their game projects, enabling easy access to essential features and functionalities Through this intuitive interface, developers can efficiently manage game settings, establish player accounts, track player activity, and utilize a range of development tools and resources.
Figure 22 interface of the playfab home page
Upon logging into the PlayFab dashboard, developers will find an intuitive interface that streamlines game development and management This user-friendly platform offers essential tools and features for efficiently managing player accounts, analytics, and game services.
To download the PlayFab package for Unity, click on the provided link to access the download page specifically designed for Unity game development.
To integrate PlayFab services into Unity, developers should open their project in the Unity editor and select the option to import a package from the Assets menu They then locate the downloaded PlayFab package file and initiate the import process.
Importing the PlayFab package into a Unity project provides developers with access to a variety of APIs, tools, and services that facilitate backend functionalities, including player authentication, data storage, and virtual currency management This integration allows developers to utilize PlayFab's robust infrastructure to enhance their Unity games with multiplayer features, social interactions, and customized backend services.
After importing the Unity package from PlayFab, developers access the Unity Editor window, which acts as the main hub for game development activities, facilitating the integration of external services such as PlayFab.
Logging into PlayFab in the Unity Editor is simple and efficient Developers who have not yet installed the PlayFab SDK can quickly do so to unlock a wide range of features and functionalities offered by PlayFab.
Creating a database on PlayFab is easy; developers can start by clicking the "New Studio" button on the PlayFab dashboard to set up a new studio for managing game-related data and services.
Upon naming the new studio, developers save the information, which establishes the studio's presence in PlayFab's ecosystem and enhances efficient data management and service utilization.
To establish a vital link between the Unity project and the PlayFab database, developers input the newly created studio information into the PlayFab extension or plugin This integration facilitates seamless communication and data exchange, enhancing the overall functionality of the project.
Integrating PlayFab into Unity projects allows developers to access a range of powerful features, including player data management and analytics This seamless integration enhances the ability to create immersive, data-driven gaming experiences that deeply engage players.
Encountering errors related to empty Studio and Title IDs during PlayFab integration can hinder communication between your Unity project and the PlayFab server Fortunately, resolving this issue is a simple process that guarantees smooth connectivity Here’s a brief outline of the steps to fix these errors effectively.
Developers must verify the Studio and Title IDs in the PlayFab settings of their Unity project, as these IDs serve as unique identifiers for the game’s studio and title within the PlayFab ecosystem.
Example how playfab works in my project
4.2.1 Login (sign in, sign up…)
In this example, I will demonstrate my customization character as how playfab work (save data, load data from playfab database)
1, Sign In or signup use case diagram
Figure 25 Login use case diagram
Player: The individual interacting with the game
Game Devices: The hardware (e.g., PC, console) that the player uses to play the game
Open a Game: The player starts the game on their device
If the player already has an account, they proceed to the login screen
If the player does not have an account, they need to sign up
The player enters their details to create a new account
Sign Up Failed: If the sign-up process fails (e.g., due to invalid input or network issues), the player is informed and can retry
Sign Up Successfully: If the sign-up process is successful, the player's details are stored in the PlayFab database
The player attempts to log in with their credentials
Sign In Failed: If the login attempt fails (e.g., incorrect password), the player is returned to the login screen to try again
Sign In Successfully: If the login is successful, the player is authenticated, and their details are verified against the PlayFab database
This is the backend service where player data is stored and managed
Upon successful login or sign-up, the PlayFab database loads the player's game data
The game retrieves the necessary data (e.g., player progress, settings) from the PlayFab database
The player can now join an online game session with the loaded data from PlayFab
Sign in or sign up Name Sign in or sign up to the system
Summary Before join a game, player must log in the game
Player login to the game to play game
Events 1 Player sign in or sign up failed
-the game console displays a wrong parameter or invalid user
2 Sign in or sign up successfully
Player has an account or login information
Table 1 Use case for Login
Some images in login screen:
4.3.2 Explain how players load and save functional
I will demonstrate how user save a data by using player customization add - on (like player can customize their armor suit in HALO series game )
Figure 29 Customize a spartan suit in Halo game series
Player database use case diagram
Player: The actor representing the person customizing their character
Game Server: The intermediary that communicates with PlayFab
PlayFab: The backend service that stores and manages player data
Open Customization Menu: The player accesses the customization interface
Select Customization Options: The player chooses customization options
Save Customization: The player saves their chosen customization
Send Customization Data to PlayFab: The game server sends the customization data to PlayFab
Store Customization Data: PlayFab stores the customization data
Retrieve Customization Data: The game server fetches the customization data from PlayFab when needed
Apply Customization: The game server applies the retrieved customization data to the player's character
Summary View, Edit, update character
Player LogIn to the game to customize character
1 Log In to the game
2 The game displays function and information
Log In into the game
Table 2 Use case for Customize characters
How my simple customize character work
Figure 31 A simple customize player model
Figure 32 Player add-on a glass
In the player prefab, I added extra equipment that becomes visible when the player is enabled This triggers a "true" value to be recorded in the PlayFab database for future reference Upon subsequent logins, players can easily access their accounts, and the additional equipment will automatically load from the PlayFab database.
Figure 33 Add-on enable will return valve true, otherwise it returns valve false
Integrating PlayFab for player character customization provides a robust solution for managing and securely storing customization data It allows players to modify and save their character preferences, ensuring easy retrieval This seamless interaction between the game client and PlayFab enhances user experience by offering persistent, personalized character appearances across gaming sessions The implementation boosts user engagement and showcases the effectiveness of cloud-based services for dynamic game features.
List of testcase
How to test Expected result
5 Sign In With a wrong password or wrong user name
Sign in in a login screen then input a wrong password
Screen pop- up a false information value to re- enter login
Console screen return a false value to re-enter
Sign in in a login screen then input a parameter
Console screen return an invalid value to re-enter login
Sign in in a login screen then input a parameter
Console screen return an invalid value to re-enter login
Sign in in a login screen then input a parameter
Console screen return an invalid value to re-enter login
9 Sign Up then sent the record to database
Sign Up an account then check an account on database
After sign up an account will be sent to database
An account which created by user has been sent to database
Sign Up in a login screen then input a parameter
Work as normal nothing happened
Console display a warning message an invalid parameter
Actual figures in testing
11 Sign Up with an invalid email in email field
Full in an invalid email then sign up
A screen pop up Then display there is an invalid email
Console display a warning message an invalid email
Sign Up in a login screen then input a parameter
Work as normal nothing happened
Console display a warning message an invalid parameter
Sign Up in a login screen then input a parameter
Work as normal nothing happened
Console display a warning message an invalid parameter
The sign-up screen for user input testing allows successful data submissions to the PlayFab database, while failures trigger a console message stating that the service is unavailable Additionally, when invalid parameters are entered, such as usernames or emails with invalid characters, the console notifies users of the error.
Figure 35 After login, player sent to Playfab server
Conlusion
In summary, PlayFab is a powerful platform for game development, effectively managing player data, in-game economies, and character customization Its cloud-based services ensure secure data storage and efficient retrieval, enhancing the gaming experience through persistent and personalized interactions By adopting PlayFab, developers gain a strategic advantage in creating dynamic, scalable, and user-centric gaming environments, ultimately fostering greater player engagement and satisfaction.