From 3d9870b82513c2aeb474e2f131a61708d9046247 Mon Sep 17 00:00:00 2001 From: miepzerino <o.skotnik@gmail.com> Date: Mon, 25 Dec 2023 23:19:58 +0000 Subject: [PATCH] Added drillable prefab to tilemap --- Assets/Characters/Player/AC_Player.controller | 58 +++++++++++++ Assets/Scripts/GenerateTileMap.cs.meta | 0 Assets/Scripts/Drillable.cs | 9 ++ Assets/TileSets/Palettes/ForestRuleTile.asset | 34 ++++---- Assets/Scripts/Managers/GameManager.cs | 19 +++- Assets/Scripts/PlayerController.cs | 43 +++++++--- Assets/Scripts/Drillable.cs.meta | 11 ++ TODOs | 1 Assets/TileSets/Palettes/DrillForest (drillable).prefab | 47 +++++++++++ Assets/Scripts/GenerateTileMap.cs | 5 Assets/TileSets/Palettes/DrillForest (drillable).prefab.meta | 7 + Assets/Scripts/Events/CharacterEvents.cs | 3 12 files changed, 192 insertions(+), 45 deletions(-) diff --git a/Assets/Characters/Player/AC_Player.controller b/Assets/Characters/Player/AC_Player.controller index cc443ad..485ff29 100644 --- a/Assets/Characters/Player/AC_Player.controller +++ b/Assets/Characters/Player/AC_Player.controller @@ -1,5 +1,30 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!1101 &-9087441188423582307 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 1 + m_ConditionEvent: IsDrillingLeftRight + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: -5387081852353806967} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0 + m_TransitionOffset: 0 + m_ExitTime: 0.875 + m_HasExitTime: 0 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 --- !u!1101 &-8857883071945152901 AnimatorStateTransition: m_ObjectHideFlags: 1 @@ -96,7 +121,7 @@ m_Position: {x: 620, y: 110, z: 0} - serializedVersion: 1 m_State: {fileID: 7984510369417086179} - m_Position: {x: 620, y: 200, z: 0} + m_Position: {x: 870, y: 200, z: 0} - serializedVersion: 1 m_State: {fileID: -8776216366201631375} m_Position: {x: 620, y: 300, z: 0} @@ -106,7 +131,7 @@ m_ChildStateMachines: - serializedVersion: 1 m_StateMachine: {fileID: -870871217648341797} - m_Position: {x: 470, y: -20, z: 0} + m_Position: {x: 620, y: -20, z: 0} m_AnyStateTransitions: [] m_EntryTransitions: [] m_StateMachineTransitions: {} @@ -114,7 +139,7 @@ m_AnyStatePosition: {x: 400, y: 310, z: 0} m_EntryPosition: {x: 50, y: 120, z: 0} m_ExitPosition: {x: 990, y: -40, z: 0} - m_ParentStateMachinePosition: {x: 830, y: 50, z: 0} + m_ParentStateMachinePosition: {x: 1070, y: 50, z: 0} m_DefaultState: {fileID: 68305137226140118} --- !u!1101 &-7913474699216770149 AnimatorStateTransition: @@ -211,6 +236,31 @@ playOnExit: 0 playAfterDelay: 0 playDelay: 0.25 +--- !u!1101 &-7054651801772689705 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 1 + m_ConditionEvent: IsDrillingDown + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: -7772001631268269027} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0 + m_TransitionOffset: 0 + m_ExitTime: 0.875 + m_HasExitTime: 0 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 --- !u!1102 &-5387081852353806967 AnimatorState: serializedVersion: 6 @@ -768,6 +818,8 @@ - {fileID: 1760657886866949958} - {fileID: -8857883071945152901} - {fileID: 3484489205103101802} + - {fileID: -9087441188423582307} + - {fileID: -7054651801772689705} m_StateMachineBehaviours: [] m_Position: {x: 50, y: 50, z: 0} m_IKOnFeet: 0 diff --git a/Assets/Scripts/Drillable.cs b/Assets/Scripts/Drillable.cs new file mode 100644 index 0000000..5c49a62 --- /dev/null +++ b/Assets/Scripts/Drillable.cs @@ -0,0 +1,9 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Drillable : MonoBehaviour +{ + public bool isDrillable = true; + +} diff --git a/Assets/Scripts/Drillable.cs.meta b/Assets/Scripts/Drillable.cs.meta new file mode 100644 index 0000000..3989369 --- /dev/null +++ b/Assets/Scripts/Drillable.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e273e4680f5bb884cad50c1fbda3d211 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Events/CharacterEvents.cs b/Assets/Scripts/Events/CharacterEvents.cs index 51c31e3..2e71dad 100644 --- a/Assets/Scripts/Events/CharacterEvents.cs +++ b/Assets/Scripts/Events/CharacterEvents.cs @@ -9,5 +9,6 @@ public static UnityAction<GameObject, int> characterDamaged; public static UnityAction<GameObject, int> characterHealed; public static UnityAction<ContactPoint2D, DrillDirection> characterDrill; - public static UnityAction<Vector3> characterDrillingToPosition; + public static UnityAction<Vector3, DrillDirection> characterDrillingToPosition; + public static UnityAction characterDrillingToPositionAbort; } diff --git a/Assets/GenerateTileMap.cs b/Assets/Scripts/GenerateTileMap.cs similarity index 93% rename from Assets/GenerateTileMap.cs rename to Assets/Scripts/GenerateTileMap.cs index 46742ed..6d5d630 100644 --- a/Assets/GenerateTileMap.cs +++ b/Assets/Scripts/GenerateTileMap.cs @@ -14,7 +14,8 @@ private float offsetX; private float offsetY; Tilemap tilemap; - public RuleTile ruleTile; + public RuleTile forestRuleTile; + public TileBase borderTile; //public List<TileBase> tiles; private void Awake() @@ -70,7 +71,7 @@ { if (!destroyedTiles.Contains(new Vector3Int(x, y, 0))) { - tilemap.SetTile(new Vector3Int(x, y), ruleTile); + tilemap.SetTile(new Vector3Int(x, y), forestRuleTile); } } diff --git a/Assets/GenerateTileMap.cs.meta b/Assets/Scripts/GenerateTileMap.cs.meta similarity index 100% rename from Assets/GenerateTileMap.cs.meta rename to Assets/Scripts/GenerateTileMap.cs.meta diff --git a/Assets/Scripts/Managers/GameManager.cs b/Assets/Scripts/Managers/GameManager.cs index 13f8eb3..61f90f9 100644 --- a/Assets/Scripts/Managers/GameManager.cs +++ b/Assets/Scripts/Managers/GameManager.cs @@ -129,12 +129,19 @@ //Debug.Log(tilemap.HasTile(cellCoord)); if (tilemap.HasTile(cellCoord)) { - tilemap.SetTile(cellCoord, null); - destroyedTiles.Add(cellCoord); - Vector3 moveToPosition = grid.CellToWorld(cellCoord); - moveToPosition.x += 0.5f; - moveToPosition.y += 0.5f; - CharacterEvents.characterDrillingToPosition.Invoke(moveToPosition); + if (tilemap.GetInstantiatedObject(cellCoord)?.GetComponent<Drillable>()?.isDrillable ?? false) + { + tilemap.SetTile(cellCoord, null); + destroyedTiles.Add(cellCoord); + Vector3 moveToPosition = grid.CellToWorld(cellCoord); + moveToPosition.x += 0.5f; + moveToPosition.y += 0.5f; + CharacterEvents.characterDrillingToPosition.Invoke(moveToPosition, drillDirection); + } + else + { + //CharacterEvents.characterDrillingToPositionAbort.Invoke(moveToPosition); + } } } #endregion diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 953e277..dd88855 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -141,11 +141,13 @@ private void OnEnable() { CharacterEvents.characterDrillingToPosition += (DrillingToPosition); + //CharacterEvents.characterDrillingToPositionAbort += (DrillingToPositionAbort); } private void OnDisable() { CharacterEvents.characterDrillingToPosition -= (DrillingToPosition); + //CharacterEvents.characterDrillingToPositionAbort -= (DrillingToPositionAbort); } private void Awake() @@ -300,26 +302,26 @@ //Debug.Log(contactPoints[0].otherRigidbody?.gameObject.name); if (contactPoints[0].otherRigidbody?.name == "Tilemap") { - boxCollider.enabled = false; - switch (drillDirection) - { - case DrillDirection.Left: - case DrillDirection.Right: - IsDrillingLeftRight = true; - break; - case DrillDirection.Down: - IsDrillingDown = true; - break; - default: - Debug.Assert(false, "Add DrillDirection here!"); - break; - } CharacterEvents.characterDrill.Invoke(contactPoints[0], drillDirection); } } - private void DrillingToPosition(Vector3 tilePosition) + private void DrillingToPosition(Vector3 tilePosition, DrillDirection drillDirection) { + boxCollider.enabled = false; + switch (drillDirection) + { + case DrillDirection.Left: + case DrillDirection.Right: + IsDrillingLeftRight = true; + break; + case DrillDirection.Down: + IsDrillingDown = true; + break; + default: + Debug.Assert(false, "Add DrillDirection here!"); + break; + } //Debug.Log("DrillingToPosition() called"); //Debug.Log(gameObject.transform.position); drillToPosition = true; @@ -328,6 +330,17 @@ drillOriginalPosition = gameObject.transform.position; //Debug.Log("drillOriginalPosition: " + drillOriginalPosition); } + //private void DrillingToPositionAbort() + //{ + // IsDrilling = false; + // //Debug.Log("DrillingToPosition() called"); + // //Debug.Log(gameObject.transform.position); + // drillToPosition = false; + // //drillTilePosition = null; + // //Debug.Log("drillTilePosition: " + drillTilePosition); + // drillOriginalPosition = gameObject.transform.position; + // //Debug.Log("drillOriginalPosition: " + drillOriginalPosition); + //} //private void DrillLeftOrRight() //{ diff --git "a/Assets/TileSets/Palettes/DrillForest \050drillable\051.prefab" "b/Assets/TileSets/Palettes/DrillForest \050drillable\051.prefab" new file mode 100644 index 0000000..2b07141 --- /dev/null +++ "b/Assets/TileSets/Palettes/DrillForest \050drillable\051.prefab" @@ -0,0 +1,47 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &3549545049718014148 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 8973229189939374991} + - component: {fileID: -776302461885629690} + m_Layer: 0 + m_Name: DrillForest (drillable) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &8973229189939374991 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148} + serializedVersion: 2 + 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_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &-776302461885629690 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e273e4680f5bb884cad50c1fbda3d211, type: 3} + m_Name: + m_EditorClassIdentifier: + isDrillable: 1 diff --git "a/Assets/TileSets/Palettes/DrillForest \050drillable\051.prefab.meta" "b/Assets/TileSets/Palettes/DrillForest \050drillable\051.prefab.meta" new file mode 100644 index 0000000..5d44362 --- /dev/null +++ "b/Assets/TileSets/Palettes/DrillForest \050drillable\051.prefab.meta" @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: c82bc431abdeded4ab41cfdd19459501 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TileSets/Palettes/ForestRuleTile.asset b/Assets/TileSets/Palettes/ForestRuleTile.asset index d13a705..9a18a00 100644 --- a/Assets/TileSets/Palettes/ForestRuleTile.asset +++ b/Assets/TileSets/Palettes/ForestRuleTile.asset @@ -13,13 +13,13 @@ m_Name: ForestRuleTile m_EditorClassIdentifier: m_DefaultSprite: {fileID: -1554015212, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_DefaultGameObject: {fileID: 0} + m_DefaultGameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_DefaultColliderType: 1 m_TilingRules: - m_Id: 0 m_Sprites: - {fileID: -1200237691, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_MinAnimationSpeed: 1 m_MaxAnimationSpeed: 1 m_PerlinScale: 0.5 @@ -35,7 +35,7 @@ - m_Id: 1 m_Sprites: - {fileID: -1554015212, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_MinAnimationSpeed: 1 m_MaxAnimationSpeed: 1 m_PerlinScale: 0.5 @@ -51,7 +51,7 @@ - m_Id: 2 m_Sprites: - {fileID: 952801214, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_MinAnimationSpeed: 1 m_MaxAnimationSpeed: 1 m_PerlinScale: 0.5 @@ -67,7 +67,7 @@ - m_Id: 3 m_Sprites: - {fileID: -1701200628, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_MinAnimationSpeed: 1 m_MaxAnimationSpeed: 1 m_PerlinScale: 0.5 @@ -84,7 +84,7 @@ - m_Id: 4 m_Sprites: - {fileID: 1210147125, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_MinAnimationSpeed: 1 m_MaxAnimationSpeed: 1 m_PerlinScale: 0.5 @@ -101,7 +101,7 @@ - m_Id: 5 m_Sprites: - {fileID: -603009601, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_MinAnimationSpeed: 1 m_MaxAnimationSpeed: 1 m_PerlinScale: 0.5 @@ -120,7 +120,7 @@ - m_Id: 6 m_Sprites: - {fileID: -1438444955, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_MinAnimationSpeed: 1 m_MaxAnimationSpeed: 1 m_PerlinScale: 0.5 @@ -137,7 +137,7 @@ - m_Id: 7 m_Sprites: - {fileID: -1608621674, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_MinAnimationSpeed: 1 m_MaxAnimationSpeed: 1 m_PerlinScale: 0.5 @@ -155,7 +155,7 @@ m_Sprites: - {fileID: 68800321, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - {fileID: 1862643484, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_MinAnimationSpeed: 1 m_MaxAnimationSpeed: 1 m_PerlinScale: 0.703 @@ -176,7 +176,7 @@ - m_Id: 9 m_Sprites: - {fileID: 1984530201, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_MinAnimationSpeed: 1 m_MaxAnimationSpeed: 1 m_PerlinScale: 0.5 @@ -194,7 +194,7 @@ - m_Id: 10 m_Sprites: - {fileID: -58827736, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_MinAnimationSpeed: 1 m_MaxAnimationSpeed: 1 m_PerlinScale: 0.5 @@ -212,7 +212,7 @@ - m_Id: 11 m_Sprites: - {fileID: 1943074245, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_MinAnimationSpeed: 1 m_MaxAnimationSpeed: 1 m_PerlinScale: 0.5 @@ -229,7 +229,7 @@ - m_Id: 13 m_Sprites: - {fileID: 956194596, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_MinAnimationSpeed: 1 m_MaxAnimationSpeed: 1 m_PerlinScale: 0.5 @@ -250,7 +250,7 @@ - m_Id: 16 m_Sprites: - {fileID: -855959738, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_MinAnimationSpeed: 1 m_MaxAnimationSpeed: 1 m_PerlinScale: 0.5 @@ -271,7 +271,7 @@ - m_Id: 14 m_Sprites: - {fileID: 1598334396, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_MinAnimationSpeed: 1 m_MaxAnimationSpeed: 1 m_PerlinScale: 0.5 @@ -292,7 +292,7 @@ - m_Id: 15 m_Sprites: - {fileID: 1451081626, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 3549545049718014148, guid: c82bc431abdeded4ab41cfdd19459501, type: 3} m_MinAnimationSpeed: 1 m_MaxAnimationSpeed: 1 m_PerlinScale: 0.5 diff --git a/TODOs b/TODOs index 3d69621..fa95e41 100644 --- a/TODOs +++ b/TODOs @@ -14,7 +14,6 @@ NEXT - Add drillable gameobject to tiles Add borders to map Add background to map -- Gitblit v1.9.3