From 05602258ff3ce5fc73382278613886f8efd5dc9d Mon Sep 17 00:00:00 2001 From: Saibotk Date: Sun, 22 Apr 2018 11:27:09 +0200 Subject: [PATCH] WIP Room enter detection --- Assets/Prefabs/StartingRoom.prefab | 63 ++++++++++---- Assets/Scripts/Door.cs | 12 +++ Assets/Scripts/EnemyAI.cs | 10 ++- Assets/Scripts/Entities/Player.cs | 2 +- Assets/Scripts/GameController.cs | 7 +- Assets/Scripts/Room.cs | 19 ++++- .../textures/FixedObjects/Rock/Thumbs.db.meta | 7 -- .../textures/FixedObjects/coin.png.meta | 84 +++++++++++++++++++ 8 files changed, 175 insertions(+), 29 deletions(-) delete mode 100644 Assets/graphics/textures/FixedObjects/Rock/Thumbs.db.meta create mode 100644 Assets/graphics/textures/FixedObjects/coin.png.meta diff --git a/Assets/Prefabs/StartingRoom.prefab b/Assets/Prefabs/StartingRoom.prefab index 4276024..dcc213f 100644 --- a/Assets/Prefabs/StartingRoom.prefab +++ b/Assets/Prefabs/StartingRoom.prefab @@ -160,6 +160,21 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 +--- !u!1 &1448116197164334 +GameObject: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 4460105983878628} + m_Layer: 0 + m_Name: Spawn + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 --- !u!1 &1528048736566048 GameObject: m_ObjectHideFlags: 1 @@ -169,7 +184,7 @@ GameObject: m_Component: - component: {fileID: 4871197587417858} m_Layer: 0 - m_Name: Spawn + m_Name: Spawn (1) m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -262,6 +277,7 @@ Transform: m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: + - {fileID: 4460105983878628} - {fileID: 4871197587417858} m_Father: {fileID: 4524829645232432} m_RootOrder: 0 @@ -287,12 +303,25 @@ Transform: m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1376851329299758} m_LocalRotation: {x: -0, y: -0, z: 0.7071068, w: 0.7071068} - m_LocalPosition: {x: -0.87, y: 9.56, z: 0} - m_LocalScale: {x: 0.10000005, y: 3.000002, z: 1} + m_LocalPosition: {x: 7.705, y: 9.56, z: 0} + m_LocalScale: {x: 0.10000005, y: 1.2849555, z: 1} m_Children: [] m_Father: {fileID: 4896145802546722} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!4 &4460105983878628 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1448116197164334} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -9, y: -4.8, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 4405955685927858} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &4524829645232432 Transform: m_ObjectHideFlags: 1 @@ -309,7 +338,7 @@ Transform: - {fileID: 4896145802546722} m_Father: {fileID: 0} m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: -180.00002} --- !u!4 &4615890080890712 Transform: m_ObjectHideFlags: 1 @@ -342,12 +371,12 @@ Transform: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1528048736566048} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 7.7, y: -0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 4405955685927858} - m_RootOrder: 0 + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!4 &4896145802546722 Transform: @@ -374,7 +403,7 @@ Transform: m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1210523432952560} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 9, z: 0} + m_LocalPosition: {x: 0, y: 9.5, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 4858022253936394} @@ -427,8 +456,8 @@ Transform: m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1691542046289400} m_LocalRotation: {x: -0, y: -0, z: 0.7071068, w: 0.7071068} - m_LocalPosition: {x: -0.87, y: 9.56, z: 0} - m_LocalScale: {x: 0.1, y: 3, z: 1} + m_LocalPosition: {x: -8.523, y: 9.56, z: 0} + m_LocalScale: {x: 0.1, y: 1.4693071, z: 1} m_Children: [] m_Father: {fileID: 4896145802546722} m_RootOrder: 0 @@ -495,7 +524,7 @@ BoxCollider2D: m_IsTrigger: 0 m_UsedByEffector: 0 m_UsedByComposite: 0 - m_Offset: {x: 0, y: 2.5762396} + m_Offset: {x: 0, y: 0.10486436} m_SpriteTilingProperty: border: {x: 0, y: 0, z: 0, w: 0} pivot: {x: 0.5, y: 0.5} @@ -506,7 +535,7 @@ BoxCollider2D: adaptiveTiling: 0 m_AutoTiling: 0 serializedVersion: 2 - m_Size: {x: 10, y: 4.847521} + m_Size: {x: 10, y: 9.790272} m_EdgeRadius: 0 --- !u!61 &61328448285356816 BoxCollider2D: @@ -570,7 +599,7 @@ BoxCollider2D: m_IsTrigger: 0 m_UsedByEffector: 0 m_UsedByComposite: 0 - m_Offset: {x: 0, y: -2.8089824} + m_Offset: {x: 0, y: -0.11346984} m_SpriteTilingProperty: border: {x: 0, y: 0, z: 0, w: 0} pivot: {x: 0.5, y: 0.5} @@ -581,7 +610,7 @@ BoxCollider2D: adaptiveTiling: 0 m_AutoTiling: 0 serializedVersion: 2 - m_Size: {x: 10, y: 4.3820353} + m_Size: {x: 10, y: 9.77306} m_EdgeRadius: 0 --- !u!61 &61881867638551418 BoxCollider2D: @@ -645,6 +674,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: graphics: {fileID: 1686504243753214} + parent: {fileID: 114795477922050694} --- !u!114 &114795477922050694 MonoBehaviour: m_ObjectHideFlags: 1 @@ -656,10 +686,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a031ae543e3871f4da5b6e402291b6f6, type: 3} m_Name: m_EditorClassIdentifier: - width: 0 - height: 0 doorsRootObject: {fileID: 1394898907781064} spawnpointRootObject: {fileID: 1560863483719772} + enemys: + - {fileID: 1971451785855062, guid: ff87b9de73979cd40a9853419833a91f, type: 2} + - {fileID: 1971451785855062, guid: ff87b9de73979cd40a9853419833a91f, type: 2} --- !u!212 &212157662384668488 SpriteRenderer: m_ObjectHideFlags: 1 diff --git a/Assets/Scripts/Door.cs b/Assets/Scripts/Door.cs index 083a153..a4bbe07 100644 --- a/Assets/Scripts/Door.cs +++ b/Assets/Scripts/Door.cs @@ -8,6 +8,9 @@ public class Door : MonoBehaviour { [SerializeField] GameObject graphics; + [SerializeField] + Room parent; + BoxCollider2D boundingBox; BoxCollider2D triggerBox; // Use this for initialization @@ -45,4 +48,13 @@ public class Door : MonoBehaviour { { return locked; } + + private void OnTriggerExit2D(Collider2D collision) + { + if (collision.tag == "Player") + { + Debug.Log("Leavin Trigger"); + parent.OnPlayerEnter(); + } + } } diff --git a/Assets/Scripts/EnemyAI.cs b/Assets/Scripts/EnemyAI.cs index 8877f7b..0256af2 100644 --- a/Assets/Scripts/EnemyAI.cs +++ b/Assets/Scripts/EnemyAI.cs @@ -25,6 +25,11 @@ public class EnemyAI : MonoBehaviour { // Update is called once per frame void Update () { + if(victim == null) + { + victim = GameController.instance.GetPlayer().gameObject; // TODO testing purpose only! + return; + } // movement agressor.transform.Translate (Vector3.Scale ((victim.transform.position - agressor.transform.position).normalized, new Vector2 (speed, speed))); @@ -32,5 +37,8 @@ public class EnemyAI : MonoBehaviour { agressor.transform.Rotate(agressor.transform.forward, Vector3.Angle(victim.transform.position - agressor.transform.position, agressor.transform.rotation * new Vector3(1, 1, 1))); } - + public void SetVictim(GameObject g) + { + victim = g; + } } diff --git a/Assets/Scripts/Entities/Player.cs b/Assets/Scripts/Entities/Player.cs index 5338c8c..6bdfb5c 100644 --- a/Assets/Scripts/Entities/Player.cs +++ b/Assets/Scripts/Entities/Player.cs @@ -28,7 +28,7 @@ public class Player : Mob { private void OnTriggerEnter2D(Collider2D other) { if (other.tag == "door") { - Debug.Log("Open door"); + //Debug.Log("Open door"); } } diff --git a/Assets/Scripts/GameController.cs b/Assets/Scripts/GameController.cs index c9453f2..56d2414 100644 --- a/Assets/Scripts/GameController.cs +++ b/Assets/Scripts/GameController.cs @@ -29,6 +29,11 @@ public class GameController : MonoBehaviour { private GameState state = GameState.UNSET; + public Player GetPlayer() // TODO Remove just comfort + { + return player; + } + // Use this for initialization void Start () { @@ -82,7 +87,7 @@ public class GameController : MonoBehaviour { playerPrefab }; start.SetObjective(new EntityObjective(start, tmp)); - start.GetObjective().Activate(); + start.OnPlayerEnter(); player = ((EntityObjective) start.GetObjective()).GetEntities()[0].GetComponent(); cam.GetComponent().SetFollow(player.gameObject); ((EntityObjective)start.GetObjective()).Remove(player.gameObject); diff --git a/Assets/Scripts/Room.cs b/Assets/Scripts/Room.cs index 77d8951..27c478a 100644 --- a/Assets/Scripts/Room.cs +++ b/Assets/Scripts/Room.cs @@ -4,8 +4,7 @@ using UnityEngine; public class Room : MonoBehaviour { - [SerializeField] - int width, height; // Gridsize for Generation + private bool activated; List doors; List spawnpoints; @@ -19,6 +18,12 @@ public class Room : MonoBehaviour { [SerializeField] private Objective objective; + enum ObjectiveType { EntityObjective } + // Params for testing + [SerializeField] + GameObject[] enemys; + + // Use this for initialization void Start () { doors = new List(); @@ -37,7 +42,8 @@ public class Room : MonoBehaviour { } Debug.Log("Spawnpoints in Room: " + spawnpoints.Count); - + if (enemys.Length != 0) + objective = new EntityObjective(this, new List (enemys)); //Unlock(); } @@ -69,8 +75,11 @@ public class Room : MonoBehaviour { public void OnPlayerEnter() { + if (activated) + return; if(objective != null) objective.Activate(); + activated = true; } public List GetSpawnpoints() @@ -78,5 +87,9 @@ public class Room : MonoBehaviour { return spawnpoints; } + public bool GetActivated() + { + return activated; + } } diff --git a/Assets/graphics/textures/FixedObjects/Rock/Thumbs.db.meta b/Assets/graphics/textures/FixedObjects/Rock/Thumbs.db.meta deleted file mode 100644 index c39d250..0000000 --- a/Assets/graphics/textures/FixedObjects/Rock/Thumbs.db.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 681b3bb9eefbd624791f90ed00ee28d0 -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/graphics/textures/FixedObjects/coin.png.meta b/Assets/graphics/textures/FixedObjects/coin.png.meta new file mode 100644 index 0000000..ce0f109 --- /dev/null +++ b/Assets/graphics/textures/FixedObjects/coin.png.meta @@ -0,0 +1,84 @@ +fileFormatVersion: 2 +guid: 8659d10a162dc4c4d9737804eeb387e6 +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 5 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -1 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: bed381f670c8110469e7fb1af6bf5d15 + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: