Ejemplo n.º 1
0
        static bool Prefix(JobLicenses license, Vector3 position, Quaternion rotation, Transform parent)
        {
            if (license != PassLicenses.Passengers1)
            {
                return(true);
            }

            // we'll try to copy from the Hazmat 1 license prefab
            GameObject licenseObj = spawnLicenseMethod.Invoke(null,
                                                              new object[] { COPIED_PREFAB_NAME, position, rotation, true, parent }) as GameObject;

            PassengerLicenseUtil.SetLicenseObjectProperties(licenseObj, PassBookletType.Passengers1License);

            PassengerJobs.ModEntry.Logger.Log("Created Passengers 1 license");
            return(false);
        }
Ejemplo n.º 2
0
        static void Prefix(ref List <StorageItemData> storageItemData, ref GameObject __state)
        {
            var bookProps = PassengerLicenseUtil.BookletProperties[PassBookletType.Passengers1License];

            StorageItemData itemData = storageItemData.Find(sid => bookProps.Name.Equals(sid.itemPrefabName));

            if (itemData != null)
            {
                storageItemData.Remove(itemData);

                GameObject licenseObj = Resources.Load(BC_CreateLicense_Patch.COPIED_PREFAB_NAME) as GameObject;
                if (licenseObj == null)
                {
                    PassengerJobs.ModEntry.Logger.Error("Couldn't spawn saved Passengers 1 license");
                    return;
                }

                // GameObject properties and state
                licenseObj = UnityEngine.Object.Instantiate(licenseObj);
                PassengerLicenseUtil.SetLicenseObjectProperties(licenseObj, PassBookletType.Passengers1License);
                licenseObj.GetComponent <InventoryItemSpec>().belongsToPlayer = itemData.belongsToPlayer;

                if (licenseObj.GetComponent <IStateSave>() is IStateSave stateSave)
                {
                    stateSave.SetStateSaveData(itemData.state);
                }

                // Position / rotation data
                Transform carTransform = null;
                Vector3   itemPos      = new Vector3(itemData.itemPositionX, itemData.itemPositionY, itemData.itemPositionZ);

                if (!string.IsNullOrEmpty(itemData.carGuid))
                {
                    var car = TrainCar.GetTrainCarByCarGuid(itemData.carGuid);
                    if (car)
                    {
                        if (car.GetComponent <TrainPhysicsLod>() is TrainPhysicsLod carPhysics)
                        {
                            carPhysics.ForceItemUpdate(false);
                        }
                        else
                        {
                            Debug.LogError($"Car {car.name} doesn't have TrainPhysicsLod component. Skipping.");
                        }

                        carTransform = car.interior;
                        itemPos     += new Vector3(0, 0.3f, 0);
                    }
                }

                licenseObj.transform.position = itemPos;
                licenseObj.transform.rotation = new Quaternion(itemData.itemRotationX, itemData.itemRotationY, itemData.itemRotationZ, itemData.itemRotationW);

                Transform worldTransform = SingletonBehaviour <WorldMover> .Exists ? SingletonBehaviour <WorldMover> .Instance.originShiftParent : null;
                licenseObj.transform.SetParent(carTransform ?? worldTransform, true);

                __state = licenseObj;
            }
            else
            {
                // itemData == null
                __state = null;
            }
        }