-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Add/Update] Add Explosion with pooling, Update RecyclableObject
- Loading branch information
1 parent
d30a0cc
commit 79a67a6
Showing
9 changed files
with
271 additions
and
26 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
MissileCommander/.idea/.idea.MissileCommander/.idea/contentModel.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!1 &2187720768327935215 | ||
GameObject: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
serializedVersion: 6 | ||
m_Component: | ||
- component: {fileID: 1153937608142943101} | ||
- component: {fileID: 8552799194955677352} | ||
m_Layer: 0 | ||
m_Name: Explosion_0 | ||
m_TagString: Untagged | ||
m_Icon: {fileID: 0} | ||
m_NavMeshLayer: 0 | ||
m_StaticEditorFlags: 0 | ||
m_IsActive: 1 | ||
--- !u!4 &1153937608142943101 | ||
Transform: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 2187720768327935215} | ||
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: 2650854474031818298} | ||
m_RootOrder: 0 | ||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||
--- !u!212 &8552799194955677352 | ||
SpriteRenderer: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 2187720768327935215} | ||
m_Enabled: 1 | ||
m_CastShadows: 0 | ||
m_ReceiveShadows: 0 | ||
m_DynamicOccludee: 1 | ||
m_MotionVectors: 1 | ||
m_LightProbeUsage: 1 | ||
m_ReflectionProbeUsage: 1 | ||
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: 5986030973748356752, guid: 32fd08a7ced0c4831a4dc8b738dbd1d0, | ||
type: 3} | ||
m_Color: {r: 1, g: 1, b: 1, a: 1} | ||
m_FlipX: 0 | ||
m_FlipY: 0 | ||
m_DrawMode: 0 | ||
m_Size: {x: 1.4, y: 1.4} | ||
m_AdaptiveModeThreshold: 0.5 | ||
m_SpriteTileMode: 0 | ||
m_WasSpriteAssigned: 1 | ||
m_MaskInteraction: 0 | ||
m_SpriteSortPoint: 0 | ||
--- !u!1 &6469101167713022457 | ||
GameObject: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
serializedVersion: 6 | ||
m_Component: | ||
- component: {fileID: 2650854474031818298} | ||
- component: {fileID: 336636678138189459} | ||
- component: {fileID: 1962218832182758602} | ||
- component: {fileID: 8426078496689282687} | ||
m_Layer: 0 | ||
m_Name: Explosion | ||
m_TagString: Untagged | ||
m_Icon: {fileID: 0} | ||
m_NavMeshLayer: 0 | ||
m_StaticEditorFlags: 0 | ||
m_IsActive: 1 | ||
--- !u!4 &2650854474031818298 | ||
Transform: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 6469101167713022457} | ||
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: 1153937608142943101} | ||
m_Father: {fileID: 0} | ||
m_RootOrder: 0 | ||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||
--- !u!50 &336636678138189459 | ||
Rigidbody2D: | ||
serializedVersion: 4 | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 6469101167713022457} | ||
m_BodyType: 1 | ||
m_Simulated: 1 | ||
m_UseFullKinematicContacts: 0 | ||
m_UseAutoMass: 0 | ||
m_Mass: 1 | ||
m_LinearDrag: 0 | ||
m_AngularDrag: 0.05 | ||
m_GravityScale: 1 | ||
m_Material: {fileID: 0} | ||
m_Interpolate: 0 | ||
m_SleepingMode: 1 | ||
m_CollisionDetection: 0 | ||
m_Constraints: 0 | ||
--- !u!58 &1962218832182758602 | ||
CircleCollider2D: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 6469101167713022457} | ||
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.5 | ||
--- !u!114 &8426078496689282687 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 6469101167713022457} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: f169c4ff18df452ea48010f9ab81b821, type: 3} | ||
m_Name: | ||
m_EditorClassIdentifier: | ||
_timeToRemove: 1 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace MissileCommander | ||
{ | ||
[RequireComponent(typeof(Rigidbody2D), typeof(CircleCollider2D))] | ||
public class Explosion : RecyclableObject | ||
{ | ||
private Rigidbody2D _rigidbody2D; | ||
private CircleCollider2D _circleCollider2D; | ||
|
||
[SerializeField] private float timeToRemove = 1f; | ||
private float _elapsedTime; | ||
|
||
private void Awake() | ||
{ | ||
_rigidbody2D = GetComponent<Rigidbody2D>(); | ||
_circleCollider2D = GetComponent<CircleCollider2D>(); | ||
|
||
_rigidbody2D.bodyType = RigidbodyType2D.Kinematic; | ||
_circleCollider2D.isTrigger = true; | ||
} | ||
|
||
private void Update() | ||
{ | ||
if (isActivated) | ||
{ | ||
_elapsedTime += Time.deltaTime; | ||
if (_elapsedTime >= timeToRemove) | ||
{ | ||
_elapsedTime = 0f; | ||
DestroySelf(); | ||
} | ||
} | ||
} | ||
|
||
private void DestroySelf() | ||
{ | ||
isActivated = false; | ||
onDestroyed?.Invoke(this); | ||
Debug.Log($"{gameObject.name} is Destroyed!"); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,32 @@ | ||
using UnityEngine; | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace MissileCommander | ||
{ | ||
public class RecyclableObject : MonoBehaviour | ||
{ | ||
protected bool isActivated = false; | ||
protected Vector3 targetPosition; | ||
public Action<RecyclableObject> onDestroyed; | ||
|
||
private Transform _cachedTransform; | ||
public Transform CachedTransform => _cachedTransform ? _cachedTransform : (_cachedTransform = transform); | ||
|
||
|
||
public virtual void Activate(Vector3 position) | ||
{ | ||
isActivated = true; | ||
transform.position = position; | ||
} | ||
|
||
public virtual void Activate(Vector3 startPos, Vector3 targetPos) | ||
{ | ||
this.targetPosition = targetPos; | ||
|
||
Vector3 direction = (targetPos - startPos).normalized; | ||
CachedTransform.SetPositionAndRotation(startPos, | ||
Quaternion.LookRotation(CachedTransform.forward, direction)); | ||
isActivated = true; | ||
} | ||
} | ||
} |