NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Map/MapEditor.cs

55 lines
1.5 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using Framework;
using UnityEngine;
using Sirenix.OdinInspector;
using TGS;
using Debug = DebugUtil;
using Object = UnityEngine.Object;
public class MapEditor : MonoBehaviour
{
private const float UPP = 100f;
private const string GROUND_NAME = "Ground";
private GameObject _ground;
private TerrainGridSystem _tgs;
private MeshRenderer GroundRenderer => _ground.GetComponent<MeshRenderer>();
private bool Valid => _ground != null && _tgs != null;
[LabelText("地表材质")]
[PreviewField(Alignment = ObjectFieldAlignment.Center)]
[AssetList(Path = (Constants.MAP_TEXTURE_PATH_WITHOUT_ASSET))]
[OnValueChanged("OnGroundTextureChanged")]
[SerializeField]
private Material _groundMat;
private void Awake()
{
_ground = GameObject.Find(GROUND_NAME);
if (_ground == null)
{
Debug.LogError("Ground Is Null!");
}
_tgs = Object.FindObjectOfType<TerrainGridSystem>();
if (_tgs == null)
{
Debug.LogError("Terrain Grid System Is Null!");
}
}
private void OnGroundTextureChanged()
{
if (Valid && _groundMat != null)
{
GroundRenderer.sharedMaterial = _groundMat;
var mapScale = (new Vector2(_groundMat.mainTexture.width,
_groundMat.mainTexture.height) / UPP) * _tgs.regularHexagonsWidth;
_ground.transform.localScale = mapScale;
}
}
}