96 lines
1.6 KiB
C#
96 lines
1.6 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace EnvSpawn
|
|
{
|
|
[Serializable]
|
|
public class Bitmask
|
|
{
|
|
public string bitmask;
|
|
|
|
public Bitmask()
|
|
{
|
|
bitmask = string.Empty;
|
|
}
|
|
|
|
public Bitmask(int length)
|
|
{
|
|
bitmask = string.Empty;
|
|
for (uint num = 0u; num <= length; num++)
|
|
{
|
|
bitmask += "0";
|
|
}
|
|
}
|
|
|
|
public Bitmask(string bmask)
|
|
{
|
|
bitmask = bmask;
|
|
}
|
|
|
|
public int Length()
|
|
{
|
|
return bitmask.Length;
|
|
}
|
|
|
|
public int Get(uint i)
|
|
{
|
|
return int.Parse(bitmask.Substring((int)i, 1));
|
|
}
|
|
|
|
public string StrGet()
|
|
{
|
|
return bitmask;
|
|
}
|
|
|
|
public bool Evaluate(uint i)
|
|
{
|
|
return (Get(i) != 0) ? true : false;
|
|
}
|
|
|
|
public bool EvaluateAll()
|
|
{
|
|
for (uint num = 0u; num < Length(); num++)
|
|
{
|
|
if (Evaluate(num))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool Insert(int i, int a)
|
|
{
|
|
if (i >= Length())
|
|
{
|
|
Debug.Log("Bitmask size is smaller than requested index " + i);
|
|
return false;
|
|
}
|
|
bitmask = bitmask.Substring(0, i) + a + bitmask.Substring(i, Length() - i);
|
|
return true;
|
|
}
|
|
|
|
public bool Replace(int i, int a)
|
|
{
|
|
if (i >= Length())
|
|
{
|
|
Debug.Log("Bitmask size is smaller than requested index " + i);
|
|
return false;
|
|
}
|
|
bitmask = bitmask.Substring(0, i) + a + bitmask.Substring(i + 1, Length() - i - 1);
|
|
return true;
|
|
}
|
|
|
|
public bool Remove(int i)
|
|
{
|
|
if (i >= Length())
|
|
{
|
|
Debug.Log("Bitmask size is smaller than requested index " + i);
|
|
return false;
|
|
}
|
|
bitmask = bitmask.Substring(0, i) + bitmask.Substring(i + 1, Length() - i - 1);
|
|
return true;
|
|
}
|
|
}
|
|
}
|