64 lines
1.1 KiB
C#
64 lines
1.1 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace GaiaCommon1
|
|
{
|
|
[Serializable]
|
|
public class UBrush
|
|
{
|
|
private float[] m_Strength;
|
|
|
|
private Texture2D m_Brush;
|
|
|
|
private const int MIN_BRUSH_SIZE = 3;
|
|
|
|
public int Size { get; private set; }
|
|
|
|
public bool Load(Texture2D brushTex, int size)
|
|
{
|
|
if (m_Brush == brushTex && size == Size && m_Strength != null)
|
|
{
|
|
return true;
|
|
}
|
|
if (brushTex != null)
|
|
{
|
|
float num = size;
|
|
Size = size;
|
|
m_Strength = new float[Size * Size];
|
|
if (Size > 3)
|
|
{
|
|
for (int i = 0; i < Size; i++)
|
|
{
|
|
for (int j = 0; j < Size; j++)
|
|
{
|
|
m_Strength[i * Size + j] = brushTex.GetPixelBilinear(((float)j + 0.5f) / num, (float)i / num).a;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int k = 0; k < m_Strength.Length; k++)
|
|
{
|
|
m_Strength[k] = 1f;
|
|
}
|
|
}
|
|
m_Brush = brushTex;
|
|
return true;
|
|
}
|
|
m_Strength = new float[1];
|
|
m_Strength[0] = 1f;
|
|
Size = 1;
|
|
return false;
|
|
}
|
|
|
|
public float GetStrengthAtCoords(int ix, int iy)
|
|
{
|
|
if (ix < 0 || Size <= ix || iy < 0 || Size <= iy)
|
|
{
|
|
return 0f;
|
|
}
|
|
return m_Strength[iy * Size + ix];
|
|
}
|
|
}
|
|
}
|