Тогда смотри какое у меня задание, я сейчас скачал стартер кит для создания стратегии, у него есть гайд, но он на версию 2018 года, мне нужно, чтобы ты использовал его документацию и объяснил мне, как сделать свою игру на его основе на версии unity 6.1
Если нужно, вот ссылка в гугл доке https://docs.google.com/document/d/1jM-qJoNewQ2HnpzaUbwVG6VSX94sXPAGT5YRK15mUDA/edit?tab=t.0
1)Обновил постПроцессинг до 3.4.0
2)Перезашёл в проект, теперь такие ошибки:
Assets\InsaneSystems\RTSStarterKit\Scripts\UI\ControlsButtons.cs(9,20): error CS0246: The type or namespace name 'Button' could not be found (are you missing a using directive or an assembly reference?)
Assets\InsaneSystems\RTSStarterKit\Scripts\UI\UIController.cs(11,20): error CS0246: The type or namespace name 'Text' could not be found (are you missing a using directive or an assembly reference?)
Assets\InsaneSystems\RTSStarterKit\Scripts\UI\Production\ProductionTypeButton.cs(15,3): error CS0246: The type or namespace name 'Button' could not be found (are you missing a using directive or an assembly reference?)
Assets\InsaneSystems\RTSStarterKit\Scripts\UI\Production\ProductionTypeButton.cs(14,3): error CS0246: The type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?)
Assets\InsaneSystems\RTSStarterKit\Scripts\UI\Production\UnitIcon.cs(15,3): error CS0246: The type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?)
Вот код ContolsButtons.cs
using InsaneSystems.RTSStarterKit.Controls;
using UnityEngine;
using UnityEngine.UI;
namespace InsaneSystems.RTSStarterKit.Scripts.UI
{
public class ControlsButtons : MonoBehaviour
{
[SerializeField] Button repairButton, sellButton;
code
void Start()
{
if (repairButton)
repairButton.onClick.AddListener(delegate
{
InputHandler.sceneInstance.SetCustomControls(CustomControls.Repair);
});
if (sellButton)
sellButton.onClick.AddListener(delegate
{
InputHandler.sceneInstance.SetCustomControls(CustomControls.Sell);
});
}
}
}
UIController.cs
using UnityEngine;
using UnityEngine.UI;
namespace InsaneSystems.RTSStarterKit.UI
{
public class UIController : MonoBehaviour
{
public static UIController instance { get; protected set; }
}
ProductionTypeButton.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace InsaneSystems.RTSStarterKit.UI
{
public class ProductionTypeButton : MonoBehaviour
{
[SerializeField] ProductionCategory productionCategory;
code
SelectProductionTypePanel controllerPanel;
Image selfImage;
Button selfButton;
Color defaultColor;
public ProductionCategory GetProductionCategory
{
get { return productionCategory; }
}
void Awake()
{
selfImage = GetComponent<Image>();
selfButton = GetComponent<Button>();
defaultColor = selfImage.color;
}
void Start() { Redraw(); }
public void SetActive() { selfImage.color = Color.green; }
public void SetUnactive() { selfImage.color = defaultColor; }
public void OnClick() { controllerPanel.OnSelectButtonClick(productionCategory); }
public void Redraw()
{
selfButton.interactable = Player.GetLocalPlayer().IsHaveProductionOfCategory(productionCategory);
}
public void SetupWithController(SelectProductionTypePanel typePanel) { controllerPanel = typePanel; }
public void SetupWithProductionCategory(ProductionCategory category)
{
productionCategory = category;
selfImage.sprite = category.icon;
Redraw();
}
}
}
ProductionTypeButton.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace InsaneSystems.RTSStarterKit.UI
{
public class ProductionTypeButton : MonoBehaviour
{
[SerializeField] ProductionCategory productionCategory;
code
SelectProductionTypePanel controllerPanel;
Image selfImage;
Button selfButton;
Color defaultColor;
public ProductionCategory GetProductionCategory
{
get { return productionCategory; }
}
void Awake()
{
selfImage = GetComponent<Image>();
selfButton = GetComponent<Button>();
defaultColor = selfImage.color;
}
void Start() { Redraw(); }
public void SetActive() { selfImage.color = Color.green; }
public void SetUnactive() { selfImage.color = defaultColor; }
public void OnClick() { controllerPanel.OnSelectButtonClick(productionCategory); }
public void Redraw()
{
selfButton.interactable = Player.GetLocalPlayer().IsHaveProductionOfCategory(productionCategory);
}
public void SetupWithController(SelectProductionTypePanel typePanel) { controllerPanel = typePanel; }
public void SetupWithProductionCategory(ProductionCategory category)
{
productionCategory = category;
selfImage.sprite = category.icon;
Redraw();
}
}
}
UnitIcon.cs
using InsaneSystems.RTSStarterKit.Controls;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
namespace InsaneSystems.RTSStarterKit.UI
{
public class UnitIcon : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
{
[SerializeField] Image fillImage;
[SerializeField] Image iconImage;
[SerializeField] Button button;
[SerializeField] Text countText, hotkeyText;
[SerializeField] GameObject hotkeyPanel;
Image hotkeyBG;
code
}
Assistant
Чтобы решить проблемы с ошибками компиляции в Unity 6.1, связанными с отсутствием типов Button, Text и Image, нужно выполнить следующие шаги:
1. Проверьте подключение UI-библиотек
Ошибка CS0246 указывает, что Unity не видит типы Button, Text, Image. Это связано с тем, что в Unity 6.1 необходимо явно включить пакет UnityEngine.UI.
Найдите пакет UI Toolkit (или UnityEngine.UI, если он доступен).
Убедитесь, что пакет установлен и активен. Если его нет, установите его.
Перезапустите Unity и пересоберите проект.
Примечание: В Unity 6.1 может быть изменена структура пакетов. Если UnityEngine.UI не отображается, проверьте, не используется ли UI Toolkit вместо него.
2. Проверьте настройки проекта
Unity 6.1 может требовать изменения настроек проекта:
Откройте Player Settings (Edit → Project Settings → Player).
Убедитесь, что Scripting Runtime Version установлен на .NET 4.x Equivalent (если это поддерживается Unity 6.1).
Проверьте, что API Compatibility Level установлен на .NET Standard 2.0 или .NET 4.x (в зависимости от вашей версии Unity).
3. Исправьте дублирование кода
В вашем коде есть дублирование класса ProductionTypeButton (два одинаковых класса в одном файле). Это приведет к ошибке компиляции.
Решение:
Удалите дублированный код из файла ProductionTypeButton.cs. Оставьте только один экземпляр класса.
4. Обновите зависимости
Стартер-кит, созданный для Unity 2018, может использовать устаревшие версии библиотек. Убедитесь, что все зависимости совместимы с Unity 6.1.
Рекомендации:
PostProcessing: Убедитесь, что версия PostProcessing (3.4.0) совместима с Unity 6.1. Если нет, попробуйте обновить до версии, поддерживаемой Unity 6.1.
UnitData unitDataTemplate;
ProductionIconsPanel selfProductionIconsPanel;
RectTransform rectTransform;
void Start()
{
rectTransform = GetComponent<RectTransform>();
if (hotkeyPanel)
hotkeyBG = hotkeyPanel.GetComponent<Image>();
}
void HotkeyDrawMode(bool visible)
{
if (!hotkeyBG)
return;
var color = hotkeyBG.color;
color.a = visible ? 1f : 0.25f;
hotkeyBG.color = color;
}
void Update() { Redraw(); }
public void Redraw()
{
var selectedProduction = SelectProductionNumberPanel.selectedBuildingProduction;
bool isBuilding = IsBuildingType();
bool isInProductionQueue = selectedProduction.IsUnitOfTypeInQueue(unitDataTemplate);
if (!selectedProduction)
return;
iconImage.sprite = unitDataTemplate.icon;
if (selectedProduction.IsUnitOfTypeCurrentlyBuilding(unitDataTemplate))
fillImage.fillAmount = 1f - selectedProduction.GetBuildProgressPercents();
else if ((isBuilding && isInProductionQueue) || (!isBuilding && isInProductionQueue))
fillImage.fillAmount = 1f;
else
fillImage.fillAmount = 0f;
int unitsCount = selectedProduction.GetUnitsOfSpecificTypeInQueue(unitDataTemplate);
countText.text = unitsCount > 0 ? unitsCount.ToString() : "";
if (isBuilding && IsAnyBuildingInQueue(selectedProduction))
SetActive(IsCurrentBuildingInQueue(selectedProduction));
HotkeyDrawMode(InputHandler.hotkeysInputMode == HotkeysInputType.Building);
}
public void SetHotkeyById(int id)
{
if (!GameController.instance.MainStorage.showHotkeysOnUI)
{
hotkeyPanel.SetActive(false);
return;
}
hotkeyText.text = InputHandler.sceneInstance.buildingInputKeys[id].ToString();
}
public void OnPointerClick(PointerEventData eventData)
{
if (eventData.button == PointerEventData.InputButton.Left)
OnClick();
else if (eventData.button == PointerEventData.InputButton.Right)
OnRightClick();
}
public void OnClick()
{
var selectedProduction = SelectProductionNumberPanel.selectedBuildingProduction;
if (!selectedProduction)
return;
if (IsBuildingType())
{
bool isBuildingReady = IsCurrentBuildingInQueue(selectedProduction) && selectedProduction.IsBuildingReady();
if (IsAnyBuildingInQueue(selectedProduction))
{
if (isBuildingReady)
GameController.instance.build.EnableBuildMode(unitDataTemplate.selfPrefab, () =>
{
selectedProduction.FinishBuilding();
selfProductionIconsPanel.Redraw();
});
return;
}
}
selectedProduction.AddUnitToQueue(unitDataTemplate);
}
void OnRightClick()
{
var selectedProduction = SelectProductionNumberPanel.selectedBuildingProduction;
if (!selectedProduction)
return;
selectedProduction.RemoveUnitFromQueue(unitDataTemplate, true);
selfProductionIconsPanel.Redraw();
}
bool IsAnyBuildingInQueue(Production production) { return production.unitsQueue.Count > 0; }
bool IsCurrentBuildingInQueue(Production production)
{
return production.unitsQueue.Count > 0 && production.unitsQueue[0] == unitDataTemplate;
}
bool IsBuildingType()
{
return SelectProductionTypePanel.selectedProductionCategory.isBuildings;
}
public void SetActive(bool value) { button.interactable = value; }
public void SetupWithUnitData(ProductionIconsPanel selfPanel, UnitData unitData)
{
selfProductionIconsPanel = selfPanel;
unitDataTemplate = unitData;
Redraw();
}
public void OnPointerEnter(PointerEventData pointerEventData)
{
UIController.instance.productionHint.Show(unitDataTemplate, rectTransform.position + new Vector3(0, rectTransform.sizeDelta.y / 2f + 10));
}
public void OnPointerExit(PointerEventData pointerEventData)
{
UIController.instance.productionHint.Hide();
}
}
UI Toolkit: Если в проекте используется UI Toolkit, проверьте, что он корректно настроен и подключен.
5. Проверьте использование using UnityEngine.UI
Убедитесь, что в каждом файле, где используются Button, Text, Image, добавлены директивы:
csharp
using UnityEngine.UI;
6. Пересоберите проект
После внесения изменений:
Закройте Unity.
Удалите папку Library в проекте.
Перезапустите Unity. Unity автоматически пересоберет проект и восстановит зависимости.
7. Проверьте настройки UI-компонентов
Если ошибки остаются:
Убедитесь, что в сцене присутствуют UI-компоненты (например, Canvas, Button, Image, Text).
Проверьте, что они правильно привязаны к скриптам через инспектор (например, repairButton, sellButton в ControlsButtons.cs).
Пример исправления кода
В файле ProductionTypeButton.cs удалите дублированный класс:
csharp
// Удалите этот блок
public class ProductionTypeButton : MonoBehaviour
{
// ... (повторяющийся код)
}
Оставьте только один класс:
csharp
public class ProductionTypeButton : MonoBehaviour
{
// ... (основной код)
}
Итог
Следуя этим шагам, вы должны устранить ошибки компиляции. Основная проблема — отсутствие поддержки UnityEngine.UI в Unity 6.1 и дублирование кода. После исправления зависимостей и структуры проекта ошибки должны исчезнуть. Если проблема сохраняется, уточните, какие именно пакеты используются в проекте, чтобы дать более точные рекомендации.