Merge pull request #2 from ProtoSharkk/Backgroundtiles/screenscalewithdesktop
background and canvas scale
This commit is contained in:
69
Assets/BackgroundTiler.cs
Normal file
69
Assets/BackgroundTiler.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BackgroundTiler : MonoBehaviour
|
||||
{
|
||||
public GameObject tilePrefab; // The background tile prefab
|
||||
public Transform player; // The player object to track
|
||||
public int tileSize = 10; // Size of each tile (assuming square tiles)
|
||||
public int renderDistance = 3; // Number of tiles to render around the player
|
||||
|
||||
private Vector2Int previousTile; // Tracks the last tile position
|
||||
private Dictionary<Vector2Int, GameObject> activeTiles = new Dictionary<Vector2Int, GameObject>();
|
||||
|
||||
void Start()
|
||||
{
|
||||
UpdateTiles(); // Generate initial tiles
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
Vector2Int currentTile = GetTilePosition(player.position);
|
||||
if (currentTile != previousTile)
|
||||
{
|
||||
previousTile = currentTile;
|
||||
UpdateTiles();
|
||||
}
|
||||
}
|
||||
|
||||
Vector2Int GetTilePosition(Vector3 position)
|
||||
{
|
||||
return new Vector2Int(Mathf.FloorToInt(position.x / tileSize), Mathf.FloorToInt(position.y / tileSize));
|
||||
}
|
||||
|
||||
void UpdateTiles()
|
||||
{
|
||||
Vector2Int currentTile = GetTilePosition(player.position);
|
||||
|
||||
// Remove tiles that are out of range
|
||||
List<Vector2Int> tilesToRemove = new List<Vector2Int>();
|
||||
foreach (var tile in activeTiles)
|
||||
{
|
||||
if (Mathf.Abs(tile.Key.x - currentTile.x) > renderDistance || Mathf.Abs(tile.Key.y - currentTile.y) > renderDistance)
|
||||
{
|
||||
tilesToRemove.Add(tile.Key);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var tile in tilesToRemove)
|
||||
{
|
||||
Destroy(activeTiles[tile]);
|
||||
activeTiles.Remove(tile);
|
||||
}
|
||||
|
||||
// Add new tiles around the player
|
||||
for (int x = -renderDistance; x <= renderDistance; x++)
|
||||
{
|
||||
for (int y = -renderDistance; y <= renderDistance; y++)
|
||||
{
|
||||
Vector2Int tilePos = new Vector2Int(currentTile.x + x, currentTile.y + y);
|
||||
if (!activeTiles.ContainsKey(tilePos))
|
||||
{
|
||||
Vector3 tilePosition = new Vector3(tilePos.x * tileSize, tilePos.y * tileSize, 0);
|
||||
GameObject newTile = Instantiate(tilePrefab, tilePosition, Quaternion.identity);
|
||||
activeTiles.Add(tilePos, newTile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/BackgroundTiler.cs.meta
Normal file
2
Assets/BackgroundTiler.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e58a9223e11a452ebfa72dded313f23
|
||||
@@ -167,10 +167,10 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_UiScaleMode: 0
|
||||
m_UiScaleMode: 1
|
||||
m_ReferencePixelsPerUnit: 100
|
||||
m_ScaleFactor: 1
|
||||
m_ReferenceResolution: {x: 800, y: 600}
|
||||
m_ReferenceResolution: {x: 1920, y: 1080}
|
||||
m_ScreenMatchMode: 0
|
||||
m_MatchWidthOrHeight: 0
|
||||
m_PhysicalUnit: 3
|
||||
@@ -327,6 +327,9 @@ PrefabInstance:
|
||||
insertIndex: -1
|
||||
addedObject: {fileID: 1873397571}
|
||||
m_AddedComponents:
|
||||
- targetCorrespondingSourceObject: {fileID: 3739677681433878215, guid: e05928a0d673caf999d31b31b994a112, type: 3}
|
||||
insertIndex: -1
|
||||
addedObject: {fileID: 1246075823}
|
||||
- targetCorrespondingSourceObject: {fileID: 8669953498445216587, guid: e05928a0d673caf999d31b31b994a112, type: 3}
|
||||
insertIndex: 1
|
||||
addedObject: {fileID: 977303808}
|
||||
@@ -447,7 +450,7 @@ MonoBehaviour:
|
||||
m_Intensity: 1
|
||||
m_LightVolumeIntensity: 1
|
||||
m_LightVolumeEnabled: 0
|
||||
m_ApplyToSortingLayers: 00000000
|
||||
m_ApplyToSortingLayers: 00000000377f5862
|
||||
m_LightCookieSprite: {fileID: 0}
|
||||
m_DeprecatedPointLightCookieSprite: {fileID: 0}
|
||||
m_LightOrder: 0
|
||||
@@ -705,11 +708,32 @@ Skybox:
|
||||
m_GameObject: {fileID: 977303806}
|
||||
m_Enabled: 1
|
||||
m_CustomSkybox: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
|
||||
--- !u!1 &1024677462 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 3739677681433878215, guid: e05928a0d673caf999d31b31b994a112, type: 3}
|
||||
m_PrefabInstance: {fileID: 309882168}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!4 &1246075822 stripped
|
||||
Transform:
|
||||
m_CorrespondingSourceObject: {fileID: 4154134366646162009, guid: e05928a0d673caf999d31b31b994a112, type: 3}
|
||||
m_PrefabInstance: {fileID: 309882168}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!114 &1246075823
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1024677462}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 7e58a9223e11a452ebfa72dded313f23, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
tilePrefab: {fileID: 9207511122995714926, guid: 18ae43c6ae22143f8b06cd29cdfab4c5, type: 3}
|
||||
player: {fileID: 1246075822}
|
||||
tileSize: 10
|
||||
renderDistance: 2
|
||||
--- !u!1 &1394869898
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -2004,10 +2004,10 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_UiScaleMode: 0
|
||||
m_UiScaleMode: 1
|
||||
m_ReferencePixelsPerUnit: 100
|
||||
m_ScaleFactor: 1
|
||||
m_ReferenceResolution: {x: 800, y: 600}
|
||||
m_ReferenceResolution: {x: 1920, y: 1080}
|
||||
m_ScreenMatchMode: 0
|
||||
m_MatchWidthOrHeight: 0
|
||||
m_PhysicalUnit: 3
|
||||
|
||||
89
Assets/backgroundtilesprefab.prefab
Normal file
89
Assets/backgroundtilesprefab.prefab
Normal file
@@ -0,0 +1,89 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &9207511122995714926
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 874902861950174750}
|
||||
- component: {fileID: 4121555577630399958}
|
||||
m_Layer: 0
|
||||
m_Name: backgroundtilesprefab
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &874902861950174750
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 9207511122995714926}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0.046691418, y: -0.21936595, z: 0}
|
||||
m_LocalScale: {x: 1.7249999, y: 3.20625, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!212 &4121555577630399958
|
||||
SpriteRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 9207511122995714926}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 0
|
||||
m_ReceiveShadows: 0
|
||||
m_DynamicOccludee: 1
|
||||
m_StaticShadowCaster: 0
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 0
|
||||
m_RayTraceProcedural: 0
|
||||
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||
m_RayTracingAccelStructBuildFlags: 1
|
||||
m_SmallMeshCulling: 1
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2}
|
||||
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: 1649966903
|
||||
m_SortingLayer: -1
|
||||
m_SortingOrder: 0
|
||||
m_Sprite: {fileID: 7415648711516331556, guid: b565bfdb85a3b444796e15075243e9db, type: 3}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_FlipX: 0
|
||||
m_FlipY: 0
|
||||
m_DrawMode: 0
|
||||
m_Size: {x: 6.26, y: 4.12}
|
||||
m_AdaptiveModeThreshold: 0.5
|
||||
m_SpriteTileMode: 0
|
||||
m_WasSpriteAssigned: 1
|
||||
m_MaskInteraction: 0
|
||||
m_SpriteSortPoint: 0
|
||||
7
Assets/backgroundtilesprefab.prefab.meta
Normal file
7
Assets/backgroundtilesprefab.prefab.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18ae43c6ae22143f8b06cd29cdfab4c5
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/whiteteotiles.jpg
Normal file
BIN
Assets/whiteteotiles.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 115 KiB |
142
Assets/whiteteotiles.jpg.meta
Normal file
142
Assets/whiteteotiles.jpg.meta
Normal file
@@ -0,0 +1,142 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b565bfdb85a3b444796e15075243e9db
|
||||
TextureImporter:
|
||||
internalIDToNameTable:
|
||||
- first:
|
||||
213: 7415648711516331556
|
||||
second: whiteteotiles_0
|
||||
externalObjects: {}
|
||||
serializedVersion: 13
|
||||
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
|
||||
flipGreenChannel: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
ignoreMipmapLimit: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 2
|
||||
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
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
swizzle: 50462976
|
||||
cookieLightType: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 4
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 4
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites:
|
||||
- serializedVersion: 2
|
||||
name: whiteteotiles_0
|
||||
rect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 626
|
||||
height: 412
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
customData:
|
||||
outline: []
|
||||
physicsShape: []
|
||||
tessellationDetail: -1
|
||||
bones: []
|
||||
spriteID: 42e930d963da9e660800000000000000
|
||||
internalID: 7415648711516331556
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
outline: []
|
||||
customData:
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spriteCustomMetadata:
|
||||
entries: []
|
||||
nameFileIdTable: {}
|
||||
mipmapLimitGroupName:
|
||||
pSDRemoveMatte: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -40,6 +40,9 @@ TagManager:
|
||||
-
|
||||
-
|
||||
m_SortingLayers:
|
||||
- name: Background
|
||||
uniqueID: 1649966903
|
||||
locked: 0
|
||||
- name: Default
|
||||
uniqueID: 0
|
||||
locked: 0
|
||||
|
||||
Reference in New Issue
Block a user