Shimizoki
Shimizoki
CC#
Created by Shimizoki on 2/8/2023 in #help
❔ [Unity?] How to have a list of generic classes in inspector cast as derived class
Ah wait... I think I am seeing where you are going
78 replies
CC#
Created by Shimizoki on 2/8/2023 in #help
❔ [Unity?] How to have a list of generic classes in inspector cast as derived class
I still don't see how that helps me get a list of all the types
78 replies
CC#
Created by Shimizoki on 2/8/2023 in #help
❔ [Unity?] How to have a list of generic classes in inspector cast as derived class
So rather than having a base : derived... I have a base<T> and the T is my fake derived?
78 replies
CC#
Created by Shimizoki on 2/8/2023 in #help
❔ [Unity?] How to have a list of generic classes in inspector cast as derived class
The thing that I'm working on is about to go down that nasty rabbit hole of having 50 of the exact same item, with no changes between any of them except for the types. Each of these items has a boilerplate copy and paste, and then in half a dozen places scattered around the code base needs to have the exact same chunk of code copied and then the names changed for this item. My goal is to prevent that. Maybe my starting premise was wrong to begin with
78 replies
CC#
Created by Shimizoki on 2/8/2023 in #help
❔ [Unity?] How to have a list of generic classes in inspector cast as derived class
I am absolutely happy to change as many things as necessary here. I even have some ability to change the actual functionality of the class. Maybe I can find a way to not use that add function at all. I'm just really looking for a way that I can have all of these different objects in an enumerable of some kind
78 replies
CC#
Created by Shimizoki on 2/8/2023 in #help
❔ [Unity?] How to have a list of generic classes in inspector cast as derived class
If I were to use an IReadOnlyCollection<U> I am able to use out U in ITrackedMarkers<out T, out U>. But I get the same runtime invalid cast exception.
78 replies
CC#
Created by Shimizoki on 2/8/2023 in #help
❔ [Unity?] How to have a list of generic classes in inspector cast as derived class
that is because U when set as a read only collection seems to state that it needs to be invariant, I could not find a way to set it to out
78 replies
CC#
Created by Shimizoki on 2/8/2023 in #help
❔ [Unity?] How to have a list of generic classes in inspector cast as derived class
i am not sure I am following. I was under the impression that co/contravariance worked in exactly that fashion.
78 replies
CC#
Created by Shimizoki on 2/8/2023 in #help
❔ [Unity?] How to have a list of generic classes in inspector cast as derived class
I saw warnings about nullability, but perhaps I am misunderstanding the error there.
78 replies
CC#
Created by Shimizoki on 2/8/2023 in #help
❔ [Unity?] How to have a list of generic classes in inspector cast as derived class
I added out to both T and U, but the same runtime exception exists
78 replies
CC#
Created by Shimizoki on 2/8/2023 in #help
❔ [Unity?] How to have a list of generic classes in inspector cast as derived class
out does not work with the Add(U u) function which takes a U as a parameter. That's why they removed it
78 replies
CC#
Created by Shimizoki on 2/8/2023 in #help
❔ [Unity?] How to have a list of generic classes in inspector cast as derived class
As a note, I set the first element in the list (in editor) to be of the correct type
78 replies
CC#
Created by Shimizoki on 2/8/2023 in #help
❔ [Unity?] How to have a list of generic classes in inspector cast as derived class
You all were able to help me get it back to compiling... which is great! But, runtime casts are still no good.
class Program
{
[SerializeField] List<TrackedMarkers<MarkerScriptable, MarkerInterface>> _trackerList;

void Start() {
var casted = (ITrackedMarkers<Scriptable1, Marker1>)_trackerList[0];
// InvalidCastException: Specified cast is not valid.
}
}
class Program
{
[SerializeField] List<TrackedMarkers<MarkerScriptable, MarkerInterface>> _trackerList;

void Start() {
var casted = (ITrackedMarkers<Scriptable1, Marker1>)_trackerList[0];
// InvalidCastException: Specified cast is not valid.
}
}
78 replies
CC#
Created by Shimizoki on 2/8/2023 in #help
❔ [Unity?] How to have a list of generic classes in inspector cast as derived class
then pass the _tag by ref?
78 replies
CC#
Created by Shimizoki on 2/8/2023 in #help
❔ [Unity?] How to have a list of generic classes in inspector cast as derived class
public string tag { get => this._tag; set => this._tag = value; }
private string _tag;
public string tag { get => this._tag; set => this._tag = value; }
private string _tag;
Something like this?
78 replies
CC#
Created by Shimizoki on 2/8/2023 in #help
❔ [Unity?] How to have a list of generic classes in inspector cast as derived class
Have an example? a quick google does not show me much. I am not used to using properties since they don't play super nice with unity
78 replies