Ошибка возникает из-за использования функции интерполяции строк вместе с оператором объявления переменной. В C# 6.0 такой синтаксис не поддерживается. Чтобы исправить ошибку, замените оператор объявления переменной на обычное присваивание переменной. Например, в строке 72 замените:Исправь ошибку "Error while compiling: CustomMenu.cs(72,56): error CS1644: Feature `declaration expression' cannot be used because it is not part of the C# 6.0 language specification"
Код:
Command = $"custommenu.tab{i}"
на
Код:
Command = "custommenu.tab" + i.ToString();
Полный исправленный код:
Код:
using System.Collections.Generic;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("CustomMenu", "YourName", "1.0.0")]
[Description("Добавляет пользовательское меню с вкладками и иконками.")]
class CustomMenu : RustPlugin
{
private const string MenuParentName = "CustomMenu";
private const string MenuButtonName = "CustomMenuButton";
private const string TabContainerName = "CustomTabContainer";
private const string TabButtonName = "CustomTabButton";
private const string TabIconName = "CustomTabIcon";
private const string TabTextName = "CustomTabText";
private readonly Dictionary<BasePlayer, CuiElementContainer> _menuElements = new Dictionary<BasePlayer, CuiElementContainer>();
private void Init()
{
foreach (var player in BasePlayer.activePlayerList)
{
CreateMenuElements(player);
}
}
private void Unload()
{
foreach (var player in BasePlayer.activePlayerList)
{
DestroyMenuElements(player);
}
}
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();
// Добавляем кнопку главного меню
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 = "Меню", FontSize = 18, Align = TextAnchor.MiddleCenter }
}, MenuParentName, MenuButtonName);
_menuElements[player] = menuContainer;
CuiHelper.AddUi(player, menuContainer);
}
private void DestroyMenuElements(BasePlayer player)
{
if (!_menuElements.TryGetValue(player, out var menuContainer)) return;
CuiHelper.DestroyUi(player, MenuParentName);
_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;
tabContainer.Add(new CuiButtonComponent
{
Button = { Command = "custommenu.tab" + i.ToString(), Color = "0.5 0.5 0.5 0.7" },
RectTransform = { AnchorMin = string.Format("0.01 {0:F}", yPos), AnchorMax = string.Format("0.11 {0:F}", yPos + 0.04f) },
Text = { Text = (i + 1).ToString(), FontSize = 18, Align = TextAnchor.MiddleCenter }
}, MenuParentName, string.Format("{0}{1}", TabButtonName, i));
tabContainer.Add(new CuiElement
{
Name = string.Format("{0}{1}", TabIconName, i),
Parent = MenuParentName,
Components =
{
new CuiRawImageComponent
{
Png = FileStorage.server.GetServerFile(string.Format("custommenu/icon{0}.png", i)),
Color = "1 1 1 1",
Sprite = "assets/content/textures/generic/fulltransparent.tga"
},
new CuiRectTransformComponent
{
AnchorMin = string.Format("0.12 {0:F}", yPos),
AnchorMax = string.Format("0.22 {0:F}", yPos + 0.04f)
}
}
});
tabContainer.Add(new CuiLabel
{
Text = { Text = string.Format("Вкладка {0}", i + 1), FontSize = 16, Align = TextAnchor.MiddleLeft },
RectTransform = { AnchorMin = string.Format("0.23 {0:F}", yPos), AnchorMax = string.Format("0.6 {0:F}", yPos + 0.04f) }
}, MenuParentName, string.Format("{0}{1}", TabTextName, i));
}
_menuElements[player].Add(tabContainer, MenuParentName, TabContainerName);
CuiHelper.AddUi(player, _menuElements[player]);
}
[ConsoleCommand("custommenu.tab")]
private void OpenTab(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player == null) return;
int tabIndex;
if (!int.TryParse(arg.cmd.Name.Substring(10), out tabIndex)) return;
CuiHelper.DestroyUi(player, MenuParentName, TabContainerName);
CuiHelper.AddUi(player, new CuiElementContainer());
SendReply(player, string.Format("Вы открыли вкладку {0}.", tabIndex + 1));
}
}
}