The Coolest Chess
  • The Chess Documentation
    • Chess Game Introduction
    • Essential Prefabs
    • Components
  • Importing Stockfish AI
  • Controller
    • Base Controller
    • Two Player Controller
  • The UIs
    • Button Prefabs
    • UI Events
    • Enquiry
    • Replacing UI
    • Others
  • Scenes Details
    • ChessPGN
    • ChessPuzzleEditor
    • ChessPuzzle
    • ChessAI
  • Honorable Mentioned
    • ChessBoard class
    • GUI Classes
    • Game Logic Classes
    • The Architecture Notice
  • Customization
    • Time AI
    • AI Draw Game
    • TypeI AI
    • TypeII AI
    • Event Based Functions
    • Chess Game Finishing Rule
  • Unit Tests
Powered by GitBook
On this page
  1. The UIs

Enquiry

Here is how you can enquiry UI information. The below example is trying to get a dropdown options count info from a dropdown UI.

PreviousUI EventsNextReplacing UI

Last updated 5 months ago

Step 1 :

Create an empty scene with any name of your liking and open the scene.

Step 2 : Adding necessary scene game objects for this exercise.

Go to the Prefabs folder inside path UIs/Essential and drag ChessGameObjectBase prefab into the scene hierachy.

Then, create a canvas and drag the dropdown prefab located inside Base folder of path Prefabs/UIs/Dropdown into the canvas. Or create a legacy dropdown of your own on the scene, the dropdown prefab is actually the same as legacy dropdown.

Step 3 :

Copy code below to ChessEnquiryManager.cs located in Scripts/Main/Communicators folder

    public delegate int TotalDropdownOptionCount();
    public static event TotalDropdownOptionCount EnquiryTotalDropdownOptionCount;
    
    public static int GetTotalDropdownOptionCount()
    {
        var hasValue = EnquiryTotalDropdownOptionCount?.Invoke();

        if (hasValue != null)
        {
            return (int)hasValue;
        }
        else
        {
            throw new System.NullReferenceException(GenerateErrorMessage(typeof(TotalDropdownOptionCount).Name));
        }
    }

Step 4 :

Create a C# script in the path Scripts/Main/UIs/Dropdowns named DummyDropdown.cs and copy the code below into it. The GetOptionsCount() function is from the base class, getting the number of dropdown options currently the dropdown have.

namespace TheChess
{
    public class DummyDropdown : ChessDropdownUI
    {
        protected override void Subscribes()
        {
            ChessEnquiryManager.EnquiryTotalDropdownOptionCount += GetOptionsCount;
        }
    
        protected override void Unsubscribes()
        {
            ChessEnquiryManager.EnquiryTotalDropdownOptionCount -= GetOptionsCount;
        }
    }
}

Step 5 :

The code below can be called in any GUI script to get the number of dropdown options.

        Debug.Log(ChessEnquiryManager.GetTotalDropdownOptionCount());