Skip to content

Commit

Permalink
fix null list on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicloay committed Mar 21, 2016
1 parent f1b27b2 commit 619df58
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Assets/NodeInspector/Scripts/Editor/GraphData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ public void AddNewAsset(Type nodeType){
}

public static bool CanCreateGraphData(ScriptableObject parentObject, FieldInfo fieldInfo, out GraphData graphData){
graphData = null;
object fieldValue = fieldInfo.GetValue(parentObject);
if (fieldValue == null){
return false;
}
Type fieldValueType = fieldValue.GetType();
graphData = null;
Type fieldValueType = fieldInfo.FieldType;
if (fieldValueType.IsGenericType && (fieldValueType.GetGenericTypeDefinition() == typeof(List<>))
&& typeof(ScriptableObject).IsAssignableFrom( fieldValueType.GetGenericArguments()[0])){

Expand All @@ -46,6 +42,12 @@ public static bool CanCreateGraphData(ScriptableObject parentObject, FieldInfo f
GraphAttribute attribute = attributes
.ToList().First((arg) => arg.GetType() == typeof(GraphAttribute)) as GraphAttribute;
if (attribute != null){
object fieldValue = fieldInfo.GetValue(parentObject);
if (fieldValue == null){
var newList = Activator.CreateInstance(fieldValueType);
fieldInfo.SetValue(parentObject, newList);
fieldValue = newList;
}
SerializedObject serializedObject = new SerializedObject(parentObject);
graphData = new GraphData();
graphData.ItemBaseType = fieldValueType.GetGenericArguments()[0];
Expand Down

0 comments on commit 619df58

Please sign in to comment.