Author Topic: SOLVED Multi-Grid Event  (Read 220 times)

visualjump3d

  • Newbie
  • *
  • Posts: 14
    • View Profile
SOLVED Multi-Grid Event
« on: June 01, 2020, 03:57:17 AM »
this is the code you provided me and it works perfectly:

Public class MultiTerrainGrid : MonoBehaviour
{
    public TerrainGridSystem grid1;
    public TerrainGridSystem grid2;   

    void Start()
    {
         grid1.OnTerritoryMouseDown += Grid1_OnOnTerritoryClick;
         grid2.OnTerritoryMouseDown += Grid2_OnOnTerritoryClick;     
    }   

    private void Grid1_OnOnTerritoryClick(int cellIndex, int buttonIndex)
    {     
        Variabili_Statiche.TerritorioSelezionato = cellIndex;
        Variabili_Statiche.TerrenoSelezionato = 1;
    }

    private void Grid2_OnOnTerritoryClick(int cellIndex, int buttonIndex)
    {       
        Variabili_Statiche.TerritorioSelezionato = cellIndex;
        Variabili_Statiche.TerrenoSelezionato = 2;
    }
}

but having many Grid-Terrains, (not just 2 as in the example above), I would have to write many (redundant) lines of code for each Grid-Terrain ... It would be possible to use a Grid-Array system in this too code ?

I have already used a Grid-Array system in another part of my code, but I cannot implement it in your code written above  ...


 void Awake()
    {       
        NumberOfGrid = GameObject.Find("GameObject_ScriptGridArray").GetComponent<GridArray>().selectorArr.Length; // object with Grid-Array     
    }

 if (Input.GetMouseButtonDown(1))
        {
            if (Variabili_Statiche.TerritorioSelezionato > 0 && OnMaps == true)
            {           
                for (int g = 0; g < NumberOfGrid; g++)
                {
                    TerrainGridSystem GR = GameObject.Find("GameObject_ScriptGridArray").GetComponent<GridArray>().selectorArr[g];
                    GR.territoryHighlightColor = ColoreTerritorioOff;
                    GR.showTerritories = false;
                }               
            }

ThankYou !!


attacched my grids-array
« Last Edit: June 01, 2020, 11:51:00 AM by visualjump3d »

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 5832
    • View Profile
Re: Multi-Grid Event
« Reply #1 on: June 01, 2020, 05:42:05 AM »
In next update you will be able to use a single event handler which receives the grid reference.

Example:
Code
...
        for (int k = 0; k < grids.Length; k++) {
            grids[k].OnCellClick += Clicker_OnCellClick;
        }
...   

    private void Clicker_OnCellClick(TerrainGridSystem sender, int cellIndex, int buttonIndex) {
        ...
    }

visualjump3d

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Multi-Grid Event
« Reply #2 on: June 01, 2020, 09:29:16 AM »
 Hi

i tried this code, but i get an error .. (  GR.OnCellClick )

using UnityEngine;
using TGS;

public class MultiTerrainGrid : MonoBehaviour
{
    public TerrainGridSystem grid1;
    public TerrainGridSystem grid2;

    public GameObject ArrayGrid;
    private int NumberOfGrid;
    public TerrainGridSystem GR;


    private void Awake()
    {
        NumberOfGrid = GameObject.Find("GameObject_ScriptGridArray").GetComponent<GridArray>().selectorArr.Length;
    }
 
    void Start()
    {
        for (int k = 0; k < NumberOfGrid; k++)
        {
            GR = GameObject.Find("GameObject_ScriptGridArray").GetComponent<GridArray>().selectorArr[k];
            GR.OnCellClick += Clicker_OnCellClick;
        }
    }

    private void Clicker_OnCellClick(TerrainGridSystem sender, int cellIndex, int buttonIndex)
    {
//..............etc etc
    }
}



Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 5832
    • View Profile
Re: Multi-Grid Event
« Reply #3 on: June 01, 2020, 09:45:11 AM »
Which error message do you get?

visualjump3d

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Multi-Grid Event
« Reply #4 on: June 01, 2020, 10:14:27 AM »
Assets\AAA GUIDO\Script\Script_GridTerrain\MultiTerrainGrid.cs(25,13): error CS0123: No overload for 'Clicker_OnCellClick' matches delegate 'CellClickEvent'

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 5832
    • View Profile
Re: Multi-Grid Event
« Reply #5 on: June 01, 2020, 10:22:05 AM »
Make sure you're using latest version.

visualjump3d

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Multi-Grid Event
« Reply #6 on: June 01, 2020, 10:45:45 AM »
ok i control it now ...

visualjump3d

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Multi-Grid Event
« Reply #7 on: June 01, 2020, 10:52:35 AM »
NO error in my ( your ) code but error on DEMO-Code ...

Assets\TerrainGridSystem\Demos\Demo22_TwoTerrains_TwoGrids\Clicker2.cs(14,9): error CS0123: No overload for 'Grid2_OnCellClick' matches delegate 'CellClickEvent'

Assets\TerrainGridSystem\Demos\Demo22_TwoTerrains_TwoGrids\Clicker2.cs(13,9): error CS0123: No overload for 'Grid1_OnCellClick' matches delegate 'CellClickEvent'

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 5832
    • View Profile
Re: Multi-Grid Event
« Reply #8 on: June 01, 2020, 11:04:59 AM »
Please remove the asset and reimport it again. That file no longer exists in the new version but since you're not deleting the asset folder it's raising the errors.

visualjump3d

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Multi-Grid Event
« Reply #9 on: June 01, 2020, 11:50:30 AM »
Ok !!

now everything works perfectly !!

ThankYou !!!