diff --git a/Mapify/SceneInitializers/GameContent/VanillaAssetSetup.cs b/Mapify/SceneInitializers/GameContent/VanillaAssetSetup.cs index 13084fc..74984b4 100644 --- a/Mapify/SceneInitializers/GameContent/VanillaAssetSetup.cs +++ b/Mapify/SceneInitializers/GameContent/VanillaAssetSetup.cs @@ -11,23 +11,11 @@ public class VanillaAssetSetup : SceneSetup public override void Run() { foreach (VanillaObject vanillaObject in Object.FindObjectsOfType()) + { + GameObject go = vanillaObject.Replace(keepChildren: vanillaObject.keepChildren, rotationOffset: vanillaObject.rotationOffset); + switch (vanillaObject.asset) { - case VanillaAsset.CareerManager: - case VanillaAsset.JobValidator: - case VanillaAsset.TrashCan: - case VanillaAsset.Dumpster: - case VanillaAsset.LostAndFoundShed: - case VanillaAsset.WarehouseMachine: - case VanillaAsset.PlayerHouse: - vanillaObject.Replace(); - break; - case VanillaAsset.PitStopStationCoal1: - case VanillaAsset.PitStopStationCoal2: - case VanillaAsset.PitStopStationWater1: - case VanillaAsset.PitStopStationWater2: - vanillaObject.Replace(keepChildren: false); - break; case VanillaAsset.StationOffice1: case VanillaAsset.StationOffice2: case VanillaAsset.StationOffice3: @@ -35,13 +23,13 @@ public override void Run() case VanillaAsset.StationOffice5: case VanillaAsset.StationOffice6: case VanillaAsset.StationOffice7: - GameObject go = vanillaObject.Replace(); - // todo: make this show in the correct location instead of removing it + // todo: make this show in the correct location instead of removing it. Then we can also get rid of this switch. Transform youAreHereFlag = go.transform.FindChildByName("PinRed"); if (youAreHereFlag != null) Object.Destroy(youAreHereFlag.gameObject); break; } + } } } } diff --git a/Mapify/Utils/Extensions.cs b/Mapify/Utils/Extensions.cs index 7f19edb..32a926c 100644 --- a/Mapify/Utils/Extensions.cs +++ b/Mapify/Utils/Extensions.cs @@ -50,14 +50,15 @@ public static T WithComponent(this GameObject gameObject) where T : Component return comp ? comp : gameObject.AddComponent(); } - public static GameObject Replace(this GameObject gameObject, GameObject other, Type[] preserveTypes = null, bool keepChildren = true) + public static GameObject Replace(this GameObject gameObject, GameObject other, Type[] preserveTypes = null, bool keepChildren = true, Vector3 rotationOffset = default) { if (gameObject == other) throw new ArgumentException("Cannot replace self with self"); - Transform t = gameObject.transform; - Transform ot = other.transform; - ot.SetParent(t.parent); - ot.SetPositionAndRotation(t.position, t.rotation); - ot.SetSiblingIndex(t.GetSiblingIndex()); + Transform thisTransform = gameObject.transform; + Transform otherTransform = other.transform; + otherTransform.SetParent(thisTransform.parent); + otherTransform.SetPositionAndRotation(thisTransform.position, thisTransform.rotation); + otherTransform.Rotate(rotationOffset); + otherTransform.SetSiblingIndex(thisTransform.GetSiblingIndex()); if (preserveTypes != null) foreach (Type type in preserveTypes) { @@ -73,8 +74,8 @@ public static GameObject Replace(this GameObject gameObject, GameObject other, T } if (keepChildren) - foreach (Transform child in t.GetChildren()) - child.SetParent(ot); + foreach (Transform child in thisTransform.GetChildren()) + child.SetParent(otherTransform); GameObject.DestroyImmediate(gameObject); return other; @@ -234,9 +235,9 @@ public static void Replace(this IEnumerable vanillaObjects, bool foreach (VanillaObject vanillaObject in vanillaObjects) vanillaObject.Replace(active, keepChildren, originShift, preserveTypes); } - public static GameObject Replace(this VanillaObject vanillaObject, bool active = true, bool keepChildren = true, bool originShift = true, Type[] preserveTypes = null) + public static GameObject Replace(this VanillaObject vanillaObject, bool active = true, bool keepChildren = true, bool originShift = true, Type[] preserveTypes = null, Vector3 rotationOffset = default) { - return vanillaObject.gameObject.Replace(AssetCopier.Instantiate(vanillaObject.asset, active, originShift), preserveTypes, keepChildren); + return vanillaObject.gameObject.Replace(AssetCopier.Instantiate(vanillaObject.asset, active, originShift), preserveTypes, keepChildren, rotationOffset); } #endregion diff --git a/MapifyEditor/Vanilla/VanillaObject.cs b/MapifyEditor/Vanilla/VanillaObject.cs index c09078c..3a93e9d 100644 --- a/MapifyEditor/Vanilla/VanillaObject.cs +++ b/MapifyEditor/Vanilla/VanillaObject.cs @@ -1,9 +1,12 @@ using UnityEngine; +using UnityEngine.Serialization; namespace Mapify.Editor { public class VanillaObject : MonoBehaviour { public VanillaAsset asset; + public bool keepChildren = true; + public Vector3 rotationOffset = Vector3.zero; } } diff --git a/PackageBuilder/Assets/Mapify/Prefabs/Service Station/Coal Station 1.prefab b/PackageBuilder/Assets/Mapify/Prefabs/Service Station/Coal Station 1.prefab index 8f6d2da..84a6eb9 100644 --- a/PackageBuilder/Assets/Mapify/Prefabs/Service Station/Coal Station 1.prefab +++ b/PackageBuilder/Assets/Mapify/Prefabs/Service Station/Coal Station 1.prefab @@ -128,6 +128,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: asset: 52 + keepChildren: 0 + rotationOffset: {x: 0, y: 0, z: 0} --- !u!114 &3957153289511670403 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/PackageBuilder/Assets/Mapify/Prefabs/Service Station/Coal Station 2.prefab b/PackageBuilder/Assets/Mapify/Prefabs/Service Station/Coal Station 2.prefab index 9a2ba5e..9afb7e1 100644 --- a/PackageBuilder/Assets/Mapify/Prefabs/Service Station/Coal Station 2.prefab +++ b/PackageBuilder/Assets/Mapify/Prefabs/Service Station/Coal Station 2.prefab @@ -23,6 +23,11 @@ PrefabInstance: propertyPath: asset value: 53 objectReference: {fileID: 0} + - target: {fileID: 3543013568023383394, guid: a21c165e9bb9547d3a86bc0a6ef1fd91, + type: 3} + propertyPath: keepChildren + value: 0 + objectReference: {fileID: 0} - target: {fileID: 6584377352624942545, guid: a21c165e9bb9547d3a86bc0a6ef1fd91, type: 3} propertyPath: m_RootOrder diff --git a/PackageBuilder/Assets/Mapify/Prefabs/Service Station/Water Tower 1.prefab b/PackageBuilder/Assets/Mapify/Prefabs/Service Station/Water Tower 1.prefab index 57e6762..12f97e4 100644 --- a/PackageBuilder/Assets/Mapify/Prefabs/Service Station/Water Tower 1.prefab +++ b/PackageBuilder/Assets/Mapify/Prefabs/Service Station/Water Tower 1.prefab @@ -128,6 +128,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: asset: 54 + keepChildren: 0 + rotationOffset: {x: 0, y: 0, z: 0} --- !u!114 &3957153289511670403 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/PackageBuilder/Assets/Mapify/Prefabs/Service Station/Water Tower 2.prefab b/PackageBuilder/Assets/Mapify/Prefabs/Service Station/Water Tower 2.prefab index 94e8e16..79b536d 100644 --- a/PackageBuilder/Assets/Mapify/Prefabs/Service Station/Water Tower 2.prefab +++ b/PackageBuilder/Assets/Mapify/Prefabs/Service Station/Water Tower 2.prefab @@ -23,6 +23,16 @@ PrefabInstance: propertyPath: asset value: 55 objectReference: {fileID: 0} + - target: {fileID: 3543013568023383394, guid: 0f09051f0758f351bb1b1f1602ec5b51, + type: 3} + propertyPath: rotationOffset.y + value: 90 + objectReference: {fileID: 0} + - target: {fileID: 3543013568023383394, guid: 0f09051f0758f351bb1b1f1602ec5b51, + type: 3} + propertyPath: keepChildren + value: 0 + objectReference: {fileID: 0} - target: {fileID: 6584377352624942545, guid: 0f09051f0758f351bb1b1f1602ec5b51, type: 3} propertyPath: m_RootOrder diff --git a/PackageBuilder/Assets/Mapify/Prefabs/Station/Dumpster.prefab b/PackageBuilder/Assets/Mapify/Prefabs/Station/Dumpster.prefab index b6e861a..9eb013b 100644 --- a/PackageBuilder/Assets/Mapify/Prefabs/Station/Dumpster.prefab +++ b/PackageBuilder/Assets/Mapify/Prefabs/Station/Dumpster.prefab @@ -46,6 +46,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: asset: 13 + keepChildren: 1 + rotationOffset: {x: 0, y: 90, z: 0} --- !u!33 &1285410329932861900 MeshFilter: m_ObjectHideFlags: 0