Personal unity_demo design ideas and journey, unity_demo design ideas

Source: Internet
Author: User

Personal unity_demo design ideas and journey, unity_demo design ideas

It may take some time to learn about Unity. Prepare a demo to try it out. The design idea is to design a small game that owns the Battle System, weapon system, and shop system according to the mmorpg game model.

The following is a UML diagram of the project code:

Combat System:

After a base class Icharactor is set up, the common interaction between the protagonist and the enemy can be achieved by calling the other's Icharactor class, and their independent methods can be placed in their respective classes, the idea used here is the idea of inheriting object-oriented languages such as c #. Public methods are placed in public base classes, and independent methods are placed in sub-classes, so they do not interfere with each other. When the main character attacks the enemy, it will call the TakeDamage method of the enemy's parent class.

Each character has various states, and the transition between States can use the state machine idea. The following is my understanding of the state machine:

Enemy Soldier class has FsmSystem state machine for State management

Using System; using System. collections; using System. collections. generic; using System. text; using UnityEngine; public class SoldierFsm: IEnemy {public GameObject enemy; FsmEnemySystem fsmSystem; private void Start () {InitFsm ();} void InitFsm () {// create FsmSystem class fsmSystem = new FsmEnemySystem (); // instantiate the state class FsmEnemyState patrol = new EnemyPatrol (fsmSystem, this); // Add the conversion condition and State patrol. addTransition (EnemyTransition. inSight, EnemyStateID. chase); FsmEnemyState chase = new EnemyChase (fsmSystem, this); chase. addTransition (EnemyTransition. outOfSight, EnemyStateID. patrol); chase. addTransition (EnemyTransition. inAttackRange, EnemyStateID. attack); FsmEnemyState attack = new EnemyAttack (fsmSystem, this); attack. addTransition (EnemyTransition. outAttackRange, EnemyStateID. chase); // Add various statuses to manage fsmSystem. addState (patrol); fsmSystem. addState (chase); fsmSystem. addState (attack);} private void Update () {fsmSystem. update (enemy );}}

Inter-State structure:

After a state machine is created, the various states of the role are managed by a separate class, such as status 1, status 2, and status 3, which are inherited from DoBeforeEntering () in FsmState and FsmState respectively () doAfterLeaving () Act () Reason () contains the methods that need to be done before and after a status switch and when the status is continuously in progress, this ensures that some methods called in Update can be implemented in Act (). This method can be executed only once in DoBeforeEntering or DoAfterLeaving.

When the Reason () method in FsmState meets the condition of another State, the role is switched to the State. In FsmSytem, transfer mtranstion is converted to the state --> execution status ID, and then the FsmState of the current ID executes Reason () method to another State to achieve state conversion.

Weapon System:

Out of childhood, I love a big fighting game: the hot blood, and one that is regarded as a god-made game: Elder brother scroll 5, in this demo, I added an equipment system that can be discarded and picked up. Each weapon inherits from the Iweapon class, And Iweapon owns the IweaponAttr class.

Store system:

The store system uses an InventoryManager for management. InventoryManager has an Inventory class for stores and backpacks. This class can store and exchange items. The specific UI implementation is completed through the slot class.

The above are some personal opinions. If there is a wrong discussion, please ask Hai Han.

After completing this demo, I found that it is not difficult to implement a specific idea in Unity. What is difficult is how to manage these classes after all classes are implemented, and how to better design the coupling between classes and call relationships. These questions are simply about the design model. After the demo is completed, I have a deeper understanding of the design model. From now on, I will try harder to read relevant books, write more concise and clear code.

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.