Initial commit
This commit is contained in:
12
Game/Assets/Scripts/Utils/Algorithms.cs
Normal file
12
Game/Assets/Scripts/Utils/Algorithms.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TransportGame.Utils
|
||||
{
|
||||
public static class Algorithmss
|
||||
{
|
||||
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Utils/Algorithms.cs.meta
Normal file
8
Game/Assets/Scripts/Utils/Algorithms.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67f24adfb8b21234184d0caf81f424ea
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
5
Game/Assets/Scripts/Utils/Algorithms.meta
Normal file
5
Game/Assets/Scripts/Utils/Algorithms.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fccffaafa6b9b0418cbdec944cef4ec
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
198
Game/Assets/Scripts/Utils/Algorithms/GridTraverseAlgorithm.cs
Normal file
198
Game/Assets/Scripts/Utils/Algorithms/GridTraverseAlgorithm.cs
Normal file
@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TransportGame.Utils.Algorithms
|
||||
{
|
||||
[Flags]
|
||||
public enum TravelDirections
|
||||
{
|
||||
North = 0x1,
|
||||
NorthEast = 0x2,
|
||||
East = 0x4,
|
||||
SouthEast = 0x8,
|
||||
South = 0x10,
|
||||
SouthWest = 0x20,
|
||||
West = 0x40,
|
||||
NorthWest = 0x80,
|
||||
NESW = North | East | West | South,
|
||||
All = North | NorthEast | East | SouthEast | South | SouthWest | West | NorthWest,
|
||||
}
|
||||
|
||||
public abstract class GridTraverseAlgorithm<T>
|
||||
{
|
||||
protected class TraverseVisitItem<TItem>
|
||||
{
|
||||
public TItem Item { get; private set; }
|
||||
public int X { get; private set; }
|
||||
public int Y { get; private set; }
|
||||
|
||||
public TraverseVisitItem(TItem item, int x, int y)
|
||||
{
|
||||
Item = item;
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
}
|
||||
|
||||
private static void GenerateDirections(out int[] dx, out int[] dy, TravelDirections dirs)
|
||||
{
|
||||
List<int> ddx = new List<int>();
|
||||
List<int> ddy = new List<int>();
|
||||
|
||||
if ((dirs & TravelDirections.North) > 0)
|
||||
{
|
||||
ddx.Add(0);
|
||||
ddy.Add(1);
|
||||
}
|
||||
if ((dirs & TravelDirections.NorthEast) > 0)
|
||||
{
|
||||
ddx.Add(1);
|
||||
ddy.Add(1);
|
||||
}
|
||||
if ((dirs & TravelDirections.East) > 0)
|
||||
{
|
||||
ddx.Add(1);
|
||||
ddy.Add(0);
|
||||
}
|
||||
if ((dirs & TravelDirections.SouthEast) > 0)
|
||||
{
|
||||
ddx.Add(1);
|
||||
ddy.Add(-1);
|
||||
}
|
||||
if ((dirs & TravelDirections.South) > 0)
|
||||
{
|
||||
ddx.Add(0);
|
||||
ddy.Add(-1);
|
||||
}
|
||||
if ((dirs & TravelDirections.SouthWest) > 0)
|
||||
{
|
||||
ddx.Add(-1);
|
||||
ddy.Add(-1);
|
||||
}
|
||||
if ((dirs & TravelDirections.West) > 0)
|
||||
{
|
||||
ddx.Add(-1);
|
||||
ddy.Add(0);
|
||||
}
|
||||
if ((dirs & TravelDirections.NorthWest) > 0)
|
||||
{
|
||||
ddx.Add(-1);
|
||||
ddy.Add(1);
|
||||
}
|
||||
|
||||
dx = ddx.ToArray();
|
||||
dy = ddy.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns element at specified position in the map
|
||||
/// </summary>
|
||||
/// <param name="x">X</param>
|
||||
/// <param name="y">Y</param>
|
||||
/// <returns>Element</returns>
|
||||
protected abstract T ElementAt(int x, int y);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the specified coordinates are valid (e.g. inside the map)
|
||||
/// </summary>
|
||||
/// <param name="x">X</param>
|
||||
/// <param name="y">Y</param>
|
||||
/// <returns>True if coordinates are valid</returns>
|
||||
protected abstract bool CoordinatesValid(int x, int y);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if specified item on the map can be visited
|
||||
/// </summary>
|
||||
/// <param name="toVisit">Item to visit</param>
|
||||
/// <param name="previous">Previous node</param>
|
||||
/// <returns>True if can be visited</returns>
|
||||
protected abstract bool CanVisit(TraverseVisitItem<T> toVisit, TraverseVisitItem<T> previous);
|
||||
|
||||
/// <summary>
|
||||
/// Called when an item enqueued to be visited later
|
||||
/// </summary>
|
||||
/// <param name="toVisit">Item to visit</param>
|
||||
/// <param name="current">Previous node</param>
|
||||
/// <returns>True if can be visited</returns>
|
||||
protected virtual void OnEnqueued(TraverseVisitItem<T> toVisit, TraverseVisitItem<T> previous)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when an item is visited
|
||||
/// </summary>
|
||||
/// <param name="item">Visited item</param>
|
||||
protected virtual void OnVisit(TraverseVisitItem<T> item)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Traverses a grid map
|
||||
/// </summary>
|
||||
/// <param name="originX">X coordinate of traversal starting point</param>
|
||||
/// <param name="originY">Y coordinate of traversal starting point</param>
|
||||
/// <param name="travelDirections">Possible traversal directions</param>
|
||||
public virtual void Traverse(IEnumerable<int> originsX, IEnumerable<int> originsY, TravelDirections travelDirections = TravelDirections.NESW)
|
||||
{
|
||||
// Get directions
|
||||
int[] dx, dy;
|
||||
GenerateDirections(out dx, out dy, travelDirections);
|
||||
|
||||
// Queue
|
||||
var toVisit = new Queue<TraverseVisitItem<T>>();
|
||||
|
||||
// Enqueue origins
|
||||
var itX = originsX.GetEnumerator();
|
||||
var itY = originsY.GetEnumerator();
|
||||
|
||||
while (itX.MoveNext() && itY.MoveNext())
|
||||
{
|
||||
if (CoordinatesValid(itX.Current, itY.Current))
|
||||
{
|
||||
var origin = new TraverseVisitItem<T>(ElementAt(itX.Current, itY.Current), itX.Current, itY.Current);
|
||||
toVisit.Enqueue(origin);
|
||||
}
|
||||
}
|
||||
|
||||
// Visit nodes in queue
|
||||
while (toVisit.Count > 0)
|
||||
{
|
||||
var item = toVisit.Dequeue();
|
||||
|
||||
// Visit item
|
||||
OnVisit(item);
|
||||
|
||||
// Enqueue neighbours in each direction
|
||||
for (int k = 0; k < dx.Length; k++)
|
||||
{
|
||||
int newx = item.X + dx[k];
|
||||
int newy = item.Y + dy[k];
|
||||
|
||||
if (CoordinatesValid(newx, newy))
|
||||
{
|
||||
var newitem = new TraverseVisitItem<T>(ElementAt(newx, newy), newx, newy);
|
||||
|
||||
if (CanVisit(newitem, item))
|
||||
{
|
||||
toVisit.Enqueue(newitem);
|
||||
OnEnqueued(newitem, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Traverses a grid map
|
||||
///// </summary>
|
||||
///// <param name="originX">X coordinate of traversal starting point</param>
|
||||
///// <param name="originY">Y coordinate of traversal starting point</param>
|
||||
///// <param name="travelDirections">Possible traversal directions</param>
|
||||
//public virtual void Traverse(int originX, int originY, TravelDirections travelDirections = TravelDirections.NESW)
|
||||
//{
|
||||
// Traverse(Enumerable.Repeat(originX, 1), Enumerable.Repeat(originY, 1), travelDirections);
|
||||
//}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 033176dc0e4c5594bbf5d1ec0034fbad
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
21
Game/Assets/Scripts/Utils/ColorHelper.cs
Normal file
21
Game/Assets/Scripts/Utils/ColorHelper.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TransportGame.Utils
|
||||
{
|
||||
public static class ColorHelper
|
||||
{
|
||||
public static Color FromArgb(int argb)
|
||||
{
|
||||
float a = ((argb >> 24) & 0xff) / 255f;
|
||||
float r = ((argb >> 16) & 0xff) / 255f;
|
||||
float g = ((argb >> 8) & 0xff) / 255f;
|
||||
float b = ((argb) & 0xff) / 255f;
|
||||
|
||||
return new Color(r, g, b, a);
|
||||
}
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Utils/ColorHelper.cs.meta
Normal file
8
Game/Assets/Scripts/Utils/ColorHelper.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec6caa7302e5ebd49815993ec3b07516
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
73
Game/Assets/Scripts/Utils/Logger.cs
Normal file
73
Game/Assets/Scripts/Utils/Logger.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TransportGame.Utils
|
||||
{
|
||||
public static class Logger
|
||||
{
|
||||
private static StreamWriter logFile;
|
||||
|
||||
public enum Level
|
||||
{
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
Critical
|
||||
}
|
||||
|
||||
public static void Log(Level level, string format, params object[] args)
|
||||
{
|
||||
// Open log file if not opened
|
||||
if (logFile == null)
|
||||
{
|
||||
logFile = new StreamWriter(String.Format("Logs\\{0}.log", DateTime.Now.Ticks));
|
||||
}
|
||||
|
||||
// Log to file
|
||||
logFile.Write("[{0}] ", Enum.GetName(typeof(Level), level));
|
||||
logFile.Write(DateTime.Now.ToLongTimeString());
|
||||
logFile.WriteLine(": " + format, args);
|
||||
|
||||
// Log to unity
|
||||
switch (level)
|
||||
{
|
||||
case Level.Warning:
|
||||
UnityEngine.Debug.LogWarning(String.Format(format, args));
|
||||
break;
|
||||
|
||||
case Level.Error:
|
||||
UnityEngine.Debug.LogError(String.Format(format, args));
|
||||
break;
|
||||
|
||||
case Level.Critical:
|
||||
UnityEngine.Debug.LogError(String.Format(format, args));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Info(string format, params object[] args)
|
||||
{
|
||||
Log(Level.Info, format, args);
|
||||
}
|
||||
|
||||
public static void Warning(string format, params object[] args)
|
||||
{
|
||||
Log(Level.Warning, format, args);
|
||||
}
|
||||
public static void Error(string format, params object[] args)
|
||||
{
|
||||
Log(Level.Error, format, args);
|
||||
}
|
||||
public static void Critical(string format, params object[] args)
|
||||
{
|
||||
Log(Level.Critical, format, args);
|
||||
}
|
||||
public static void Exception(Exception ex)
|
||||
{
|
||||
Log(Level.Critical, "{0}: {1}\nStack trace:{2}", ex.GetType().ToString(), ex.Message, ex.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Utils/Logger.cs.meta
Normal file
8
Game/Assets/Scripts/Utils/Logger.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab20d455f95d206489bf47b3c54fea3a
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
20
Game/Assets/Scripts/Utils/RandomExtensions.cs
Normal file
20
Game/Assets/Scripts/Utils/RandomExtensions.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TransportGame.Utils
|
||||
{
|
||||
public static class RandomExtensions
|
||||
{
|
||||
public static float NextSingle(this Random @this)
|
||||
{
|
||||
return Convert.ToSingle(@this.NextDouble());
|
||||
}
|
||||
|
||||
public static float NextSingle(this Random @this, float minValue, float maxValue)
|
||||
{
|
||||
return @this.NextSingle() * (maxValue - minValue) + minValue;
|
||||
}
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Utils/RandomExtensions.cs.meta
Normal file
8
Game/Assets/Scripts/Utils/RandomExtensions.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f49fb05c61ea6943963db5618373c75
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
29
Game/Assets/Scripts/Utils/Range.cs
Normal file
29
Game/Assets/Scripts/Utils/Range.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace TransportGame.Utils
|
||||
{
|
||||
public class Range
|
||||
{
|
||||
[XmlAttribute("min")]
|
||||
public float Minimum { get; set; }
|
||||
|
||||
[XmlAttribute("max")]
|
||||
public float Maximum { get; set; }
|
||||
|
||||
public Range()
|
||||
{
|
||||
Minimum = 0;
|
||||
Maximum = 1;
|
||||
}
|
||||
|
||||
public Range(float min, float max)
|
||||
{
|
||||
Minimum = min;
|
||||
Maximum = max;
|
||||
}
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Utils/Range.cs.meta
Normal file
8
Game/Assets/Scripts/Utils/Range.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b436281f9c7d49f4d935ae009d4559a8
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
197
Game/Assets/Scripts/Utils/Texture2DExtensions.cs
Normal file
197
Game/Assets/Scripts/Utils/Texture2DExtensions.cs
Normal file
@ -0,0 +1,197 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TransportGame.Utils
|
||||
{
|
||||
public static class Texture2DExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Draws a line between two vectors
|
||||
/// </summary>
|
||||
/// <param name="this">Texture</param>
|
||||
/// <param name="color">Color</param>
|
||||
/// <param name="p0">Position 1</param>
|
||||
/// <param name="p1">Position 2</param>
|
||||
public static void DrawLine(this Texture2D @this, Color color, Vector2 p0, Vector2 p1)
|
||||
{
|
||||
DrawLine(@this, color, Convert.ToInt32(p0.x), Convert.ToInt32(p0.y), Convert.ToInt32(p1.x), Convert.ToInt32(p1.y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a line between 2 points
|
||||
/// </summary>
|
||||
/// <param name="this">The texture</param>
|
||||
/// <param name="x0">X0</param>
|
||||
/// <param name="y0">Y0</param>
|
||||
/// <param name="x1">X1</param>
|
||||
/// <param name="y1">Y1</param>
|
||||
/// <param name="color">Color</param>
|
||||
public static void DrawLine(this Texture2D @this, Color color, int x0, int y0, int x1, int y1)
|
||||
{
|
||||
int dy = (int)(y1 - y0);
|
||||
int dx = (int)(x1 - x0);
|
||||
int stepx, stepy;
|
||||
|
||||
if (dy < 0) { dy = -dy; stepy = -1; }
|
||||
else { stepy = 1; }
|
||||
if (dx < 0) { dx = -dx; stepx = -1; }
|
||||
else { stepx = 1; }
|
||||
dy <<= 1;
|
||||
dx <<= 1;
|
||||
|
||||
float fraction = 0;
|
||||
|
||||
@this.SetPixelSafe(x0, y0, color);
|
||||
if (dx > dy)
|
||||
{
|
||||
fraction = dy - (dx >> 1);
|
||||
while (Mathf.Abs(x0 - x1) > 1)
|
||||
{
|
||||
if (fraction >= 0)
|
||||
{
|
||||
y0 += stepy;
|
||||
fraction -= dx;
|
||||
}
|
||||
x0 += stepx;
|
||||
fraction += dy;
|
||||
@this.SetPixelSafe(x0, y0, color);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fraction = dx - (dy >> 1);
|
||||
while (Mathf.Abs(y0 - y1) > 1)
|
||||
{
|
||||
if (fraction >= 0)
|
||||
{
|
||||
x0 += stepx;
|
||||
fraction -= dy;
|
||||
}
|
||||
y0 += stepy;
|
||||
fraction += dx;
|
||||
@this.SetPixelSafe(x0, y0, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rhombus-like point
|
||||
/// </summary>
|
||||
/// <param name="this">Texture</param>
|
||||
/// <param name="p0">Position</param>
|
||||
/// <param name="radius">Radius</param>
|
||||
/// <param name="color">Color</param>
|
||||
public static void DrawPoint(this Texture2D @this, Color color, Vector2 p0, int radius)
|
||||
{
|
||||
DrawPoint(@this, color, Convert.ToInt32(p0.x), Convert.ToInt32(p0.y), radius);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rhombus-like point
|
||||
/// </summary>
|
||||
/// <param name="this">Texture</param>
|
||||
/// <param name="x0">Position</param>
|
||||
/// <param name="y0">Position</param>
|
||||
/// <param name="radius">Radius</param>
|
||||
/// <param name="color">Color</param>
|
||||
public static void DrawPoint(this Texture2D @this, Color color, int x0, int y0, int radius)
|
||||
{
|
||||
for (int y = y0 - radius; y <= y0 + radius; ++y)
|
||||
{
|
||||
int pts = radius - Math.Abs(y - y0);
|
||||
|
||||
for (int x = x0 - pts; x <= x0 + pts; ++x)
|
||||
@this.SetPixelSafe(x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fills a polygon
|
||||
/// </summary>
|
||||
/// <param name="this">Texture</param>
|
||||
/// <param name="color">color</param>
|
||||
/// <param name="points">Points</param>
|
||||
public static void FillPolygon(this Texture2D @this, Color color, params Vector2[] points)
|
||||
{
|
||||
int minY = Int32.MaxValue, maxY = Int32.MinValue;
|
||||
// Unused... int[] ptX = points.Select(p => Convert.ToInt32(p.x)).ToArray();
|
||||
int[] ptY = points.Select(p => Convert.ToInt32(p.y)).ToArray();
|
||||
|
||||
// Find min and max row
|
||||
for (int i = 0; i < points.Length; i++)
|
||||
{
|
||||
minY = Math.Min(minY, ptY[i]);
|
||||
maxY = Math.Max(maxY, ptY[i]);
|
||||
}
|
||||
|
||||
List<int> intersPoints = new List<int>();
|
||||
|
||||
// Go through each row
|
||||
for (int y = minY; y <= maxY; ++y)
|
||||
{
|
||||
intersPoints.Clear();
|
||||
|
||||
// Find intersection points
|
||||
int j = points.Length - 1;
|
||||
for (int i = 0; i < points.Length; ++i)
|
||||
{
|
||||
// Treat special case where we have 2 points on the y axis
|
||||
if (ptY[i] == y && ptY[j] == y)
|
||||
{
|
||||
intersPoints.Add(Convert.ToInt32(points[i].x));
|
||||
intersPoints.Add(Convert.ToInt32(points[j].x));
|
||||
}
|
||||
|
||||
// Intersection
|
||||
else if ((ptY[i] >= y && ptY[j] <= y) ||
|
||||
(ptY[i] <= y && ptY[j] >= y))
|
||||
{
|
||||
int x = Convert.ToInt32(points[i].x + (y - points[i].y) * (points[j].x - points[i].x) / (points[j].y - points[i].y));
|
||||
intersPoints.Add(x);
|
||||
}
|
||||
|
||||
j = i;
|
||||
}
|
||||
|
||||
// Order pairs
|
||||
var intersPointsSorted = intersPoints.OrderBy(x => x).Distinct().ToArray();
|
||||
|
||||
// Draw
|
||||
for (int i = 0; i < intersPointsSorted.Length / 2; i++)
|
||||
{
|
||||
for (int x = intersPointsSorted[2 * i]; x <= intersPointsSorted[2 * i + 1]; x++)
|
||||
@this.SetPixelSafe(x, y, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fills texture with specified color
|
||||
/// </summary>
|
||||
/// <param name="this">Texture</param>
|
||||
/// <param name="color">Color</param>
|
||||
public static void Fill(this Texture2D @this, Color color)
|
||||
{
|
||||
for (int x = 0; x < @this.width; ++x)
|
||||
for (int y = 0; y < @this.height; ++y)
|
||||
@this.SetPixelSafe(x, y, color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a pixel after checking if coordinates are inside image
|
||||
/// </summary>
|
||||
/// <param name="this">Texture</param>
|
||||
/// <param name="x">X</param>
|
||||
/// <param name="y">Y</param>
|
||||
/// <param name="color">Color</param>
|
||||
public static void SetPixelSafe(this Texture2D @this, int x, int y, Color color)
|
||||
{
|
||||
if (x >= 0 && y >= 0 && x < @this.width && y < @this.height)
|
||||
@this.SetPixel(x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
8
Game/Assets/Scripts/Utils/Texture2DExtensions.cs.meta
Normal file
8
Game/Assets/Scripts/Utils/Texture2DExtensions.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d8f9264c2fb7e4459a82d533613c0f1
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
Reference in New Issue
Block a user