Exemple #1
0
        public static void ExportLocoControllerCurves(CommandArg[] args)
        {
            if (Terminal.IssuedError)
            {
                return;
            }

            string name = args[0].String;

            if (Enum.TryParse(name, out TrainCarType carType))
            {
                GameObject prefab = CarTypes.GetCarPrefab(carType);
                if (!prefab)
                {
                    Debug.LogError($"CarType {name} has missing prefab");
                    return;
                }

                LocoControllerBase locoController = prefab.GetComponent <LocoControllerBase>();
                if (!locoController)
                {
                    Debug.LogWarning($"CarType {name} prefab does not have a loco controller");
                    return;
                }

                var props = new JObject();

                // brake & traction
                JObject brakeCurve = ComponentsToJson.AnimationCurve(locoController.brakePowerCurve);
                props.Add("brakePowerCurve", brakeCurve);

                if (locoController is LocoControllerDiesel lcd)
                {
                    var tractionCurve = ComponentsToJson.AnimationCurve(lcd.tractionTorqueCurve);
                    props.Add("tractionTorqueCurve", tractionCurve);
                }
                else if (locoController is LocoControllerSteam lcs)
                {
                    var tractionCurve = ComponentsToJson.AnimationCurve(lcs.tractionTorqueCurve);
                    props.Add("tractionTorqueCurve", tractionCurve);
                }
                else if (locoController is LocoControllerShunter lcShunt)
                {
                    var tractionCurve = ComponentsToJson.AnimationCurve(lcShunt.tractionTorqueCurve);
                    props.Add("tractionTorqueCurve", tractionCurve);
                }

                // driving force
                props.Add("drivingForce", ComponentsToJson.DrivingForce(locoController.drivingForce));

                GameObjectDumper.SendJsonToFile(name, "loco_curves", props);
            }
        }
Exemple #2
0
        private static JObject GetCollidersRecursive(Transform currentLevel)
        {
            var collidersOnThis = currentLevel.gameObject.GetComponents <Collider>();

            JArray colliderList = null;

            if (collidersOnThis.Length > 0)
            {
                colliderList = ComponentsToJson.Colliders(collidersOnThis);
            }

            JArray children = null;

            if (currentLevel.childCount > 0)
            {
                children = new JArray();

                foreach (Transform child in currentLevel)
                {
                    JObject childJson = GetCollidersRecursive(child);
                    if (childJson != null)
                    {
                        children.Add(childJson);
                    }
                }
            }

            if ((colliderList != null) || ((children != null) && (children.Count > 0)))
            {
                JObject result = new JObject()
                {
                    new JProperty("name", currentLevel.name)
                };

                if (colliderList != null)
                {
                    result.Add(new JProperty("colliders", colliderList));
                }

                if ((children != null) && (children.Count > 0))
                {
                    result.Add(new JProperty("children", children));
                }

                return(result);
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
        public static void ExportDamageProperties(CommandArg[] args)
        {
            if (Terminal.IssuedError)
            {
                return;
            }

            string name = args[0].String;

            if (Enum.TryParse(name, out TrainCarType carType))
            {
                GameObject prefab = CarTypes.GetCarPrefab(carType);
                if (!prefab)
                {
                    Debug.LogError($"CarType {name} has missing prefab");
                    return;
                }

                var damage = prefab.GetComponent <DamageController>();
                if (!damage)
                {
                    Debug.LogWarning($"CarType {name} prefab does not have a damage controller");
                    return;
                }

                var ctrlProps = new JObject
                {
                    { "wheelsHP", damage.wheels.fullHitPoints },
                    { "speedToBrakeDamageCurve", ComponentsToJson.AnimationCurve(damage.speedToBrakeDamageCurve) },
                };

                if (damage is DamageControllerDiesel dcd)
                {
                    ctrlProps.Add("engineHP", dcd.engine.fullHitPoints);
                }
                else if (damage is DamageControllerShunter dcs)
                {
                    ctrlProps.Add("engineHP", dcs.engine.fullHitPoints);
                }

                if (TrainCarAndCargoDamageProperties.carDamageProperties.TryGetValue(carType, out CarDamageProperties dmgProps))
                {
                    ctrlProps.Add("bodyDamage", ComponentsToJson.CarDamageProperties(dmgProps));
                }

                GameObjectDumper.SendJsonToFile(name, "damage", ctrlProps);
            }
        }
Exemple #4
0
        public static void ExportCabControls(CommandArg[] args)
        {
            if (Terminal.IssuedError)
            {
                return;
            }

            string name = args[0].String;

            if (Enum.TryParse(name, out TrainCarType carType))
            {
                GameObject prefab = CarTypes.GetCarPrefab(carType);
                if (!prefab)
                {
                    Debug.LogError($"CarType {name} has missing prefab");
                    return;
                }

                TrainCar car = prefab.GetComponent <TrainCar>();
                if (!car)
                {
                    Debug.LogError($"Couldn't find TrainCar on carType {name}");
                    return;
                }

                if (!car.interiorPrefab)
                {
                    Debug.LogWarning($"TrainCar on carType {name} doesn't have an interiorPrefab assigned");
                    return;
                }

                var specList     = new JArray();
                var controlSpecs = car.interiorPrefab.GetComponentsInChildren <ControlSpec>();
                foreach (ControlSpec spec in controlSpecs)
                {
                    specList.Add(ComponentsToJson.GenericObject(spec));
                }

                var indicators = car.interiorPrefab.GetComponentsInChildren <Indicator>();
                foreach (Indicator ind in indicators)
                {
                    specList.Add(ComponentsToJson.GenericObject(ind));
                }

                GameObjectDumper.SendJsonToFile(name, "control_spec", specList);
            }
        }
Exemple #5
0
        public static void ExportCarColliders(CommandArg[] args)
        {
            if (Terminal.IssuedError)
            {
                return;
            }

            string name = args[0].String;

            if (Enum.TryParse(name, out TrainCarType carType))
            {
                GameObject prefab = CarTypes.GetCarPrefab(carType);
                if (!prefab)
                {
                    Debug.LogError($"CarType {name} has missing prefab");
                    return;
                }

                Transform colliderRoot = prefab.transform.Find("[colliders]");
                if (!colliderRoot)
                {
                    Debug.LogWarning($"CarType {name} does not have a colliders root transform");
                    return;
                }

                var colliderDict = new JObject();

                foreach (string categoryName in colliderCategories)
                {
                    Transform subTransform = colliderRoot.Find(categoryName);
                    if (subTransform)
                    {
                        Collider[] colliders = subTransform.gameObject.GetComponentsInChildren <Collider>();

                        var colliderCategory = ComponentsToJson.Colliders(colliders);
                        colliderDict.Add(new JProperty(categoryName, colliderCategory));
                    }
                }

                GameObjectDumper.SendJsonToFile(name, "colliders", colliderDict);
            }
            else
            {
                Debug.LogWarning("Invalid car type " + name);
            }
        }
        public static void DumpComponentPools(CommandArg[] args)
        {
            if (Terminal.IssuedError)
            {
                return;
            }

            JToken audioPool = ComponentsToJson.AudioPoolReferences(TrainComponentPool.Instance.audioPoolReferences);
            //JToken cargoPool = ComponentsToJson.GenericObject(TrainComponentPool.Instance.cargoPoolReferences.poolData);

            var output = new JObject()
            {
                new JProperty("audioPool", audioPool),
                //new JProperty("cargoPool", cargoPool)
            };

            GameObjectDumper.SendJsonToFile("TrainComponentPool", "members", output);
        }