using System; using UnityEngine; namespace PWCommon1 { [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) { ix = Mathf.Clamp(ix, 0, Size - 1); iy = Mathf.Clamp(iy, 0, Size - 1); return m_Strength[iy * Size + ix]; } } }