Optimize performance for skin component properties.

This commit is contained in:
2022-12-20 16:04:35 +08:00
parent 207dee9932
commit 571320630b
3 changed files with 11 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
using Cryville.Common.Pdt; using Cryville.Common;
using Cryville.Common.Pdt;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@@ -7,21 +8,21 @@ namespace Cryville.Crtr.Components {
/// <summary> /// <summary>
/// The property operators of the component. /// The property operators of the component.
/// </summary> /// </summary>
public Dictionary<string, SkinProperty> Properties { get; private set; } public Dictionary<int, SkinProperty> Properties { get; private set; }
/// <summary> /// <summary>
/// Submits a property. /// Submits a property.
/// </summary> /// </summary>
/// <param name="name">The name of the property.</param> /// <param name="name">The name of the property.</param>
/// <param name="property">The property.</param> /// <param name="property">The property.</param>
protected void SubmitProperty(string name, PdtOperator property, int uct = 1) { protected void SubmitProperty(string name, PdtOperator property, int uct = 1) {
Properties.Add(name, new SkinProperty(property, uct)); Properties.Add(IdentifierManager.SharedInstance.Request(name), new SkinProperty(property, uct));
} }
/// <summary> /// <summary>
/// Creates a skin component. /// Creates a skin component.
/// </summary> /// </summary>
protected SkinComponent() { protected SkinComponent() {
Properties = new Dictionary<string, SkinProperty>(); Properties = new Dictionary<int, SkinProperty>();
} }
public virtual void Init() { } public virtual void Init() { }

View File

@@ -69,7 +69,7 @@ namespace Cryville.Crtr {
} }
public struct SkinPropertyKey { public struct SkinPropertyKey {
public Type Component; public Type Component;
public string Name; public int Name;
} }
public class SkinElementBinder : EmptyBinder { public class SkinElementBinder : EmptyBinder {
public override object ChangeType(object value, Type type, CultureInfo culture) { public override object ChangeType(object value, Type type, CultureInfo culture) {
@@ -81,9 +81,9 @@ namespace Cryville.Crtr {
if (key[0] == '*') if (key[0] == '*')
return new SkinPropertyKey { Component = GetComponentByName(key.Substring(1)) }; return new SkinPropertyKey { Component = GetComponentByName(key.Substring(1)) };
else else
return new SkinPropertyKey { Component = typeof(TransformInterface), Name = key }; return new SkinPropertyKey { Component = typeof(TransformInterface), Name = IdentifierManager.SharedInstance.Request(key) };
case 2: case 2:
return new SkinPropertyKey { Component = GetComponentByName(cp[0]), Name = cp[1] }; return new SkinPropertyKey { Component = GetComponentByName(cp[0]), Name = IdentifierManager.SharedInstance.Request(cp[1]) };
} }
} }
return base.ChangeType(value, type, culture); return base.ChangeType(value, type, culture);

View File

@@ -1,4 +1,4 @@
using Cryville.Common.Pdt; using Cryville.Common.Pdt;
using Cryville.Crtr.Components; using Cryville.Crtr.Components;
using Cryville.Crtr.Event; using Cryville.Crtr.Event;
using System; using System;
@@ -35,7 +35,7 @@ namespace Cryville.Crtr {
void MatchStatic(SkinElement rel, ContainerState context, Transform anchor = null) { void MatchStatic(SkinElement rel, ContainerState context, Transform anchor = null) {
ChartPlayer.etor.ContextTransform = anchor; ChartPlayer.etor.ContextTransform = anchor;
foreach (var p in rel.properties) { foreach (var p in rel.properties) {
if (p.Key.Name == null) if (p.Key.Name == 0)
anchor.gameObject.AddComponent(p.Key.Component); anchor.gameObject.AddComponent(p.Key.Component);
else { else {
ChartPlayer.etor.Evaluate(GetPropOp(anchor, p.Key).Operator, p.Value); ChartPlayer.etor.Evaluate(GetPropOp(anchor, p.Key).Operator, p.Value);
@@ -82,7 +82,7 @@ namespace Cryville.Crtr {
void MatchDynamic(SkinElement rel, ContainerState context, Transform anchor = null) { void MatchDynamic(SkinElement rel, ContainerState context, Transform anchor = null) {
ChartPlayer.etor.ContextTransform = anchor; ChartPlayer.etor.ContextTransform = anchor;
foreach (var p in rel.properties) { foreach (var p in rel.properties) {
if (p.Key.Name == null) if (p.Key.Name == 0)
throw new InvalidOperationException("Component creation in dynamic context is not allowed"); throw new InvalidOperationException("Component creation in dynamic context is not allowed");
var prop = GetPropOp(anchor, p.Key); var prop = GetPropOp(anchor, p.Key);
if (context.CloneType > prop.UpdateCloneType) continue; if (context.CloneType > prop.UpdateCloneType) continue;