Skip to content

Commit 0704420

Browse files
committed
CSV読み込み時にHighLegが間違ってキャラクターのルートに追加される現象を修正
1 parent 93abdb2 commit 0704420

File tree

2 files changed

+24
-43
lines changed

2 files changed

+24
-43
lines changed

UnityChan.SpringBone/Script/SpringBone/Setup/SpringSetupComponentDefiners.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ protected virtual string GetTypeToken()
7171

7272
protected virtual void AppendProperties(StringBuilder builder, Component component)
7373
{
74-
// Default implementation
7574
var builderStrings = UnityComponentStringListBuilder.BuildBuilderStringList(component);
7675
builder.Append(string.Join(",", builderStrings.ToArray()));
7776
builder.Append(",");
@@ -95,8 +94,26 @@ Queue<string> definitionItems
9594
)
9695
{
9796
// Default implementation
97+
// First remove all old components of the same type
98+
// Todo: What if we want two or more of the same type of component on the same GameObject?
99+
var oldComponents = owner.GetComponents(componentType);
100+
var newComponent = owner.AddComponent(componentType);
98101
var rootObject = owner.transform.root.gameObject;
99-
return definitionItems.DequeueComponent(componentType, rootObject);
102+
if (definitionItems.DequeueComponent(newComponent, rootObject))
103+
{
104+
// Succeeded; destroy the old components
105+
foreach (var oldComponent in oldComponents)
106+
{
107+
Object.DestroyImmediate(oldComponent);
108+
}
109+
}
110+
else
111+
{
112+
// Failed; destroy the component we added
113+
Object.DestroyImmediate(newComponent);
114+
newComponent = null;
115+
}
116+
return newComponent;
100117
}
101118
}
102119
}

UnityChan.SpringBone/Script/Utility/ObjectBuilding/StringQueueObjectBuilder.cs

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,19 @@ public static Transform DequeueTransform(this Queue<string> queue, GameObject ga
5353
return gameObject.transform;
5454
}
5555

56-
public static Component DequeueComponent
56+
public static bool DequeueComponent
5757
(
5858
this Queue<string> queue,
59-
System.Type type,
59+
Component component,
6060
GameObject rootObject = null,
6161
IEnumerable<TypedStringToValueMap> valueMaps = null
6262
)
6363
{
64-
if (type == typeof(Transform))
65-
{
66-
return DequeueTransform(queue, rootObject);
67-
}
68-
64+
var type = component.GetType();
6965
var succeeded = true;
70-
var item = rootObject.AddComponent(type);
7166
try
7267
{
73-
queue.DequeueFields(type, item, rootObject, valueMaps);
68+
queue.DequeueFields(type, component, rootObject, valueMaps);
7469
}
7570
catch (System.InvalidOperationException exception)
7671
{
@@ -85,38 +80,7 @@ public static Component DequeueComponent
8580
Debug.LogError("Error dequeueing fields for " + type.ToString() + "\n\n"
8681
+ exception.ToString());
8782
}
88-
89-
if (!succeeded)
90-
{
91-
Object.DestroyImmediate(item);
92-
item = null;
93-
}
94-
return item;
95-
}
96-
97-
public static T DequeueComponent<T>
98-
(
99-
this Queue<string> queue,
100-
GameObject rootObject = null,
101-
IEnumerable<TypedStringToValueMap> valueMaps = null
102-
)
103-
where T : Component
104-
{
105-
return DequeueComponent(queue, typeof(T), rootObject, valueMaps) as T;
106-
}
107-
108-
public static T DequeueComponent<T>
109-
(
110-
this Queue<string> queue,
111-
GameObject rootObject,
112-
TypedStringToValueMap valueMap
113-
)
114-
where T : MonoBehaviour
115-
{
116-
return DequeueComponent<T>(
117-
queue,
118-
rootObject,
119-
new TypedStringToValueMap[] { valueMap });
83+
return succeeded;
12084
}
12185

12286
public static void DequeueFields

0 commit comments

Comments
 (0)