I wrote several relatively simple custom classes for my sample project (a clone of the Ticket to Ride board game) and marked them all Serializable to check their values as I go. The first few classes displayed their values just fine, but the next batch of classes did not.
The Board class displays contents of the City (not uploaded), TrackPath, (not uploaded) TrackSinglePath (not uploaded), and TrackBrick classes just fine without writing any custom editor code or anything, but then TrainCardDeck, comprised of TrainCard classes isn’t displaying the same way.
I’m not sure what the difference in what I did is, especially if the solution ends up being that I need to customize the editor, because it’s weird that I should have to do that for some of my classes but not all, right?
[If you need to see the three classes I didn’t upload, let me know. I could only upload 5 attachments here.]
Some of the calling code in my main game script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameMain : MonoBehaviour
{
...
TrackBrick[] usaSinglePathAtlantaCharleston, usaSinglePathAtlantaMiami, usaSinglePathAtlantaNashville, ... ;
TrackSinglePath[] usaPathAtlantaCharleston, usaPathAtlantaMiami, usaPathAtlantaNashville, ... ;
TrackPath[] usaPaths;
...
[SerializeField]
public TrainCardDeck deckTrainCards;
public float BOARD_USA_WIDTH = 935f, BOARD_USA_HEIGHT = 560f;
public Board usa;
void Start()
{
mapSR = GetComponent<SpriteRenderer>();
mapObjectsParent = GameObject.FindGameObjectWithTag("MapObjects").transform;
usaCities = new City[] { new City("Atlanta", 745, 380),
new City("Boston", 910, 95), ... };
#region TrackBrick[] CONSTRUCTORS
usaSinglePathAtlantaCharleston = new TrackBrick[] { new TrackBrick(775, 390, 90.5f, TrackColor.any),
new TrackBrick(810, 391, 90.5f, TrackColor.any) };
usaSinglePathAtlantaMiami = new TrackBrick[] { new TrackBrick(759, 409, -40.8f, TrackColor.blue),
new TrackBrick(781, 437, -38.9f, TrackColor.blue),
new TrackBrick(803, 464, -39.4f, TrackColor.blue),
new TrackBrick(825, 491, -39.5f, TrackColor.blue),
new TrackBrick(847, 518, -39f, TrackColor.blue) };
...
#endregion
#region TrackSinglePath[] CONSTRUCTORS
usaPathAtlantaCharleston = new TrackSinglePath[] { new TrackSinglePath(usaSinglePathAtlantaCharleston) };
usaPathAtlantaMiami = new TrackSinglePath[] { new TrackSinglePath(usaSinglePathAtlantaMiami) };
...
#endregion
usaPaths = new TrackPath[] { new TrackPath("Atlanta", "Charleston", true, usaPathAtlantaCharleston),
new TrackPath("Atlanta", "Miami", true, usaPathAtlantaMiami), ... };
#region Card AND Deck OBJECT CONSTRUCTORS
deckTrainCards = new TrainCardDeck();
//add USA base game train cards
deckTrainCards.AddCard(new TrainCard("T01001", TrackColor.black, texture_TrainCardBlack));
deckTrainCards.AddCard(new TrainCard("T01002", TrackColor.black, texture_TrainCardBlack));
deckTrainCards.AddCard(new TrainCard("T01003", TrackColor.black, texture_TrainCardBlack));
...
deckTrainCards.AddCard(new TrainCard("T01110", TrackColor.black, texture_TrainCardLoco));
#endregion
usa = new Board("USA", BOARD_USA_WIDTH, BOARD_USA_HEIGHT, usaCities, usaPaths);
PlaceCitiesOnMap(usa);
PlaceEmptyTrackPathsOnMap(usa);
}
void Update()
{
}
...
}
9020860–1244242–Board.cs (1.3 KB)
9020860–1244254–TrackBrick.cs (575 Bytes)
9020860–1244257–TrainCardDeck.cs (1.88 KB)
9020860–1244260–TrainCard.cs (420 Bytes)