Skip to content

Commit

Permalink
Remove the automatic scaling and moved to the fixed scale buildings i…
Browse files Browse the repository at this point in the history
…n the menu for simplicity
  • Loading branch information
brainwipe committed Apr 27, 2018
1 parent 2465676 commit a19fa8d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 86 deletions.
4 changes: 3 additions & 1 deletion Assets/Resources/Buildings/boiler-medium.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ GameObject:
- component: {fileID: 33756047860429876}
- component: {fileID: 23391628909767502}
- component: {fileID: 95445277600182920}
- component: {fileID: 114067011724942954}
- component: {fileID: 65475248975301464}
- component: {fileID: 114067011724942954}
m_Layer: 0
m_Name: boiler-medium
m_TagString: Building
Expand Down Expand Up @@ -133,3 +133,5 @@ MonoBehaviour:
Size:
WidthX: 2
LengthZ: 2
MenuPosition: {x: 0, y: -0.074, z: 0}
MenuScale: 0.0045
4 changes: 3 additions & 1 deletion Assets/Resources/Buildings/bridge-standard.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ GameObject:
- component: {fileID: 33907099343462824}
- component: {fileID: 23152673258847120}
- component: {fileID: 95455686480732832}
- component: {fileID: 114757617169345188}
- component: {fileID: 65262408838371700}
- component: {fileID: 114757617169345188}
m_Layer: 0
m_Name: bridge-standard
m_TagString: Building
Expand Down Expand Up @@ -133,3 +133,5 @@ MonoBehaviour:
Size:
WidthX: 1
LengthZ: 1
MenuPosition: {x: 0, y: -0.078, z: 0}
MenuScale: 0.015
4 changes: 3 additions & 1 deletion Assets/Resources/Buildings/house-small-one.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ GameObject:
- component: {fileID: 33733372547811596}
- component: {fileID: 23992140298746848}
- component: {fileID: 95892162910594084}
- component: {fileID: 114141047168434516}
- component: {fileID: 65430304006819890}
- component: {fileID: 114141047168434516}
m_Layer: 0
m_Name: house-small-one
m_TagString: Building
Expand Down Expand Up @@ -133,3 +133,5 @@ MonoBehaviour:
Size:
WidthX: 1
LengthZ: 1
MenuPosition: {x: 0, y: -0.04, z: 0}
MenuScale: 0.02
8 changes: 5 additions & 3 deletions Assets/Resources/Buildings/weapon-cannon.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Transform:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1838906278851360}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 4.3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
Expand All @@ -127,14 +127,14 @@ Transform:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1235554380841272}
m_LocalRotation: {x: 0, y: -0.052335896, z: 0, w: 0.9986295}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4654036869397706}
m_Father: {fileID: 4487288415505626}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: -6, z: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!23 &23353440015258612
MeshRenderer:
m_ObjectHideFlags: 1
Expand Down Expand Up @@ -291,6 +291,8 @@ MonoBehaviour:
Size:
WidthX: 1
LengthZ: 1
MenuPosition: {x: 0, y: -0.07, z: 0}
MenuScale: 0.018
--- !u!136 &136077999746810440
CapsuleCollider:
m_ObjectHideFlags: 1
Expand Down
66 changes: 8 additions & 58 deletions Assets/Scenes/main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ RectTransform:
m_Children:
- {fileID: 1858897634}
m_Father: {fileID: 0}
m_RootOrder: 9
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand Down Expand Up @@ -441,7 +441,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &343202122 stripped
GameObject:
Expand Down Expand Up @@ -475,7 +475,7 @@ Transform:
m_Children:
- {fileID: 837146817}
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &654624880
MonoBehaviour:
Expand Down Expand Up @@ -1176,7 +1176,7 @@ Transform:
- {fileID: 104885799}
- {fileID: 46305672}
m_Father: {fileID: 0}
m_RootOrder: 7
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 19.467, y: 0, z: 0}
--- !u!1 &1173164697
GameObject:
Expand Down Expand Up @@ -1399,56 +1399,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c3f0899a5c19e1746bfff44fccc5f1ea, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &1506637560
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4483587615472010, guid: a1aea20643c34d0448b5d4fd4757af56, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4483587615472010, guid: a1aea20643c34d0448b5d4fd4757af56, type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4483587615472010, guid: a1aea20643c34d0448b5d4fd4757af56, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4483587615472010, guid: a1aea20643c34d0448b5d4fd4757af56, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4483587615472010, guid: a1aea20643c34d0448b5d4fd4757af56, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4483587615472010, guid: a1aea20643c34d0448b5d4fd4757af56, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4483587615472010, guid: a1aea20643c34d0448b5d4fd4757af56, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4483587615472010, guid: a1aea20643c34d0448b5d4fd4757af56, type: 2}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1838906278851360, guid: a1aea20643c34d0448b5d4fd4757af56, type: 2}
propertyPath: m_TagString
value: Building
objectReference: {fileID: 0}
- target: {fileID: 1235554380841272, guid: a1aea20643c34d0448b5d4fd4757af56, type: 2}
propertyPath: m_TagString
value: Building
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: a1aea20643c34d0448b5d4fd4757af56, type: 2}
m_IsPrefabParent: 0
--- !u!1001 &1682990462
Prefab:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1732,7 +1682,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0}
--- !u!1 &1817614950
GameObject:
Expand Down Expand Up @@ -2033,7 +1983,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4455065497538944, guid: 4422eabe9ef5e194988b0bd3917a9f11, type: 2}
propertyPath: m_RootOrder
value: 5
value: 4
objectReference: {fileID: 0}
- target: {fileID: 114447722083175718, guid: 4422eabe9ef5e194988b0bd3917a9f11,
type: 2}
Expand Down Expand Up @@ -2077,7 +2027,7 @@ Transform:
- {fileID: 1376252815}
- {fileID: 1173164701}
m_Father: {fileID: 0}
m_RootOrder: 3
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2028971219
GameObject:
Expand Down Expand Up @@ -2286,7 +2236,7 @@ Transform:
- {fileID: 1966825438}
- {fileID: 260987470}
m_Father: {fileID: 0}
m_RootOrder: 6
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2125013691
GameObject:
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Builder/BuildSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void MouseDown()
selectedBuilding.transform.localPosition = GridSpaceToLocalSpace(building);
selectedBuilding.transform.localScale = Vector3.one;
selectedBuilding.transform.localRotation = Quaternion.identity;
var renderer = selectedBuilding.GetComponent<Renderer>();
var renderer = selectedBuilding.GetComponentInChildren<Renderer>();
originalMaterial = renderer.sharedMaterial;
}
}
Expand Down Expand Up @@ -208,7 +208,7 @@ void MouseUp()
if (selectedBuilding != null)
{
var building = selectedBuilding.GetComponent<Building>();
var renderer = selectedBuilding.GetComponent<Renderer>();
var renderer = selectedBuilding.GetComponentInChildren<Renderer>();
ClearBuildingIfExists(building);
renderer.sharedMaterial = originalMaterial;
SaveBuilding(building);
Expand Down
24 changes: 4 additions & 20 deletions Assets/Scripts/Builder/Building.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,14 @@ public class Building : MonoBehaviour, IAmBuilding, IHaveGridSpace {

public Grid GridSpaceLocation { get; set; }
public BuildingSize Size;
public Vector3 MenuPosition;
public float MenuScale;

public void SetupForMenu(int menuLayer)
{
gameObject.layer = menuLayer;
transform.localRotation = Quaternion.identity;

var bounds = CalculateUnscaledBounds();

float newScale = (1 / bounds.extents.magnitude) * 0.11f;
transform.localScale = new Vector3(newScale * 2, newScale * 2, newScale * 2);

var offsetPosition = new Vector3(0, bounds.center.y * newScale, 0);
transform.localPosition -= offsetPosition;
transform.localPosition = MenuPosition;
transform.localScale = new Vector3(MenuScale,MenuScale,MenuScale);
}

private Bounds CalculateUnscaledBounds()
{
var bounds = new Bounds(transform.position, Vector3.zero);

foreach(MeshFilter meshFilter in GetComponentsInChildren<MeshFilter>())
{
bounds.Encapsulate(meshFilter.mesh.bounds);
}
return bounds;
}

}

0 comments on commit a19fa8d

Please sign in to comment.