Ejemplo n.º 1
0
        public static bool TryCreateFromSave(TransportSave transportSave, out TrainTransport trainTransport)
        {
            trainTransport = null;

            if (transportSave.type == _trackCalculationType.name &&
                Train.TrainAnimations.ContainsKey(transportSave.itemName) &&
                Train.TrainTypes.ContainsKey(transportSave.itemName))
            {
                trainTransport = new TrainTransport(transportSave);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        public static TrainTransport CreateTrain(ICSType cSType, Vector3 spawnPosition)
        {
            TrainTransport trainTransport = new TrainTransport(spawnPosition, TrainAnimations[cSType.name], cSType);

            TransportManager.RegisterTransport(trainTransport);

            if (!string.IsNullOrEmpty(cSType.ConnectedBlock?.BlockType))
            {
                if (!TrainTransports.ContainsKey(cSType.ConnectedBlock.BlockType))
                {
                    TrainTransports.Add(cSType.ConnectedBlock.BlockType, new List <TrainTransport>());
                }

                TrainTransports[cSType.ConnectedBlock.BlockType].Add(trainTransport);
            }

            return(trainTransport);
        }
Ejemplo n.º 3
0
        private static void Initialize()
        {
            foreach (var train in TrainTypes.Values)
            {
                var animatedObject = AnimationManager.RegisterNewAnimatedObject(train.name, train.mesh, train.sideall);
                animatedObject.ObjSettings.colliders = new List <RotatedBounds>()
                {
                    new RotatedBounds(Vector3.zero, train.TrainConfiguration.TrainBounds, Quaternion.identity)
                };
                animatedObject.ObjSettings.InterpolationLooseness = 1.5f;
                animatedObject.ObjSettings.sendUpdateRadius       = 500;

                TrainAnimations[train.name] = animatedObject;
            }

            var worldFile = Path.Combine(GameInitializer.SAVE_LOC, "world.json");

            if (File.Exists(worldFile))
            {
                JObject rootObj = JsonConvert.DeserializeObject <JObject>(File.ReadAllText(worldFile));

                if (rootObj.TryGetValue("transports", out JToken transports))
                {
                    if (transports.Type != JTokenType.Array)
                    {
                        return;
                    }

                    List <TransportSave> trainSaves = transports.ToObject <List <TransportSave> >();

                    foreach (var save in trainSaves)
                    {
                        if (TrainTransport.TryCreateFromSave(save, out var trainTransport))
                        {
                            TransportManager.RegisterTransport(trainTransport);
                        }
                    }
                }
            }
        }