- Home /
Duplicate Question
Showing properties from a base class in inspector?
Trying to show properties in the inspector of a base class on the child class of mine that I am making. So far The only things I can get to show are the private variables in the base class. I can see them if I enter debug on the inspector which is ok but not really what I am going for. Still new to this and have been searching for hours on google and the like trying to find an answer. Tried making a custom editor but I could not get that to work and I haven't messed around with the editor too much. Here is the code for the base class, just property declaration and constructors. The only items that pop up in inspector are Recharge delay flag and Reactivation counter.
using UnityEngine;
using System.Collections;
using System.IO;
[System.Serializable]
public abstract class ShipComponent : MonoBehaviour
{
[SerializeField]
public virtual int compHP {get;private set;} //current component hit points
protected int compEnergyRechargeRate {get;private set;} //set var on how fast this component recharges
public int compEnergy{get;private set;} //duh
protected string compName {get;private set;} //whats a name anyways??
protected bool isDestroyed {get;private set;} //is this a useable component, or destroyed
protected bool canUse {get;private set;} // is this an activatable component
protected bool isShielded {get;private set;}//do we need to mitigate for shield damage or is this an unshielded component like a missile. Are shields on as well
[SerializeField]
protected string ownerName {get; private set;} //who does this belong to, useful so i can find a certain players component without getting every component in game.
[SerializeField]
protected abstract bool isRepairable {get;}//will this fix itself over time
[SerializeField]
protected abstract int maxHP {get;}
[SerializeField]protected abstract int maxEnergy{get;}
[SerializeField]
protected abstract int compEnergyOnUse {get;} //how much energy this comp uses per activation
[SerializeField]
protected abstract int compEnergyContinuous {get;}// how much energy used after activated and continuously held down, useful for active shielding
[SerializeField]
private bool rechargeDelayFlag;
protected float reactivationDelay {get;private set;}
[SerializeField]
private float reactivationCounter;
protected ShipComponent(int compEnergyRechargeRate, bool canUse,string ownerName, float reactivationDelay)
{
this.compHP = this.maxHP;
this.compEnergyRechargeRate = compEnergyRechargeRate;
this.compEnergy = this.maxEnergy;
this.isDestroyed = false;
this.canUse = canUse;
this.isShielded = false;
this.ownerName = ownerName;
this.rechargeDelayFlag = false;
this.reactivationDelay = reactivationDelay;
}
here is the code for the child class:
using UnityEngine;
using System.Collections;
[System.Serializable]
public class EngineScript : ShipComponent {
public EngineScript() : base(0,true,"Roger",1.0f){}//contructor
#region implemented abstract members of ShipComponent
[SerializeField]
protected override bool isRepairable
{get {return true;}}
[SerializeField]
protected override int maxHP
{get {return 100;}}
[SerializeField]
protected override int maxEnergy
{get {return 100;}}
[SerializeField]protected override int compEnergyOnUse
{get {return 0;}}
protected override int compEnergyContinuous
{get { return 0;}}
#endregion
I know it is a bit messy but been messing with it to try and figure it out but not having much luck. Anyone able to point me to my error?
hmm link didn't work but yes, my googlefu is not working on this question but ill see what I can find in the Wiki. TYV$$anonymous$$
Ah yep believe this is what I was looking for. Guess I just have to figure out how to make editor scripts work. TYVm much better example then what I found.
Follow this Question
Related Questions
If I have a bool method, how can I see in the inspector whether it returns true or false? 2 Answers
Custom Inspector. Aligning properties? 1 Answer
Populating list of custom class through inspector 1 Answer
Why can't a MonoBehaviour subtype with generic arguments be serialized in a list since Unity 4.5? 0 Answers
Saving editor-only variables 0 Answers