Creating New Admin Panel Menu

Class Functions

  • Init() - [OPTIONAL] class initialization.

  • OnOpen() - [OPTIONAL] called when player clicks on tab.

  • GetName() - [REQUIRED] return displayed tab name, return string [DEFAULT: "Unknown"].

Local Properties

  • adminPanel - return AdminPanel class.

Local Functions

  • SendToEveryone(string FunctionName, params object[] arguments) - send command to every player to call function with arguments.

  • SendToClient(string FunctionName, NetworkConnection connection, params object[] arguments) - send command to player with connection to call function with arguments.

  • SendToServer(string FunctionName, params object[] arguments) - send command to server to call function with arguments.

  • Invoke(Function, float seconds) - same logic as UnityEngine.Object.Invoke, call function after time.

Example

using System.Collections.Generic;
using UnityEngine;

namespace Plugin.AdminPanel
{
    public class NewPanel : Akequ.Base.AdminPanel
    {
        Transform gridLayout;

        public override string GetName()
        {
            return "New Panel";
        }

        public override void OnOpen()
        {
            gridLayout = adminPanel.CreateGridLayout().transform;
            gridLayout.parent.parent.localPosition = new Vector3(0, 44.2f, 0);
            gridLayout.parent.parent.GetComponent<RectTransform>().sizeDelta = new Vector2(511, 340);
            GameObject button = gridLayout.GetChild(0).gameObject;
            int randomItemCount = Random.Range(5, 15);
            for (int i = 0; i < randomItemCount; i++)
            {
                GameObject b = GameObject.Instantiate(button, gridLayout);
                string itemName = "Item_" + i;
                b.name = "Item_" + i;
                b.SetActive(true);
                b.GetComponentInChildren<UnityEngine.UI.Text>().text = itemName;
                UIManager.BindAction(b.GetComponent<UnityEngine.UI.Button>().onClick, () => { ItemPressed(itemName); });
            }
            Transform giveMe = adminPanel.CreateButtonWithHeader("Press Me", "Press Me X2").transform;
            giveMe.localPosition = new Vector3(0, -185, 0);
            UIManager.BindAction(giveMe.GetComponent<UnityEngine.UI.Button>().onClick, GiveMe);
        }

        void GiveMe()
        {
            SendToServer("TestServer", "PRESSED X2");
        }

        void ItemPressed(string str)
        {
            SendToServer("TestServer", str);
        }

        public void TestServer(string item, Mirror.NetworkConnectionToClient conn)
        {
            Player admin = PlayerUtilities.GetServerPlayer(conn);
            if (admin.isAdmin)
            {
                Debug.Log("Got from client item: " + item);
            }
        }
    }
}

Example Solution can be downloaded here: Link to archive

Testing

Now we can compile this plugin and move library to server plugins folder according to Folder Structure Now we can see our new window in admin panel:

Last updated