Skip to content

Commit

Permalink
CSV読み込み時にHighLegが間違ってキャラクターのルートに追加される現象を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
FUJonathan committed May 22, 2018
1 parent 93abdb2 commit 0704420
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ protected virtual string GetTypeToken()

protected virtual void AppendProperties(StringBuilder builder, Component component)
{
// Default implementation
var builderStrings = UnityComponentStringListBuilder.BuildBuilderStringList(component);
builder.Append(string.Join(",", builderStrings.ToArray()));
builder.Append(",");
Expand All @@ -95,8 +94,26 @@ Queue<string> definitionItems
)
{
// Default implementation
// First remove all old components of the same type
// Todo: What if we want two or more of the same type of component on the same GameObject?
var oldComponents = owner.GetComponents(componentType);
var newComponent = owner.AddComponent(componentType);
var rootObject = owner.transform.root.gameObject;
return definitionItems.DequeueComponent(componentType, rootObject);
if (definitionItems.DequeueComponent(newComponent, rootObject))
{
// Succeeded; destroy the old components
foreach (var oldComponent in oldComponents)
{
Object.DestroyImmediate(oldComponent);
}
}
else
{
// Failed; destroy the component we added
Object.DestroyImmediate(newComponent);
newComponent = null;
}
return newComponent;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,19 @@ public static Transform DequeueTransform(this Queue<string> queue, GameObject ga
return gameObject.transform;
}

public static Component DequeueComponent
public static bool DequeueComponent
(
this Queue<string> queue,
System.Type type,
Component component,
GameObject rootObject = null,
IEnumerable<TypedStringToValueMap> valueMaps = null
)
{
if (type == typeof(Transform))
{
return DequeueTransform(queue, rootObject);
}

var type = component.GetType();
var succeeded = true;
var item = rootObject.AddComponent(type);
try
{
queue.DequeueFields(type, item, rootObject, valueMaps);
queue.DequeueFields(type, component, rootObject, valueMaps);
}
catch (System.InvalidOperationException exception)
{
Expand All @@ -85,38 +80,7 @@ public static Component DequeueComponent
Debug.LogError("Error dequeueing fields for " + type.ToString() + "\n\n"
+ exception.ToString());
}

if (!succeeded)
{
Object.DestroyImmediate(item);
item = null;
}
return item;
}

public static T DequeueComponent<T>
(
this Queue<string> queue,
GameObject rootObject = null,
IEnumerable<TypedStringToValueMap> valueMaps = null
)
where T : Component
{
return DequeueComponent(queue, typeof(T), rootObject, valueMaps) as T;
}

public static T DequeueComponent<T>
(
this Queue<string> queue,
GameObject rootObject,
TypedStringToValueMap valueMap
)
where T : MonoBehaviour
{
return DequeueComponent<T>(
queue,
rootObject,
new TypedStringToValueMap[] { valueMap });
return succeeded;
}

public static void DequeueFields
Expand Down

0 comments on commit 0704420

Please sign in to comment.