mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
no message
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
using HPJ.Simulation.Enums;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace HPJ.Simulation.Utilities
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
public static float Distance(this IntVector2 vector)
|
||||
{
|
||||
return (float)System.Math.Sqrt(vector.x * vector.x + vector.y * vector.y);
|
||||
}
|
||||
|
||||
public static int SqrDistance(this IntVector2 vector)
|
||||
{
|
||||
return vector.x * vector.x + vector.y * vector.y;
|
||||
}
|
||||
|
||||
public static string TilesToString(this TileTypes[] Tiles)
|
||||
{
|
||||
if (Tiles.Length == 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
string ReturnString = "";
|
||||
for(int i = 0; i < Tiles.Length - 1; i++)
|
||||
{
|
||||
ReturnString += $"{Tiles[i]}.";
|
||||
}
|
||||
ReturnString += $"{Tiles[Tiles.Length - 1]}.";
|
||||
|
||||
return ReturnString;
|
||||
}
|
||||
|
||||
public static string TilesToString(this List<TileTypes> Tiles)
|
||||
{
|
||||
if (Tiles.Count == 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
string ReturnString = "";
|
||||
for (int i = 0; i < Tiles.Count - 1; i++)
|
||||
{
|
||||
ReturnString += $"{Tiles[i]}.";
|
||||
}
|
||||
ReturnString += $"{Tiles[Tiles.Count - 1]}.";
|
||||
|
||||
return ReturnString;
|
||||
}
|
||||
|
||||
public static TileTypes[] StringToTilesArray(this string TilesStringArray)
|
||||
{
|
||||
string[] Split = TilesStringArray.Split('.');
|
||||
|
||||
if (Split.Length == 0)
|
||||
{
|
||||
return new TileTypes[1] { TileTypes.Free };
|
||||
}
|
||||
|
||||
TileTypes[] ReturnArr = new TileTypes[Split.Length];
|
||||
|
||||
string[] EnumNames = System.Enum.GetNames(typeof(TileTypes));
|
||||
for (int splitIndex = 0; splitIndex < Split.Length; splitIndex++)
|
||||
{
|
||||
for(int enumIndex = 0; enumIndex < EnumNames.Length; enumIndex++)
|
||||
{
|
||||
if (EnumNames[enumIndex] == Split[splitIndex])
|
||||
{
|
||||
ReturnArr[splitIndex] = (TileTypes)enumIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ReturnArr;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf82f03bbe52cc14c8644aca8076615f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b17713f3d6762747909224fe3c9184e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,59 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace HPJ.Simulation.Utilities
|
||||
{
|
||||
[System.Serializable]
|
||||
public class Pool<T>
|
||||
{
|
||||
public List<T> Active;
|
||||
public List<T> Inactive;
|
||||
|
||||
public Pool()
|
||||
{
|
||||
Active = new List<T>();
|
||||
Inactive = new List<T>();
|
||||
}
|
||||
|
||||
public T GetItem()
|
||||
{
|
||||
if (Inactive.Count > 0)
|
||||
{
|
||||
T Item = Inactive[0];
|
||||
Inactive.RemoveAt(0);
|
||||
return Item;
|
||||
}
|
||||
|
||||
return default(T);
|
||||
}
|
||||
|
||||
public void ReturnItem(T Item)
|
||||
{
|
||||
if (Active.Contains(Item))
|
||||
{
|
||||
Active.Remove(Item);
|
||||
Inactive.Add(Item);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddItem(T Item, bool AddToActiveList = true)
|
||||
{
|
||||
if (AddToActiveList)
|
||||
{
|
||||
Active.Add(Item);
|
||||
}
|
||||
else
|
||||
{
|
||||
Inactive.Add(Item);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReturnAll()
|
||||
{
|
||||
for (int i = 0; i < Active.Count; i++)
|
||||
{
|
||||
Inactive.Add(Active[i]);
|
||||
}
|
||||
Active.Clear();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8bf26b81289be840af5d4dfdb184443
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user