Optimize anchor identifiers.

This commit is contained in:
2022-12-22 14:06:05 +08:00
parent 451ebbe91a
commit 8175ca7e82
4 changed files with 27 additions and 20 deletions

View File

@@ -1,3 +1,4 @@
using Cryville.Common;
using Cryville.Crtr.Components;
using System;
using System.Collections.Generic;
@@ -36,7 +37,7 @@ namespace Cryville.Crtr.Event {
/// </summary>
public Transform gogroup;
public readonly Dictionary<string, Anchor> Anchors = new Dictionary<string, Anchor>();
public readonly Dictionary<int, Anchor> Anchors = new Dictionary<int, Anchor>();
protected Transform a_head;
protected Transform a_tail;
public Vector3 Position {
@@ -75,17 +76,22 @@ namespace Cryville.Crtr.Event {
public abstract string TypeName {
get;
}
protected readonly static int _a_head = IdentifierManager.SharedInstance.Request("head");
protected readonly static int _a_tail = IdentifierManager.SharedInstance.Request("tail");
public virtual void PreInit() {
gogroup = new GameObject(TypeName + ":" + Container.GetHashCode().ToString(CultureInfo.InvariantCulture)).transform;
if (cs.Parent != null)
gogroup.SetParent(cs.Parent.Handler.gogroup, false);
a_head = new GameObject("::head").transform;
a_head.SetParent(gogroup, false);
Anchors.Add("head", new Anchor() { Transform = a_head });
a_tail = new GameObject("::tail").transform;
a_tail.SetParent(gogroup, false);
Anchors.Add("tail", new Anchor() { Transform = a_tail });
a_head = RegisterAnchor(_a_head);
a_tail = RegisterAnchor(_a_tail);
}
protected Transform RegisterAnchor(int name) {
var go = new GameObject("." + IdentifierManager.SharedInstance.Retrieve(name)).transform;
go.SetParent(gogroup, false);
Anchors.Add(name, new Anchor() { Transform = go });
return go;
}
/// <summary>
/// Called upon StartUpdate of ps 17.
/// </summary>
@@ -108,10 +114,10 @@ namespace Cryville.Crtr.Event {
protected virtual void PreAwake(ContainerState s) {
if (gogroup) gogroup.gameObject.SetActive(true);
Awoken = true; Alive = true;
OpenAnchor("head");
OpenAnchor(_a_head);
}
protected virtual void Awake(ContainerState s) {
CloseAnchor("head");
CloseAnchor(_a_head);
}
protected virtual void GetPosition(ContainerState s) { }
public virtual void StartUpdate(ContainerState s) {
@@ -138,10 +144,10 @@ namespace Cryville.Crtr.Event {
}
}
public virtual void Anchor() { }
protected void OpenAnchor(string name) {
protected void OpenAnchor(int name) {
if (Anchors.ContainsKey(name)) Anchors[name].Open();
}
protected void CloseAnchor(string name) {
protected void CloseAnchor(int name) {
if (Anchors.ContainsKey(name)) Anchors[name].Close();
}
}