Unity3d object-oriented design ideas (III) (Object splitting)

Source: Internet
Author: User

I recently read a Demo of Native 2d ON THE Unity3d official website and found that Unity3d is a pure object-oriented game engine,

I was amazed at the degree of object-oriented.

Normally, objects work independently. For example, in an ordinary ARPG game, a character has weapons and can attack monsters,

We can encapsulate attack actions into characters so that the characters have attack attributes and can attack the enemy.

However, this is not acceptable in a purely object-oriented encapsulated language. This will complicate the program.

It does not matter, so the attack has nothing to do with the characters, the attack action will not be bound to the character role itself,

The attack itself is related to weapons, and the attack action should be carried out by weapons. This analysis is in line with the object-oriented thinking;

 

In addition, if there is music in the game, if it is an attack sound, it can be played during the attack. If the character is hurt, the sound will be played when the character is hurt,

What if it is the main sound of the game and the background music? We can all help set it to the main Camera, and then play it again after determining the logic of the Camera,

This is all possible. However, Unity3d does not propose to do this. In Unity3d, all game elements are objects, and so is music,

We can encapsulate the main background music into an object for convenient management.

 

There is also a car running on the road, which involves drivers. We can simply encapsulate it:

Car behavior: forward, backward, brake, acceleration, parking

Features of the car itself: high-end vehicles, medium-end vehicles, and low-end vehicles

Car features or speed performance: Engine

The driver object should be consistent with the behavior of the car itself. Of course, the driver has his own simple behavior, ridicule, and technology.

Specific moving behavior: tires

In a qualified object-oriented encapsulation, the speed of the car should be reflected in the engine and Driver technology. I personally think that if the object is encapsulated,

A mobile engine must be encapsulated to drive the speed of the car.

 

In fact, object orientation is inseparable from reality. All objects in real life are objects. For example, I am writing a blog:

Simply put, it is people and computers. The input content should act on a keyboard, and the content is displayed on a computer screen.

The behavior of a character is a kind of fiction and thought.

 

:)

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.