Added map save/load + seed generation
| | |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using UnityEngine.Tilemaps; |
| | | using UnityEngine.UIElements; |
| | | |
| | | public class GenerateTileMap : MonoBehaviour |
| | | { |
| | | public int? seed; |
| | | public int width = 256; |
| | | public int height = 256; |
| | | public float scale = 20f; |
| | | public float offsetX = 0f; |
| | | public float offsetY = 0f; |
| | | private float scale; |
| | | private float offsetX; |
| | | private float offsetY; |
| | | Tilemap tilemap; |
| | | public RuleTile ruleTile; |
| | | //public List<TileBase> tiles; |
| | |
| | | private void Awake() |
| | | { |
| | | tilemap = GetComponent<Tilemap>(); |
| | | #if DEBUG |
| | | //seed = 0123456789; |
| | | #endif |
| | | if (seed == null) |
| | | { |
| | | seed = GenerateSeed(9); |
| | | } |
| | | |
| | | SetSettingsFromSeed(seed.Value); |
| | | } |
| | | |
| | | public IEnumerator GenerateTiles(Action finishedCallback) |
| | | public void SetSettingsFromSeed(int seed) |
| | | { |
| | | UnityEngine.Random.State randomState = UnityEngine.Random.state; |
| | | |
| | | UnityEngine.Random.InitState(seed); |
| | | scale = UnityEngine.Random.Range(17f, 23f); |
| | | offsetX = UnityEngine.Random.Range(-10000f, 10000f); |
| | | offsetY = UnityEngine.Random.Range(-10000f, 10000f); |
| | | |
| | | UnityEngine.Random.state = randomState; |
| | | |
| | | } |
| | | |
| | | private int GenerateSeed(int size) |
| | | { |
| | | System.Random rand = new System.Random(); |
| | | string seedNumbers = "0123456789"; |
| | | char[] chars = new char[size]; |
| | | for (int i = 0; i < size; i++) |
| | | { |
| | | chars[i] = seedNumbers[rand.Next(seedNumbers.Length)]; |
| | | } |
| | | return int.Parse(new string(chars)); |
| | | } |
| | | |
| | | public IEnumerator GenerateTiles(Action finishedCallback, List<Vector3Int> destroyedTiles) |
| | | { |
| | | for (int x = 0; x < width; x++) |
| | | { |
| | |
| | | |
| | | if (perlinNoise >= 0.3f) |
| | | { |
| | | tilemap.SetTile(new Vector3Int(x, y), ruleTile); |
| | | if (!destroyedTiles.Contains(new Vector3Int(x, y, 0))) |
| | | { |
| | | tilemap.SetTile(new Vector3Int(x, y), ruleTile); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | m_Script: {fileID: 11500000, guid: a75ef9c1b88892d40b6007a3ab585271, type: 3} |
| | | m_Name: |
| | | m_EditorClassIdentifier: |
| | | --- !u!1 &3844785706809086879 |
| | | GameObject: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | serializedVersion: 6 |
| | | m_Component: |
| | | - component: {fileID: 6284251417818347539} |
| | | - component: {fileID: 1160294125566254827} |
| | | - component: {fileID: 8332668438839698828} |
| | | m_Layer: 5 |
| | | m_Name: Spinner |
| | | m_TagString: Untagged |
| | | m_Icon: {fileID: 0} |
| | | m_NavMeshLayer: 0 |
| | | m_StaticEditorFlags: 0 |
| | | m_IsActive: 0 |
| | | --- !u!224 &6284251417818347539 |
| | | RectTransform: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 3844785706809086879} |
| | | 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: 6682212171457450865} |
| | | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
| | | m_AnchorMin: {x: 0.5, y: 0.5} |
| | | m_AnchorMax: {x: 0.5, y: 0.5} |
| | | m_AnchoredPosition: {x: 0, y: 0} |
| | | m_SizeDelta: {x: 32, y: 32} |
| | | m_Pivot: {x: 0.5, y: 0.5} |
| | | --- !u!222 &1160294125566254827 |
| | | CanvasRenderer: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 3844785706809086879} |
| | | m_CullTransparentMesh: 1 |
| | | --- !u!114 &8332668438839698828 |
| | | MonoBehaviour: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 3844785706809086879} |
| | | m_Enabled: 1 |
| | | m_EditorHideFlags: 0 |
| | | m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} |
| | | m_Name: |
| | | m_EditorClassIdentifier: |
| | | m_Material: {fileID: 0} |
| | | m_Color: {r: 1, g: 1, b: 1, a: 1} |
| | | m_RaycastTarget: 1 |
| | | m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} |
| | | m_Maskable: 1 |
| | | m_OnCullStateChanged: |
| | | m_PersistentCalls: |
| | | m_Calls: [] |
| | | m_Sprite: {fileID: -161760997, guid: 8bdab73b8571efc4ba2f350bfc5bf34c, type: 3} |
| | | m_Type: 0 |
| | | m_PreserveAspect: 0 |
| | | m_FillCenter: 1 |
| | | m_FillMethod: 4 |
| | | m_FillAmount: 1 |
| | | m_FillClockwise: 1 |
| | | m_FillOrigin: 0 |
| | | m_UseSpriteMesh: 0 |
| | | m_PixelsPerUnitMultiplier: 1 |
| | | --- !u!1 &4140913647654720710 |
| | | GameObject: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | serializedVersion: 6 |
| | | m_Component: |
| | | - component: {fileID: 712703440348202741} |
| | | - component: {fileID: 4758794796871118532} |
| | | - component: {fileID: 4321010892148685286} |
| | | m_Layer: 5 |
| | | m_Name: GameLoadingText (TMP) |
| | | m_TagString: Untagged |
| | | m_Icon: {fileID: 0} |
| | | m_NavMeshLayer: 0 |
| | | m_StaticEditorFlags: 0 |
| | | m_IsActive: 1 |
| | | --- !u!224 &712703440348202741 |
| | | RectTransform: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 4140913647654720710} |
| | | m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} |
| | | m_LocalPosition: {x: 0, y: 0, z: 0} |
| | | m_LocalScale: {x: 0.75, y: 0.75, z: 1} |
| | | m_ConstrainProportionsScale: 0 |
| | | m_Children: [] |
| | | m_Father: {fileID: 6682212171457450865} |
| | | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
| | | m_AnchorMin: {x: 1, y: 0} |
| | | m_AnchorMax: {x: 1, y: 0} |
| | | m_AnchoredPosition: {x: 0, y: 0} |
| | | m_SizeDelta: {x: 450, y: 100} |
| | | m_Pivot: {x: 1, y: 0} |
| | | --- !u!222 &4758794796871118532 |
| | | CanvasRenderer: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 4140913647654720710} |
| | | m_CullTransparentMesh: 1 |
| | | --- !u!114 &4321010892148685286 |
| | | MonoBehaviour: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 4140913647654720710} |
| | | m_Enabled: 1 |
| | | m_EditorHideFlags: 0 |
| | | m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} |
| | | m_Name: |
| | | m_EditorClassIdentifier: |
| | | m_Material: {fileID: 0} |
| | | m_Color: {r: 1, g: 1, b: 1, a: 1} |
| | | m_RaycastTarget: 1 |
| | | m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} |
| | | m_Maskable: 1 |
| | | m_OnCullStateChanged: |
| | | m_PersistentCalls: |
| | | m_Calls: [] |
| | | m_text: Game loading... |
| | | m_isRightToLeft: 0 |
| | | m_fontAsset: {fileID: 11400000, guid: dfaa183353a3e5c4bbc9aabee7dd8268, type: 2} |
| | | m_sharedMaterial: {fileID: -8621457483150523135, guid: dfaa183353a3e5c4bbc9aabee7dd8268, type: 2} |
| | | m_fontSharedMaterials: [] |
| | | m_fontMaterial: {fileID: 0} |
| | | m_fontMaterials: [] |
| | | m_fontColor32: |
| | | serializedVersion: 2 |
| | | rgba: 4294967295 |
| | | m_fontColor: {r: 1, g: 1, b: 1, a: 1} |
| | | m_enableVertexGradient: 0 |
| | | m_colorMode: 3 |
| | | m_fontColorGradient: |
| | | topLeft: {r: 1, g: 1, b: 1, a: 1} |
| | | topRight: {r: 1, g: 1, b: 1, a: 1} |
| | | bottomLeft: {r: 1, g: 1, b: 1, a: 1} |
| | | bottomRight: {r: 1, g: 1, b: 1, a: 1} |
| | | m_fontColorGradientPreset: {fileID: 0} |
| | | m_spriteAsset: {fileID: 0} |
| | | m_tintAllSprites: 0 |
| | | m_StyleSheet: {fileID: 0} |
| | | m_TextStyleHashCode: -1183493901 |
| | | m_overrideHtmlColors: 0 |
| | | m_faceColor: |
| | | serializedVersion: 2 |
| | | rgba: 4294967295 |
| | | m_fontSize: 78 |
| | | m_fontSizeBase: 78 |
| | | m_fontWeight: 400 |
| | | m_enableAutoSizing: 0 |
| | | m_fontSizeMin: 18 |
| | | m_fontSizeMax: 72 |
| | | m_fontStyle: 0 |
| | | m_HorizontalAlignment: 32 |
| | | m_VerticalAlignment: 8192 |
| | | m_textAlignment: 65535 |
| | | m_characterSpacing: 0 |
| | | m_wordSpacing: 0 |
| | | m_lineSpacing: 0 |
| | | m_lineSpacingMax: 0 |
| | | m_paragraphSpacing: 0 |
| | | m_charWidthMaxAdj: 0 |
| | | m_enableWordWrapping: 1 |
| | | m_wordWrappingRatios: 0.4 |
| | | m_overflowMode: 0 |
| | | m_linkedTextComponent: {fileID: 0} |
| | | parentLinkedComponent: {fileID: 0} |
| | | m_enableKerning: 1 |
| | | m_enableExtraPadding: 0 |
| | | checkPaddingRequired: 0 |
| | | m_isRichText: 1 |
| | | m_parseCtrlCharacters: 1 |
| | | m_isOrthographic: 1 |
| | | m_isCullingEnabled: 0 |
| | | m_horizontalMapping: 0 |
| | | m_verticalMapping: 0 |
| | | m_uvLineOffset: 0 |
| | | m_geometrySortingOrder: 0 |
| | | m_IsTextObjectScaleStatic: 0 |
| | | m_VertexBufferAutoSizeReduction: 0 |
| | | m_useMaxVisibleDescender: 1 |
| | | m_pageToDisplay: 1 |
| | | m_margin: {x: 0, y: 0, z: 0, w: 0} |
| | | m_isUsingLegacyAnimationComponent: 0 |
| | | m_isVolumetricText: 0 |
| | | m_hasFontAssetChanged: 0 |
| | | m_baseMaterial: {fileID: 0} |
| | | m_maskOffset: {x: 0, y: 0, z: 0, w: 0} |
| | | --- !u!1 &4958470436171505954 |
| | | GameObject: |
| | | m_ObjectHideFlags: 0 |
| | |
| | | m_ConstrainProportionsScale: 0 |
| | | m_Children: |
| | | - {fileID: 6098923997719688514} |
| | | - {fileID: 6682212171457450865} |
| | | m_Father: {fileID: 7044154378667287598} |
| | | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
| | | m_AnchorMin: {x: 0, y: 0} |
| | |
| | | m_BlockingMask: |
| | | serializedVersion: 2 |
| | | m_Bits: 4294967295 |
| | | --- !u!1 &8556222640122415663 |
| | | GameObject: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | serializedVersion: 6 |
| | | m_Component: |
| | | - component: {fileID: 6682212171457450865} |
| | | - component: {fileID: 8205283534925286976} |
| | | - component: {fileID: 5749254209960849005} |
| | | m_Layer: 5 |
| | | m_Name: LoadingScreen |
| | | m_TagString: Untagged |
| | | m_Icon: {fileID: 0} |
| | | m_NavMeshLayer: 0 |
| | | m_StaticEditorFlags: 0 |
| | | m_IsActive: 1 |
| | | --- !u!224 &6682212171457450865 |
| | | RectTransform: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 8556222640122415663} |
| | | 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: |
| | | - {fileID: 6284251417818347539} |
| | | - {fileID: 712703440348202741} |
| | | m_Father: {fileID: 1837984479501285253} |
| | | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
| | | m_AnchorMin: {x: 0, y: 0} |
| | | m_AnchorMax: {x: 1, y: 1} |
| | | m_AnchoredPosition: {x: 0, y: 0} |
| | | m_SizeDelta: {x: 0, y: 0} |
| | | m_Pivot: {x: 0.5, y: 0.5} |
| | | --- !u!222 &8205283534925286976 |
| | | CanvasRenderer: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 8556222640122415663} |
| | | m_CullTransparentMesh: 1 |
| | | --- !u!114 &5749254209960849005 |
| | | MonoBehaviour: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 8556222640122415663} |
| | | m_Enabled: 1 |
| | | m_EditorHideFlags: 0 |
| | | m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} |
| | | m_Name: |
| | | m_EditorClassIdentifier: |
| | | m_Material: {fileID: 0} |
| | | m_Color: {r: 0, g: 0, b: 0, a: 0} |
| | | m_RaycastTarget: 0 |
| | | m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} |
| | | m_Maskable: 1 |
| | | m_OnCullStateChanged: |
| | | m_PersistentCalls: |
| | | m_Calls: [] |
| | | m_Sprite: {fileID: 0} |
| | | m_Type: 0 |
| | | m_PreserveAspect: 0 |
| | | m_FillCenter: 1 |
| | | m_FillMethod: 4 |
| | | m_FillAmount: 1 |
| | | m_FillClockwise: 1 |
| | | m_FillOrigin: 0 |
| | | m_UseSpriteMesh: 0 |
| | | m_PixelsPerUnitMultiplier: 1 |
| | |
| | | m_AddedGameObjects: [] |
| | | m_AddedComponents: [] |
| | | m_SourcePrefab: {fileID: 100100000, guid: 5549e8180a8b1ba49bf0de3848e7bcf9, type: 3} |
| | | --- !u!224 &405367630 stripped |
| | | RectTransform: |
| | | m_CorrespondingSourceObject: {fileID: 1837984479501285253, guid: 1727dce3407104540a6bf21deb2957a8, type: 3} |
| | | m_PrefabInstance: {fileID: 1007461191} |
| | | m_PrefabAsset: {fileID: 0} |
| | | --- !u!4 &427702723 stripped |
| | | Transform: |
| | | m_CorrespondingSourceObject: {fileID: 3069410814361871794, guid: 5549e8180a8b1ba49bf0de3848e7bcf9, type: 3} |
| | |
| | | m_EditorClassIdentifier: |
| | | cam: {fileID: 519420031} |
| | | followTarget: {fileID: 254538002} |
| | | --- !u!1 &700639980 |
| | | GameObject: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | serializedVersion: 6 |
| | | m_Component: |
| | | - component: {fileID: 700639981} |
| | | - component: {fileID: 700639983} |
| | | - component: {fileID: 700639982} |
| | | m_Layer: 5 |
| | | m_Name: LoadingScreen |
| | | m_TagString: Untagged |
| | | m_Icon: {fileID: 0} |
| | | m_NavMeshLayer: 0 |
| | | m_StaticEditorFlags: 0 |
| | | m_IsActive: 1 |
| | | --- !u!224 &700639981 |
| | | RectTransform: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 700639980} |
| | | 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: |
| | | - {fileID: 1083067552} |
| | | - {fileID: 1934276584} |
| | | m_Father: {fileID: 405367630} |
| | | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
| | | m_AnchorMin: {x: 0, y: 0} |
| | | m_AnchorMax: {x: 1, y: 1} |
| | | m_AnchoredPosition: {x: 0, y: 0} |
| | | m_SizeDelta: {x: 0, y: 0} |
| | | m_Pivot: {x: 0.5, y: 0.5} |
| | | --- !u!114 &700639982 |
| | | MonoBehaviour: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 700639980} |
| | | m_Enabled: 1 |
| | | m_EditorHideFlags: 0 |
| | | m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} |
| | | m_Name: |
| | | m_EditorClassIdentifier: |
| | | m_Material: {fileID: 0} |
| | | m_Color: {r: 0, g: 0, b: 0, a: 0} |
| | | m_RaycastTarget: 0 |
| | | m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} |
| | | m_Maskable: 1 |
| | | m_OnCullStateChanged: |
| | | m_PersistentCalls: |
| | | m_Calls: [] |
| | | m_Sprite: {fileID: 0} |
| | | m_Type: 0 |
| | | m_PreserveAspect: 0 |
| | | m_FillCenter: 1 |
| | | m_FillMethod: 4 |
| | | m_FillAmount: 1 |
| | | m_FillClockwise: 1 |
| | | m_FillOrigin: 0 |
| | | m_UseSpriteMesh: 0 |
| | | m_PixelsPerUnitMultiplier: 1 |
| | | --- !u!222 &700639983 |
| | | CanvasRenderer: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 700639980} |
| | | m_CullTransparentMesh: 1 |
| | | --- !u!1 &720777868 stripped |
| | | GameObject: |
| | | m_CorrespondingSourceObject: {fileID: 8421115849835234403, guid: 19b26cb080fd5b841970a693f820fc0f, type: 3} |
| | |
| | | objectReference: {fileID: 0} |
| | | m_RemovedComponents: [] |
| | | m_RemovedGameObjects: [] |
| | | m_AddedGameObjects: |
| | | - targetCorrespondingSourceObject: {fileID: 1837984479501285253, guid: 1727dce3407104540a6bf21deb2957a8, type: 3} |
| | | insertIndex: -1 |
| | | addedObject: {fileID: 700639981} |
| | | m_AddedGameObjects: [] |
| | | m_AddedComponents: [] |
| | | m_SourcePrefab: {fileID: 100100000, guid: 1727dce3407104540a6bf21deb2957a8, type: 3} |
| | | --- !u!1 &1029677422 |
| | |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 1042147644} |
| | | m_CullTransparentMesh: 1 |
| | | --- !u!1 &1083067551 |
| | | GameObject: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | serializedVersion: 6 |
| | | m_Component: |
| | | - component: {fileID: 1083067552} |
| | | - component: {fileID: 1083067554} |
| | | - component: {fileID: 1083067553} |
| | | m_Layer: 5 |
| | | m_Name: Spinner |
| | | m_TagString: Untagged |
| | | m_Icon: {fileID: 0} |
| | | m_NavMeshLayer: 0 |
| | | m_StaticEditorFlags: 0 |
| | | m_IsActive: 0 |
| | | --- !u!224 &1083067552 |
| | | RectTransform: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 1083067551} |
| | | 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: 700639981} |
| | | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
| | | m_AnchorMin: {x: 0.5, y: 0.5} |
| | | m_AnchorMax: {x: 0.5, y: 0.5} |
| | | m_AnchoredPosition: {x: 0, y: 0} |
| | | m_SizeDelta: {x: 32, y: 32} |
| | | m_Pivot: {x: 0.5, y: 0.5} |
| | | --- !u!114 &1083067553 |
| | | MonoBehaviour: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 1083067551} |
| | | m_Enabled: 1 |
| | | m_EditorHideFlags: 0 |
| | | m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} |
| | | m_Name: |
| | | m_EditorClassIdentifier: |
| | | m_Material: {fileID: 0} |
| | | m_Color: {r: 1, g: 1, b: 1, a: 1} |
| | | m_RaycastTarget: 1 |
| | | m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} |
| | | m_Maskable: 1 |
| | | m_OnCullStateChanged: |
| | | m_PersistentCalls: |
| | | m_Calls: [] |
| | | m_Sprite: {fileID: -161760997, guid: 8bdab73b8571efc4ba2f350bfc5bf34c, type: 3} |
| | | m_Type: 0 |
| | | m_PreserveAspect: 0 |
| | | m_FillCenter: 1 |
| | | m_FillMethod: 4 |
| | | m_FillAmount: 1 |
| | | m_FillClockwise: 1 |
| | | m_FillOrigin: 0 |
| | | m_UseSpriteMesh: 0 |
| | | m_PixelsPerUnitMultiplier: 1 |
| | | --- !u!222 &1083067554 |
| | | CanvasRenderer: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 1083067551} |
| | | m_CullTransparentMesh: 1 |
| | | --- !u!1 &1219825711 |
| | | GameObject: |
| | |
| | | m_EditorClassIdentifier: |
| | | width: 256 |
| | | height: 256 |
| | | scale: 20 |
| | | offsetX: 0 |
| | | offsetY: 0 |
| | | ruleTile: {fileID: 11400000, guid: e77c00aec3ec74f4a9ec15ef63c3f9a7, type: 2} |
| | | --- !u!1 &1934276583 |
| | | GameObject: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | serializedVersion: 6 |
| | | m_Component: |
| | | - component: {fileID: 1934276584} |
| | | - component: {fileID: 1934276586} |
| | | - component: {fileID: 1934276585} |
| | | m_Layer: 5 |
| | | m_Name: GameLoadingText (TMP) |
| | | m_TagString: Untagged |
| | | m_Icon: {fileID: 0} |
| | | m_NavMeshLayer: 0 |
| | | m_StaticEditorFlags: 0 |
| | | m_IsActive: 1 |
| | | --- !u!224 &1934276584 |
| | | RectTransform: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 1934276583} |
| | | m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} |
| | | m_LocalPosition: {x: 0, y: 0, z: 0} |
| | | m_LocalScale: {x: 0.75, y: 0.75, z: 1} |
| | | m_ConstrainProportionsScale: 0 |
| | | m_Children: [] |
| | | m_Father: {fileID: 700639981} |
| | | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
| | | m_AnchorMin: {x: 1, y: 0} |
| | | m_AnchorMax: {x: 1, y: 0} |
| | | m_AnchoredPosition: {x: 0, y: 0} |
| | | m_SizeDelta: {x: 450, y: 100} |
| | | m_Pivot: {x: 1, y: 0} |
| | | --- !u!114 &1934276585 |
| | | MonoBehaviour: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 1934276583} |
| | | m_Enabled: 1 |
| | | m_EditorHideFlags: 0 |
| | | m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} |
| | | m_Name: |
| | | m_EditorClassIdentifier: |
| | | m_Material: {fileID: 0} |
| | | m_Color: {r: 1, g: 1, b: 1, a: 1} |
| | | m_RaycastTarget: 1 |
| | | m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} |
| | | m_Maskable: 1 |
| | | m_OnCullStateChanged: |
| | | m_PersistentCalls: |
| | | m_Calls: [] |
| | | m_text: Game loading... |
| | | m_isRightToLeft: 0 |
| | | m_fontAsset: {fileID: 11400000, guid: dfaa183353a3e5c4bbc9aabee7dd8268, type: 2} |
| | | m_sharedMaterial: {fileID: -8621457483150523135, guid: dfaa183353a3e5c4bbc9aabee7dd8268, type: 2} |
| | | m_fontSharedMaterials: [] |
| | | m_fontMaterial: {fileID: 0} |
| | | m_fontMaterials: [] |
| | | m_fontColor32: |
| | | serializedVersion: 2 |
| | | rgba: 4294967295 |
| | | m_fontColor: {r: 1, g: 1, b: 1, a: 1} |
| | | m_enableVertexGradient: 0 |
| | | m_colorMode: 3 |
| | | m_fontColorGradient: |
| | | topLeft: {r: 1, g: 1, b: 1, a: 1} |
| | | topRight: {r: 1, g: 1, b: 1, a: 1} |
| | | bottomLeft: {r: 1, g: 1, b: 1, a: 1} |
| | | bottomRight: {r: 1, g: 1, b: 1, a: 1} |
| | | m_fontColorGradientPreset: {fileID: 0} |
| | | m_spriteAsset: {fileID: 0} |
| | | m_tintAllSprites: 0 |
| | | m_StyleSheet: {fileID: 0} |
| | | m_TextStyleHashCode: -1183493901 |
| | | m_overrideHtmlColors: 0 |
| | | m_faceColor: |
| | | serializedVersion: 2 |
| | | rgba: 4294967295 |
| | | m_fontSize: 78 |
| | | m_fontSizeBase: 78 |
| | | m_fontWeight: 400 |
| | | m_enableAutoSizing: 0 |
| | | m_fontSizeMin: 18 |
| | | m_fontSizeMax: 72 |
| | | m_fontStyle: 0 |
| | | m_HorizontalAlignment: 32 |
| | | m_VerticalAlignment: 8192 |
| | | m_textAlignment: 65535 |
| | | m_characterSpacing: 0 |
| | | m_wordSpacing: 0 |
| | | m_lineSpacing: 0 |
| | | m_lineSpacingMax: 0 |
| | | m_paragraphSpacing: 0 |
| | | m_charWidthMaxAdj: 0 |
| | | m_enableWordWrapping: 1 |
| | | m_wordWrappingRatios: 0.4 |
| | | m_overflowMode: 0 |
| | | m_linkedTextComponent: {fileID: 0} |
| | | parentLinkedComponent: {fileID: 0} |
| | | m_enableKerning: 1 |
| | | m_enableExtraPadding: 0 |
| | | checkPaddingRequired: 0 |
| | | m_isRichText: 1 |
| | | m_parseCtrlCharacters: 1 |
| | | m_isOrthographic: 1 |
| | | m_isCullingEnabled: 0 |
| | | m_horizontalMapping: 0 |
| | | m_verticalMapping: 0 |
| | | m_uvLineOffset: 0 |
| | | m_geometrySortingOrder: 0 |
| | | m_IsTextObjectScaleStatic: 0 |
| | | m_VertexBufferAutoSizeReduction: 0 |
| | | m_useMaxVisibleDescender: 1 |
| | | m_pageToDisplay: 1 |
| | | m_margin: {x: 0, y: 0, z: 0, w: 0} |
| | | m_isUsingLegacyAnimationComponent: 0 |
| | | m_isVolumetricText: 0 |
| | | m_hasFontAssetChanged: 0 |
| | | m_baseMaterial: {fileID: 0} |
| | | m_maskOffset: {x: 0, y: 0, z: 0, w: 0} |
| | | --- !u!222 &1934276586 |
| | | CanvasRenderer: |
| | | m_ObjectHideFlags: 0 |
| | | m_CorrespondingSourceObject: {fileID: 0} |
| | | m_PrefabInstance: {fileID: 0} |
| | | m_PrefabAsset: {fileID: 0} |
| | | m_GameObject: {fileID: 1934276583} |
| | | m_CullTransparentMesh: 1 |
| | | --- !u!1 &1990316377 |
| | | GameObject: |
| | | m_ObjectHideFlags: 0 |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Reflection; |
| | | using Unity.VisualScripting.Dependencies.NCalc; |
| | | using UnityEngine; |
| | | using static UnityEngine.Rendering.DebugUI; |
| | | |
| | |
| | | result[0] = value.x; |
| | | result[1] = value.y; |
| | | result[2] = value.z; |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Will get a float array for a given vector2 value |
| | | /// </summary> |
| | | /// <param name="value"></param> |
| | | /// <returns>float[x,y]</returns> |
| | | public static float[] ConvertToFloatArray(this Vector2 value) |
| | | { |
| | | float[] result = new float[2]; |
| | | result[0] = value.x; |
| | | result[1] = value.y; |
| | | return result; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Will get a float array for a given vector2 value |
| | | /// </summary> |
| | | /// <param name="value"></param> |
| | | /// <returns>float[x,y]</returns> |
| | | public static float[] ConvertToFloatArray(this Vector2 value) |
| | | { |
| | | float[] result = new float[2]; |
| | | result[0] = value.x; |
| | | result[1] = value.y; |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Will get a vector2 for a given float array value |
| | | /// </summary> |
| | | /// <param name="value"></param> |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Will get a float array for a given vector2 value |
| | | /// </summary> |
| | | /// <param name="value"></param> |
| | | /// <returns>float[x,y]</returns> |
| | | public static List<int[]> ConvertToListIntArray(this List<Vector3Int> value) |
| | | { |
| | | List<int[]> result = new List<int[]>(); |
| | | for (int i = 0; i < value.Count; i++) |
| | | { |
| | | int[] intVector = new int[2]; |
| | | intVector[0] = value[i].x; |
| | | intVector[1] = value[i].y; |
| | | result.Add(intVector); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Will get a vector2 for a given float array value |
| | | /// </summary> |
| | | /// <param name="value"></param> |
| | | /// <returns>Vector2</returns> |
| | | public static List<Vector3Int> ConvertToVector3Int(this List<int[]> value) |
| | | { |
| | | List<Vector3Int> result = new List<Vector3Int>(); |
| | | if (value != null && value.Count > 0) |
| | | { |
| | | for (int i = 0; i < value.Count; i++) |
| | | { |
| | | Vector3Int vector = new Vector3Int(); |
| | | vector.x = value[0][0]; |
| | | vector.y = value[0][1]; |
| | | result.Add(vector); |
| | | } |
| | | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public static Vector3Int ConvertToVector3Int(this int[] value) |
| | | { |
| | | Vector3Int result = new Vector3Int(); |
| | | switch (value.Length) |
| | | { |
| | | case 2: |
| | | result.x = value[0]; |
| | | result.y = value[1]; |
| | | break; |
| | | case 3: |
| | | result.x = value[0]; |
| | | result.y = value[1]; |
| | | result.z = value[2]; |
| | | break; |
| | | default: |
| | | Debug.Assert(false, "ConvertToVector3Int() got wrong array size, expected size is 2 or 3. recieved size: " + value.Length); |
| | | break; |
| | | } |
| | | return result; |
| | | } |
| | | } |
| | | } |
| | |
| | | using Assets.Scripts.Enums; |
| | | using Assets.Scripts.Helpers; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using TMPro; |
| | | using Unity.VisualScripting; |
| | | using UnityEngine; |
| | | using UnityEngine.Tilemaps; |
| | | |
| | |
| | | public Canvas pauseMenuUI; |
| | | public GameObject levelChanger; |
| | | public Tilemap tilemap; |
| | | GenerateTileMap generateTileMap; |
| | | [NonSerialized] |
| | | public GenerateTileMap generateTileMap; |
| | | [NonSerialized] |
| | | public List<Vector3Int> destroyedTiles = new List<Vector3Int>(); |
| | | |
| | | private void Awake() |
| | | { |
| | |
| | | |
| | | private void LoadTileMaps(bool loadFromSave) |
| | | { |
| | | generateTileMap = tilemap.GetComponent<GenerateTileMap>(); |
| | | pauseMenuUI.GetComponent<PauseMenu>().Pause(); |
| | | levelChanger.GetComponent<Animator>().SetBool("SceneLoading", true); |
| | | generateTileMap = tilemap.GetComponent<GenerateTileMap>(); |
| | | Debug.Log("waiting for async"); |
| | | StartCoroutine(generateTileMap.GenerateTiles(LoadTileMapsFinished)); |
| | | if (loadFromSave) |
| | | { |
| | | LoadMapState(); |
| | | } |
| | | Debug.Log("waiting for async map loading"); |
| | | StartCoroutine(generateTileMap.GenerateTiles(LoadTileMapsFinished, destroyedTiles)); |
| | | } |
| | | |
| | | private void LoadMapState() |
| | | { |
| | | SaveDataMap mapState = SaveSystem.LoadMapState(); |
| | | if (mapState != null) |
| | | { |
| | | generateTileMap.SetSettingsFromSeed(mapState.seed); |
| | | if (mapState.destroyedTiles != null && mapState.destroyedTiles.Count > 0) |
| | | { |
| | | // TODO rework load map (it's fucky wucky currently as I had to make an extra class for it to jsonify the tiles correctly, as unity does not like lists of arrays or 2d arrays) |
| | | foreach (DestroyedTile tile in mapState.destroyedTiles) |
| | | { |
| | | destroyedTiles.Add(tile.tileCoord.ConvertToVector3Int()); |
| | | } //destroyedTiles.AddRange(mapState.destroyedTiles.Select(tile => { return tile.tileCoord; }).ToList().ConvertToVector3Int()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void LoadTileMapsFinished() |
| | | { |
| | | Debug.Log("done async"); |
| | | Debug.Log("done async map loading"); |
| | | levelChanger.GetComponent<Animator>().SetBool("SceneLoading", false); |
| | | GameLoaded(); |
| | | } |
| | |
| | | if (tilemap.HasTile(cellCoord)) |
| | | { |
| | | tilemap.SetTile(cellCoord, null); |
| | | destroyedTiles.Add(cellCoord); |
| | | Vector3 moveToPosition = grid.CellToWorld(cellCoord); |
| | | moveToPosition.x += 0.5f; |
| | | moveToPosition.y += 0.5f; |
| | |
| | | public void OnGameSaveClicked() |
| | | { |
| | | PlayerController playerController = GameObject.Find("Player").GetComponent<PlayerController>(); |
| | | SaveSystem.SavePlayer(playerController); |
| | | SaveSystem.SavePlayer(new SaveDataPlayer(playerController)); |
| | | GameManager gameManager= GameObject.Find("GameManager").GetComponent<GameManager>(); |
| | | SaveSystem.SaveMapState(new SaveDataMap(gameManager.destroyedTiles, gameManager.generateTileMap.seed.Value)); |
| | | animator.SetTrigger("GameSaved"); |
| | | } |
| | | |
| | |
| | | boxCollider = GetComponent<BoxCollider2D>(); |
| | | if (SaveSystem.isGameLoaded) |
| | | { |
| | | SaveData save = SaveSystem.LoadPlayer(); |
| | | health.MaxHealth = save.maxHealth; |
| | | health.Health = save.health; |
| | | transform.position = VectorHelper.ConvertToVector3(save.position); |
| | | rb.velocity = VectorHelper.ConvertToVector2(save.velocity); |
| | | LoadPlayer(); |
| | | } |
| | | } |
| | | |
| | | private void LoadPlayer() |
| | | { |
| | | SaveDataPlayer save = SaveSystem.LoadPlayer(); |
| | | health.MaxHealth = save.maxHealth; |
| | | health.Health = save.health; |
| | | transform.position = VectorHelper.ConvertToVector3(save.position); |
| | | rb.velocity = VectorHelper.ConvertToVector2(save.velocity); |
| | | } |
| | | |
| | | private void FixedUpdate() |
| | | { |
| | | if (CanMove) |
| | |
| | | using UnityEngine; |
| | | |
| | | [Serializable] |
| | | public class SaveData |
| | | public class SaveDataPlayer |
| | | { |
| | | public int maxHealth; |
| | | public int health; |
| | | public float[] position; |
| | | public float[] velocity; |
| | | public SaveData(PlayerController player) |
| | | public SaveDataPlayer(PlayerController player) |
| | | { |
| | | maxHealth = player.health.MaxHealth; |
| | | health = player.health.Health; |
| | |
| | | velocity = player.rb.velocity.ConvertToFloatArray(); |
| | | } |
| | | } |
| | | |
| | | [Serializable] |
| | | public class SaveDataMap |
| | | { |
| | | public int seed; |
| | | public List<DestroyedTile> destroyedTiles; |
| | | public SaveDataMap(List<Vector3Int> destroyedTiles, int seed) |
| | | { |
| | | this.seed = seed; |
| | | this.destroyedTiles = new List<DestroyedTile>(); |
| | | foreach (var item in destroyedTiles.ConvertToListIntArray()) |
| | | { |
| | | this.destroyedTiles.Add(new DestroyedTile(item)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | [Serializable] |
| | | public class DestroyedTile |
| | | { |
| | | public DestroyedTile(int[] tileCoord) |
| | | { |
| | | this.tileCoord = tileCoord; |
| | | } |
| | | public int[] tileCoord; |
| | | } |
| | |
| | | public static class SaveSystem |
| | | { |
| | | public static bool isGameLoaded = false; |
| | | public static void SavePlayer(PlayerController player) |
| | | public static void SavePlayer(SaveDataPlayer player) |
| | | { |
| | | if (player != null) |
| | | { |
| | | string path = System.IO.Path.Combine(Application.persistentDataPath, "player.savefile"); |
| | | |
| | | SaveData saveData = new SaveData(player); |
| | | string saveDataJSON = JsonUtility.ToJson(saveData); |
| | | string saveDataJSON = JsonUtility.ToJson(player); |
| | | |
| | | using (FileStream fs = new FileStream(path, FileMode.Create)) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | Debug.Log("Not saved as no playerController was sent"); |
| | | Debug.Log("Not saved as no playerData was sent"); |
| | | } |
| | | } |
| | | |
| | | public static SaveData LoadPlayer () |
| | | public static SaveDataPlayer LoadPlayer() |
| | | { |
| | | SaveData result; |
| | | SaveDataPlayer result; |
| | | string path = System.IO.Path.Combine(Application.persistentDataPath, "player.savefile"); |
| | | if (File.Exists(path)) |
| | | { |
| | |
| | | using (StreamReader sr = new StreamReader(fs)) |
| | | { |
| | | string saveData = sr.ReadToEnd(); |
| | | result = JsonUtility.FromJson<SaveData>(saveData); |
| | | result = JsonUtility.FromJson<SaveDataPlayer>(saveData); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Debug.LogError("Save file not found in: " + path); |
| | | return null; |
| | | } |
| | | return result; |
| | | } |
| | | public static void SaveMapState(SaveDataMap mapState) |
| | | { |
| | | if (mapState != null) |
| | | { |
| | | string path = System.IO.Path.Combine(Application.persistentDataPath, "map.savefile"); |
| | | string saveDataJSON = JsonUtility.ToJson(mapState); |
| | | |
| | | using (FileStream fs = new FileStream(path, FileMode.Create)) |
| | | { |
| | | using (StreamWriter sw = new StreamWriter(fs)) |
| | | { |
| | | sw.Write(saveDataJSON); |
| | | |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Debug.Log("Not saved as no mapData was sent"); |
| | | } |
| | | } |
| | | |
| | | public static SaveDataMap LoadMapState() |
| | | { |
| | | SaveDataMap result; |
| | | string path = System.IO.Path.Combine(Application.persistentDataPath, "map.savefile"); |
| | | if (File.Exists(path)) |
| | | { |
| | | using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) |
| | | { |
| | | using (StreamReader sr = new StreamReader(fs)) |
| | | { |
| | | string saveData = sr.ReadToEnd(); |
| | | result = JsonUtility.FromJson<SaveDataMap>(saveData); |
| | | } |
| | | } |
| | | } |