WIP: show mini map textures

This commit is contained in:
Le Duc Anh
2026-01-20 23:59:28 +07:00
parent 0906634e3b
commit aec46e91d3
6 changed files with 354 additions and 95 deletions
+52 -88
View File
@@ -1,5 +1,44 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &413745454176280031
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 75608124384920614}
m_Layer: 0
m_Name: container
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &75608124384920614
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 413745454176280031}
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: 8174535735387258491}
- {fileID: 8054206389698391244}
- {fileID: 7794785241219751657}
- {fileID: 670009488162588346}
m_Father: {fileID: 121983901978661093}
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!1 &604329566345129304
GameObject:
m_ObjectHideFlags: 0
@@ -25,12 +64,12 @@ RectTransform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 604329566345129304}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
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: 121983901978661093}
m_Father: {fileID: 75608124384920614}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
@@ -72,78 +111,6 @@ MonoBehaviour:
y: 0
width: 1
height: 1
--- !u!1 &3357147516908433896
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 9106786228963300034}
- component: {fileID: 6311338615591418915}
- component: {fileID: 6879076171068205754}
m_Layer: 0
m_Name: minimapdir (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &9106786228963300034
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3357147516908433896}
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: 121983901978661093}
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 &6311338615591418915
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3357147516908433896}
m_CullTransparentMesh: 1
--- !u!114 &6879076171068205754
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3357147516908433896}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1344c3c82d62a2a41a3576d8abb8e3ea, 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_Texture: {fileID: 2800000, guid: f275f12a0e90a05409507b6e81547541, type: 3}
m_UVRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
--- !u!1 &4582549600041979364
GameObject:
m_ObjectHideFlags: 0
@@ -168,16 +135,12 @@ RectTransform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4582549600041979364}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
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: 8174535735387258491}
- {fileID: 8054206389698391244}
- {fileID: 7794785241219751657}
- {fileID: 670009488162588346}
- {fileID: 9106786228963300034}
- {fileID: 75608124384920614}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 1}
@@ -197,8 +160,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: dbb3be46f1d07224f90ade7b25776f34, type: 3}
m_Name:
m_EditorClassIdentifier:
m_pA3DRadarBack: {fileID: 0}
m_pA3DTexMask: {fileID: 0}
rowNum: 0
colNum: 0
subPath:
--- !u!1 &6081591716560099349
GameObject:
m_ObjectHideFlags: 0
@@ -224,12 +188,12 @@ RectTransform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6081591716560099349}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
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: 121983901978661093}
m_Father: {fileID: 75608124384920614}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
@@ -296,12 +260,12 @@ RectTransform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6612164655648313035}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
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: 121983901978661093}
m_Father: {fileID: 75608124384920614}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
@@ -368,12 +332,12 @@ RectTransform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7896377897001408850}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
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: 121983901978661093}
m_Father: {fileID: 75608124384920614}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace BrewMonster.Scripts
{
public class APoint<T> where T : IComparable<T>
{
public T x, y;
public APoint()
{
x = default(T);
y = default(T);
}
public APoint(T x, T y)
{
this.x = x;
this.y = y;
}
public APoint(APoint<T> p)
{
x = p.x;
y = p.y;
}
// Offset point
public void Offset(T ox, T oy)
{
x = Add(x, ox);
y = Add(y, oy);
}
// Set point
public void Set(T _x, T _y) { x = _x; y = _y; }
// helpers for int/float only
static T Add(T a, T b)
{
if (typeof(T) == typeof(int)) return (T)(object)((int)(object)a + (int)(object)b);
if (typeof(T) == typeof(float)) return (T)(object)((float)(object)a + (float)(object)b);
throw new NotSupportedException("APoint<T> supports only int and float");
}
static T Sub(T a, T b)
{
if (typeof(T) == typeof(int)) return (T)(object)((int)(object)a - (int)(object)b);
if (typeof(T) == typeof(float)) return (T)(object)((float)(object)a - (float)(object)b);
throw new NotSupportedException("APoint<T> supports only int and float");
}
static T Neg(T a)
{
if (typeof(T) == typeof(int)) return (T)(object)(-(int)(object)a);
if (typeof(T) == typeof(float)) return (T)(object)(-(float)(object)a);
throw new NotSupportedException("APoint<T> supports only int and float");
}
// == and != operator
public static bool operator !=(APoint<T> p1, APoint<T> p2)
{
return !(p1 == p2);
}
public static bool operator ==(APoint<T> p1, APoint<T> p2)
{
return EqualityComparer<T>.Default.Equals(p1.x, p2.x) &&
EqualityComparer<T>.Default.Equals(p1.y, p2.y);
}
// + and - operator
public static APoint<T> operator +(APoint<T> p1, APoint<T> p2)
{
return new APoint<T>(
Add(p1.x, p2.x),
Add(p1.y, p2.y)
);
}
public static APoint<T> operator -(APoint<T> p1, APoint<T> p2)
{
return new APoint<T>(
Sub(p1.x, p2.x),
Sub(p1.y, p2.y)
);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e211dffb7c0e84f2c83f6e397b134ecf
+15 -1
View File
@@ -4,6 +4,13 @@ using UnityEngine;
namespace BrewMonster.Scripts
{
/// <summary>
/// A rectangular area in 2D space.
/// </summary>
/// <remarks>
/// WARNING: This class contains many boxing and unboxing operations.
/// We have to go back and optimize this later.
/// </remarks>
public class ARect<T> where T : IComparable<T>
{
public T left, top, right, bottom;
@@ -45,6 +52,13 @@ namespace BrewMonster.Scripts
if (typeof(T) == typeof(float)) return (T)(object)((float)(object)a - (float)(object)b);
throw new NotSupportedException("ARect<T> supports only int and float");
}
static T Divide(T a, T b)
{
if (typeof(T) == typeof(int)) return (T)(object)((int)(object)a / (int)(object)b);
if (typeof(T) == typeof(float)) return (T)(object)((float)(object)a / (float)(object)b);
throw new NotSupportedException("ARect<T> supports only int and float");
}
static T Neg(T a)
{
if (typeof(T) == typeof(int)) return (T)(object)(-(int)(object)a);
@@ -199,7 +213,7 @@ namespace BrewMonster.Scripts
return Sub(bottom, top);
}
// Get center point of rectangle
//public APoint<T> CenterPoint() { return new APoint<T>((left + right) / 2, (top + bottom) / 2); }
public APoint<T> CenterPoint() { return new APoint<T>(Divide(Add(left, right), FromInt(2)), Divide(Add(top, bottom), FromInt(2))); }
// Set rectangle value
public void SetRect(T _left, T _top, T _right, T _bottom)
{
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: d0c06c588e2a6442488a3542551fb243
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,3 +1,6 @@
using BrewMonster;
using BrewMonster.Scripts;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
@@ -5,13 +8,198 @@ namespace PerfectWorld.UI.MiniMap
{
public class MiniMapUI : MonoBehaviour
{
// the background texture of the mini map
[SerializeField] private Texture2D m_pA3DRadarBack;
// the mask texture of the mini map
[SerializeField] private Texture2D m_pA3DTexMask;
public void Awake()
// constants
private const int MINIMAP_UL = 0;
private const int MINIMAP_UR = 1;
private const int MINIMAP_LL = 2;
private const int MINIMAP_LR = 3;
private const int MINIMAP_MAX = 4;
[SerializeField] private byte nRow, nCol; // number of rows and cols in the current map instances.txt
[SerializeField] private string subPath; // path to the minimap textures folder "surfaces/minimaps/"
[SerializeField] private RectTransform pObjMiniMap;
[SerializeField] private TMP_Text txtHostPos;
private float m_fZoom = 1.0f;
private bool m_bShowMark = true;
private bool m_bShowTargetArrow = true;
// map state
private bool isShowMiniMap = true;
CECHostPlayer m_pHostPlayer;
void Update()
{
UpdateMiniMap();
}
private void UpdateMiniMap()
{
m_pHostPlayer = GetHostPlayer();
if (m_pHostPlayer == null) return;
Vector3 vecPosHost = m_pHostPlayer.transform.position;
txtHostPos.text = $"{Mathf.RoundToInt(vecPosHost.x) / 10 + 400}, {Mathf.RoundToInt(vecPosHost.z)}";
float fRatio = 512.0f / 1024.0f / m_fZoom;
float fNormal = fRatio;
if( m_fZoom < 1.0f )
fNormal = fRatio * m_fZoom;
vecPosHost.x = Mathf.Floor(vecPosHost.x * fNormal) / fNormal;
vecPosHost.z = Mathf.Floor(vecPosHost.z * fNormal) / fNormal;
Rect rcMiniMap = pObjMiniMap.rect;
//ASSERT(rcMiniMap.Width() == rcMiniMap.Height());
int W = (int)rcMiniMap.width;
int H = (int)rcMiniMap.height;
Vector2 C = rcMiniMap.center;
Vector2 ptHost = new Vector2();
Vector2 idxHost = new Vector2();
Vector2 ptThisCenter = new Vector2();
Vector2[] idxCorner = new Vector2[MINIMAP_MAX];
Rect rcHost = new Rect();
Rect rcThis = new Rect();
Rect[] rcCell = new Rect[MINIMAP_MAX];
Rect[] rcInter = new Rect[MINIMAP_MAX];
int nSide = 256;
float fCell = 1024.0f;
float fSide = nSide;
float fOffsetX = nCol * fCell / 2.0f;
float fOffsetY = nRow * fCell / 2.0f;
ptHost.x = Mathf.FloorToInt((vecPosHost.x + fOffsetX) * 512.0f / 1024.0f);
ptHost.y = Mathf.FloorToInt((fOffsetY - vecPosHost.z) * 512.0f / 1024.0f);
idxHost.x = ptHost.x / nSide;
idxHost.y = ptHost.y / nSide;
rcThis.x = idxHost.x * nSide;
rcThis.y = idxHost.y * nSide;
rcThis.width = nSide;
rcThis.height = nSide;
ptThisCenter = rcThis.center;
if( ptHost.y <= ptThisCenter.y )
{
if( ptHost.x <= ptThisCenter.x ) // Upper left.
{
idxCorner[MINIMAP_UL].x = idxHost.x - 1;
idxCorner[MINIMAP_UL].y = idxHost.y - 1;
idxCorner[MINIMAP_UR].x = idxHost.x;
idxCorner[MINIMAP_UR].y = idxHost.y - 1;
idxCorner[MINIMAP_LL].x = idxHost.x - 1;
idxCorner[MINIMAP_LL].y = idxHost.y;
idxCorner[MINIMAP_LR].x = idxHost.x;
idxCorner[MINIMAP_LR].y = idxHost.y;
}
else // Upper right.
{
idxCorner[MINIMAP_UL].x = idxHost.x;
idxCorner[MINIMAP_UL].y = idxHost.y - 1;
idxCorner[MINIMAP_UR].x = idxHost.x + 1;
idxCorner[MINIMAP_UR].y = idxHost.y - 1;
idxCorner[MINIMAP_LL].x = idxHost.x;
idxCorner[MINIMAP_LL].y = idxHost.y;
idxCorner[MINIMAP_LR].x = idxHost.x + 1;
idxCorner[MINIMAP_LR].y = idxHost.y;
}
}
else
{
if( ptHost.x <= ptThisCenter.x ) // Lower left.
{
idxCorner[MINIMAP_UL].x = idxHost.x - 1;
idxCorner[MINIMAP_UL].y = idxHost.y;
idxCorner[MINIMAP_UR].x = idxHost.x;
idxCorner[MINIMAP_UR].y = idxHost.y;
idxCorner[MINIMAP_LL].x = idxHost.x - 1;
idxCorner[MINIMAP_LL].y = idxHost.y + 1;
idxCorner[MINIMAP_LR].x = idxHost.x;
idxCorner[MINIMAP_LR].y = idxHost.y + 1;
}
else // Lower right.
{
idxCorner[MINIMAP_UL].x = idxHost.x;
idxCorner[MINIMAP_UL].y = idxHost.y;
idxCorner[MINIMAP_UR].x = idxHost.x + 1;
idxCorner[MINIMAP_UR].y = idxHost.y;
idxCorner[MINIMAP_LL].x = idxHost.x;
idxCorner[MINIMAP_LL].y = idxHost.y + 1;
idxCorner[MINIMAP_LR].x = idxHost.x + 1;
idxCorner[MINIMAP_LR].y = idxHost.y + 1;
}
}
rcHost.x = ptHost.x - Mathf.FloorToInt(W * m_fZoom) / 2;
rcHost.y = ptHost.y - Mathf.FloorToInt(H * m_fZoom) / 2;
rcHost.width = Mathf.FloorToInt(W * m_fZoom);
rcHost.height = Mathf.FloorToInt(H * m_fZoom);
int i, j;
bool bval;
/*/
char szIndex[20];
AString strIndex;
bool bLoadNewMap = false;
for( i = MINIMAP_UL; i < MINIMAP_MAX; i++ )
{
rcCell[i].left = idxCorner[i].x * nSide;
rcCell[i].top = idxCorner[i].y * nSide;
rcCell[i].right = rcCell[i].left + nSide;
rcCell[i].bottom = rcCell[i].top + nSide;
rcInter[i] = rcCell[i] & rcHost;
if( rcInter[i].IsEmpty() )
rcInter[i].Offset(rcCell[i].left, rcCell[i].top);
sprintf(szIndex, "%02d%02d", idxCorner[i].y, idxCorner[i].x);
strIndex = szIndex;
if( !m_TexMap[strIndex] )
{
A3DTexture *pA3DTex = m_pA3DRadarBack;
if( idxCorner[i].x >= 0 && idxCorner[i].x < nCol * 2 &&
idxCorner[i].y >= 0 && idxCorner[i].y < nRow * 2 )
{
pA3DTex = new A3DTexture;
AString strFile;
if(GetWorld()->IsRandomMap())
{
strFile = "temp\\Surfaces\\MiniMaps\\" + GetGameRun()->GetRandomMapProc()->GetMapName() + "\\" + strIndex + ".dds";
pA3DTex->SetNoDownSample(true);
unsigned char* pData = NULL;
int iLen = 0;
if(GetGameRun()->GetRandomMapProc()->EncodeMap(strFile,pData,iLen))
{
bool bval = pA3DTex->LoadFromMemory(m_pA3DDevice,pData,iLen,256,256,A3DFMT_UNKNOWN);
ASSERT(bval);
delete [] pData;
}
}
else
{
strFile = "Surfaces\\MiniMaps\\" + strSubPath + "\\" + strIndex + ".dds";
pA3DTex->SetNoDownSample(true);
pA3DTex->LoadFromFile(m_pA3DDevice, strFile, strFile);
}
}
m_TexMap[strIndex] = pA3DTex;
bLoadNewMap = true;
}
}
//*/
}
private CECHostPlayer GetHostPlayer()
{
return CECGameRun.Instance.GetHostPlayer();
}
}
}