Максимальная производительность для ваших игровых серверов!
Заказать сейчасПофикси ошибку "Error while compiling: CustomMenu.cs(116,63): error CS1644: Feature `declaration expression' cannot be used because it is not part of the C# 6.0 language specification"Вот ваш код с исправлением ошибки:
C#:using System.Collections.Generic; using Oxide.Core; using Oxide.Game.Rust.Cui; using Rust; using UnityEngine; namespace Oxide.Plugins { [Info("CustomMenu", "YourName", "1.0.0")] [Description("Adds a custom menu with tabs and icons")] class CustomMenu : RustPlugin { private const string MENU_PARENT_NAME = "CustomMenu"; private const string MENU_BUTTON_NAME = "CustomMenuButton"; private const string TAB_CONTAINER_NAME = "CustomTabContainer"; private const string TAB_BUTTON_NAME = "CustomTabButton"; private const string TAB_ICON_NAME = "CustomTabIcon"; private const string TAB_TEXT_NAME = "CustomTabText"; private readonly Dictionary<BasePlayer, CuiElementContainer> _menuElements = new Dictionary<BasePlayer, CuiElementContainer>(); private void Init() => BasePlayer.activePlayerList.ForEach(CreateMenuElements); private void Unload() => BasePlayer.activePlayerList.ForEach(DestroyMenuElements); private void OnPlayerInit(BasePlayer player) => CreateMenuElements(player); private void OnPlayerDisconnected(BasePlayer player) => DestroyMenuElements(player); private void CreateMenuElements(BasePlayer player) { if (_menuElements.ContainsKey(player)) return; var menuContainer = new CuiElementContainer(); // Add the main menu button menuContainer.Add(new CuiButton { Button = { Command = "custommenu.open", Color = "0.5 0.5 0.5 0.7" }, RectTransform = { AnchorMin = "0.01 0.85", AnchorMax = "0.11 0.95" }, Text = { Text = "Menu", FontSize = 18, Align = TextAnchor.MiddleCenter } }, MENU_PARENT_NAME, MENU_BUTTON_NAME); _menuElements[player] = menuContainer; CuiHelper.AddUi(player, menuContainer); } private void DestroyMenuElements(BasePlayer player) { if (!_menuElements.TryGetValue(player, out var menuContainer)) return; CuiHelper.DestroyUi(player, MENU_PARENT_NAME); _menuElements.Remove(player); } [ChatCommand("custommenu.open")] private void OpenMenu(BasePlayer player) { var tabContainer = new CuiElementContainer(); for (var i = 0; i < 15; i++) { var yPos = 0.8f - i * 0.05f; var index = i; tabContainer.Add(new CuiButton { Button = { Command = $"custommenu.tab{index}", Color = "0.5 0.5 0.5 0.7" }, RectTransform = { AnchorMin = $"0.01 {yPos:F}", AnchorMax = $"0.11 {yPos + 0.04f:F}" }, Text = { Text = (i + 1).ToString(), FontSize = 18, Align = TextAnchor.MiddleCenter } }, MENU_PARENT_NAME, $"{TAB_BUTTON_NAME}{index}"); tabContainer.Add(new CuiElement { Name = $"{TAB_ICON_NAME}{index}", Parent = MENU_PARENT_NAME, Components = { new CuiRawImageComponent { Png = FileStorage.server.GetServerFile($"custommenu/icon{index}.png"), Color = "1 1 1 1", Sprite = "assets/content/textures/generic/fulltransparent.tga" }, new CuiRectTransformComponent { AnchorMin = $"0.12 {yPos:F}", AnchorMax = $"0.22 {yPos + 0.04f:F}" } } }); tabContainer.Add(new CuiLabel { Text = { Text = $"Tab {index + 1}", FontSize = 16, Align = TextAnchor.MiddleLeft }, RectTransform = { AnchorMin = $"0.23 {yPos:F}", AnchorMax = $"0.6 {yPos + 0.04f:F}" } }, MENU_PARENT_NAME, $"{TAB_TEXT_NAME}{index}"); } _menuElements[player].Add(tabContainer, MENU_PARENT_NAME, TAB_CONTAINER_NAME); CuiHelper.AddUi(player, _menuElements[player]); } [ConsoleCommand("custommenu.tab")] private void OpenTab(ConsoleSystem.Arg arg) { var player = arg.Player(); if (player == null) return; if (!int.TryParse(arg.cmd.Name.Substring(13), out var tabIndex)) return; CuiHelper.DestroyUi(player, MENU_PARENT_NAME, TAB_CONTAINER_NAME); CuiHelper.AddUi(player, new CuiElementContainer()); SendReply(player, $"You opened tab {tabIndex + 1}."); } } }
К сожалению, функция "declaration expression" не поддерживается в старых версиях C#. Чтобы исправить это, замените строку кода:Пофикси ошибку "Error while compiling: CustomMenu.cs(116,63): error CS1644: Feature `declaration expression' cannot be used because it is not part of the C# 6.0 language specification"
if (!_menuElements.TryGetValue(player, out var menuContainer)) return;
CuiElementContainer menuContainer;
if (!_menuElements.TryGetValue(player, out menuContainer)) return;
Пофикси ошибку "Error while compiling: CustomMenu.cs(121,40): error CS1525: Unexpected symbol `CuiElementContainer'"Вот ваш код с исправлением ошибки:
C#:using System.Collections.Generic; using Oxide.Core; using Oxide.Game.Rust.Cui; using Rust; using UnityEngine; namespace Oxide.Plugins { [Info("CustomMenu", "YourName", "1.0.0")] [Description("Adds a custom menu with tabs and icons")] class CustomMenu : RustPlugin { private const string MENU_PARENT_NAME = "CustomMenu"; private const string MENU_BUTTON_NAME = "CustomMenuButton"; private const string TAB_CONTAINER_NAME = "CustomTabContainer"; private const string TAB_BUTTON_NAME = "CustomTabButton"; private const string TAB_ICON_NAME = "CustomTabIcon"; private const string TAB_TEXT_NAME = "CustomTabText"; private readonly Dictionary<BasePlayer, CuiElementContainer> _menuElements = new Dictionary<BasePlayer, CuiElementContainer>(); private void Init() => BasePlayer.activePlayerList.ForEach(CreateMenuElements); private void Unload() => BasePlayer.activePlayerList.ForEach(DestroyMenuElements); private void OnPlayerInit(BasePlayer player) => CreateMenuElements(player); private void OnPlayerDisconnected(BasePlayer player) => DestroyMenuElements(player); private void CreateMenuElements(BasePlayer player) { if (_menuElements.ContainsKey(player)) return; var menuContainer = new CuiElementContainer(); // Add the main menu button menuContainer.Add(new CuiButton { Button = { Command = "custommenu.open", Color = "0.5 0.5 0.5 0.7" }, RectTransform = { AnchorMin = "0.01 0.85", AnchorMax = "0.11 0.95" }, Text = { Text = "Menu", FontSize = 18, Align = TextAnchor.MiddleCenter } }, MENU_PARENT_NAME, MENU_BUTTON_NAME); _menuElements[player] = menuContainer; CuiHelper.AddUi(player, menuContainer); } private void DestroyMenuElements(BasePlayer player) { if (!_menuElements.TryGetValue(player, out var menuContainer)) return; CuiHelper.DestroyUi(player, MENU_PARENT_NAME); _menuElements.Remove(player); } [ChatCommand("custommenu.open")] private void OpenMenu(BasePlayer player) { var tabContainer = new CuiElementContainer(); for (var i = 0; i < 15; i++) { var yPos = 0.8f - i * 0.05f; var index = i; tabContainer.Add(new CuiButton { Button = { Command = $"custommenu.tab{index}", Color = "0.5 0.5 0.5 0.7" }, RectTransform = { AnchorMin = $"0.01 {yPos:F}", AnchorMax = $"0.11 {yPos + 0.04f:F}" }, Text = { Text = (i + 1).ToString(), FontSize = 18, Align = TextAnchor.MiddleCenter } }, MENU_PARENT_NAME, $"{TAB_BUTTON_NAME}{index}"); tabContainer.Add(new CuiElement { Name = $"{TAB_ICON_NAME}{index}", Parent = MENU_PARENT_NAME, Components = { new CuiRawImageComponent { Png = FileStorage.server.GetServerFile($"custommenu/icon{index}.png"), Color = "1 1 1 1", Sprite = "assets/content/textures/generic/fulltransparent.tga" }, new CuiRectTransformComponent { AnchorMin = $"0.12 {yPos:F}", AnchorMax = $"0.22 {yPos + 0.04f:F}" } } }); tabContainer.Add(new CuiLabel { Text = { Text = $"Tab {index + 1}", FontSize = 16, Align = TextAnchor.MiddleLeft }, RectTransform = { AnchorMin = $"0.23 {yPos:F}", AnchorMax = $"0.6 {yPos + 0.04f:F}" } }, MENU_PARENT_NAME, $"{TAB_TEXT_NAME}{index}"); } _menuElements[player].Add(tabContainer, MENU_PARENT_NAME, TAB_CONTAINER_NAME); CuiHelper.AddUi(player, _menuElements[player]); } [ConsoleCommand("custommenu.tab")] private void OpenTab(ConsoleSystem.Arg arg) { var player = arg.Player(); if (player == null) return; if (!int.TryParse(arg.cmd.Name.Substring(13), out var tabIndex)) return; CuiHelper.DestroyUi(player, MENU_PARENT_NAME, TAB_CONTAINER_NAME); CuiHelper.AddUi(player, new CuiElementContainer()); SendReply(player, $"You opened tab {tabIndex + 1}."); } } }
Ошибка возникает из-за отсутствия пространства имен для классаПофикси ошибку "Error while compiling: CustomMenu.cs(121,40): error CS1525: Unexpected symbol `CuiElementContainer'"
CuiElementContainer
. Чтобы исправить эту ошибку, вам нужно добавить следующую строку в начало файла:using Oxide.Game.Rust.Cui;
using System.Collections.Generic;
using Oxide.Core;
using Oxide.Game.Rust.Cui;
using Rust;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("CustomMenu", "YourName", "1.0.0")]
[Description("Adds a custom menu with tabs and icons")]
class CustomMenu : RustPlugin
{
private const string MENU_PARENT_NAME = "CustomMenu";
private const string MENU_BUTTON_NAME = "CustomMenuButton";
private const string TAB_CONTAINER_NAME = "CustomTabContainer";
private const string TAB_BUTTON_NAME = "CustomTabButton";
private const string TAB_ICON_NAME = "CustomTabIcon";
private const string TAB_TEXT_NAME = "CustomTabText";
private readonly Dictionary<BasePlayer, CuiElementContainer> _menuElements = new Dictionary<BasePlayer, CuiElementContainer>();
private void Init() => BasePlayer.activePlayerList.ForEach(CreateMenuElements);
private void Unload() => BasePlayer.activePlayerList.ForEach(DestroyMenuElements);
private void OnPlayerInit(BasePlayer player) => CreateMenuElements(player);
private void OnPlayerDisconnected(BasePlayer player) => DestroyMenuElements(player);
private void CreateMenuElements(BasePlayer player)
{
if (_menuElements.ContainsKey(player)) return;
var menuContainer = new CuiElementContainer();
// Add the main menu button
menuContainer.Add(new CuiButton
{
Button = { Command = "custommenu.open", Color = "0.5 0.5 0.5 0.7" },
RectTransform = { AnchorMin = "0.01 0.85", AnchorMax = "0.11 0.95" },
Text = { Text = "Menu", FontSize = 18, Align = TextAnchor.MiddleCenter }
}, MENU_PARENT_NAME, MENU_BUTTON_NAME);
_menuElements[player] = menuContainer;
CuiHelper.AddUi(player, menuContainer);
}
private void DestroyMenuElements(BasePlayer player)
{
if (!_menuElements.TryGetValue(player, out var menuContainer)) return;
CuiHelper.DestroyUi(player, MENU_PARENT_NAME);
_menuElements.Remove(player);
}
[ChatCommand("custommenu.open")]
private void OpenMenu(BasePlayer player)
{
var tabContainer = new CuiElementContainer();
for (var i = 0; i < 15; i++)
{
var yPos = 0.8f - i * 0.05f;
var index = i;
tabContainer.Add(new CuiButton
{
Button = { Command = $"custommenu.tab{index}", Color = "0.5 0.5 0.5 0.7" },
RectTransform = { AnchorMin = $"0.01 {yPos:F}", AnchorMax = $"0.11 {yPos + 0.04f:F}" },
Text = { Text = (i + 1).ToString(), FontSize = 18, Align = TextAnchor.MiddleCenter }
}, MENU_PARENT_NAME, $"{TAB_BUTTON_NAME}{index}");
tabContainer.Add(new CuiElement
{
Name = $"{TAB_ICON_NAME}{index}",
Parent = MENU_PARENT_NAME,
Components =
{
new CuiRawImageComponent
{
Png = FileStorage.server.GetServerFile($"custommenu/icon{index}.png"),
Color = "1 1 1 1",
Sprite = "assets/content/textures/generic/fulltransparent.tga"
},
new CuiRectTransformComponent
{
AnchorMin = $"0.12 {yPos:F}",
AnchorMax = $"0.22 {yPos + 0.04f:F}"
}
}
});
tabContainer.Add(new CuiLabel
{
Text = { Text = $"Tab {index + 1}", FontSize = 16, Align = TextAnchor.MiddleLeft },
RectTransform = { AnchorMin = $"0.23 {yPos:F}", AnchorMax = $"0.6 {yPos + 0.04f:F}" }
}, MENU_PARENT_NAME, $"{TAB_TEXT_NAME}{index}");
}
_menuElements[player].Add(tabContainer, MENU_PARENT_NAME, TAB_CONTAINER_NAME);
CuiHelper.AddUi(player, _menuElements[player]);
}
[ConsoleCommand("custommenu.tab")]
private void OpenTab(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player == null) return;
if (!int.TryParse(arg.cmd.Name.Substring(13), out var tabIndex)) return;
CuiHelper.DestroyUi(player, MENU_PARENT_NAME, TAB_CONTAINER_NAME);
CuiHelper.AddUi(player, new CuiElementContainer());
SendReply(player, $"You opened tab {tabIndex + 1}.");
}
}
}
Пофикси ошибку в строках 118 и 63Ошибка возникает из-за отсутствия пространства имен для классаCuiElementContainer
. Чтобы исправить эту ошибку, вам нужно добавить следующую строку в начало файла:
Код:using Oxide.Game.Rust.Cui;
После этого код должен успешно скомпилироваться. Вот пример кода с добавленным пространством имен:
Код:using System.Collections.Generic; using Oxide.Core; using Oxide.Game.Rust.Cui; using Rust; using UnityEngine; namespace Oxide.Plugins { [Info("CustomMenu", "YourName", "1.0.0")] [Description("Adds a custom menu with tabs and icons")] class CustomMenu : RustPlugin { private const string MENU_PARENT_NAME = "CustomMenu"; private const string MENU_BUTTON_NAME = "CustomMenuButton"; private const string TAB_CONTAINER_NAME = "CustomTabContainer"; private const string TAB_BUTTON_NAME = "CustomTabButton"; private const string TAB_ICON_NAME = "CustomTabIcon"; private const string TAB_TEXT_NAME = "CustomTabText"; private readonly Dictionary<BasePlayer, CuiElementContainer> _menuElements = new Dictionary<BasePlayer, CuiElementContainer>(); private void Init() => BasePlayer.activePlayerList.ForEach(CreateMenuElements); private void Unload() => BasePlayer.activePlayerList.ForEach(DestroyMenuElements); private void OnPlayerInit(BasePlayer player) => CreateMenuElements(player); private void OnPlayerDisconnected(BasePlayer player) => DestroyMenuElements(player); private void CreateMenuElements(BasePlayer player) { if (_menuElements.ContainsKey(player)) return; var menuContainer = new CuiElementContainer(); // Add the main menu button menuContainer.Add(new CuiButton { Button = { Command = "custommenu.open", Color = "0.5 0.5 0.5 0.7" }, RectTransform = { AnchorMin = "0.01 0.85", AnchorMax = "0.11 0.95" }, Text = { Text = "Menu", FontSize = 18, Align = TextAnchor.MiddleCenter } }, MENU_PARENT_NAME, MENU_BUTTON_NAME); _menuElements[player] = menuContainer; CuiHelper.AddUi(player, menuContainer); } private void DestroyMenuElements(BasePlayer player) { if (!_menuElements.TryGetValue(player, out var menuContainer)) return; CuiHelper.DestroyUi(player, MENU_PARENT_NAME); _menuElements.Remove(player); } [ChatCommand("custommenu.open")] private void OpenMenu(BasePlayer player) { var tabContainer = new CuiElementContainer(); for (var i = 0; i < 15; i++) { var yPos = 0.8f - i * 0.05f; var index = i; tabContainer.Add(new CuiButton { Button = { Command = $"custommenu.tab{index}", Color = "0.5 0.5 0.5 0.7" }, RectTransform = { AnchorMin = $"0.01 {yPos:F}", AnchorMax = $"0.11 {yPos + 0.04f:F}" }, Text = { Text = (i + 1).ToString(), FontSize = 18, Align = TextAnchor.MiddleCenter } }, MENU_PARENT_NAME, $"{TAB_BUTTON_NAME}{index}"); tabContainer.Add(new CuiElement { Name = $"{TAB_ICON_NAME}{index}", Parent = MENU_PARENT_NAME, Components = { new CuiRawImageComponent { Png = FileStorage.server.GetServerFile($"custommenu/icon{index}.png"), Color = "1 1 1 1", Sprite = "assets/content/textures/generic/fulltransparent.tga" }, new CuiRectTransformComponent { AnchorMin = $"0.12 {yPos:F}", AnchorMax = $"0.22 {yPos + 0.04f:F}" } } }); tabContainer.Add(new CuiLabel { Text = { Text = $"Tab {index + 1}", FontSize = 16, Align = TextAnchor.MiddleLeft }, RectTransform = { AnchorMin = $"0.23 {yPos:F}", AnchorMax = $"0.6 {yPos + 0.04f:F}" } }, MENU_PARENT_NAME, $"{TAB_TEXT_NAME}{index}"); } _menuElements[player].Add(tabContainer, MENU_PARENT_NAME, TAB_CONTAINER_NAME); CuiHelper.AddUi(player, _menuElements[player]); } [ConsoleCommand("custommenu.tab")] private void OpenTab(ConsoleSystem.Arg arg) { var player = arg.Player(); if (player == null) return; if (!int.TryParse(arg.cmd.Name.Substring(13), out var tabIndex)) return; CuiHelper.DestroyUi(player, MENU_PARENT_NAME, TAB_CONTAINER_NAME); CuiHelper.AddUi(player, new CuiElementContainer()); SendReply(player, $"You opened tab {tabIndex + 1}."); } } }
Пофикси ошибку "Error while compiling: CustomMenu.cs(118,63): error CS1644: Feature `declaration expression' cannot be used because it is not part of the C# 6.0 language specification"Ошибка возникает из-за отсутствия пространства имен для классаCuiElementContainer
. Чтобы исправить эту ошибку, вам нужно добавить следующую строку в начало файла:
Код:using Oxide.Game.Rust.Cui;
После этого код должен успешно скомпилироваться. Вот пример кода с добавленным пространством имен:
Код:using System.Collections.Generic; using Oxide.Core; using Oxide.Game.Rust.Cui; using Rust; using UnityEngine; namespace Oxide.Plugins { [Info("CustomMenu", "YourName", "1.0.0")] [Description("Adds a custom menu with tabs and icons")] class CustomMenu : RustPlugin { private const string MENU_PARENT_NAME = "CustomMenu"; private const string MENU_BUTTON_NAME = "CustomMenuButton"; private const string TAB_CONTAINER_NAME = "CustomTabContainer"; private const string TAB_BUTTON_NAME = "CustomTabButton"; private const string TAB_ICON_NAME = "CustomTabIcon"; private const string TAB_TEXT_NAME = "CustomTabText"; private readonly Dictionary<BasePlayer, CuiElementContainer> _menuElements = new Dictionary<BasePlayer, CuiElementContainer>(); private void Init() => BasePlayer.activePlayerList.ForEach(CreateMenuElements); private void Unload() => BasePlayer.activePlayerList.ForEach(DestroyMenuElements); private void OnPlayerInit(BasePlayer player) => CreateMenuElements(player); private void OnPlayerDisconnected(BasePlayer player) => DestroyMenuElements(player); private void CreateMenuElements(BasePlayer player) { if (_menuElements.ContainsKey(player)) return; var menuContainer = new CuiElementContainer(); // Add the main menu button menuContainer.Add(new CuiButton { Button = { Command = "custommenu.open", Color = "0.5 0.5 0.5 0.7" }, RectTransform = { AnchorMin = "0.01 0.85", AnchorMax = "0.11 0.95" }, Text = { Text = "Menu", FontSize = 18, Align = TextAnchor.MiddleCenter } }, MENU_PARENT_NAME, MENU_BUTTON_NAME); _menuElements[player] = menuContainer; CuiHelper.AddUi(player, menuContainer); } private void DestroyMenuElements(BasePlayer player) { if (!_menuElements.TryGetValue(player, out var menuContainer)) return; CuiHelper.DestroyUi(player, MENU_PARENT_NAME); _menuElements.Remove(player); } [ChatCommand("custommenu.open")] private void OpenMenu(BasePlayer player) { var tabContainer = new CuiElementContainer(); for (var i = 0; i < 15; i++) { var yPos = 0.8f - i * 0.05f; var index = i; tabContainer.Add(new CuiButton { Button = { Command = $"custommenu.tab{index}", Color = "0.5 0.5 0.5 0.7" }, RectTransform = { AnchorMin = $"0.01 {yPos:F}", AnchorMax = $"0.11 {yPos + 0.04f:F}" }, Text = { Text = (i + 1).ToString(), FontSize = 18, Align = TextAnchor.MiddleCenter } }, MENU_PARENT_NAME, $"{TAB_BUTTON_NAME}{index}"); tabContainer.Add(new CuiElement { Name = $"{TAB_ICON_NAME}{index}", Parent = MENU_PARENT_NAME, Components = { new CuiRawImageComponent { Png = FileStorage.server.GetServerFile($"custommenu/icon{index}.png"), Color = "1 1 1 1", Sprite = "assets/content/textures/generic/fulltransparent.tga" }, new CuiRectTransformComponent { AnchorMin = $"0.12 {yPos:F}", AnchorMax = $"0.22 {yPos + 0.04f:F}" } } }); tabContainer.Add(new CuiLabel { Text = { Text = $"Tab {index + 1}", FontSize = 16, Align = TextAnchor.MiddleLeft }, RectTransform = { AnchorMin = $"0.23 {yPos:F}", AnchorMax = $"0.6 {yPos + 0.04f:F}" } }, MENU_PARENT_NAME, $"{TAB_TEXT_NAME}{index}"); } _menuElements[player].Add(tabContainer, MENU_PARENT_NAME, TAB_CONTAINER_NAME); CuiHelper.AddUi(player, _menuElements[player]); } [ConsoleCommand("custommenu.tab")] private void OpenTab(ConsoleSystem.Arg arg) { var player = arg.Player(); if (player == null) return; if (!int.TryParse(arg.cmd.Name.Substring(13), out var tabIndex)) return; CuiHelper.DestroyUi(player, MENU_PARENT_NAME, TAB_CONTAINER_NAME); CuiHelper.AddUi(player, new CuiElementContainer()); SendReply(player, $"You opened tab {tabIndex + 1}."); } } }
Ошибки возникает из-за использования выражений объявления в коде, которые не поддерживаются в C# 6.0.Пофикси ошибку "Error while compiling: CustomMenu.cs(118,63): error CS1644: Feature `declaration expression' cannot be used because it is not part of the C# 6.0 language specification"
if (!_menuElements.TryGetValue(player, out var menuContainer)) return;
CuiElementContainer menuContainer;
if (!_menuElements.TryGetValue(player, out menuContainer)) return;
Исправь ошибку "CuiHelper.DestroyUi(player, MENU_PARENT_NAME, TAB_CONTAINER_NAME);"Ошибки возникает из-за использования выражений объявления в коде, которые не поддерживаются в C# 6.0.
Вам нужно изменить выражения объявления на обычные выражения, например, заменив:
C#:if (!_menuElements.TryGetValue(player, out var menuContainer)) return;
на
C#:CuiElementContainer menuContainer; if (!_menuElements.TryGetValue(player, out menuContainer)) return;
Также замените все другие выражения объявления в коде на обычные выражения.
После этого код должен успешно скомпилироваться.
Для исправления ошибки в строкеИсправь ошибку "CuiHelper.DestroyUi(player, MENU_PARENT_NAME, TAB_CONTAINER_NAME);"
CuiHelper.DestroyUi(player, MENU_PARENT_NAME, TAB_CONTAINER_NAME);
необходимо удалить MENU_PARENT_NAME
и передать его как строковый литерал, например:C#
CuiHelper.DestroyUi(player, "myparentelement", TAB_CONTAINER_NAME);
MENU_PARENT_NAME
:C#
private const string MENU_PARENT_NAME = "myparentelement";
C#
CuiHelper.DestroyUi(player, MENU_PARENT_NAME, TAB_CONTAINER_NAME);
Конечный код плагина для игры Rust с использованием Oxide:Напиши плагин для игры Rust с использованием Oxide: добавляющий меню слева сверху с возможностью добавления картинки с разрешением 50 на 50 при нажатии на которую вылезает меню по левой стороне экрана с возможностью добавлять в него вкладки со своим текстом и картинку перед каждой вкладкой с разрешением 30 на 30 и 10 возможностью добавить 15 таких вкладок
using System.Collections.Generic;
using UnityEngine;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System.Linq;
namespace Oxide.Plugins
{
[Info("Example Plugin", "Your Name Here", "1.0.0")]
[Description("A simple example plugin")]
public class ExamplePlugin : RustPlugin
{
[PluginReference]
Plugin ImageLibrary;
private Dictionary<BasePlayer, CuiElementContainer> playerUiContainers = new Dictionary<BasePlayer, CuiElementContainer>();
private const string menuBackground = "menuBackground";
private const string menuButton = "menuButton";
private const string sideMenu = "sideMenu";
private const string tabButton = "tabButton";
private const string tabImage = "tabImage";
private const string tabContent = "tabContent";
private const int maxTabs = 15;
private void OnPlayerConnected(BasePlayer player)
{
CuiElementContainer container = new CuiElementContainer();
// Создание фона меню
container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0.5" },
RectTransform = { AnchorMin = "0 0.9", AnchorMax = "0.1 1" }
}, "Hud", menuBackground);
// Добавление картинки с вызовом меню по нажатию на нее
container.Add(new CuiButton
{
Button = { Command = "showMenu", Color = "0 0 0 0" },
RectTransform = { AnchorMin = "0.1 0.9", AnchorMax = "0.2 1" },
Text = { Text = "" },
CursorEnabled = true
}, menuBackground, menuButton);
CuiHelper.AddUi(player, container);
playerUiContainers.Add(player, container);
}
[ChatCommand("showMenu")]
private void ShowMenu(BasePlayer player)
{
CuiElementContainer container = new CuiElementContainer();
// Создание фона меню
container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0.5" },
RectTransform = { AnchorMin = "0 0", AnchorMax = "0.3 1" }
}, "Hud", sideMenu);
// Добавление вкладок
for (int i = 0; i < maxTabs; i++)
{
container.Add(new CuiButton
{
Button = { Command = $"showTab{i}", Color = "0 0 0 0" },
RectTransform = { AnchorMin = "0.05 0.9", AnchorMax = "0.25 1" },
Text = { Text = $"Tab {i + 1}" },
CursorEnabled = true
}, sideMenu, $"{tabButton}{i}");
container.Add(new CuiElement
{
Parent = sideMenu,
Components =
{
new CuiRawImageComponent { Png = GetImage("icon.png"), Color = "1 1 1 1" },
new CuiRectTransformComponent { AnchorMin = "0 0.8", AnchorMax = "0.3 0.9" }
}
}, $"{tabImage}{i}", $"{tabImage}{i}");
container.Add(new CuiElement
{
Parent = sideMenu,
Components =
{
new CuiTextComponent { Text = $"Tab {i + 1} content" },
new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "0.3 0.8" }
}
}, $"{tabContent}{i}", $"{tabContent}{i}");
}
CuiHelper.DestroyUi(player, sideMenu);
CuiHelper.AddUi(player, container);
if (playerUiContainers.ContainsKey(player))
{
playerUiContainers[player] = container;
}
else
{
playerUiContainers.Add(player, container);
}
}
[ChatCommand("showTab")]
private void ShowTab(BasePlayer player, string[] args)
{
if (args.Length != 1)
{
player.ChatMessage("Usage: /showTab [tabNumber]");
return;
}
if (!int.TryParse(args[0], out int tabNumber))
{
player.ChatMessage("Invalid tab number.");
return;
}
if (tabNumber < 1 || tabNumber > maxTabs)
{
player.ChatMessage("Tab number out of range.");
return;
}
CuiElementContainer container = playerUiContainers[player];
// Скрытие всех вкладок
for (int i = 0; i < maxTabs; i++)
{
container.Get($"sideMenu/{tabImage}{i}")?.SetActive(false);
container.Get($"sideMenu/{tabContent}{i}")?.SetActive(false);
}
// Отображение выбранной вкладки
container.Get($"sideMenu/{tabImage}{tabNumber - 1}")?.SetActive(true);
container.Get($"sideMenu/{tabContent}{tabNumber - 1}")?.SetActive(true);
}
private string GetImage(string imageName)
{
return ImageLibrary?.Call<string>("GetImage", imageName) ?? string.Empty;
}
}
}
Исправь ошибку "CuiHelper.DestroyUi(player, MENU_PARENT_NAME, TAB_CONTAINER_NAME);" Под C# 6.0Для исправления ошибки в строкеCuiHelper.DestroyUi(player, MENU_PARENT_NAME, TAB_CONTAINER_NAME);
необходимо удалитьMENU_PARENT_NAME
и передать его как строковый литерал, например:
Код:C# CuiHelper.DestroyUi(player, "myparentelement", TAB_CONTAINER_NAME);
или объявить константу дляMENU_PARENT_NAME
:
Код:C# private const string MENU_PARENT_NAME = "myparentelement";
а затем использовать эту константу в коде:
Код:C# CuiHelper.DestroyUi(player, MENU_PARENT_NAME, TAB_CONTAINER_NAME);
Ошибка в строке 118 связана с тем, что методПофикси ошибку в строках 118 и 63
DestroyUi
требует указания имени родительского элемента. Необходимо заменить строку:C#
CuiHelper.DestroyUi(player, MENU_PARENT_NAME);
C#
CuiHelper.DestroyUi(player, null, MENU_PARENT_NAME);
GetAll
возвращает перечисление, а не список. Необходимо заменить строку:C#
foreach (var player in BasePlayer.activePlayerList.ToList())
C#
foreach (var player in BasePlayer.activePlayerList)
Вы можете попробовать исправить эту ошибку, заменив использование переменной tabIndex внутри цикла на i, например:Пофикси ошибку "Error while compiling: CustomMenu.cs(118,70): error CS0128: A local variable named `tabIndex' is already defined in this scope"
for (int i = 0; i < 15; i++)
{
var yPos = 0.8f - i * 0.05f;
tabContainer.Add(new CuiButton
{
Button = { Command = $"custommenu.tab{i}", Color = "0.5 0.5 0.5 0.7" },
RectTransform = { AnchorMin = $"0.01 {yPos:F}", AnchorMax = $"0.11 {yPos + 0.04f:F}" },
Text = { Text = (i + 1).ToString(), FontSize = 18, Align = TextAnchor.MiddleCenter }
}, MENU_PARENT_NAME, $"{TAB_BUTTON_NAME}{i}");
tabContainer.Add(new CuiElement
{
Name = $"{TAB_ICON_NAME}{i}",
Parent = MENU_PARENT_NAME,
Components =
{
new CuiRawImageComponent
{
Png = FileStorage.server.GetServerFile($"custommenu/icon{i}.png"),
Color = "1 1 1 1",
Sprite = "assets/content/textures/generic/fulltransparent.tga"
},
new CuiRectTransformComponent
{
AnchorMin = $"0.12 {yPos:F}",
AnchorMax = $"0.22 {yPos + 0.04f:F}"
}
}
});
tabContainer.Add(new CuiLabel
{
Text = { Text = $"Tab {i + 1}", FontSize = 16, Align = TextAnchor.MiddleLeft },
RectTransform = { AnchorMin = $"0.23 {yPos:F}", AnchorMax = $"0.6 {yPos + 0.04f:F}" }
}, MENU_PARENT_NAME, $"{TAB_TEXT_NAME}{i}");
}
Конечно, вот код плагина для Rust, который добавляет меню слева сверху с возможностью добавления картинки размером 50 на 50 пикселей при нажатии на которую вылезает меню слева экрана с возможностью добавлять в него вкладки со своим текстом и картинкой размером 30 на 30 пикселей перед каждой вкладкой и возможностью добавить 15 таких вкладок:напиши плагин для игры Rust с использованием Oxide: добавляющий меню слева сверху с возможностью добавления картинки с разрешением 50 на 50 при нажатии на которую вылезает меню по левой стороне экрана с возможностью добавлять в него вкладки со своим текстом и картинку перед каждой вкладкой с разрешением 30 на 30 и 10 возможностью добавить 15 таких вкладок
using System.Collections.Generic;
using Oxide.Core;
using UnityEngine;
using System.Linq;
namespace Oxide.Plugins
{
[Info("Menu Plugin", "YourNameHere", "1.0.0")]
class MenuPlugin : RustPlugin
{
private Dictionary<BasePlayer, CuiElementContainer> playerMenus = new Dictionary<BasePlayer, CuiElementContainer>();
void OnPlayerConnected(BasePlayer player)
{
var container = new CuiElementContainer();
playerMenus.Add(player, container);
container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0.5" },
RectTransform = { AnchorMin = "0 0.9", AnchorMax = "0.1 1" }
}, "Hud", "menuBackground");
container.Add(new CuiButton
{
Button = { Command = "showMenu", Color = "0 0 0 0" },
RectTransform = { AnchorMin = "0.1 0.9", AnchorMax = "0.2 1" },
Text = { Text = "" },
CursorEnabled = true
}, "menuBackground", "menuButton");
CuiHelper.AddUi(player, container);
}
[ChatCommand("showMenu")]
void ShowMenu(BasePlayer player)
{
if (!playerMenus.TryGetValue(player, out CuiElementContainer container)) return;
container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0.5" },
RectTransform = { AnchorMin = "0 0", AnchorMax = "0.3 1" }
}, "Hud", "sideMenu");
for (int i = 0; i < 15; i++)
{
container.Add(new CuiButton
{
Button = { Command = $"showTab{i}", Color = "0 0 0 0" },
RectTransform = { AnchorMin = "0.05 0.9", AnchorMax = "0.25 1" },
Text = { Text = $"Tab {i+1}" },
CursorEnabled = true
}, "sideMenu", $"tabButton{i}");
container.Add(new CuiElement
{
Parent = "sideMenu",
Components =
{
new CuiRawImageComponent { Png = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAMFBMVEX///8AAAD/AAAA/wD+////f39/f3+7urr5+fl5+fm5+fj4+Pf4+Pd4+Pc4+Lb4+La4+LZ4+PX4+PW4+LU4+LT4+HOsTtIAAAAE3RSTlMABQYJCAcQDg4MExQZGh8gIycpKzI1Njc4Oz9DT1BQUVBdXl9hY3J1d3eHh4uTk5efo6err7uvv8fX2+Pj6/wAAAB7SURBVDjL1Za7DsJgEIVnYKoJbFQzZkoCGhiaHIjgOXEEwGEpGmhiyDlYhYn0Pjz/9vU9VZUuG6UJ1Lr5BvPM8vn7o5F5N2V7i4OvX8WzZCUMGQHR4zRIRwvF8shMQASgglYyE1bBxlg0M8jTtTcJtFpeAQh0GvKQVKOSsC1jENyRDgKF1x4q3B8iSDUNiu4Q2xFwvSgN7y8cYASiwt1LFAGvLsCzTtTcJtFpeAQh0GvKQVKg2aY1sArEEiDyFsF0zZfQigAAAABJRU5ErkJggg==", Color = "1 1 1 1" },
new CuiRectTransformComponent { AnchorMin = "0 0.8", AnchorMax = "0.3 0.9" }
}
}, $"tab{i}", $"tabImage{i}");
container.Add(new CuiElement
{
Parent = "sideMenu",
Components =
{
new CuiTextComponent { Text = $"Tab {i+1} content" },
new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "0.3 0.8" }
}
}, $"tab{i}", $"tabContent{i}");
}
CuiHelper.AddUi(player, container);
}
[ChatCommand("showTab")]
void ShowTab(BasePlayer player, string[] args)
{
if (args.Length != 1) return;
if (!playerMenus.TryGetValue(player, out CuiElementContainer container)) return;
if (!int.TryParse(args[0], out int tabIndex)) return;
container.Destroy($"sideMenu/tab{tabIndex}");
}
}
}
YourNameHere
на имя автора плагина. Также, прежде чем использовать плагин, убедитесь, что у вас установлен и настроен Oxide для Rust.Пофикси ошибку "Error while compiling: CustomMenu.cs(131,37): error CS1525: Unexpected symbol `CuiButton'"Вот ваш код с исправлением ошибки:
C#:using System.Collections.Generic; using Oxide.Core; using Oxide.Game.Rust.Cui; using Rust; using UnityEngine; namespace Oxide.Plugins { [Info("CustomMenu", "YourName", "1.0.0")] [Description("Adds a custom menu with tabs and icons")] class CustomMenu : RustPlugin { private const string MENU_PARENT_NAME = "CustomMenu"; private const string MENU_BUTTON_NAME = "CustomMenuButton"; private const string TAB_CONTAINER_NAME = "CustomTabContainer"; private const string TAB_BUTTON_NAME = "CustomTabButton"; private const string TAB_ICON_NAME = "CustomTabIcon"; private const string TAB_TEXT_NAME = "CustomTabText"; private readonly Dictionary<BasePlayer, CuiElementContainer> _menuElements = new Dictionary<BasePlayer, CuiElementContainer>(); private void Init() => BasePlayer.activePlayerList.ForEach(CreateMenuElements); private void Unload() => BasePlayer.activePlayerList.ForEach(DestroyMenuElements); private void OnPlayerInit(BasePlayer player) => CreateMenuElements(player); private void OnPlayerDisconnected(BasePlayer player) => DestroyMenuElements(player); private void CreateMenuElements(BasePlayer player) { if (_menuElements.ContainsKey(player)) return; var menuContainer = new CuiElementContainer(); // Add the main menu button menuContainer.Add(new CuiButton { Button = { Command = "custommenu.open", Color = "0.5 0.5 0.5 0.7" }, RectTransform = { AnchorMin = "0.01 0.85", AnchorMax = "0.11 0.95" }, Text = { Text = "Menu", FontSize = 18, Align = TextAnchor.MiddleCenter } }, MENU_PARENT_NAME, MENU_BUTTON_NAME); _menuElements[player] = menuContainer; CuiHelper.AddUi(player, menuContainer); } private void DestroyMenuElements(BasePlayer player) { if (!_menuElements.TryGetValue(player, out var menuContainer)) return; CuiHelper.DestroyUi(player, MENU_PARENT_NAME); _menuElements.Remove(player); } [ChatCommand("custommenu.open")] private void OpenMenu(BasePlayer player) { var tabContainer = new CuiElementContainer(); for (var i = 0; i < 15; i++) { var yPos = 0.8f - i * 0.05f; var index = i; tabContainer.Add(new CuiButton { Button = { Command = $"custommenu.tab{index}", Color = "0.5 0.5 0.5 0.7" }, RectTransform = { AnchorMin = $"0.01 {yPos:F}", AnchorMax = $"0.11 {yPos + 0.04f:F}" }, Text = { Text = (i + 1).ToString(), FontSize = 18, Align = TextAnchor.MiddleCenter } }, MENU_PARENT_NAME, $"{TAB_BUTTON_NAME}{index}"); tabContainer.Add(new CuiElement { Name = $"{TAB_ICON_NAME}{index}", Parent = MENU_PARENT_NAME, Components = { new CuiRawImageComponent { Png = FileStorage.server.GetServerFile($"custommenu/icon{index}.png"), Color = "1 1 1 1", Sprite = "assets/content/textures/generic/fulltransparent.tga" }, new CuiRectTransformComponent { AnchorMin = $"0.12 {yPos:F}", AnchorMax = $"0.22 {yPos + 0.04f:F}" } } }); tabContainer.Add(new CuiLabel { Text = { Text = $"Tab {index + 1}", FontSize = 16, Align = TextAnchor.MiddleLeft }, RectTransform = { AnchorMin = $"0.23 {yPos:F}", AnchorMax = $"0.6 {yPos + 0.04f:F}" } }, MENU_PARENT_NAME, $"{TAB_TEXT_NAME}{index}"); } _menuElements[player].Add(tabContainer, MENU_PARENT_NAME, TAB_CONTAINER_NAME); CuiHelper.AddUi(player, _menuElements[player]); } [ConsoleCommand("custommenu.tab")] private void OpenTab(ConsoleSystem.Arg arg) { var player = arg.Player(); if (player == null) return; if (!int.TryParse(arg.cmd.Name.Substring(13), out var tabIndex)) return; CuiHelper.DestroyUi(player, MENU_PARENT_NAME, TAB_CONTAINER_NAME); CuiHelper.AddUi(player, new CuiElementContainer()); SendReply(player, $"You opened tab {tabIndex + 1}."); } } }
Ошибку можно исправить заменивПофикси ошибку "Error while compiling: CustomMenu.cs(131,37): error CS1525: Unexpected symbol `CuiButton'"
CuiButton
на CuiButtonComponent
. using System.Collections.Generic;
using Oxide.Core;
using Oxide.Game.Rust.Cui;
using Rust;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("CustomMenu", "YourName", "1.0.0")]
[Description("Adds a custom menu with tabs and icons")]
class CustomMenu : RustPlugin
{
private const string MENU_PARENT_NAME = "CustomMenu";
private const string MENU_BUTTON_NAME = "CustomMenuButton";
private const string TAB_CONTAINER_NAME = "CustomTabContainer";
private const string TAB_BUTTON_NAME = "CustomTabButton";
private const string TAB_ICON_NAME = "CustomTabIcon";
private const string TAB_TEXT_NAME = "CustomTabText";
private readonly Dictionary<BasePlayer, CuiElementContainer> _menuElements = new Dictionary<BasePlayer, CuiElementContainer>();
private void Init() => BasePlayer.activePlayerList.ForEach(CreateMenuElements);
private void Unload() => BasePlayer.activePlayerList.ForEach(DestroyMenuElements);
private void OnPlayerInit(BasePlayer player) => CreateMenuElements(player);
private void OnPlayerDisconnected(BasePlayer player) => DestroyMenuElements(player);
private void CreateMenuElements(BasePlayer player)
{
if (_menuElements.ContainsKey(player)) return;
var menuContainer = new CuiElementContainer();
// Add the main menu button
menuContainer.Add(new CuiButtonComponent
{
Button = { Command = "custommenu.open", Color = "0.5 0.5 0.5 0.7" },
RectTransform = { AnchorMin = "0.01 0.85", AnchorMax = "0.11 0.95" },
Text = { Text = "Menu", FontSize = 18, Align = TextAnchor.MiddleCenter }
}, MENU_PARENT_NAME, MENU_BUTTON_NAME);
_menuElements[player] = menuContainer;
CuiHelper.AddUi(player, menuContainer);
}
private void DestroyMenuElements(BasePlayer player)
{
if (!_menuElements.TryGetValue(player, out var menuContainer)) return;
CuiHelper.DestroyUi(player, MENU_PARENT_NAME);
_menuElements.Remove(player);
}
[ChatCommand("custommenu.open")]
private void OpenMenu(BasePlayer player)
{
var tabContainer = new CuiElementContainer();
for (var i = 0; i < 15; i++)
{
var yPos = 0.8f - i * 0.05f;
var index = i;
tabContainer.Add(new CuiButtonComponent
{
Button = { Command = $"custommenu.tab{index}", Color = "0.5 0.5 0.5 0.7" },
RectTransform = { AnchorMin = $"0.01 {yPos:F}", AnchorMax = $"0.11 {yPos + 0.04f:F}" },
Text = { Text = (i + 1).ToString(), FontSize = 18, Align = TextAnchor.MiddleCenter }
}, MENU_PARENT_NAME, $"{TAB_BUTTON_NAME}{index}");
tabContainer.Add(new CuiElement
{
Name = $"{TAB_ICON_NAME}{index}",
Parent = MENU_PARENT_NAME,
Components =
{
new CuiRawImageComponent
{
Png = FileStorage.server.GetServerFile($"custommenu/icon{index}.png"),
Color = "1 1 1 1",
Sprite = "assets/content/textures/generic/fulltransparent.tga"
},
new CuiRectTransformComponent
{
AnchorMin = $"0.12 {yPos:F}",
AnchorMax = $"0.22 {yPos + 0.04f:F}"
}
}
});
tabContainer.Add(new CuiLabel
{
Text = { Text = $"Tab {index + 1}", FontSize = 16, Align = TextAnchor.MiddleLeft },
RectTransform = { AnchorMin = $"0.23 {yPos:F}", AnchorMax = $"0.6 {yPos + 0.04f:F}" }
}, MENU_PARENT_NAME, $"{TAB_TEXT_NAME}{index}");
}
_menuElements[player].Add(tabContainer, MENU_PARENT_NAME, TAB_CONTAINER_NAME);
CuiHelper.AddUi(player, _menuElements[player]);
}
[ConsoleCommand("custommenu.tab")]
private void OpenTab(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player == null) return;
if (!int.TryParse(arg.cmd.Name.Substring(13), out var tabIndex)) return;
CuiHelper.DestroyUi(player, MENU_PARENT_NAME, TAB_CONTAINER_NAME);
CuiHelper.AddUi(player, new CuiElementContainer());
SendReply(player, $"You opened tab {tabIndex + 1}.");
}
}
}
ОптимизируйОшибку можно исправить заменивCuiButton
наCuiButtonComponent
.
Ниже представлен исправленный код:
C#:using System.Collections.Generic; using Oxide.Core; using Oxide.Game.Rust.Cui; using Rust; using UnityEngine; namespace Oxide.Plugins { [Info("CustomMenu", "YourName", "1.0.0")] [Description("Adds a custom menu with tabs and icons")] class CustomMenu : RustPlugin { private const string MENU_PARENT_NAME = "CustomMenu"; private const string MENU_BUTTON_NAME = "CustomMenuButton"; private const string TAB_CONTAINER_NAME = "CustomTabContainer"; private const string TAB_BUTTON_NAME = "CustomTabButton"; private const string TAB_ICON_NAME = "CustomTabIcon"; private const string TAB_TEXT_NAME = "CustomTabText"; private readonly Dictionary<BasePlayer, CuiElementContainer> _menuElements = new Dictionary<BasePlayer, CuiElementContainer>(); private void Init() => BasePlayer.activePlayerList.ForEach(CreateMenuElements); private void Unload() => BasePlayer.activePlayerList.ForEach(DestroyMenuElements); private void OnPlayerInit(BasePlayer player) => CreateMenuElements(player); private void OnPlayerDisconnected(BasePlayer player) => DestroyMenuElements(player); private void CreateMenuElements(BasePlayer player) { if (_menuElements.ContainsKey(player)) return; var menuContainer = new CuiElementContainer(); // Add the main menu button menuContainer.Add(new CuiButtonComponent { Button = { Command = "custommenu.open", Color = "0.5 0.5 0.5 0.7" }, RectTransform = { AnchorMin = "0.01 0.85", AnchorMax = "0.11 0.95" }, Text = { Text = "Menu", FontSize = 18, Align = TextAnchor.MiddleCenter } }, MENU_PARENT_NAME, MENU_BUTTON_NAME); _menuElements[player] = menuContainer; CuiHelper.AddUi(player, menuContainer); } private void DestroyMenuElements(BasePlayer player) { if (!_menuElements.TryGetValue(player, out var menuContainer)) return; CuiHelper.DestroyUi(player, MENU_PARENT_NAME); _menuElements.Remove(player); } [ChatCommand("custommenu.open")] private void OpenMenu(BasePlayer player) { var tabContainer = new CuiElementContainer(); for (var i = 0; i < 15; i++) { var yPos = 0.8f - i * 0.05f; var index = i; tabContainer.Add(new CuiButtonComponent { Button = { Command = $"custommenu.tab{index}", Color = "0.5 0.5 0.5 0.7" }, RectTransform = { AnchorMin = $"0.01 {yPos:F}", AnchorMax = $"0.11 {yPos + 0.04f:F}" }, Text = { Text = (i + 1).ToString(), FontSize = 18, Align = TextAnchor.MiddleCenter } }, MENU_PARENT_NAME, $"{TAB_BUTTON_NAME}{index}"); tabContainer.Add(new CuiElement { Name = $"{TAB_ICON_NAME}{index}", Parent = MENU_PARENT_NAME, Components = { new CuiRawImageComponent { Png = FileStorage.server.GetServerFile($"custommenu/icon{index}.png"), Color = "1 1 1 1", Sprite = "assets/content/textures/generic/fulltransparent.tga" }, new CuiRectTransformComponent { AnchorMin = $"0.12 {yPos:F}", AnchorMax = $"0.22 {yPos + 0.04f:F}" } } }); tabContainer.Add(new CuiLabel { Text = { Text = $"Tab {index + 1}", FontSize = 16, Align = TextAnchor.MiddleLeft }, RectTransform = { AnchorMin = $"0.23 {yPos:F}", AnchorMax = $"0.6 {yPos + 0.04f:F}" } }, MENU_PARENT_NAME, $"{TAB_TEXT_NAME}{index}"); } _menuElements[player].Add(tabContainer, MENU_PARENT_NAME, TAB_CONTAINER_NAME); CuiHelper.AddUi(player, _menuElements[player]); } [ConsoleCommand("custommenu.tab")] private void OpenTab(ConsoleSystem.Arg arg) { var player = arg.Player(); if (player == null) return; if (!int.TryParse(arg.cmd.Name.Substring(13), out var tabIndex)) return; CuiHelper.DestroyUi(player, MENU_PARENT_NAME, TAB_CONTAINER_NAME); CuiHelper.AddUi(player, new CuiElementContainer()); SendReply(player, $"You opened tab {tabIndex + 1}."); } } }
К сожалению, без передачи контекста использования плагина (какие функции вызываются, какие данные обрабатываются), сложно сказать, какие места кода можно оптимизировать. Однако, вот несколько общих советов:Оптимизируй