1
Fork 0
mirror of https://github.com/Steffo99/gravity-fusion.git synced 2024-11-21 16:04:18 +00:00

Merge into suns

This commit is contained in:
Steffo 2019-10-05 13:06:48 +02:00
parent fe03b38480
commit bd75ae9524
7 changed files with 248 additions and 147 deletions

View file

@ -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<Merge>();
mergeables.Add(otherMerge);
if(CanMerge()) DoMerge();
if(otherMerge != null) {
mergeables.Add(otherMerge);
if(CanMerge()) DoMerge();
}
}
private void OnTriggerExit2D(Collider2D other) {
Merge otherMerge = other.GetComponent<Merge>();
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>();
mergedInfo.mergedCount = mergeables.Count;
foreach(Merge merged in mergeables) {
foreach(Merge merged in mergeables.ToArray()) {
Rigidbody2D mergedBody = merged.GetComponentInParent<Rigidbody2D>();
if(mergedBody != null) {
mergedInfo.mergedMass += mergedBody.mass;
}
Destroy(merged.transform.parent);
Destroy(merged.transform.parent.gameObject);
}
if(setMergedMassFromTotal) {
Rigidbody2D mergeRigidbody = mergeResult.GetComponent<Rigidbody2D>();
if(mergeRigidbody != null) {
mergeRigidbody.useAutoMass = false;
mergeRigidbody.mass = mergedInfo.mergedMass;
}
}
}
}

View file

@ -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

View file

@ -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}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: d810808c92b542d418721ca53dca1fee
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

122
Assets/Prefabs/Sun.prefab Normal file
View file

@ -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

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 81be647bed73a164cb47269e43863cac
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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}