276 lines
6.0 KiB
C#
276 lines
6.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[Serializable]
|
|
public class splat_output_class
|
|
{
|
|
public bool active;
|
|
|
|
public bool foldout;
|
|
|
|
public Color color_splat;
|
|
|
|
public float strength;
|
|
|
|
public List<float> mix;
|
|
|
|
public bool splat_custom_foldout;
|
|
|
|
public string splat_text;
|
|
|
|
public bool terrain_splat_assigned;
|
|
|
|
public mix_mode_enum mix_mode;
|
|
|
|
public Rect rect;
|
|
|
|
public List<animation_curve_class> curves;
|
|
|
|
public animation_curve_math_class animation_curve_math;
|
|
|
|
public List<int> splat;
|
|
|
|
public value_class splat_value;
|
|
|
|
public List<string> swap_text;
|
|
|
|
public List<splat_custom_class> splat_custom;
|
|
|
|
public splat_output_class()
|
|
{
|
|
foldout = true;
|
|
color_splat = new Color(2f, 2f, 2f, 1f);
|
|
strength = 1f;
|
|
mix = new List<float>();
|
|
splat_custom_foldout = true;
|
|
splat_text = "Splat:";
|
|
curves = new List<animation_curve_class>();
|
|
animation_curve_math = new animation_curve_math_class();
|
|
splat = new List<int>();
|
|
splat_value = new value_class();
|
|
swap_text = new List<string>();
|
|
splat_custom = new List<splat_custom_class>();
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
add_splat(i, i, 0);
|
|
}
|
|
}
|
|
|
|
public virtual void SyncSplatCustom(int splatLength)
|
|
{
|
|
int num = splat.Count - splat_custom.Count;
|
|
if (num > 0)
|
|
{
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
splat_custom.Add(new splat_custom_class(splatLength));
|
|
}
|
|
}
|
|
else if (num < 0)
|
|
{
|
|
for (int i = 0; i < -num; i++)
|
|
{
|
|
splat_custom.RemoveAt(splat_custom.Count - 1);
|
|
}
|
|
}
|
|
for (int i = 0; i < splat_custom.Count; i++)
|
|
{
|
|
num = splatLength - splat_custom[i].value.Count;
|
|
if (num > 0)
|
|
{
|
|
for (int j = 0; j < num; j++)
|
|
{
|
|
splat_custom[i].value.Add(0f);
|
|
}
|
|
}
|
|
else if (num < 0)
|
|
{
|
|
for (int j = 0; j < -num; j++)
|
|
{
|
|
splat_custom[i].value.RemoveAt(splat_custom[i].value.Count - 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public virtual void FoldAllSplatCustom(bool invert)
|
|
{
|
|
for (int i = 0; i < splat_custom.Count; i++)
|
|
{
|
|
if (invert)
|
|
{
|
|
splat_custom[i].foldout = !splat_custom[i].foldout;
|
|
}
|
|
else
|
|
{
|
|
splat_custom[i].foldout = splat_custom_foldout;
|
|
}
|
|
}
|
|
if (!invert)
|
|
{
|
|
splat_custom_foldout = !splat_custom_foldout;
|
|
}
|
|
}
|
|
|
|
public virtual void add_splat(int splat_number, int splat_index, int splatLength)
|
|
{
|
|
splat.Insert(splat_number, splat_index);
|
|
curves.Insert(splat_number, new animation_curve_class());
|
|
mix.Insert(splat_number, 0.5f);
|
|
splat_value.add_value(splat_number, 50f);
|
|
swap_text.Insert(splat_number, "S");
|
|
splat_custom.Insert(splat_number, new splat_custom_class(splatLength));
|
|
set_splat_curve();
|
|
set_splat_text();
|
|
}
|
|
|
|
public virtual void erase_splat(int splat_number)
|
|
{
|
|
if (splat.Count > 0)
|
|
{
|
|
splat.RemoveAt(splat_number);
|
|
mix.RemoveAt(splat_number);
|
|
curves.RemoveAt(splat_number);
|
|
splat_value.erase_value(splat_number);
|
|
swap_text.RemoveAt(splat_number);
|
|
splat_custom.RemoveAt(splat_number);
|
|
set_splat_curve();
|
|
set_splat_text();
|
|
}
|
|
}
|
|
|
|
public virtual void clear_splat()
|
|
{
|
|
splat.Clear();
|
|
splat_custom.Clear();
|
|
splat_value.clear_value();
|
|
mix.Clear();
|
|
curves.Clear();
|
|
swap_text.Clear();
|
|
set_splat_curve();
|
|
set_splat_text();
|
|
}
|
|
|
|
public virtual void swap_splat(int splat_number1, int splat_number2)
|
|
{
|
|
if (splat_number2 > -1 && splat_number2 < splat.Count)
|
|
{
|
|
float num = splat[splat_number1];
|
|
splat_custom_class value = splat_custom[splat_number1];
|
|
splat[splat_number1] = splat[splat_number2];
|
|
splat_custom[splat_number1] = splat_custom[splat_number2];
|
|
splat_custom[splat_number2] = value;
|
|
splat[splat_number2] = (int)num;
|
|
splat_value.swap_value(splat_number1, splat_number2);
|
|
set_splat_curve();
|
|
}
|
|
}
|
|
|
|
public virtual void set_splat_curve()
|
|
{
|
|
float num = curves.Count;
|
|
int num2 = 0;
|
|
int num3 = default(int);
|
|
Keyframe[] array = null;
|
|
for (int i = 0; i < curves.Count; i++)
|
|
{
|
|
if (!splat_value.active[i])
|
|
{
|
|
curves[i].curve = AnimationCurve.Linear(0f, 0f, 0f, 0f);
|
|
num -= 1f;
|
|
}
|
|
}
|
|
if (num == 1f)
|
|
{
|
|
curves[0].curve = AnimationCurve.Linear(0f, 1f, 1f, 1f);
|
|
return;
|
|
}
|
|
float num4 = default(float);
|
|
num4 = 1f / num;
|
|
float num5 = default(float);
|
|
float num6 = default(float);
|
|
for (int i = 0; i < curves.Count; i++)
|
|
{
|
|
if (!splat_value.active[i])
|
|
{
|
|
num2++;
|
|
continue;
|
|
}
|
|
num3 = i - num2;
|
|
curves[i].curve = new AnimationCurve();
|
|
if (mix_mode == mix_mode_enum.Single)
|
|
{
|
|
if (num3 == 0)
|
|
{
|
|
num5 = (1f - mix[1]) * (num4 / 2f);
|
|
}
|
|
if (num3 > 0 && !((float)num3 >= num - 1f))
|
|
{
|
|
num5 = (1f - mix[i]) * (num4 / 2f);
|
|
num6 = (1f - mix[i + 1]) * (num4 / 2f);
|
|
}
|
|
if ((float)num3 == num - 1f)
|
|
{
|
|
num6 = (1f - mix[i]) * (num4 / 2f);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
num5 = (1f - mix[0]) * (num4 / 2f);
|
|
num6 = (1f - mix[0]) * (num4 / 2f);
|
|
}
|
|
if (num <= 1f)
|
|
{
|
|
continue;
|
|
}
|
|
if (num3 == 0)
|
|
{
|
|
array = new Keyframe[3]
|
|
{
|
|
new Keyframe(0f, 1f),
|
|
new Keyframe(num5 + num4 / 2f, 1f),
|
|
new Keyframe(num4 * (float)(num3 + 1) - num5 + 1E-07f + num4 / 2f, 0f)
|
|
};
|
|
}
|
|
if (num3 > 0 && !((float)num3 >= num - 1f))
|
|
{
|
|
array = new Keyframe[4]
|
|
{
|
|
new Keyframe(num4 * (float)(num3 - 1) + num5 - 1E-07f + num4 / 2f, 0f),
|
|
new Keyframe(num4 * (float)num3 - num5 + num4 / 2f, 1f),
|
|
default(Keyframe),
|
|
default(Keyframe)
|
|
};
|
|
if (!Mathf.Approximately(num4 * (float)num3 - num5 + num4 / 2f, num4 * (float)num3 + num6 + num4 / 2f))
|
|
{
|
|
array[2] = new Keyframe(num4 * (float)num3 + num6 + num4 / 2f, 1f);
|
|
}
|
|
array[3] = new Keyframe(num4 * (float)(num3 + 1) - num6 + 1E-07f + num4 / 2f, 0f);
|
|
}
|
|
if ((float)num3 == num - 1f)
|
|
{
|
|
array = new Keyframe[3]
|
|
{
|
|
new Keyframe(num4 * (float)(num3 - 1) + num6 - 1E-07f + num4 / 2f, 0f),
|
|
new Keyframe(1f - num6 - num4 / 2f, 1f),
|
|
new Keyframe(1f, 1f)
|
|
};
|
|
}
|
|
curves[i].curve = animation_curve_math.set_curve_linear(new AnimationCurve(array));
|
|
}
|
|
}
|
|
|
|
public virtual void set_splat_text()
|
|
{
|
|
if (splat.Count > 1)
|
|
{
|
|
splat_text = "Splats(" + splat.Count + ")";
|
|
}
|
|
else
|
|
{
|
|
splat_text = "Splat";
|
|
}
|
|
}
|
|
}
|