Example #1
0
    void Init()
    {
        performingEvent = true;

        // register event
        EventProxyManager.RegisterForEvent(EventName.Initialized, HandleEvent);
        EventProxyManager.RegisterForEvent(EventName.UnitSpawned, HandleEvent);
        EventProxyManager.RegisterForEvent(EventName.RoundSetup, HandleEvent);
        EventProxyManager.RegisterForEvent(EventName.UnitActivated, HandleEvent);
        EventProxyManager.RegisterForEvent(EventName.TurnStarted, HandleEvent);
        EventProxyManager.RegisterForEvent(EventName.BMapTileTapped, HandleEvent);
        EventProxyManager.RegisterForEvent(EventName.BUnitTapped, HandleEvent);
        EventProxyManager.RegisterForEvent(EventName.UnitMoved, HandleEvent);
        EventProxyManager.RegisterForEvent(EventName.UnitAttacked, HandleEvent);
        EventProxyManager.RegisterForEvent(EventName.UnitLoseHealth, HandleEvent);
        EventProxyManager.RegisterForEvent(EventName.UnitDied, HandleEvent);
        EventProxyManager.RegisterForEvent(EventName.ToppingSpawned, HandleEvent);
        EventProxyManager.RegisterForEvent(EventName.ToppingDestroyed, HandleEvent);
        EventProxyManager.RegisterForEvent(EventName.Gameover, HandleEvent);
        EventProxyManager.RegisterForEvent(EventName.EventDone, HandleEventDone);
        EventProxyManager.RegisterForEvent(EventName.DebugLog, HandleDebugLog);
        // find scene references
        bCombatMenu   = GameObject.FindObjectOfType <BCombatMenu>();
        bInputManager = GameObject.FindObjectOfType <BInputManager>();
        bCameraMover  = GameObject.FindObjectOfType <BCameraMover>();

        // instatiate marker
        unitMarker = (GameObject)Instantiate(bActiveMarkerPrefab);

        MapTile[][] mapTiles = new MapTile[bMap.lengthX][];
        for (int i = 0; i < bMap.lengthX; i++)
        {
            mapTiles[i] = new MapTile[bMap.lengthY];
            for (int j = 0; j < bMap.lengthY; j++)
            {
                bMap[i, j].UpdateTopping();                 // this is required to tranfer the topping data to the mapTile
                mapTiles[i][j] = bMap[i, j].mapTile;
            }
        }

        BUnit[] startBUnits = GameObject.FindObjectsOfType <BUnit>();
        bUnits = new List <BUnit>();
        Unit[] units = new Unit[startBUnits.Length];
        for (int i = 0; i < units.Length; i++)
        {
            // add units from scene to an array
            units[i] = startBUnits[i].unit;
            // set maptile reference by scene position
            int x = Mathf.FloorToInt(startBUnits[i].transform.position.x);
            int y = Mathf.FloorToInt(startBUnits[i].transform.position.z);
            units[i].mapTile    = mapTiles[x][y];
            mapTiles[x][y].unit = units[i];
            // add bUnit to list
            startBUnits[i].Init(this, bCombatMenu);
            bUnits.Add(startBUnits[i]);
        }

        // start the game
        controller = new Controller(this, mapTiles, units);

        EventProxyManager.FireEvent(this, new EventDoneEvent());
    }