Skip to content

Commit

Permalink
fix-asteroid
Browse files Browse the repository at this point in the history
  • Loading branch information
AliceMonGithub committed Jul 2, 2023
1 parent 0bd4859 commit 35e9059
Show file tree
Hide file tree
Showing 31 changed files with 2,423 additions and 266 deletions.
113 changes: 113 additions & 0 deletions Assets/Content/Prefabs/Asteroid.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4763396351559766122
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4763396351559766127}
- component: {fileID: 4763396351559766126}
- component: {fileID: 4763396351559766125}
- component: {fileID: 4763396351559766124}
- component: {fileID: 4763396351559766123}
m_Layer: 0
m_Name: Asteroid
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4763396351559766127
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4763396351559766122}
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_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &4763396351559766126
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4763396351559766122}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &4763396351559766125
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4763396351559766122}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10303, 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: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!135 &4763396351559766124
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4763396351559766122}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &4763396351559766123
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4763396351559766122}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e1f185a3cf0cb234c8b5242579f4aaca, type: 3}
m_Name:
m_EditorClassIdentifier:
_transform: {fileID: 4763396351559766127}
7 changes: 7 additions & 0 deletions Assets/Content/Prefabs/Asteroid.prefab.meta

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

45 changes: 39 additions & 6 deletions Assets/Content/Scenes/Game/Game.unity
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &10621123
GameObject:
Expand Down Expand Up @@ -385,15 +385,17 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
_brickPrefab: {fileID: 2924173047908104221, guid: 04e413ce033e11a40a28920ebd9f0faf, type: 3}
_asteroidPrefab: {fileID: 4763396351559766123, guid: de433ae923e100f4198d5bf8f9994335, type: 3}
_ghostPrefab: {fileID: 3688605834632060143, guid: 9eba08440d2d86d41ae8948ea9774d67, type: 3}
_brickBootstrapper: {fileID: 371654050}
_startPosition: {x: 0, y: 5, z: 0}
_surfaceSize: {x: 3, y: 3}
_worldPositionAnchor: {fileID: 2125726324}
_asteroidSpawnPoint: {fileID: 1989299151}
_brickInput: {fileID: 127704352}
_asteroidDestroyArea:
- {x: 0, y: 0, z: 0}
_asteroidFlyTimer: 4
_asteroidFlyTimer: 2.5
--- !u!114 &129096733
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -769,7 +771,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 069879b598f57c144b4092444aea33f2, type: 3}
m_Name:
m_EditorClassIdentifier:
_lowerTick: 99
_lowerTick: 3
_startBrickPosition: {x: 0, y: 5, z: 0}
--- !u!1 &427632497
GameObject:
Expand Down Expand Up @@ -885,7 +887,7 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &541241257
GameObject:
Expand Down Expand Up @@ -2116,10 +2118,41 @@ MonoBehaviour:
m_GameObject: {fileID: 1979752294}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0d88d00c9e667bd469f2ab08733116e4, type: 3}
m_Script: {fileID: 11500000, guid: bec72f860cf6b9142a5afb8ca9f39dd0, type: 3}
m_Name:
m_EditorClassIdentifier:
_asteroidSpawnRate: 5
_spawnIfCounterValueIs: 4
--- !u!1 &1989299150
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1989299151}
m_Layer: 0
m_Name: AsteroidSpawnPoint
m_TagString: Untagged
m_Icon: {fileID: 7148428337604731935, guid: 0000000000000000d000000000000000, type: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1989299151
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1989299150}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -12.86, y: 5.69, z: 2.76}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2012905826
GameObject:
m_ObjectHideFlags: 0
Expand Down
44 changes: 0 additions & 44 deletions Assets/Sources/Client/AsteroidLogic/AsteroidsBootstrapper.cs

This file was deleted.

8 changes: 8 additions & 0 deletions Assets/Sources/Client/AsteroidLogic/Bootstrapper.meta

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Client.BootstrapperLogic;
using Server.AsteroidLogic;
using Server.BrickLogic;
using UnityEngine;
using Zenject;

namespace Client.AsteroidLogic
{
internal sealed class AsteroidsBootstrapper : Bootstrapper
{
[SerializeField] private float _spawnIfCounterValueIs;

[Space]

private AsteroidWrapper _asteroidWrapper;
private IAsteroidViewFactory _factory;
private IReadOnlyBricksDatabase _database;

private int _counter;

[Inject]
private void Constructor(AsteroidWrapper asteroidWrapper, IAsteroidViewFactory factory, IReadOnlyBricksDatabase database)
{
_asteroidWrapper = asteroidWrapper;
_factory = factory;
_database = database;
}

public override void Boot()
{
_database.OnAddBrick += UpdateCounter;
}

private void UpdateCounter()
{
_counter++;

if(_counter >= _spawnIfCounterValueIs)
{
SpawnAsteroid();

_counter = 0;
}
}

private void Update()
{
_asteroidWrapper.FlyTick();
}

private void SpawnAsteroid()
{
IReadOnlyAsteroid instance;

try
{
instance = _asteroidWrapper.TryThrowRandomAsteroid();
}
catch
{
return;
}

AsteroidView viewInstance = _factory.Create(instance.Target);

viewInstance.SetCallbacks(instance, _database.Surface);
}
}
}

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

8 changes: 8 additions & 0 deletions Assets/Sources/Client/AsteroidLogic/Factories.meta

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using UnityEngine;

namespace Client.AsteroidLogic
{
internal sealed class AsteroidViewFactory : IAsteroidViewFactory
{
private readonly AsteroidView _prefab;
private readonly Transform _spawnPoint;

public AsteroidViewFactory(AsteroidView prefab, Transform spawnPoint)
{
_prefab = prefab;
_spawnPoint = spawnPoint;
}

public AsteroidView Create(Vector3Int target)
{
AsteroidView instance = Object.Instantiate(_prefab, _spawnPoint.position, Quaternion.identity);

instance.Initialize(target);

return instance;
}
}
}

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

Loading

0 comments on commit 35e9059

Please sign in to comment.