refactor: Update Unity to 2022.3.62

This commit is contained in:
2025-06-21 01:22:02 +08:00
parent d71bf7d4a5
commit 283783954f
112 changed files with 778 additions and 907 deletions

View File

@@ -14,7 +14,7 @@ namespace Cryville.Crtr.Skin.Components {
SubmitProperty("zindex", new PropOp.Integer(v => ZIndex = (short)v));
}
protected MeshWrapper mesh = new MeshWrapper();
protected MeshWrapper mesh = new();
protected Material[] materials;
short _zindex;

View File

@@ -6,13 +6,13 @@ using UnityEngine;
namespace Cryville.Crtr.Skin.Components {
public class PolygonSGO : SectionalGameObject {
static readonly SimpleObjectPool<List<Vector3>> _ptPool = new SimpleObjectPool<List<Vector3>>(1024);
static readonly SimpleObjectPool<List<float>> _lPool = new SimpleObjectPool<List<float>>(1024);
static readonly SimpleObjectPool<List<Vector3>> _ptPool = new(1024);
static readonly SimpleObjectPool<List<float>> _lPool = new(1024);
static readonly ListPool<int> _indexPool = new ListPool<int>();
static readonly ListPool<Vector3> _vertPool = new ListPool<Vector3>();
static readonly ListPool<Vector2> _uvPool = new ListPool<Vector2>();
static readonly ArrayPool<Vector2> _shapePool = new ArrayPool<Vector2>(0x100, 0x10000);
static readonly ListPool<int> _indexPool = new();
static readonly ListPool<Vector3> _vertPool = new();
static readonly ListPool<Vector2> _uvPool = new();
static readonly ArrayPool<Vector2> _shapePool = new(0x100, 0x10000);
public PolygonSGO() {
SubmitProperty("head", new PropOp.String(v => head.FrameName = v));
@@ -50,9 +50,9 @@ namespace Cryville.Crtr.Skin.Components {
return r;
}
public SpriteInfo head = new SpriteInfo();
public SpriteInfo body = new SpriteInfo();
public SpriteInfo tail = new SpriteInfo();
public SpriteInfo head = new();
public SpriteInfo body = new();
public SpriteInfo tail = new();
List<Vector3> vertices;
List<float> lengths;
@@ -104,7 +104,7 @@ namespace Cryville.Crtr.Skin.Components {
List<Vector3> verts;
List<Vector2> uvs;
List<int> trih = null, trib = null, trit = null;
static readonly List<int> _emptyTris = new List<int>();
static readonly List<int> _emptyTris = new();
public override void Seal() {
if (vertCount <= 1 || sumLength == 0) return;

View File

@@ -27,8 +27,7 @@ namespace Cryville.Crtr.Skin.Components {
}
else {
var id = new Identifier(value);
AnimationSpan anim;
if (!ChartPlayer.pskin.animations.TryGetValue(id, out anim)) {
if (!ChartPlayer.pskin.animations.TryGetValue(id, out AnimationSpan anim)) {
Game.MainLogger.Log(4, "Skin", "Animation {0} not found", id.Name);
_anim = null;
return;

View File

@@ -45,7 +45,7 @@ namespace Cryville.Crtr.Skin.Components {
}
else Frame = null;
if (_mat != null) {
_mat.mainTexture = Frame == null ? null : Frame.Texture;
_mat.mainTexture = Frame?.Texture;
}
}
public static bool IsNullOrEmpty(SpriteInfo sprite) {
@@ -88,7 +88,7 @@ namespace Cryville.Crtr.Skin.Components {
OnFrameUpdate();
}
}
SpriteInfo[] m_frames = new SpriteInfo[] { new SpriteInfo() };
SpriteInfo[] m_frames = new SpriteInfo[] { new() };
public string[] Frames {
set {
m_frames = new SpriteInfo[value.Length];
@@ -169,12 +169,12 @@ namespace Cryville.Crtr.Skin.Components {
protected override Vector3 BaseScale {
get {
switch (m_fit) {
case FitMode.none: return Vector3.one;
case FitMode.width: return new Vector3(1, 1, 1 / CurrentFrame.Ratio);
case FitMode.height: return new Vector3(CurrentFrame.Ratio, 1, 1);
default: throw new NotSupportedException("Unsupported fit mode");
}
return m_fit switch {
FitMode.none => Vector3.one,
FitMode.width => new Vector3(1, 1, 1 / CurrentFrame.Ratio),
FitMode.height => new Vector3(CurrentFrame.Ratio, 1, 1),
_ => throw new NotSupportedException("Unsupported fit mode"),
};
}
}

View File

@@ -9,7 +9,7 @@ namespace Cryville.Crtr.Skin.Components {
}
static readonly Dictionary<float, int> uvrefl
= new Dictionary<float, int>() {
= new() {
{-0.5f, 0}, {-0.4f, 1}, {0.4f, 2}, {0.5f, 3},
};
static Vector2[] _origuv;
@@ -30,7 +30,7 @@ namespace Cryville.Crtr.Skin.Components {
}
}
Vector2 _border = new Vector2(0, 1);
Vector2 _border = new(0, 1);
public Vector2 Border {
get { return _border; }
set {
@@ -67,12 +67,12 @@ namespace Cryville.Crtr.Skin.Components {
case 3: x = 1; bx = 1; break;
default: throw new NotSupportedException("Built-in resource corrupted");
}
float y;
switch ((int)muv[i].y) {
case 0: y = 0; break;
case 3: y = 1; break;
default: throw new NotSupportedException("Built-in resource corrupted");
}
var y = (int)muv[i].y switch {
0 => 0,
3 => (float)1,
_ => throw new NotSupportedException("Built-in resource corrupted"),
};
_uvs[i] = frame.Frame.GetUV(x, y);
bx -= 0.5f; y -= 0.5f;
_verts[i] = new Vector3(bx, 0, y);

View File

@@ -22,8 +22,7 @@ namespace Cryville.Crtr.Skin.Components {
protected override unsafe void Execute() {
var keys = GetOperand(0).AsString();
var values = GetOperand(1);
int arrtype; int len;
values.GetArraySuffix(out arrtype, out len);
values.GetArraySuffix(out int arrtype, out int len);
if (arrtype != PdtInternalType.String) throw new InvalidCastException("Not an array of strings");
if (len != keys.Length) throw new ArgumentException("Length of key not equal to frame count");
var result = new Dictionary<char, SpriteInfo>(len);
@@ -49,7 +48,7 @@ namespace Cryville.Crtr.Skin.Components {
set { m_frames = value; UpdateFrames(); }
}
readonly TargetString m_value = new TargetString();
readonly TargetString m_value = new();
public TargetString Value { get { return m_value; } }
public float m_size;
@@ -103,10 +102,10 @@ namespace Cryville.Crtr.Skin.Components {
}
float sum_x;
readonly Dictionary<Texture2D, MeshWrapper> meshes = new Dictionary<Texture2D, MeshWrapper>();
readonly Dictionary<Texture2D, List<Vector3>> verts = new Dictionary<Texture2D, List<Vector3>>();
readonly Dictionary<Texture2D, List<Vector2>> uvs = new Dictionary<Texture2D, List<Vector2>>();
readonly Dictionary<Texture2D, List<int>> tris = new Dictionary<Texture2D, List<int>>();
readonly Dictionary<Texture2D, MeshWrapper> meshes = new();
readonly Dictionary<Texture2D, List<Vector3>> verts = new();
readonly Dictionary<Texture2D, List<Vector2>> uvs = new();
readonly Dictionary<Texture2D, List<int>> tris = new();
void UpdateMeshes() {
if (meshes.Count == 0) return;
sum_x = 0;
@@ -117,8 +116,7 @@ namespace Cryville.Crtr.Skin.Components {
tris[key].Clear();
}
foreach (var c in m_value) {
SpriteInfo f;
if (!m_frames.TryGetValue(c, out f)) {
if (!m_frames.TryGetValue(c, out SpriteInfo f)) {
Game.MainLogger.Log(3, "Skin", "Could not render the character '{0}' in the string \"{1}\" on the text component because no image is assigned to that character.", c, m_value);
continue;
}
@@ -173,7 +171,7 @@ namespace Cryville.Crtr.Skin.Components {
UpdateFrames();
mesh.Mesh.Clear();
UpdateScale();
Value.OnUpdate += UpdateScale;
Value.Updated += UpdateScale;
}
}
}

View File

@@ -3,7 +3,7 @@ using UnityEngine;
namespace Cryville.Crtr.Skin.Components {
public class TrackLine : SectionalGameObject {
readonly List<Vector3> vertices = new List<Vector3>();
readonly List<Vector3> vertices = new();
LineRenderer lineRenderer;

View File

@@ -8,7 +8,7 @@ namespace Cryville.Crtr.Skin {
readonly EffectPool _pool;
class EffectPool : ObjectPool<EffectInstance> {
readonly List<EffectInstance> _instances
= new List<EffectInstance>();
= new();
readonly EffectGroup _group;
public EffectPool(EffectGroup group) : base(256) {
_group = group;
@@ -23,9 +23,9 @@ namespace Cryville.Crtr.Skin {
}
}
readonly Dictionary<float, EffectInstance> _instances
= new Dictionary<float, EffectInstance>();
= new();
readonly List<EffectInstance> _endQueue
= new List<EffectInstance>();
= new();
public EffectGroup(EffectDefinition def) {
Definition = def;
_pool = new EffectPool(this);
@@ -51,8 +51,7 @@ namespace Cryville.Crtr.Skin {
}
}
public void Emit(float index, Transform target = null) {
EffectInstance instance;
bool flag = _instances.TryGetValue(index, out instance);
bool flag = _instances.TryGetValue(index, out EffectInstance instance);
if (!flag) _instances.Add(index, instance = _pool.Rent());
instance.Index = index;
if (instance.CanEmit()) {

View File

@@ -33,7 +33,7 @@ namespace Cryville.Crtr.Skin {
ChartEvent _ctxev;
ContainerState _ctxstate;
internal static readonly int _VAR_EFFECT_INDEX = IdentifierManager.Shared.Request("effect_index");
readonly PropStores.Float _indexst = new PropStores.Float();
readonly PropStores.Float _indexst = new();
public float Index {
get { return _indexst.Value; }
set { _indexst.Value = value; }

View File

@@ -6,7 +6,7 @@ using UnityEngine;
namespace Cryville.Crtr.Skin {
public class EffectManager {
readonly IntKeyedDictionary<EffectGroup> _groups
= new IntKeyedDictionary<EffectGroup>();
= new();
public EffectManager(PdtSkin skin) {
foreach (var e in skin.effects) {
_groups.Add(e.Key.Key, new EffectGroup(e.Value));
@@ -22,8 +22,7 @@ namespace Cryville.Crtr.Skin {
GetGroup(id).Emit(index, target);
}
EffectGroup GetGroup(int id) {
EffectGroup result;
if (_groups.TryGetValue(id, out result)) return result;
if (_groups.TryGetValue(id, out EffectGroup result)) return result;
throw new ArgumentException(string.Format("The effect \"{0}\" is not found", IdentifierManager.Shared.Retrieve(id)));
}
public void Dispose() {

View File

@@ -9,12 +9,12 @@ namespace Cryville.Crtr.Skin {
readonly ISkinnableGroup _group;
readonly SkinElement _rootElement;
readonly DynamicStack[] _stacks = new DynamicStack[3];
readonly HashSet<SkinPropertyKey> _once = new HashSet<SkinPropertyKey>();
public readonly IntKeyedDictionary<PropStores.Float> Variables = new IntKeyedDictionary<PropStores.Float>();
readonly HashSet<SkinPropertyKey> _once = new();
public readonly IntKeyedDictionary<PropStores.Float> Variables = new();
class DynamicStack {
public readonly List<DynamicProperty> Properties = new List<DynamicProperty>();
public readonly List<DynamicElement> Elements = new List<DynamicElement>();
public readonly List<DynamicProperty> Properties = new();
public readonly List<DynamicElement> Elements = new();
public void Clear() {
Properties.Clear();
Elements.Clear();
@@ -78,7 +78,7 @@ namespace Cryville.Crtr.Skin {
var stack = _stacks[dl];
if (stack.Properties.Count == 0 && stack.Elements.Count == 0) return;
var nstack = dl + 1 < _stacks.Length ? _stacks[dl + 1] : null;
if (nstack != null) nstack.Clear();
nstack?.Clear();
Profiler.BeginSample("SkinContainer.MatchDynamic");
if (!recursive) PdtEvaluator.Instance.ContextSkinContainer = this;
for (int i = 0; i < stack.Properties.Count; i++) {
@@ -150,7 +150,7 @@ namespace Cryville.Crtr.Skin {
}
if (rc.PropSrcs != null) PdtEvaluator.Instance.ContextCascadeDiscard();
}
readonly PropStores.Float _rtimest = new PropStores.Float();
readonly PropStores.Float _rtimest = new();
public void MatchAnimation(AnimationSpan span, float rtime, RuntimeSkinContext ctx) {
PdtEvaluator.Instance.ContextSkinContainer = this;
PdtEvaluator.Instance.ContextSelfValue = _rtimest.Source;

View File

@@ -20,37 +20,35 @@ namespace Cryville.Crtr.Skin {
[JsonRequired]
public string ruleset;
public List<string> frames = new List<string>();
public List<string> frames = new();
[JsonIgnore]
public PdtSkin Root { get; private set; }
public void LoadPdt(DirectoryInfo dir) {
using (StreamReader pdtreader = new StreamReader(Path.Combine(dir.FullName, data + ".pdt"), Encoding.UTF8)) {
var src = pdtreader.ReadToEnd();
var interpreter = new SkinInterpreter(src, null);
var format = interpreter.GetFormatVersion();
if (format.Length == 1) {
Root = new PdtSkin();
Root.elements = (SkinElement)new SkinInterpreter(src, new PdtBinder()).Interpret(typeof(SkinElement));
}
else {
switch (format[1]) {
case 1:
Root = (PdtSkin)new SkinInterpreter(src, new PdtBinder()).Interpret(typeof(PdtSkin));
break;
default: throw new NotSupportedException("Unsupported skin format");
}
}
using StreamReader pdtreader = new(Path.Combine(dir.FullName, data + ".pdt"), Encoding.UTF8);
var src = pdtreader.ReadToEnd();
var interpreter = new SkinInterpreter(src, null);
var format = interpreter.GetFormatVersion();
if (format.Length == 1) {
Root = new PdtSkin {
elements = (SkinElement)new SkinInterpreter(src, new PdtBinder()).Interpret(typeof(SkinElement))
};
}
else {
Root = format[1] switch {
1 => (PdtSkin)new SkinInterpreter(src, new PdtBinder()).Interpret(typeof(PdtSkin)),
_ => throw new NotSupportedException("Unsupported skin format"),
};
}
}
}
public class PdtSkin {
public Dictionary<Identifier, AnimationSpan> animations
= new Dictionary<Identifier, AnimationSpan>();
= new();
public Dictionary<Identifier, EffectDefinition> effects
= new Dictionary<Identifier, EffectDefinition>();
= new();
public SkinElement elements;
public void Optimize(PdtEvaluator etor) {
@@ -74,11 +72,11 @@ namespace Cryville.Crtr.Skin {
public class SkinElement {
[ElementList]
public PairList<SkinSelectors, SkinElement> elements
= new PairList<SkinSelectors, SkinElement>();
= new();
[PropertyList]
public PairList<SkinPropertyKey, PdtExpression> properties
= new PairList<SkinPropertyKey, PdtExpression>();
= new();
public bool IsDynamic {
get;
@@ -102,19 +100,18 @@ namespace Cryville.Crtr.Skin {
}
public class EffectDefinition {
static readonly Identifier _ident_init = new Identifier("<init>");
static readonly Identifier _ident_init = new("<init>");
#pragma warning disable IDE1006
public PdtExpression duration {
set {
EffectState s;
if (!states.TryGetValue(_ident_init, out s))
if (!states.TryGetValue(_ident_init, out EffectState s))
throw new InvalidOperationException("Cannot set duration and states at the same time");
s.duration = value;
}
}
#pragma warning restore IDE1006
public Identifier init = _ident_init;
public Dictionary<Identifier, EffectState> states = new Dictionary<Identifier, EffectState> {
public Dictionary<Identifier, EffectState> states = new() {
{ _ident_init, new EffectState() { rewind = _ident_init } }
};
public SkinElement elements;
@@ -129,11 +126,11 @@ namespace Cryville.Crtr.Skin {
public class AnimationSpan {
[ElementList]
public PairList<Clip, AnimationSpan> spans
= new PairList<Clip, AnimationSpan>();
= new();
[PropertyList]
public PairList<SkinPropertyKey, PdtExpression> properties
= new PairList<SkinPropertyKey, PdtExpression>();
= new();
public void Optimize(PdtEvaluator etor) {
foreach (var p in properties) {

View File

@@ -7,9 +7,9 @@ namespace Cryville.Crtr.Skin {
public class SkinInterpreter : PdtInterpreter {
public SkinInterpreter(string src, Binder binder) : base(src, binder) { }
readonly List<SkinSelector> s = new List<SkinSelector>();
readonly HashSet<string> a = new HashSet<string>();
readonly List<string> k = new List<string>(2);
readonly List<SkinSelector> s = new();
readonly HashSet<string> a = new();
readonly List<string> k = new(2);
protected override object InterpretKey(Type type) {
if (typeof(SkinElement).IsAssignableFrom(type))
return InterpretSkinElementKey();

View File

@@ -40,8 +40,7 @@ namespace Cryville.Crtr.Skin {
throw new FormatException("Unknown error");
}
static Type GetComponentByName(string name) {
Type result;
if (BuiltinResources.Components.TryGetValue(name, out result)) return result;
if (BuiltinResources.Components.TryGetValue(name, out Type result)) return result;
throw new ArgumentException(string.Format("Component type \"{0}\" not found", name));
}
}
@@ -102,8 +101,7 @@ namespace Cryville.Crtr.Skin {
"Trying to set property \"{0}\" but the component is not found",
IdentifierManager.Shared.Retrieve(Name)
));
SkinProperty result;
if (!comp.Properties.TryGetValue(Name, out result))
if (!comp.Properties.TryGetValue(Name, out SkinProperty result))
throw new InvalidOperationException(string.Format(
"Property \"{0}\" not found on component",
IdentifierManager.Shared.Retrieve(Name)
@@ -186,15 +184,13 @@ namespace Cryville.Crtr.Skin {
}
public override bool IsValueRequired { get { return true; } }
public override void ExecuteStatic(ISkinnableGroup group, RuntimeSkinContext ctx, PdtExpression exp, IntKeyedDictionary<PropStores.Float> vars) {
PropStores.Float v;
if (!vars.TryGetValue(Name, out v))
if (!vars.TryGetValue(Name, out PropStores.Float v))
vars.Add(Name, v = new PropStores.Float());
if (!PdtEvaluator.Instance.Evaluate(v.Target, exp))
throw new EvaluationFailureException();
}
public override void ExecuteDynamic(ISkinnableGroup group, RuntimeSkinContext ctx, PdtExpression exp, IntKeyedDictionary<PropStores.Float> vars, int dl) {
PropStores.Float v;
if (!vars.TryGetValue(Name, out v))
if (!vars.TryGetValue(Name, out PropStores.Float v))
throw new InvalidOperationException(string.Format("Variable \"{0}\" not defined", IdentifierManager.Shared.Retrieve(Name)));
if (!PdtEvaluator.Instance.Evaluate(v.Target, exp))
throw new EvaluationFailureException();

View File

@@ -75,7 +75,7 @@ namespace Cryville.Crtr.Skin {
var obj = new GameObject("__obj__");
obj.transform.SetParent(c.Transform, false);
obj.AddComponent<TransformInterface>();
return new SkinContext[] { new SkinContext(obj.transform) };
return new SkinContext[] { new(obj.transform) };
}
}
public class Anchor : SkinSelector {
@@ -86,8 +86,7 @@ namespace Cryville.Crtr.Skin {
public override string ToString() { return string.Format(".{0}", IdentifierManager.Shared.Retrieve(Name)); }
public override IEnumerable<SkinContext> MatchStatic(ISkinnableGroup g, SkinContext c) {
IReadOnlyCollection<CAnchor> anchors;
if (g.TryGetAnchorsByName(Name, out anchors)) {
if (g.TryGetAnchorsByName(Name, out IReadOnlyCollection<CAnchor> anchors)) {
return anchors.Select(a => a.SkinContext);
}
else return Enumerable.Empty<SkinContext>();