Git Product home page Git Product logo

unity3dturnmanager's Introduction

Unity3DTurnManager

Example implementation of an event-driven turn manager and message system in Unity3d πŸ‘ΎπŸ•ΉοΈπŸŽ²

Simple implementaion of an event-driven turn manager for gameobjects in unity3d.

The most basic implementaion of the interface can be seen in Assets/Scripts/Game/GameManager.cs

  //these values injected via the inspector
  public GameObject Player;
  public GameObject Enemy;
  public GameObject EnemyB;
  public TurnManager TurnManager;
  
  //The game manager (and thusly, the turn manager) is to be accessed as a singleton in other parts of code
  private static GameManager GameManagerInstance;
  
  public static GameManager GetInstance(){
    return GameManagerInstance;
  }
  
  void Awake(){
    GameManagerInstance = this;
    //create the player turn, initalized with a list of game objects that need to give the OK/DONE signal to progress
    List<GameObject> PlayerTurnEntities = new List<GameObject>();
    PlayerTurnEntities.Add(Player);
    Turn PlayerTurn = new Turn(PlayerTurnEntities, (int) TurnSignals.Done);
    //create the enemy turn
    List<GameObject> EnemyTurnEntities = new List<GameObject>();
    EnemyTurnEntities.Add(Enemy);
    EnemyTurnEntities.Add(EnemyB);
    Turn EnemyTurn = new Turn(EnemyTurnEntities, (int) TurnSignals.Done);
    //add the turns to a turn manager instance
    TurnManager.AddTurn(PlayerTurn);
    TurnManager.AddTurn(EnemyTurn);
  }

In order to progress through each turn stage, each game object in the Turn must send a OK/DONE singal to the TurnManager (Check Assets/Scripts/Enums for the actual signal used).

Signals are sent to the TurnManager in the behaviour scripts, via the GameManager singleton reference

//Where the TurnEventHandler (of type OnTurnEventHandler) is injected via the inspector, (or accessed via GetComponent<T>())
TurnEventHandler.OnTurnStart.AddListener(delegate(TurnEventData data){
  Debug.Log("player turn start!");
  GameManager.GetInstance().TurnManager.GetCurrentTurn().Signals.SendSignal(this.gameObject, (int) TurnSignals.Done);
});

unity3dturnmanager's People

Contributors

zombietfk avatar

Stargazers

jay down avatar をキラ avatar

Watchers

 avatar

Forkers

nasa03

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.