Advertisement
medvedya

Vector2int

Jan 10th, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEngine;
  6.  
  7. namespace Medvedya.FOR2D
  8. {
  9.     [System.Serializable]
  10.     public struct Vector2int
  11.     {
  12.         public int X;
  13.         public int Y;
  14.         public static Vector2int UP { get { return new Vector2int(0, 1); } }
  15.         public static Vector2int DOWN { get { return new Vector2int(0, -1); } }
  16.         public static Vector2int LEFT { get { return new Vector2int(-1, 0); } }
  17.         public static Vector2int RIGHT { get { return new Vector2int(1, 0); } }
  18.         public static Vector2int ZERO { get { return new Vector2int(0, 0); } }
  19.         public static Vector2int[] allDirections = { UP, RIGHT, DOWN, LEFT };
  20.         public Vector2int(int x, int y)
  21.         {
  22.             X = x;
  23.             Y = y;
  24.         }
  25.         public static Vector2int operator +(Vector2int v1, Vector2int v2)
  26.         {
  27.             return new Vector2int(v1.X + v2.X, v1.Y + v2.Y);
  28.         }
  29.         public static Vector2int operator -(Vector2int v1, Vector2int v2)
  30.         {
  31.             return new Vector2int(v1.X - v2.X, v1.Y - v2.Y);
  32.         }
  33.         public static Vector2int operator *(Vector2int v1, int intValue)
  34.         {
  35.             return new Vector2int(v1.X * intValue, v1.Y * intValue);
  36.         }
  37.         public static Vector2int operator *(int intValue, Vector2int v1)
  38.         {
  39.             return v1 * intValue;
  40.         }
  41.        
  42.         public static Vector2 operator *(Vector2int v1, float floatValue)
  43.         {
  44.             return new Vector2(v1.X * floatValue, v1.Y * floatValue);
  45.         }
  46.         public static Vector2 operator *(float floatValue, Vector2int v1)
  47.         {
  48.             return v1 * floatValue;
  49.         }
  50.            
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement