Знающие люди, помогите не могу найти откуда ошибка
Вот сам плагин:
using System.Collections.Generic;
using System.Text;
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)
{
CuiElement menuContainer;
if (!_menuElements.TryGetValue(player, out menuContainer)) return;
for (var i = 0; i < 15; i++)
{
var yPos = 0.8f - i * 0.05f;
var tabButtonName = TabButtonName + i.ToString();
var tabIconName = TabIconName + i.ToString();
var tabTextName = TabTextName + i.ToString();
menuContainer.Remove(tabButtonName);
menuContainer.Remove(tabIconName);
menuContainer.Remove(tabTextName);
}
menuContainer.Remove(TabContainerName);
_menuElements.Remove(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))
{
// код, который использует переменную tabIndex
}
else
{
return;
}
CuiHelper.DestroyUi(player, MenuParentName, TabContainerName);
CuiHelper.AddUi(player, new CuiElementContainer());
SendReply(player, string.Format("Вы открыли вкладку {0}.", tabIndex + 1));
}
[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,
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, TabButtonName + i.ToString());
tabContainer.Add(new CuiElement
{
Name = TabIconName + i.ToString(),
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, TabTextName + i.ToString());
}
_menuElements[player].Add(tabContainer, MenuParentName, TabContainerName);
CuiHelper.AddUi(player, _menuElements[player]);
}
}
}
И вот ошибка:
Error while compiling: CustomMenu.cs(189,39): error CS1503: Argument `#1' cannot convert `Oxide.Game.Rust.Cui.CuiElementContainer' expression to type `Oxide.Game.Rust.Cui.CuiButton'
Вот сам плагин:
using System.Collections.Generic;
using System.Text;
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)
{
CuiElement menuContainer;
if (!_menuElements.TryGetValue(player, out menuContainer)) return;
for (var i = 0; i < 15; i++)
{
var yPos = 0.8f - i * 0.05f;
var tabButtonName = TabButtonName + i.ToString();
var tabIconName = TabIconName + i.ToString();
var tabTextName = TabTextName + i.ToString();
menuContainer.Remove(tabButtonName);
menuContainer.Remove(tabIconName);
menuContainer.Remove(tabTextName);
}
menuContainer.Remove(TabContainerName);
_menuElements.Remove(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))
{
// код, который использует переменную tabIndex
}
else
{
return;
}
CuiHelper.DestroyUi(player, MenuParentName, TabContainerName);
CuiHelper.AddUi(player, new CuiElementContainer());
SendReply(player, string.Format("Вы открыли вкладку {0}.", tabIndex + 1));
}
[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,
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, TabButtonName + i.ToString());
tabContainer.Add(new CuiElement
{
Name = TabIconName + i.ToString(),
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, TabTextName + i.ToString());
}
_menuElements[player].Add(tabContainer, MenuParentName, TabContainerName);
CuiHelper.AddUi(player, _menuElements[player]);
}
}
}
И вот ошибка:
Error while compiling: CustomMenu.cs(189,39): error CS1503: Argument `#1' cannot convert `Oxide.Game.Rust.Cui.CuiElementContainer' expression to type `Oxide.Game.Rust.Cui.CuiButton'