Hi! I have encounter an issue where I cannot view the SerializeFields that I need in the inspector.
I have a super class named public class Role : MonoBehaviour and a child inheritor public class Character : Role, ICharacter.
I have another child class named public class Player : Character.
I am trying to see Character : Role, ICharacter’s SerializedFields in the inspector but simply cannot.
I checked and if I replace public class Character : Role, ICharacter to public class Character : MonoBehaviour, ICharacter it works just fine.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum CharacterType { Player, NPC }
public enum Roles { Warrior, Defender, Enchanter, Rogue }
public class Role : MonoBehaviour
{
[SerializeField] internal CharacterType _characterType;
public CharacterType DefinedCharacterType { get => _characterType; set => _ = value; }
[SerializeField] internal Roles _role;
public Roles DefinedRole { get => _role; set => _ = value; }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class Character : Role, ICharacter
{
private delegate void State();
private State _state;
private PlayerControls _playerControls;
private InputAction _interact;
[SerializeField] private CharacterData _data;
public CharacterData Data => _data;
[SerializeField] private GameObject _lastGameObjectClickedOn;
[SerializeField] private bool _startCombat = false, _finishedCombat = false, _startWaiting = false, _finishedWaiting = false, _startAttacking = false,
_finishedAttacking = false, _startResolving = false, _finishedResolving = false, _isAlive = true;
public GameObject LastGameObjectClickedOn => _lastGameObjectClickedOn;
public bool IsAlive { get => _isAlive; set => _ = value; }
private Camera _camera;
private Mouse _cursor;
private Vector2 _cursorPos;
#region MonoBehaviour Callbacks
private void Awake()
{
this.Initialize();
}
private void OnEnable()
{
if (_characterType == CharacterType.Player)
{
_interact.Enable();
_interact.performed += Interact;
}
}
private void Update()
{
if (_characterType == CharacterType.Player)
{
_cursorPos = _cursor.position.ReadValue();
}
_state.Invoke();
Debug.Log($"Current player state: {_state.Method.Name}");
}
private void OnDisable()
{
if (_characterType == CharacterType.Player)
{
_interact.Disable();
}
}
#endregion
#region States
private void OutsideOfCombat() // while situation where combat do not take place
{
// happens before the loop of the first frame where the condition is met
if (_finishedCombat)
_state = Waiting;
// ---------------------------------------------------------------------
// happens after the loop of the first frame where the condition is met
if (_startCombat)
_startCombat = false;
}
private void Waiting() // while waiting for this character's turn
{
// happens before the loop of the first frame where the condition is met
if (_finishedCombat)
_state = OutsideOfCombat;
if (_finishedWaiting)
_state = Attacking;
// ---------------------------------------------------------------------
// happens after the loop of the first frame where the condition is met
if (_startWaiting)
_startWaiting = false;
}
private void Attacking() // while this character's attacks
{
// happens before the loop of the first frame where the condition is met
if (_finishedCombat)
_state = OutsideOfCombat;
if (_finishedAttacking)
_state = Waiting;
// ---------------------------------------------------------------------
// happens after the loop of the first frame where the condition is met
if (_startAttacking)
_startAttacking = false;
}
private void Resolving() // after this character's has being attacked
{
// happens before the loop of the first frame where the condition is met
if (_data.CurrentHealth <= 0)
Die();
if (_finishedCombat)
_state = OutsideOfCombat;
if (_finishedResolving)
_state = Waiting;
// ---------------------------------------------------------------------
// happens after the loop of the first frame where the condition is met
if (_startResolving)
_startResolving = false;
}
#endregion
private void Initialize()
{
if (_characterType == CharacterType.Player)
{
_playerControls = new PlayerControls();
_camera = Camera.main;
_cursor = Mouse.current;
_interact = _playerControls.Player.Interact;
}
_state = OutsideOfCombat;
}
public void Interact(InputAction.CallbackContext interactContext)
{
if (_characterType != CharacterType.Player)
return;
Ray ray = _camera.ScreenPointToRay(_cursorPos);
RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);
if (hit.collider)
_lastGameObjectClickedOn = hit.collider.gameObject;
else
_lastGameObjectClickedOn = null;
}
#region ICharacter
public void OpenSkillMenu()
{
// open skill menu
}
public void Attack()
{
// attack
}
public void Die()
{
// die
}
#endregion
#region overrides
public override string ToString()
{
return $"Name: {_data.name}, Role: {_role}, Lvl: {_data.CurrentLevel}";
}
public override bool Equals(object other)
{
return base.Equals(other);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
#endregion
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : Character
{
}