Пример #1
0
    public void CreateOrDeleteSpritesBasedOnPointValues()
    {
        // Real Time Update
        if (realTimeRunning)
        {
            DoRealTimeUpdate();
        }
        if (pointValuesChanged)
        {
            // Create points based on pointValues data
            for (int i = 0; i < pointValues.Count; i++)
            {
                if (points.Count <= i)
                {
                    GameObject curObj = theGraph.CreateNode(nodePrefab, nodeParent);

                    theGraph.addNodeClickEvent(curObj);
                    theGraph.addNodeMouseEnterEvent(curObj);
                    theGraph.addNodeMouseLeaveEvent(curObj);

                    curObj.GetComponent <WMG_Node>().radius = -1 * linePadding;
                    theGraph.SetActive(curObj, false);
                    points.Add(curObj);
                    if (i > 0)
                    {
                        WMG_Node fromNode = points[i - 1].GetComponent <WMG_Node>();
                        curObj = theGraph.CreateLink(fromNode, curObj, theGraph.linkPrefabs[linkPrefab], linkParent);

                        theGraph.addLinkClickEvent(curObj);
                        theGraph.addLinkMouseEnterEvent(curObj);
                        theGraph.addLinkMouseLeaveEvent(curObj);

                        theGraph.SetActive(curObj, false);
                        lines.Add(curObj);
                    }
                }
            }
            // If there are more points than pointValues data, delete the extras
            for (int i = points.Count - 1; i >= 0; i--)
            {
                if (points[i] != null && i >= pointValues.Count)
                {
                    WMG_Node thePoint = points[i].GetComponent <WMG_Node>();
                    foreach (GameObject child in thePoint.links)
                    {
                        lines.Remove(child);
                    }
                    theGraph.DeleteNode(thePoint);
                    points.RemoveAt(i);
                }
                // Delete existing connect first to last
                if (i > 1 && i < pointValues.Count - 1)
                {
                    WMG_Node firstNode = points[0].GetComponent <WMG_Node>();
                    WMG_Node toNode    = points[i].GetComponent <WMG_Node>();
                    WMG_Link delLink   = theGraph.GetLink(firstNode, toNode);
                    if (delLink != null)
                    {
                        lines.Remove(delLink.gameObject);
                        theGraph.DeleteLink(delLink);
                    }
                }
            }
            // Connect first to last
            if (points.Count > 2)
            {
                WMG_Node firstNode = points[0].GetComponent <WMG_Node>();
                WMG_Node toNode    = points[points.Count - 1].GetComponent <WMG_Node>();
                WMG_Link delLink   = theGraph.GetLink(firstNode, toNode);
                if (connectFirstToLast && delLink == null)
                {
                    GameObject curObj = theGraph.CreateLink(firstNode, toNode.gameObject, theGraph.linkPrefabs[linkPrefab], linkParent);

                    theGraph.addLinkClickEvent(curObj);
                    theGraph.addLinkMouseEnterEvent(curObj);
                    theGraph.addLinkMouseLeaveEvent(curObj);

                    theGraph.SetActive(curObj, false);
                    lines.Add(curObj);
                }
                if (!connectFirstToLast && delLink != null)
                {
                    lines.Remove(delLink.gameObject);
                    theGraph.DeleteLink(delLink);
                }
            }
            // Create the legend if it doesn't exist
            if (legendEntryNode == null)
            {
                legendEntryNode = theGraph.CreateNode(nodePrefab, legendEntryParent);

                theGraph.addNodeClickEvent_Leg(legendEntryNode);
                theGraph.addNodeMouseEnterEvent_Leg(legendEntryNode);
                theGraph.addNodeMouseLeaveEvent_Leg(legendEntryNode);

                WMG_Node cNode = legendEntryNode.GetComponent <WMG_Node>();
                theGraph.changeSpritePivot(cNode.objectToColor, WMG_Graph_Manager.WMGpivotTypes.Center);
                cNode.Reposition(0, 0);

                legendEntryLink = theGraph.CreateLink(legendEntryNodeRight.GetComponent <WMG_Node>(), legendEntryNodeLeft, theGraph.linkPrefabs[linkPrefab], legendEntryParent);

                theGraph.addLinkClickEvent_Leg(legendEntryLink);
                theGraph.addLinkMouseEnterEvent_Leg(legendEntryLink);
                theGraph.addLinkMouseLeaveEvent_Leg(legendEntryLink);

                theGraph.bringSpriteToFront(legendEntryNode);
            }
        }
    }