Skip to content

Commit

Permalink
Fix water tower 2 and dumpster rotation (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
t0stiman authored Nov 9, 2023
1 parent fe810bd commit 757a52e
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 27 deletions.
22 changes: 5 additions & 17 deletions Mapify/SceneInitializers/GameContent/VanillaAssetSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,25 @@ public class VanillaAssetSetup : SceneSetup
public override void Run()
{
foreach (VanillaObject vanillaObject in Object.FindObjectsOfType<VanillaObject>())
{
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:
case VanillaAsset.StationOffice4:
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;
}
}
}
}
}
21 changes: 11 additions & 10 deletions Mapify/Utils/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ public static T WithComponent<T>(this GameObject gameObject) where T : Component
return comp ? comp : gameObject.AddComponent<T>();
}

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)
{
Expand All @@ -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;
Expand Down Expand Up @@ -234,9 +235,9 @@ public static void Replace(this IEnumerable<VanillaObject> 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
Expand Down
3 changes: 3 additions & 0 deletions MapifyEditor/Vanilla/VanillaObject.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions PackageBuilder/Assets/Mapify/Prefabs/Station/Dumpster.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 757a52e

Please sign in to comment.