Hands On Game Development Patterns with Unity 2019

Posted revoid

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Hands On Game Development Patterns with Unity 2019相关的知识,希望对你有一定的参考价值。

https://github.com/PacktPublishing/Hands-On-Game-Development-Patterns-with-Unity-2018

 

1. Unity Engine Architecture

2. Game Loop and Update Method

3. Prototype

4. The Factory Method

5. Abstract Factory

6. Singleton

7. Strategy

8. Command

9. Observer

10. State

11. Visitor

12. Facade

13. Adapter

14. Decorator

15. Event Bus

16. Service Locator

17. Dependency Injection

18. Object Pool

19. Spatial Partition

20. The Anti-Patterns

 

1. Unity Engine Architecture

 

2. Game Loop and Update Method

 

3. Prototype

技术图片
public interface iCopyable 
    iCopyalbe Copy();


public class Enemy: MonoBehaviour, iCopyable 
    public iCopyable Copy() 
        return Instantiate(this);
    


public class Sniper: Enemy 
    public void Shoot() 
        // Implement shooting functionality
    


public class Drone: Enemy 
    public void Fly() 
        // Implement flying functionality
    
    
    public void Fire() 
        // Implement laser fire functionality.
    


public class EnemySpawner: MonoBehaviour 
    public iCopyable m_Copy;
    
    public Enmey SpawnEnemy(Enemy prototype) 
        m_Copy = prototype.Copy();
        return (Enemy)m_Copy;
    


public class Client: MonoBehaviour 
    public Drone m_Drone;
    public Sniper m_Sniper;
    public EnemySpawner m_Spawner;
    
    private Enemy m_Spawn;
    
    private int m_IncrementorDrone = 0;
    private int m_IncrementorSniper = 0;
    
    public void Update() 
        if (Input.GetKeyDown(KeyCode.D)) 
            m_Spawn = m_Spawner.SpawnEnemy(m_Drone);
            
            m_Spawn.name = "Drone_Clone_" + ++m_IncrementorDrone;
        
        
        if (Input.GetKeyDown(KeyCode.S)) 
            m_Spawn = m_Spawner.SpawnEnemy(m_Sniper);
            
            m_Spawn.name = "Sniper_Clone_" + ++m_IncrementorSniper;
        
    
View Code

4. The Factory Method

技术图片
public enum NPCType 
    Farmer,
    Beggar,
    Shopowner



public interface INPC 
    void Speak();


public class Farmer: INPC 
    public void Speak() 
        Debug.Log("Farmer: You reap what you sow!");
    


public class Beggar: INPC 
    public void Speak() 
        Debug.Log("Beggar: Do you have some change to spare?");
    


public class Shopowner: INPC 
    public void Speak() 
        Debug.Log("Shopowner: Do you wish to purchase something");
    


public class NPCFactory: MonoBehaviour 
    public INPC GetNPC(NPCType type) 
        switch (type) 
            case NPCType.Beggar:
                INPC beggar = new Beggar();
                return beggar;
            case NPCType.Farmer:
                INPC farmer = new Farmer();
                return farmer;
            case NPCType.Shopowner:
                INPC shopowner = new Shopowner();
                return shopowner;
        
        return null;
    


public class NPCSpanwer: MonoBehaviour 
    public NPCFactory m_Factory;
    
    private INPC m_Farmer;
    private INPC m_Beggar;
    private INPC m_Shopowner;
    
    public void SpawnVillagers() 
        m_Beggar = m_Factory.GetNPC(NPCType.Beggar);
        m_Farmer = m_Factory.GetNPC(NPCType.Farmer);
        m_Shopowner = m_Factory.GetNPC(NPCType.Shopowner);
        
        m_Beggar.Speak();
        m_Farmer.Speak();
        m_Shopowner.Speak();
    


public class Client: MonoBehaviour 
    public NPCSpanwer m_SpawnerNPC;
    
    public void Update() 
        if (Input.GetKeyDown(KeyCode.S)) 
            m_SpawnerNPC.SpawnVillagers();
        
    
View Code

5. Abstract Factory

 

6. Singleton

 

7. Strategy

 

8. Command

 

9. Observer

 

10. State

 

11. Visitor

 

12. Facade

 

13. Adapter

 

14. Decorator

 

15. Event Bus

 

16. Service Locator

 

17. Dependency Injection

 

18. Object Pool

 

19. Spatial Partition

 

20. The Anti-Patterns

 

以上是关于Hands On Game Development Patterns with Unity 2019的主要内容,如果未能解决你的问题,请参考以下文章

hands-on-data-analysis 第二单元 2,3节

Hands-on data analysis 第一章

Wireshark Hands-on Assignmen

0. Hands on Machine Learning - Outline

hands-on-data-analysis 第二单元 - 数据清洗及特征处理

Hands-on data analysis 第一章