From bd75ae9524bf2534b3b7bd09ea5f1de9ef830301 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 5 Oct 2019 13:06:48 +0200 Subject: [PATCH] Merge into suns --- Assets/Components/Merge.cs | 27 +++-- Assets/Prefabs/Gravitation Object.prefab | 61 +++++++++- Assets/Prefabs/Nothing.prefab | 32 ++++++ Assets/Prefabs/Nothing.prefab.meta | 7 ++ Assets/Prefabs/Sun.prefab | 122 ++++++++++++++++++++ Assets/Prefabs/Sun.prefab.meta | 7 ++ Assets/Scenes/Game.unity | 139 +---------------------- 7 files changed, 248 insertions(+), 147 deletions(-) create mode 100644 Assets/Prefabs/Nothing.prefab create mode 100644 Assets/Prefabs/Nothing.prefab.meta create mode 100644 Assets/Prefabs/Sun.prefab create mode 100644 Assets/Prefabs/Sun.prefab.meta diff --git a/Assets/Components/Merge.cs b/Assets/Components/Merge.cs index dbbdef7..2a451d1 100644 --- a/Assets/Components/Merge.cs +++ b/Assets/Components/Merge.cs @@ -7,6 +7,7 @@ public class Merge : MonoBehaviour { [Header("Config")] public GameObject mergeIntoPrefab; + public bool setMergedMassFromTotal; [Header("References")] protected new CircleCollider2D collider; @@ -23,30 +24,42 @@ public class Merge : MonoBehaviour private void OnTriggerEnter2D(Collider2D other) { Merge otherMerge = other.GetComponent(); - mergeables.Add(otherMerge); - - if(CanMerge()) DoMerge(); + if(otherMerge != null) { + mergeables.Add(otherMerge); + if(CanMerge()) DoMerge(); + } } private void OnTriggerExit2D(Collider2D other) { Merge otherMerge = other.GetComponent(); - mergeables.Remove(otherMerge); + if(otherMerge != null) { + mergeables.Remove(otherMerge); + } } protected bool CanMerge() { - return false; + return mergeables.Count >= 5; } protected void DoMerge() { GameObject mergeResult = Instantiate(mergeIntoPrefab, transform.position, Quaternion.identity); MergedInfo mergedInfo = mergeResult.AddComponent(); mergedInfo.mergedCount = mergeables.Count; - foreach(Merge merged in mergeables) { + + foreach(Merge merged in mergeables.ToArray()) { Rigidbody2D mergedBody = merged.GetComponentInParent(); if(mergedBody != null) { mergedInfo.mergedMass += mergedBody.mass; } - Destroy(merged.transform.parent); + Destroy(merged.transform.parent.gameObject); + } + + if(setMergedMassFromTotal) { + Rigidbody2D mergeRigidbody = mergeResult.GetComponent(); + if(mergeRigidbody != null) { + mergeRigidbody.useAutoMass = false; + mergeRigidbody.mass = mergedInfo.mergedMass; + } } } } diff --git a/Assets/Prefabs/Gravitation Object.prefab b/Assets/Prefabs/Gravitation Object.prefab index ad6ac48..eeac4e8 100644 --- a/Assets/Prefabs/Gravitation Object.prefab +++ b/Assets/Prefabs/Gravitation Object.prefab @@ -13,7 +13,6 @@ GameObject: - component: {fileID: 5473375028011702753} - component: {fileID: 5473375028011702752} - component: {fileID: 5473375028011702755} - - component: {fileID: 720206987848026506} m_Layer: 0 m_Name: Gravitation Object m_TagString: Untagged @@ -31,7 +30,8 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: -2, y: 0.88, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] + m_Children: + - {fileID: 851405983337701308} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -135,17 +135,66 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: positionInList: 0 ---- !u!114 &720206987848026506 +--- !u!1 &8635663089806839545 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 851405983337701308} + - component: {fileID: 392989897224966342} + - component: {fileID: 7106168952007636313} + m_Layer: 0 + m_Name: MergeTrigger + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &851405983337701308 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8635663089806839545} + 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: [] + m_Father: {fileID: 5473375028011702783} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!58 &392989897224966342 +CircleCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8635663089806839545} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: 0} + serializedVersion: 2 + m_Radius: 0.55 +--- !u!114 &7106168952007636313 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 5473375028011702754} + m_GameObject: {fileID: 8635663089806839545} m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 1010c8363cc1ebd4e9c1808f9a2737e2, type: 3} m_Name: m_EditorClassIdentifier: - requiredForce: 5 - transformIntoPrefab: {fileID: 0} + mergeIntoPrefab: {fileID: 5508245818244581766, guid: 81be647bed73a164cb47269e43863cac, + type: 3} + setMergedMassFromTotal: 1 diff --git a/Assets/Prefabs/Nothing.prefab b/Assets/Prefabs/Nothing.prefab new file mode 100644 index 0000000..4e64710 --- /dev/null +++ b/Assets/Prefabs/Nothing.prefab @@ -0,0 +1,32 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &6786529680537240613 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 7085311716076432966} + m_Layer: 0 + m_Name: Nothing + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &7085311716076432966 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6786529680537240613} + 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: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Prefabs/Nothing.prefab.meta b/Assets/Prefabs/Nothing.prefab.meta new file mode 100644 index 0000000..747ca20 --- /dev/null +++ b/Assets/Prefabs/Nothing.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: d810808c92b542d418721ca53dca1fee +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Sun.prefab b/Assets/Prefabs/Sun.prefab new file mode 100644 index 0000000..faa72b3 --- /dev/null +++ b/Assets/Prefabs/Sun.prefab @@ -0,0 +1,122 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &5508245818244581766 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6572685539244401289} + - component: {fileID: 7383058586621682203} + - component: {fileID: 3951280190561447455} + - component: {fileID: 5758426961102176851} + m_Layer: 0 + m_Name: Sun + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6572685539244401289 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5508245818244581766} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -2.31, y: -0.09, z: 0} + m_LocalScale: {x: 1.5, y: 1.5, z: 1.5} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!212 &7383058586621682203 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5508245818244581766} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_Sprite: {fileID: 21300000, guid: d8cf31929ca287542bdc219ec19f002e, type: 3} + m_Color: {r: 1, g: 1, b: 0, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 1, y: 1} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_MaskInteraction: 0 + m_SpriteSortPoint: 0 +--- !u!50 &3951280190561447455 +Rigidbody2D: + serializedVersion: 4 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5508245818244581766} + m_BodyType: 0 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 1 + m_Mass: 5 + m_LinearDrag: 0 + m_AngularDrag: 0.05 + m_GravityScale: 0 + m_Material: {fileID: 0} + m_Interpolate: 0 + m_SleepingMode: 1 + m_CollisionDetection: 0 + m_Constraints: 0 +--- !u!58 &5758426961102176851 +CircleCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5508245818244581766} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: 0} + serializedVersion: 2 + m_Radius: 0.5 diff --git a/Assets/Prefabs/Sun.prefab.meta b/Assets/Prefabs/Sun.prefab.meta new file mode 100644 index 0000000..156bf7d --- /dev/null +++ b/Assets/Prefabs/Sun.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 81be647bed73a164cb47269e43863cac +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index d9d2284..8c93692 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -121,140 +121,6 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} ---- !u!1 &467926748 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 467926753} - - component: {fileID: 467926752} - - component: {fileID: 467926751} - - component: {fileID: 467926750} - - component: {fileID: 467926749} - m_Layer: 0 - m_Name: Sun - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &467926749 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 467926748} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: d16f17bda197c324f8b088f106c66c5c, type: 3} - m_Name: - m_EditorClassIdentifier: - positionInList: 0 ---- !u!58 &467926750 -CircleCollider2D: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 467926748} - m_Enabled: 1 - m_Density: 1 - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_UsedByEffector: 0 - m_UsedByComposite: 0 - m_Offset: {x: 0, y: 0} - serializedVersion: 2 - m_Radius: 0.5 ---- !u!50 &467926751 -Rigidbody2D: - serializedVersion: 4 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 467926748} - m_BodyType: 0 - m_Simulated: 1 - m_UseFullKinematicContacts: 0 - m_UseAutoMass: 0 - m_Mass: 10 - m_LinearDrag: 0 - m_AngularDrag: 0.05 - m_GravityScale: 0 - m_Material: {fileID: 0} - m_Interpolate: 0 - m_SleepingMode: 1 - m_CollisionDetection: 0 - m_Constraints: 0 ---- !u!212 &467926752 -SpriteRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 467926748} - m_Enabled: 1 - m_CastShadows: 0 - m_ReceiveShadows: 0 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 0 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_Sprite: {fileID: 21300000, guid: d8cf31929ca287542bdc219ec19f002e, type: 3} - m_Color: {r: 1, g: 1, b: 0, a: 1} - m_FlipX: 0 - m_FlipY: 0 - m_DrawMode: 0 - m_Size: {x: 1, y: 1} - m_AdaptiveModeThreshold: 0.5 - m_SpriteTileMode: 0 - m_WasSpriteAssigned: 1 - m_MaskInteraction: 0 - m_SpriteSortPoint: 0 ---- !u!4 &467926753 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 467926748} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 2, y: 2, z: 2} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &1803533283597936005 PrefabInstance: m_ObjectHideFlags: 0 @@ -391,5 +257,10 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 1504932582, guid: 6baf9ec6ad712d940a83a3bf6ae3e6b1, type: 3} + propertyPath: prefabToSpawn + value: + objectReference: {fileID: 5473375028011702754, guid: e73d8e05bd7498c4a80a63094f4594a8, + type: 3} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 6baf9ec6ad712d940a83a3bf6ae3e6b1, type: 3}