NodeInspector.Editor.GraphData.SetDefaultStartNodeIfNothingSelected C# (CSharp) Method

SetDefaultStartNodeIfNothingSelected() public method

public SetDefaultStartNodeIfNothingSelected ( ) : void
return void
        void SetDefaultStartNodeIfNothingSelected()
        {
            if (StartNode != null && StartNode.objectReferenceValue == null && ItemList.Count > 0){
                StartNode.objectReferenceValue = ItemList[0] as UnityEngine.Object;
                StartNode.serializedObject.ApplyModifiedProperties();
            }
        }

Usage Example

Exemplo n.º 1
0
        public static bool CanCreateGraphData(ScriptableObject parentObject, FieldInfo fieldInfo, out GraphData graphData)
        {
            graphData = null;
            Type fieldValueType = fieldInfo.FieldType;

            if (fieldValueType.IsGenericType && (fieldValueType.GetGenericTypeDefinition() == typeof(List <>)) &&
                typeof(ScriptableObject).IsAssignableFrom(fieldValueType.GetGenericArguments()[0]))
            {
                object[] attributes = fieldInfo.GetCustomAttributes(false);
                if (attributes == null || attributes.Length == 0)
                {
                    return(false);
                }
                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];
                    graphData.ItemList           = fieldValue as IList;
                    graphData.PropertyName       = fieldInfo.Name;
                    graphData.ParentObject       = parentObject;
                    graphData.SerializedItemList = serializedObject.FindProperty(fieldInfo.Name);
                    if (string.IsNullOrEmpty(graphData.PropertyName))
                    {
                        graphData.PropertyName = fieldInfo.Name;
                    }
                    graphData.StartNode = null;
                    if (!string.IsNullOrEmpty(attribute.StartNode))
                    {
                        graphData.StartNode = serializedObject.FindProperty(attribute.StartNode);
                        if (graphData.StartNode == null)
                        {
                            Debug.LogError("Cant find property with name " + attribute.StartNode + " for this graph");
                        }
                        else if (false)    //fixme through reflexion get field type
                        {
                            graphData.StartNode = null;
                            Debug.LogError("Start node type is not assignable from graph node type");
                        }
                    }
                    graphData.SetDefaultStartNodeIfNothingSelected();
                    return(true);
                }
            }


            return(false);
        }
All Usage Examples Of NodeInspector.Editor.GraphData::SetDefaultStartNodeIfNothingSelected