Skip to content

Commit

Permalink
[Update] Update DestroyEffect spawn position, Bind event
Browse files Browse the repository at this point in the history
  • Loading branch information
SeungHuLee committed Dec 3, 2019
1 parent 5fa42dd commit 805b9c2
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 127 additions & 0 deletions MissileCommander/Assets/Game/Core/DestroyEffect.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &6752188890843315280
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7176714262414095371}
- component: {fileID: 8081201054838013091}
m_Layer: 0
m_Name: DestroyEffect_0
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7176714262414095371
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6752188890843315280}
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: 8440115618531013871}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &8081201054838013091
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6752188890843315280}
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: -1864373156434754777, guid: a288b627034cd4497ab612861d948f9a,
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.2, y: 1.2}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!1 &6951797282581088142
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8440115618531013871}
- component: {fileID: 6117580419327657503}
m_Layer: 0
m_Name: DestroyEffect
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8440115618531013871
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6951797282581088142}
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: 7176714262414095371}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &6117580419327657503
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6951797282581088142}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cdbcc414a06341c5a9585ad907a01c32, type: 3}
m_Name:
m_EditorClassIdentifier:
7 changes: 7 additions & 0 deletions MissileCommander/Assets/Game/Core/DestroyEffect.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions MissileCommander/Assets/_Scripts/BuildingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public Vector3 GetRandomBuildingPosition()
private void OnBuildingDestroyed(Building building)
{
Vector3 lastPos = building.transform.position;
lastPos.y += building.GetComponent<BoxCollider2D>().size.y * 0.5f;

building.onDestroyed -= this.OnBuildingDestroyed;
int index = _buildings.IndexOf(building);
Expand All @@ -63,6 +64,13 @@ private void OnBuildingDestroyed(Building building)

RecyclableObject effect = _effectFactory.Get();
effect.Activate(lastPos);
effect.onDestroyed += OnEffectDestroyed;
}

private void OnEffectDestroyed(RecyclableObject effect)
{
effect.onDestroyed -= this.OnEffectDestroyed;
_effectFactory.ReturnToPool(effect);
}
}
}
20 changes: 18 additions & 2 deletions MissileCommander/Assets/_Scripts/DestroyEffect.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
using UnityEngine;
using System;
using UnityEngine;

namespace MissileCommander
{
public class DestroyEffect : RecyclableObject
{

[SerializeField] private float effectTime = 0.5f;
private float _elapsedTime = 0f;

private void Update()
{
if (!isActivated) { return; }

_elapsedTime += Time.deltaTime;
if (_elapsedTime >= effectTime)
{
_elapsedTime = 0f;
isActivated = false;

onDestroyed?.Invoke(this);
}
}
}
}

0 comments on commit 805b9c2

Please sign in to comment.