Почему перечисление всегда находится в том состоянии, в котором перечисление указано первым?C#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Почему перечисление всегда находится в том состоянии, в котором перечисление указано первым?

Сообщение Anonymous »

Я предоставлю вам код расположения перечисления.

Код: Выделить всё

using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using static KitchenObjectType;
using static PlateCompleteVisual;

public class KitchenObject : MonoBehaviour
{
private void OnDestroy()
{
Debug.LogError("I was just destroyed! ");
}

[Serializable]
public enum ObjectType
{

Lettuce,
Bread,
Cheese,
Tomato,
// Add more types as needed
}

public ObjectType objectTypes;
public void IdentifyKitchenObject(ObjectType objectType)
{
switch (objectType)
{

case ObjectType.Lettuce:
Debug.Log("Found lettuce!");
// Handle lettuce-specific logic
break;
case ObjectType.Bread:
Debug.Log("Found bread!");
// Handle bread-specific logic
break;
case ObjectType.Cheese:
Debug.Log("Found cheese!");
// Handle cheese-specific logic
break;
case ObjectType.Tomato:
Debug.Log("Found tomato!");
break;
// Add cases for other types as needed
default:
Debug.Log("Unknown kitchen object type!");
break;
}
}

[SerializeField] KitchenObjectSO kitchenObjectSO;
private IKitchenObjectParent kitchenObjectParent;

public KitchenObjectSO GetKitchenObjectSO()
{
return kitchenObjectSO;
}

public void SetKitchenObjectParent(IKitchenObjectParent KitchenObjectParent)
{
if (this.kitchenObjectParent != null)
{
this.kitchenObjectParent.ClearKitchenObject();
}

this.kitchenObjectParent = KitchenObjectParent;
KitchenObjectParent.SetKitchenObject(this);

transform.parent = KitchenObjectParent.GetKitchenObjectFollowTransform();
transform.localPosition = Vector3.zero;
}
public IKitchenObjectParent GetKitchenObjectParent()
{
return kitchenObjectParent;
}

public void DestroySelf()
{
kitchenObjectParent.ClearKitchenObject();
Destroy(gameObject);
}

public bool TryGetPlate(out PlateKitchenObject plateKitchenObject)
{
if (this is PlateKitchenObject)
{
plateKitchenObject = this as PlateKitchenObject;
return true;
}else
{
plateKitchenObject = null;
return false;
}

}

public static KitchenObject SpawnKitchenObject(KitchenObjectSO kitchenObjectSO, IKitchenObjectParent kitchenObjectParent)
{
Transform kitchenObjectTransform = Instantiate(kitchenObjectSO.prefab);

if (kitchenObjectTransform == null)
{
Debug.LogError("Failed to instantiate kitchen object from prefab: " + kitchenObjectSO.prefab.name);
return null;
}
KitchenObject kitchenObject = kitchenObjectTransform.GetComponent();

if (kitchenObject == null)
{
Debug.LogWarning("KitchenObject component not found on instantiated object.  Adding the component...");

// If KitchenObject component is not present, add it
kitchenObject = kitchenObjectTransform.gameObject.AddComponent();
}

kitchenObject.SetKitchenObjectParent(kitchenObjectParent);
return kitchenObject;
}

[Serializable]
public struct KitchenObjectSO_GameObject
{
public KitchenObjectSO kitchenObjectSO;
public GameObject gameObject;
}

[SerializeField] private PlateKitchenObject plateKitchenObject;
[SerializeField] private List kitchenObjectSOGameObjectList;

private void Start()
{
plateKitchenObject.OnIngredientAdded += PlateKitchenObject_OnIngredientAdded;

}

private KitchenObject kitchenObject;
private void PlateKitchenObject_OnIngredientAdded(object sender, PlateKitchenObject.OnIngredientAddedEventArgs e)
{
IdentifyKitchenObject(objectTypes);
}

}

Таким образом, перечисление типа объекта, кажется, всегда переводит его в состояние того, что указано первым. Я пробовал менять местами, и кажется, что оно всегда первое. Кстати, я присваиваю переменную objectTypes в редакторе. Спасибо.
Я попробовал проверить Интернет по причинам, потому что, честно говоря, я ничего не знаю и очень новичок в программировании, очевидно, это не сработало.

Подробнее здесь: https://stackoverflow.com/questions/781 ... sted-first
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»