public bool AddGraphByGUID(string graphGUID) { GraphInstanceMetaContainer newInstance = CreateNewGraphMetaContainer(graphGUID); if (newInstance == null) { return(false); } if (m_sortRule != SortRule.NONE) { int insertIndex = 0; if (m_sortRule == SortRule.NAME) { insertIndex = m_graphInstances.BinarySearch(newInstance, GraphInstanceMetaContainer.NameSorter); } else if (m_sortRule == SortRule.TYPE_AND_NAME) { insertIndex = m_graphInstances.BinarySearch(newInstance, GraphInstanceMetaContainer.TypeAndNameSorter); } if (insertIndex > 0) { m_foldout.Insert(insertIndex, newInstance.DisplayField); m_graphInstances.Insert(insertIndex, newInstance); } else { m_foldout.Insert(~insertIndex, newInstance.DisplayField); m_graphInstances.Insert(~insertIndex, newInstance); } } else { m_foldout.Add(newInstance.DisplayField); m_graphInstances.Add(newInstance); } style.display = DisplayStyle.Flex; SetFoldoutName(m_foldoutName); return(true); }
private GraphInstanceMetaContainer CreateNewGraphMetaContainer(string guid) { GraphInstanceMetaContainer newInstance = new GraphInstanceMetaContainer(guid); if (!newInstance.IsValid && !string.IsNullOrEmpty(guid)) // The case where the graph SHOULD have existed but did not. Ignore this guid. { return(null); } newInstance.DisplayField.OnDoubleClick += (UnityEngine.Object obj) => { m_onElementDoubleClick?.Invoke(m_graphInstances.Find(x => x.ObjectRef == (obj as NodeGraph)).GUID); }; for (int i = 0; i < m_manipulators.Count; i++) { newInstance.DisplayField.AddManipulator(m_manipulators[i](newInstance.GUID)); } return(newInstance); }
public bool AddByIndex(int index, string graphGUID) { if (m_sortRule != SortRule.NONE) { Debug.LogError("Cannot add by index when sort rule exists!"); } GraphInstanceMetaContainer newInstance = CreateNewGraphMetaContainer(graphGUID); if (newInstance == null) { return(false); } m_foldout.Insert(0, newInstance.DisplayField); m_graphInstances.Insert(0, newInstance); style.display = DisplayStyle.Flex; return(true); }