[ad_1]
I’m utilizing C# in a Unity challenge and am attempting to know whether it is attainable and the way to lengthen courses in order that I can implement my very own customized code with out modifying the inventory courses – which is able to enable me to simply replace the inventory code base sooner or later.
This is an instance – right here is an easy illustration of the inventory code:
public summary class StockClassA : StockClassX
{
public int MethodIWantToOverride()
{
return 0;
}
}
// THIS IS A COMPONENT PLACED IN A UNITY OBJECT AND ITS METHODS CALLED
// BY OTHER COMPONENTS (these different parts have a saved reference to this)
[Serializable]
...
public class StockClassB : StockClassA
{
// ... varied public strategies ... (I'll wish to override a few of these as nicely)
}
In inventory type, varied parts in unity makes use of the reference to StockClassB and name the MethodIWantToOverride() – as in :
StockClassB.MethodIWantToOverride();
The downside is that if I lengthen StockClassB, add my substitute methodology and replace all of the references within the unity parts to my new class, my new methodology by no means will get referred to as.
Example of my code:
// my class needs to be of kind StockClassB as a result of different courses
// are on the lookout for that kind (and I dont wish to change the sort
// as a result of that will require altering the inventory code in these parts)
public class MYStockClassB : StockClassB
{
public new int MethodIWantToOverride()
{
return 1;
}
}
[ad_2]