Developing Games with Object Composition: a Case Study Using the Unity3d Platform

Developing Games with Object Composition: a Case Study Using the Unity3d Platform

SBC – Proceedings of SBGames 2015 | ISSN: 2179-2259 Computing Track – Short Papers Developing games with object composition: A case study using the Unity3D platform Marcelo B. Barbosa Andreza B. Rêgo Igor de Medeiros Federal Institute of Education, Science and Technology of Rio Grande do Norte, Brazil Abstract projected classes in order to group them on the hierarchy base levels. Consequently, the super-classes Unity3D is a game development framework that placed on the top levels possess more general gathers various tools with the purpose to ease the game properties. This tactic supports the generation of development process. Unity3D uses the concept of subclasses with more specific behaviors. object composition applied to a component-based architecture to customize the core elements of the An alternative for reusing functionality is object game: the Game Objects. Yet object inheritance composition. This technique is focused on assembling remains as one of the most common techniques for smaller objects to create a more complex functionality code reuse, object composition offer its own [Gamma et al. 1995]. Despite sharing the same advantages. This article presents a comparison between purpose, inheritance and object composition differs object composition and inheritance on the game substantially. Each one of the mechanisms has its own development context. To observe the practical aspect advantages and disadvantages. The maintenance and of object composition, we developed a game called modification of class’ implementation is easier than orBITa using the Unity3D game engine. We will reusing functionality through inheritance, for instance. present the benefits and disadvantages of using this For our project goal, object composition appears as a object oriented mechanism and demonstrate how it more suitable choice for its inherent capabilities. affects the structure of the scripts components developed. We focused on working with the Unity3D platform for the development of our game. Unity3D is currently Keywords: game development, object-oriented design, one of the most used engines available in the industry. object composition, unity3d For our purposes, the free version of the framework is sufficient. The necessary features for producing a Authors’ contact: simple 2D game are included in the free package. [email protected] Unity3D utilizes up-to-date tools and holds an active [email protected] community, ready to answer common questions related [email protected] to the framework. 1. Introduction Objects in Unity3D are defined by a Game Object class that inherits from a base class called The object-oriented paradigm is often used on game MonoBehaviour. Every script automatically derives programming. Game object elements may appear as from MonoBehaviour. This super-class assures that a instances of a bigger Game class, to represent the Game Object can handle events, has a state machine entities composing a game scene, like characters, for its actions and applies physics to the object. enemies, environment objects and projectiles. Although, every other behavior defined for a Game However, an object-oriented approach must experience Object is attributed to a compositional routine difficulties if implemented with inheritance [Passos et implemented by programming scripts called al. 2009]. Objects that inherit from two different Components. Developing games using components can hierarchies may have similar functionality, leading to minimize development costs and reduce the code redundancies. development time [Folmer 2007]. Thus, a component- based architecture is perfectly satisfactory to construct Inheritance is a powerful feature of object oriented our game efficiently. programming which allows the definition of relationships between classes to ease code reuse and In this paper, we expose the contrast and achieve a better overall design [Weisfeld 2008]. A new correlation between object composition and class class can be created by inheriting methods and inheritance in a functional way, through the attributes from a class that has a similar behavior. But development of the 2D game orBITa. The object this often leads to an organizational issue, though it is composition in Unity3D is displayed as a result of not always plausible to have a single super-class that association between Game Objects and programming owns all the resources inherited by a set of subclasses. scripts called Components. The main focus is the An object oriented project can become more organized analysis of those elements which are responsible for using hierarchic inheritance. As noted by Horstmann applying specific behaviors to the Game Objects. [2013], while structuring a class hierarchy we can verify which resources are commonly inherited by the 2. Related Work XIV SBGames – Teresina – PI – Brazil, November 11th - 13th, 2015 240 SBC – Proceedings of SBGames 2015 | ISSN: 2179-2259 Computing Track – Short Papers dependency between components or Game Objects A method proposed by Bitman [1997] aggregate instances [Passos et al. 2009]. The proposed solution is various studies and shows how software reuse is the utilization of the Dependency Injection pattern in affected by the structure of the code. The work the system architecture. This design pattern intends to proposes a model that estimates that applications built provide a flexible way to manage indirect association from independent composed components shall possess between dependent components. It removes the higher cohesion and usability than what is commonly responsibility for the programmer to deal with creating experienced when using inheritance. The model can be instances for composed objects. used as a basis to ensure the applicability of the object composition technique is desirable for improving 3. Composition over Inheritance quality for the proposed scripting process. Nevertheless, the platform has to allow the usage of a An object oriented design requires careful management compositional structure. The Unity3D manual explains to remain efficient. Design patterns and other that the preferred configuration for working with Game techniques shall be used to achieve the necessary goals Objects relates to the component-based architecture and solve problems that may show up during most of [UnityTechnologies 2015]. Object composition is not the development phases. The main idea is referenced in the documentation, but it stands as the straightforward: favor object composition over class conventional way to work with those types of elements inheritance. This affirmative relies basically on the fact in a lower level programming perspective. that compositional design will produce more objects and the system’s behavior will rely upon the A Game Entity represents a generalization of the relationships between objects instead of behaviors Unity3D Game Object concept, as different game from a super-class [Gamma et al. 1995]. platforms and frameworks may embrace different environments to represent objects existing within the The Decorator pattern also applies as a reasonable game world. Until lately, class hierarchy game entities solution for object oriented design issues. It basically where represented by class hierarchy, and promotes the attachment of similar responsibilities to consequently, used the object inheritance technique to an object dynamically [Freeman and Freeman 2013], reuse functionality. West [2007] described a full similarly to what is proposed for the compositional refactoring process made inside a company from the method. A remarkable fact is that this design pattern game industry. The entities were refactored from a still encourages the use of inheritance. The main hierarchic inheritance architecture to a compositional difference in that case is that object inheritance does one. A new framework was established to allow the not have the intention to extend behaviors from the usage of this kind of structural design with aggregation super-classes: It uses the inheritance in order to of components. After the implementation of the achieve type matching. That is only because the framework, the conversion from object inheritance to decorator class needs to have the same interface as the object composition went slowly, mainly because of the components it wraps. development team struggle to familiarize with the new context. Hence, this process produced positive results In practical terms, compositional reuse techniques over time: codes became cleaner and easier to maintain share, among others, the following advantages: primarily for the encapsulation of functionality in Independent, composed components are created; independent components. Components are encapsulated; Potentially lower maintenance costs. On the other hand, it shows some Other frameworks and game engines have their disadvantages: Object composition requires greater own style of working with game entities. The Unreal expertise to use; It increases the development time Engine, for example, acts similarly to Unity3D. On its significantly. Inheritance does not contemplate these manual, it is stated that Actors, which are subclasses of advantages; but it has a couple of its own, including: a wider Object class, are objects composed by Eliminates successfully duplication of code, shortens specialized parts called Components [EpicgamesInc development time and demands less proficiency to 2015]. Therefore, it is noted that Unreal Engine 4 uses work with. This leads to the comprehension that an a hybrid approach for its OO design,

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us