private void NotifyChange(DataRole role, object newValue, object oldValue)
    {
        var change = new Change {
            role = role, newValue = newValue, oldValue = oldValue
        };

        if (changed != null)
        {
            changed(this, change);
        }

        MathBook book = mathBook;

        // If the field is being removed from a book then send the notification through the former book
        if (role == DataRole.Owner)
        {
            if (oldValue != null)
            {
                book = oldValue as MathBook;
            }
        }

        if (book != null)
        {
            book.inputOutputs.NotifyFieldChange(this, change);
        }
    }
 public MathNode Get(MathBook book)
 {
     if (book == null)
     {
         return(null);
     }
     return(book.Get(this));
 }
    public override void OnInspectorGUI()
    {
        MathBook mathBook = target as MathBook;

        foreach (MathBookField input in mathBook.inputOutputs.inputs)
        {
            input.value = EditorGUILayout.FloatField(new GUIContent(input.name, input.toolTip), input.value);
        }
        foreach (MathBookField output in mathBook.inputOutputs.outputs)
        {
            EditorGUILayout.LabelField(new GUIContent(output.name, output.toolTip), new GUIContent(output.value.ToString()));
        }
    }
        public virtual void OnEnable()
        {
            var assets = AssetDatabase.LoadAllAssetsAtPath(MathBookHelper.GetAssetPath());

            if (assets == null || assets.Length == 0)
            {
                MathBookHelper.ResetOrCreateAsset();
                assets = AssetDatabase.LoadAllAssetsAtPath(MathBookHelper.GetAssetPath());

                if (assets == null || assets.Length == 0)
                {
                    Debug.LogError("Could not load Math asset.");
                    return;
                }
            }

            // Find the MathBook.
            foreach (var asset in assets)
            {
                if (asset is MathBook)
                {
                    m_MathBook = asset as MathBook;
                    break;
                }
            }

            var simpleGraphView = new SimpleGraphView(this, withWindowedTools);

            graphView = simpleGraphView;

            graphView.name        = "MathBook";
            graphView.viewDataKey = "MathBook";
            graphView.StretchToParentSize();

            rootVisualElement.Add(graphView);

            StyleSheet sheetAsset = Resources.Load("SimpleGraph", typeof(StyleSheet)) as StyleSheet;

            graphView.styleSheets.Add(sheetAsset);

            m_SimpleGraphViewCallbacks.Init(m_MathBook, simpleGraphView);

            graphView.nodeCreationRequest += OnRequestNodeCreation;

            titleContent.text = "Simple Graph";

            Reload();
        }
Exemple #5
0
        public void Init(MathBook mathBook, SimpleGraphView graphView)
        {
            m_MathBook  = mathBook;
            m_GraphView = graphView;

            m_GraphView.graphViewChanged        += GraphViewChanged;
            m_GraphView.groupTitleChanged        = OnGroupTitleChanged;
            m_GraphView.elementsAddedToGroup     = OnElementsAddedToGroup;
            m_GraphView.elementsRemovedFromGroup = OnElementsRemovedFromGroup;

            m_GraphView.elementsInsertedToStackNode  = OnElementsInsertedToStackNode;
            m_GraphView.elementsRemovedFromStackNode = OnElementsRemovedFromStackNode;

            graphView.RegisterCallback <DragUpdatedEvent>(OnDragUpdatedEvent);
            graphView.RegisterCallback <DragPerformEvent>(OnDragPerformEvent);

            //m_GraphView.elementDeleted = ElementDeletedCallback;
            //m_GraphView.edgeConnected = EdgeConnected;
            //m_GraphView.edgeDisconnected = EdgeDisconnected;
        }
Exemple #6
0
    public static void ResetOrCreateAsset()
    {
        MathBook book = Create();

        AssetDatabase.CreateAsset(book, GetAssetPath());

        for (int i = 0; i < book.nodes.Count; ++i)
        {
            AssetDatabase.AddObjectToAsset(book.nodes[i], book);
        }

        for (int i = 0; i < book.stickyNotes.Count; ++i)
        {
            AssetDatabase.AddObjectToAsset(book.stickyNotes[i], book);
        }

        for (int i = 0; i < book.placemats.Count; ++i)
        {
            AssetDatabase.AddObjectToAsset(book.placemats[i], book);
        }

        AssetDatabase.SaveAssets();
    }