Page 1 of 1

Grid Controller Script References

Posted: Fri Feb 14, 2025 12:08 am
by PunkyEggCrusher
Hi there,

I've really liked the editor/inspector level experience of GridController, but I am admittedly struggling with the coding side.

I've checked through the demo and scripts as well as the api page of the site, but I still can't seem to sort out how to access a lot of the pieces. The API seems like it might be out of date though given the Surface example in the forums and trial and error lead me to using

Code: Select all

GridController.Instance
for what I could access.

However, I'm still struggling to sort out how to access OnEnterPosition, for example. I was able to use ForwardPressed successfully but that only applies to keyboard controls not UI buttons, and will affect a character that has not moved, but tried to move. (In this case I want to trigger some effects if the character successfully moves in any direction).

Sorry for the bit of ramble there. I'm been trying to sort this and feeling like I'm missing something right in front of me.
Are there any example scripts in the asset or updated references I might be missing to help me sort things out?

Re: Grid Controller Script References

Posted: Fri Feb 14, 2025 7:45 am
by Tony Li
Hi!

The GridController class has a number of events that your code can hook into. (Scroll down to the Events section in the API reference, which I just updated in case it was a little behind.)

For example, if you want to know when the player enters a square, you can hook into GridController.Instance.EnteredPosition:

Code: Select all

void Start() => GridController.Instance.EnteredPosition += OnEnteredPosition;
void OnDestroy() => GridController.Instance.EnteredPosition -= OnEnteredPosition;

void OnEnteredPosition(Vector3 newPosition)
{
    Debug.Log($"Player just entered square {newPosition}");
}

Re: Grid Controller Script References

Posted: Fri Feb 14, 2025 9:52 am
by PunkyEggCrusher
Hi, Tony!

Thank you so much. Your example cleared things up for me. I guess I should have taken a code break sooner :idea:

Did some quick experimenting and added a Crouch check as well - just to make sure I could replicate for other circumstances and was able to get that sorted.
Just going to drop that updated code snippet in case anyone else needs or in case I forget down the line :lol:

Code: Select all

private void Start() {
      GridController.Instance.EnteredPosition += OnEnteredPosition;
      GridController.Instance.Crouched += OnCrouch;
  }

  private void OnDestroy() {
      GridController.Instance.EnteredPosition -= OnEnteredPosition;
      GridController.Instance.Crouched -= OnCrouch;
  }

  void OnEnteredPosition(Vector3 newPosition) {
      Debug.Log($"Player just entered square {newPosition}");
  }

  void OnCrouch(Vector3 crouchPosition) {
      Debug.Log($"Player just crouched {crouchPosition}");
  }

Re: Grid Controller Script References

Posted: Fri Feb 14, 2025 11:20 am
by Tony Li
Glad to help! Thanks for sharing the Crouch detection code.

Side note: If you only need to check every once in a while (vs. every frame) if the player is crouched, you can check the Boolean property GridController.Instance.IsCrouching.