Мои игровые объекты продолжают удаляться после размещения на тарелке «Кухонный объект», а не что-либо еще, и это, вероятно, связано с тем, что я внедрил в свой код новую вещь, позволяющую определять, какой «Кухонный объект» находится на тарелке.
/>
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlateCompleteVisual : MonoBehaviour
{
[Serializable]
public struct KitchenObjectSO_GameObject
{
public KitchenObjectSO kitchenObjectSO;
public GameObject gameObject;
}
[SerializeField] private PlateKitchenObject plateKitchenObject;
public List kitchenObjectSOGameObjectList;
private void Start()
{
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using static KitchenObjectType;
using static PlateCompleteVisual;
public class KitchenObject : MonoBehaviour
{
public enum ObjectType
{
Bread,
Lettuce,
Cheese,
Tomato,
// Add more types as needed
}
public static void IdentifyKitchenObject(ObjectType objectType)
{
switch (objectType)
{
case ObjectType.Bread:
Debug.Log("Found bread!");
// Handle bread-specific logic
break;
case ObjectType.Lettuce:
Debug.Log("Found lettuce!");
// Handle lettuce-specific logic
break;
case ObjectType.Cheese:
Debug.Log("Found cheese!");
// Handle cheese-specific logic
break;
case ObjectType.Tomato:
Debug.Log("Found tomato!");
// Handle tomato-specific logic
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);
if (KitchenObjectParent.HasKitchenObject())
{
Debug.LogError("IKitchenObjectParent already has a kitchen object");
}
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;
}
public void CheckForLettuceWithoutOther()
{
// Assuming PlateCompleteVisual is attached to a GameObject in the scene
PlateCompleteVisual plateCompleteVisual = FindObjectOfType
();
if (plateCompleteVisual != null)
{
foreach (PlateCompleteVisual.KitchenObjectSO_GameObject kitchenObjectSOGameObject in plateCompleteVisual.kitchenObjectSOGameObjectList)
{
// Perform necessary logic here
}
}
}
[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 void PlateKitchenObject_OnIngredientAdded(object sender, PlateKitchenObject.OnIngredientAddedEventArgs e)
{
foreach (KitchenObjectSO_GameObject kitchenObjectSOGameObject in kitchenObjectSOGameObjectList)
{
if (kitchenObjectSOGameObject.kitchenObjectSO == e.kitchenObjectSO)
{
kitchenObjectSOGameObject.gameObject.SetActive(true);
KitchenObjectType.IdentifyKitchenObject((KitchenObjectSO.ObjectType)(ObjectType)kitchenObjectSOGameObject.kitchenObjectSO.objectType);
}
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KitchenObjectType : MonoBehaviour
{
public enum ObjectType
{
Bread,
Lettuce,
Cheese,
Tomato,
// Add more types as needed
}
public static void IdentifyKitchenObject(ObjectType objectType)
{
switch (objectType)
{
case ObjectType.Bread:
Debug.Log("Found bread!");
// Handle bread-specific logic
break;
case ObjectType.Lettuce:
Debug.Log("Found lettuce!");
// Handle lettuce-specific logic
break;
case ObjectType.Cheese:
Debug.Log("Found cheese!");
// Handle cheese-specific logic
break;
case ObjectType.Tomato:
Debug.Log("Found tomato!");
// Handle tomato-specific logic
break;
// Add cases for other types as needed
default:
Debug.Log("Unknown kitchen object type!");
break;
}
}
internal static void IdentifyKitchenObject(KitchenObjectSO.ObjectType objectType)
{
throw new NotImplementedException();
}
public static explicit operator KitchenObject.ObjectType(KitchenObjectType v)
{
throw new NotImplementedException();
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlateKitchenObject : KitchenObject
{
public event EventHandler OnIngredientAdded;
public class OnIngredientAddedEventArgs : EventArgs
{
public KitchenObjectSO kitchenObjectSO;
}
[SerializeField] private List validKitchenObjectList;
private List kitchenObjectSOList;
private void Awake()
{
kitchenObjectSOList = new List();
}
public bool TryAddIngredient(KitchenObjectSO kitchenObjectSO)
{
if (!validKitchenObjectList.Contains(kitchenObjectSO))
{
return false;
}
if (kitchenObjectSOList.Contains(kitchenObjectSO))
{
return false;
}
else
{
OnIngredientAdded?.Invoke(this, new OnIngredientAddedEventArgs
{
kitchenObjectSO = kitchenObjectSO
});
kitchenObjectSOList.Add(kitchenObjectSO);
return true;
}
}
}
Я пробовал много разных подходов к этому, но, похоже, не могу понять этого, и, поскольку я новичок в программировании, я решил спросить общественность, спасибо.
Мои игровые объекты продолжают удаляться после размещения на тарелке «Кухонный объект», а не что-либо еще, и это, вероятно, связано с тем, что я внедрил в свой код новую вещь, позволяющую определять, какой «Кухонный объект» находится на тарелке. />[code]using System; using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlateCompleteVisual : MonoBehaviour {
[Serializable] public struct KitchenObjectSO_GameObject { public KitchenObjectSO kitchenObjectSO; public GameObject gameObject; }
[SerializeField] private PlateKitchenObject plateKitchenObject; public List kitchenObjectSOGameObjectList;
private void Start() {
}
}
using System; using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; using static KitchenObjectType; using static PlateCompleteVisual;
public class KitchenObject : MonoBehaviour {
public enum ObjectType { Bread, Lettuce, Cheese, Tomato, // Add more types as needed }
public static void IdentifyKitchenObject(ObjectType objectType) { switch (objectType) { case ObjectType.Bread: Debug.Log("Found bread!"); // Handle bread-specific logic break; case ObjectType.Lettuce: Debug.Log("Found lettuce!"); // Handle lettuce-specific logic break; case ObjectType.Cheese: Debug.Log("Found cheese!"); // Handle cheese-specific logic break; case ObjectType.Tomato: Debug.Log("Found tomato!"); // Handle tomato-specific logic break; // Add cases for other types as needed default: Debug.Log("Unknown kitchen object type!"); break; } }
public void CheckForLettuceWithoutOther() { // Assuming PlateCompleteVisual is attached to a GameObject in the scene PlateCompleteVisual plateCompleteVisual = FindObjectOfType ();
if (plateCompleteVisual != null) { foreach (PlateCompleteVisual.KitchenObjectSO_GameObject kitchenObjectSOGameObject in plateCompleteVisual.kitchenObjectSOGameObjectList) { // Perform necessary logic here } } }
[Serializable] public struct KitchenObjectSO_GameObject { public KitchenObjectSO kitchenObjectSO; public GameObject gameObject; }
[SerializeField] private PlateKitchenObject plateKitchenObject; [SerializeField] private List kitchenObjectSOGameObjectList;
using System; using System.Collections; using System.Collections.Generic; using UnityEngine;
public class KitchenObjectType : MonoBehaviour { public enum ObjectType { Bread, Lettuce, Cheese, Tomato, // Add more types as needed }
public static void IdentifyKitchenObject(ObjectType objectType) { switch (objectType) { case ObjectType.Bread: Debug.Log("Found bread!"); // Handle bread-specific logic break; case ObjectType.Lettuce: Debug.Log("Found lettuce!"); // Handle lettuce-specific logic break; case ObjectType.Cheese: Debug.Log("Found cheese!"); // Handle cheese-specific logic break; case ObjectType.Tomato: Debug.Log("Found tomato!"); // Handle tomato-specific logic break; // Add cases for other types as needed default: Debug.Log("Unknown kitchen object type!"); break; } }
internal static void IdentifyKitchenObject(KitchenObjectSO.ObjectType objectType) { throw new NotImplementedException(); }
public static explicit operator KitchenObject.ObjectType(KitchenObjectType v) { throw new NotImplementedException(); } }
using System; using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlateKitchenObject : KitchenObject {
public event EventHandler OnIngredientAdded;
public class OnIngredientAddedEventArgs : EventArgs { public KitchenObjectSO kitchenObjectSO; }
[SerializeField] private List validKitchenObjectList; private List kitchenObjectSOList;
private void Awake() { kitchenObjectSOList = new List(); }
public bool TryAddIngredient(KitchenObjectSO kitchenObjectSO) { if (!validKitchenObjectList.Contains(kitchenObjectSO)) { return false; } if (kitchenObjectSOList.Contains(kitchenObjectSO)) { return false; } else {
OnIngredientAdded?.Invoke(this, new OnIngredientAddedEventArgs { kitchenObjectSO = kitchenObjectSO }); kitchenObjectSOList.Add(kitchenObjectSO);
return true; } }
}
[/code] Я пробовал много разных подходов к этому, но, похоже, не могу понять этого, и, поскольку я новичок в программировании, я решил спросить общественность, спасибо.
мне нужно поместить изображение в нижнюю часть последней страницы PDF (но выше счетчика страницы, которая находится в поле правой нижней страницы).
@page {
size: A4 landscape;
margin: 20mm 10mm 20mm 20mm;
@bottom-right {
content:...
Начинающий разработчик C# в Unity, работаю с Oculus 2. Я экспериментирую с функциями отслеживания рук Unity XR. Пока что я могу схватить объект руками, масштабировать его, повернуть и отпустить. Теперь у меня есть родительский игровой объект...
В моей игре есть система инвентаря, которая активируется при нажатии кнопки. Я сделал игровые объекты системы инвентаря DontDestroyOnLoad при переключении между сценами. Когда игрок возвращается в главное меню, игровые объекты становятся...
Я пытаюсь отложить создание моего префаба, и я пытался сделать это с помощью сопрограмм. В режиме воспроизведения сначала происходило появление, а затем отображалось сообщение отладки, показывающее, что прошло 2 секунды. Итак, я пришел к выводу, что...