public class Entity : MonoBehaviour
{
[SerializeField] private EntityScriptableObject _scriptableObject;
public EntityScriptableObject ScriptableObject => _scriptableObject;
}
public class Document : Entity
{
[SerializeField] private DocumentScriptableObject _scriptableObject;
public new DocumentScriptableObject ScriptableObject => _scriptableObject;
}
Теперь из-за того что поле базового класса также сериализуется - в инспекторе появляются оба поля из базового класса и из класса компонента.
public class EntityScriptableObject : ScriptableObject
{
[SerializeField] private EntityType _type;
[SerializeField] private string _name;
[SerializeField] private string _raycastFeedbackText;
[SerializeField] private GameObject _prefab;
public EntityType Type => _type;
public string Name => _name;
public string RaycastFeedbackText => _raycastFeedbackText;
public GameObject Prefab => _prefab;
}
public class ItemScriptableObject : ScriptableObject
{
[SerializeField] private ItemType _type;
[SerializeField] private string _description;
[SerializeField] private string _raycastFeedbackText;
[SerializeField] private Sprite _sprite;
public ItemType Type => _type;
public string Description => _description;
public string RaycastFeedbackText => _raycastFeedbackText;
public Sprite Sprite => _sprite;
}
public class DocumentScriptableObject : ScriptableObject
{
[SerializeField] private DocumentType _type;
[SerializeField] private string _text;
[SerializeField] private string _raycastFeedbackText;
public DocumentType Type => _type;
public string Text => _text;
public string RaycastFeedbackText => _raycastFeedbackText;
}
public class Entity : MonoBehaviour
{
[SerializeField] private EntityScriptableObject _entityScriptableObject;
public EntityScriptableObject EntityScriptableObject => _entityScriptableObject;
public virtual void Interact(){}
public void StopInteraction(){}
}
public class Item : Entity
{
[SerializeField] private ItemScriptableObject _itemScriptableObject;
public ItemScriptableObject ItemScriptableObject => _itemScriptableObject;
public Item (ItemScriptableObject scriptableObject)
{
_itemScriptableObject = scriptableObject;
}
public void Use(){}
public override void Interact(){}
}
public class Document : Entity
{
[SerializeField] private DocumentScriptableObject _documentScriptableObject;
public DocumentScriptableObject DocumentScriptableObject => _documentScriptableObject;
public void Read(){}
public override void Interact(){}
}
public class Entity : MonoBehaviour
{
[SerializeField] private EntityScriptableObject _scriptableObject;
public EntityScriptableObject ScriptableObject => _scriptableObject;
}
[SerializeField] private EntityScriptableObject _scriptableObject;
public EntityScriptableObject ScriptableObject => _scriptableObject;
И вам же четко пишет, что у вас два поля с одинаковыми именами. Вот:
[SerializeField] private EntityScriptableObject _scriptableObject;
И вот:
public EntityScriptableObject ScriptableObject => _scriptableObject;
[SerializeField] private EntityScriptableObject _scriptableObject;
[SerializeField] private DocumentScriptableObject _scriptableObject;
public class Entity : MonoBehaviour
{
[field: SerializeField]
public virtual EntityScriptableObject ScriptableObject
{
get;
private set;
}
public void Interact()
{
Transform interactionPoint;
switch (ScriptableObject.Type)
{
case EntityType.Key:
Player.Inventory.Add(this as Item);
Destroy(gameObject);
break;
case EntityType.VideoTape:
Player.Inventory.Add(this as Item);
Destroy(gameObject);
break;
case EntityType.Note:
Player.Journal.Add(this as Document);
Destroy(gameObject);
break;
case EntityType.Painting:
GameManager.ChangeTypeOfControll(TypesOfControl.InspectionControll);
ObjectInspectorController.Instance.enabled = true;
ObjectInspectorController.Instance.Initialize(this);
break;
case EntityType.TV:
GameManager.PauseGame();
interactionPoint = InteractionPoints.Instance.TV.transform;
InteractionController.Instance.InteractionPoint = interactionPoint;
InteractionController.Instance.CurrentInteraction = InteractionType.TV;
InteractionController.Instance.MoveToInteractionPoint();
InteractionController.Instance.OnStopInteraction += StopInteraction;
UIController.Instance.OpenInventory();
PlayerController.Instance.enabled = false;
break;
case EntityType.Door:
DoorController door = gameObject.GetComponent<DoorController>();
if (door.IsOpen)
door.CloseDoor();
else
door.OpenDoor();
break;
case EntityType.SafeDigital:
GameManager.PauseGame();
GameManager.ChangeTypeOfControll(TypesOfControl.InteractionControl);
interactionPoint = InteractionPoints.Instance.SafeDigital.transform;
InteractionController.Instance.InteractionPoint = interactionPoint;
InteractionController.Instance.CurrentInteraction = InteractionType.SafeNumeric;
InteractionController.Instance.MoveToInteractionPoint();
InteractionController.Instance.OnStopInteraction += StopInteraction;
PlayerController.Instance.enabled = false;
CameraController.Instance.enabled = false;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
gameObject.GetComponentInChildren<SafeDoor>().enabled = true;
break;
case EntityType.SafePadlock:
GameManager.PauseGame();
GameManager.ChangeTypeOfControll(TypesOfControl.InteractionControl);
interactionPoint = InteractionPoints.Instance.SafePadlock.transform;
InteractionController.Instance.InteractionPoint = interactionPoint;
InteractionController.Instance.CurrentInteraction = InteractionType.SafePadlock;
InteractionController.Instance.MoveToInteractionPoint();
InteractionController.Instance.OnStopInteraction += StopInteraction;
PlayerController.Instance.enabled = false;
CameraController.Instance.enabled = false;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
gameObject.GetComponentInChildren<Padlock>().enabled = true;
break;
default:
break;
}
}
public void StopInteraction()
{
switch (ScriptableObject.Type)
{
case EntityType.Key:
break;
case EntityType.VideoTape:
break;
case EntityType.Note:
break;
case EntityType.Painting:
break;
case EntityType.TV:
InteractionController.Instance.OnStopInteraction -= StopInteraction;
InteractionController.Instance.ReturnToInteractionPosition();
InteractionController.Instance.CurrentInteraction = InteractionType.None;
GameManager.ResumeGame();
break;
case EntityType.Door:
break;
case EntityType.SafeDigital:
gameObject.GetComponentInChildren<SafeDoor>().enabled = false;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
PlayerController.Instance.enabled = true;
CameraController.Instance.enabled = true;
InteractionController.Instance.OnStopInteraction -= StopInteraction;
InteractionController.Instance.CurrentInteraction = InteractionType.None;
InteractionController.Instance.ReturnToInteractionPosition();
GameManager.ChangeTypeOfControll(TypesOfControl.PlayerControl);
GameManager.ResumeGame();
break;
case EntityType.SafePadlock:
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
PlayerController.Instance.enabled = true;
CameraController.Instance.enabled = true;
InteractionController.Instance.OnStopInteraction -= StopInteraction;
InteractionController.Instance.CurrentInteraction = InteractionType.None;
InteractionController.Instance.ReturnToInteractionPosition();
GameManager.ChangeTypeOfControll(TypesOfControl.PlayerControl);
GameManager.ResumeGame();
break;
default:
break;
}
}
}
public class Item : Entity
{
[SerializeField] private ItemScriptableObject _scriptableObject;
public override EntityScriptableObject ScriptableObject => _scriptableObject;
public void Use()
{
switch (_scriptableObject.Type)
{
case EntityType.Key:
Player.Inventory.Remove(this);
Debug.Log("Key used.");
break;
case EntityType.VideoTape:
if (InteractionController.Instance.CurrentInteraction != InteractionType.TV)
return;
Player.Inventory.Remove(this);
Debug.Log("Tape inserted.");
break;
case EntityType.Note:
break;
case EntityType.Painting:
break;
case EntityType.TV:
break;
case EntityType.Door:
break;
case EntityType.SafeDigital:
break;
case EntityType.SafePadlock:
break;
default:
break;
}
}
}
public class Document : Entity
{
[SerializeField] private DocumentScriptableObject _scriptableObject;
public override EntityScriptableObject ScriptableObject => _scriptableObject;
public void Read()
{
switch (ScriptableObject.Type)
{
case EntityType.Key:
break;
case EntityType.VideoTape:
break;
case EntityType.Note:
DocumentInspectorController.Instance.enabled = true;
DocumentInspectorController.Instance.Initialize(_scriptableObject.Text);
break;
case EntityType.Painting:
break;
case EntityType.TV:
break;
case EntityType.Door:
break;
case EntityType.SafeDigital:
break;
case EntityType.SafePadlock:
break;
default:
break;
}
}
}
public class EntityScriptableObject : ScriptableObject
{
[SerializeField] private EntityType _type;
[SerializeField] private string _displayName;
[SerializeField] private string _description;
[SerializeField] private string _raycastFeedbackText;
[SerializeField] private GameObject _prefab;
public EntityType Type => _type;
public string DisplayName => _displayName;
public string Description => _description;
public string RaycastFeedbackText => _raycastFeedbackText;
public GameObject Prefab => _prefab;
}
public class ItemScriptableObject : EntityScriptableObject
{
[SerializeField] private Sprite _sprite;
public Sprite Sprite => _sprite;
}
public class DocumentScriptableObject : EntityScriptableObject
{
[SerializeField] private string _text;
public string Text => _text;
}
[SerializeField]
с одним именем для родителя и потомка, еще более сомнительно. если сериализуете, то как десериализуете? в конкретный тип? или в object? или есть автоопределение?постараюсь объяснить логику которую задумал :)ок. благие намерения в целом все более понятны..
Вместо класса, вероятно, тебе нужно использовать интерфейс в котором будет обобщённое свойство для ScriptableObjectот Василий Банников, скорее ближе к решению.. но
во что сериализуете? json/bson/bd?не снимется..