第一次提交
This commit is contained in:
10
Assets/Scripts/Utils/APIs.cs
Normal file
10
Assets/Scripts/Utils/APIs.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
public class APIs
|
||||
{
|
||||
public static bool IsUInt(string str)
|
||||
{
|
||||
Regex myReg = new Regex(@"\d+$");
|
||||
return myReg.IsMatch(str);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Utils/APIs.cs.meta
Normal file
11
Assets/Scripts/Utils/APIs.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b181c6e8a607d14eb5b6cac95d3ebdf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
Assets/Scripts/Utils/PathUtil.cs
Normal file
20
Assets/Scripts/Utils/PathUtil.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
public class PathUtil
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>Ҽ<EFBFBD><D2BC><EFBFBD>texture ·<><C2B7>
|
||||
public static string GetTexture(int mapId, string name, string suffix)
|
||||
{
|
||||
return $"{Application.dataPath}/GameAssets/Maps/{mapId}/Texture/{name}.{suffix}";
|
||||
}
|
||||
|
||||
|
||||
#region XML
|
||||
|
||||
public static string GetXmlPath(int mapId, string fileName)
|
||||
{
|
||||
return $"{Application.dataPath}/GameAssets/Maps/{mapId}/XML/{fileName}.xml";
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
11
Assets/Scripts/Utils/PathUtil.cs.meta
Normal file
11
Assets/Scripts/Utils/PathUtil.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf197c687843a764c9b6e1a17bea86eb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
84
Assets/Scripts/Utils/UIMouseOver.cs
Normal file
84
Assets/Scripts/Utils/UIMouseOver.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class UIMouseOver : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
Coroutine _trackCor;
|
||||
private RectTransform _canvasRectTransform;//<2F><><EFBFBD><EFBFBD>
|
||||
|
||||
//地图的宽高
|
||||
public int worldWidth;
|
||||
public int worldHeight;
|
||||
|
||||
//
|
||||
private float _initX;
|
||||
private float _initY;
|
||||
|
||||
private Vector3 _overPos;
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if(UIWindow.Instance.uiMapPanel.CurOpenMapId < 0)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("先打开地图");
|
||||
return;
|
||||
}
|
||||
|
||||
worldWidth = MapManager.Instance.mapWidth;
|
||||
worldHeight = MapManager.Instance.mapHeight;
|
||||
|
||||
_canvasRectTransform = UIWindow.Instance.newMapTrans.parent.GetComponent<RectTransform>();
|
||||
|
||||
_trackCor = StartCoroutine(TrackPointer());
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (_trackCor == null)
|
||||
return;
|
||||
|
||||
StopCoroutine(_trackCor);
|
||||
|
||||
_trackCor = null;
|
||||
}
|
||||
|
||||
IEnumerator TrackPointer()
|
||||
{
|
||||
while (Application.isPlaying)
|
||||
{
|
||||
CurMousePosition();
|
||||
yield return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void CurMousePosition()
|
||||
{
|
||||
Vector2 pos;
|
||||
Vector2 screenPos = RectTransformUtility.WorldToScreenPoint(Camera.main, Input.mousePosition);
|
||||
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(_canvasRectTransform, Input.mousePosition, Camera.main, out pos))
|
||||
{
|
||||
float offsetX = UIWindow.Instance.newMapTrans.GetComponent<RectTransform>().anchoredPosition.x - _initX;
|
||||
float offsetY = UIWindow.Instance.newMapTrans.GetComponent<RectTransform>().anchoredPosition.y - _initY;
|
||||
|
||||
float x = pos.x - offsetX;
|
||||
float y = pos.y - offsetY;
|
||||
|
||||
Debug.Log($"坐标:{x + worldWidth / 10 / 2}, {y + worldHeight / 10 / 2}");
|
||||
_overPos = new Vector3(x + worldWidth / 10 / 2, 0, y + worldHeight / 10 / 2);
|
||||
}
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
_initX = UIWindow.Instance.newMapTrans.transform.GetComponent<RectTransform>().anchoredPosition.x;
|
||||
_initY = UIWindow.Instance.newMapTrans.transform.GetComponent<RectTransform>().anchoredPosition.y;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Utils/UIMouseOver.cs.meta
Normal file
11
Assets/Scripts/Utils/UIMouseOver.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd5845003f63cbd4db0eb1b6d59c51bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
96
Assets/Scripts/Utils/UnityOpenFolder.cs
Normal file
96
Assets/Scripts/Utils/UnityOpenFolder.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using Ookii.Dialogs;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
public class UnityOpenFolder
|
||||
{
|
||||
public struct ExtensionFilter
|
||||
{
|
||||
public string Name;
|
||||
public string[] Extensions;
|
||||
|
||||
public ExtensionFilter(string filterName, params string[] filterExtensions)
|
||||
{
|
||||
Name = filterName;
|
||||
Extensions = filterExtensions;
|
||||
}
|
||||
}
|
||||
|
||||
public class WindowWrapper : IWin32Window
|
||||
{
|
||||
private IntPtr _hwnd;
|
||||
public WindowWrapper(IntPtr handle) { _hwnd = handle; }
|
||||
public IntPtr Handle { get { return _hwnd; } }
|
||||
}
|
||||
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern IntPtr GetActiveWindow();
|
||||
|
||||
public static string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect)
|
||||
{
|
||||
var fd = new VistaOpenFileDialog();
|
||||
fd.Title = title;
|
||||
if (extensions != null)
|
||||
{
|
||||
fd.Filter = GetFilterFromFileExtensionList(extensions);
|
||||
fd.FilterIndex = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fd.Filter = string.Empty;
|
||||
}
|
||||
fd.Multiselect = multiselect;
|
||||
if (!string.IsNullOrEmpty(directory))
|
||||
{
|
||||
fd.FileName = GetDirectoryPath(directory);
|
||||
}
|
||||
var res = fd.ShowDialog(new WindowWrapper(GetActiveWindow()));
|
||||
var filenames = res == DialogResult.OK ? fd.FileNames : new string[0];
|
||||
fd.Dispose();
|
||||
return filenames;
|
||||
}
|
||||
|
||||
|
||||
private static string GetFilterFromFileExtensionList(ExtensionFilter[] extensions)
|
||||
{
|
||||
var filterString = "";
|
||||
foreach (var filter in extensions)
|
||||
{
|
||||
filterString += filter.Name + "(";
|
||||
|
||||
foreach (var ext in filter.Extensions)
|
||||
{
|
||||
filterString += "*." + ext + ",";
|
||||
}
|
||||
|
||||
filterString = filterString.Remove(filterString.Length - 1);
|
||||
filterString += ") |";
|
||||
|
||||
foreach (var ext in filter.Extensions)
|
||||
{
|
||||
filterString += "*." + ext + "; ";
|
||||
}
|
||||
|
||||
filterString += "|";
|
||||
}
|
||||
filterString = filterString.Remove(filterString.Length - 1);
|
||||
return filterString;
|
||||
}
|
||||
|
||||
private static string GetDirectoryPath(string directory)
|
||||
{
|
||||
var directoryPath = Path.GetFullPath(directory);
|
||||
if (!directoryPath.EndsWith("\\"))
|
||||
{
|
||||
directoryPath += "\\";
|
||||
}
|
||||
if (Path.GetPathRoot(directoryPath) == directoryPath)
|
||||
{
|
||||
return directory;
|
||||
}
|
||||
return Path.GetDirectoryName(directoryPath) + Path.DirectorySeparatorChar;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Utils/UnityOpenFolder.cs.meta
Normal file
11
Assets/Scripts/Utils/UnityOpenFolder.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b16c05e51eca00748a397a3b56819109
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user