Пример #1
0
 public void UpdatePointWidthHeight()
 {
     if (pointWidthHeightChanged)
     {
         // Series line point dimensions
         if (theGraph.graphType == WMG_Axis_Graph.graphTypes.line)
         {
             for (int i = 0; i < pointValues.Count; i++)
             {
                 WMG_Node thePoint = points[i].GetComponent <WMG_Node>();
                 theGraph.changeSpriteHeight(thePoint.objectToColor, Mathf.RoundToInt(pointWidthHeight));
                 theGraph.changeSpriteWidth(thePoint.objectToColor, Mathf.RoundToInt(pointWidthHeight));
             }
         }
         // Legend point / bar dimensions
         WMG_Node legendPoint = legendEntryNode.GetComponent <WMG_Node>();
         theGraph.changeSpriteHeight(legendPoint.objectToColor, Mathf.RoundToInt(pointWidthHeight));
         theGraph.changeSpriteWidth(legendPoint.objectToColor, Mathf.RoundToInt(pointWidthHeight));
         // Legend empty objects to get line to center correctly
         if (theGraph.isDaikon())
         {
             theGraph.changeSpriteHeight(legendEntryNodeLeft, Mathf.RoundToInt(pointWidthHeight));
             theGraph.changeSpriteWidth(legendEntryNodeLeft, Mathf.RoundToInt(pointWidthHeight));
             theGraph.changeSpriteHeight(legendEntryNodeRight, Mathf.RoundToInt(pointWidthHeight));
             theGraph.changeSpriteWidth(legendEntryNodeRight, Mathf.RoundToInt(pointWidthHeight));
         }
     }
 }
Пример #2
0
    private void TooltipNodeMouseEnter(WMG_Series aSeries, WMG_Node aNode, bool state)
    {
        if (isTooltipObjectNull())
        {
            return;
        }
        if (state)
        {
            Vector3 newVec = new Vector3(2, 2, 1);
            if (!aSeries.seriesIsLine)
            {
                if (theGraph.orientationType == WMG_Axis_Graph.orientationTypes.vertical)
                {
                    newVec = new Vector3(1, 1.1f, 1);
                }
                else
                {
                    newVec = new Vector3(1.1f, 1, 1);
                }
            }

            MouseEnterCommon(tooltipLabeler(aSeries, aNode), aNode.gameObject, newVec);
        }
        else
        {
            MouseExitCommon(aNode.gameObject);
        }
    }
Пример #3
0
    private void TooltipLegendNodeMouseEnter(WMG_Series aSeries, WMG_Node aNode, bool state)
    {
        if (isTooltipObjectNull())
        {
            return;
        }
        if (state)
        {
            // Set the text
            changeLabelText(theGraph.toolTipLabel, aSeries.seriesName);

            // Resize this control to match the size of the contents
            changeSpriteWidth(theGraph.toolTipPanel, Mathf.RoundToInt(getSpriteWidth(theGraph.toolTipLabel)) + 24);

            // Ensure tooltip is in position before showing it so it doesn't appear to jump
            repositionTooltip();

            // Display the base panel
            showControl(theGraph.toolTipPanel);
            bringSpriteToFront(theGraph.toolTipPanel);

            performTooltipAnimation(aNode.transform, new Vector3(2, 2, 1));
        }
        else
        {
            hideControl(theGraph.toolTipPanel);
            sendSpriteToBack(theGraph.toolTipPanel);

            performTooltipAnimation(aNode.transform, new Vector3(1, 1, 1));
        }
    }
Пример #4
0
	// Only Used in Editor - 
	public void RepositionRelativeToNode (WMG_Node fromNode, bool fixAngle, int degreeStep, float lengthStep) {
		// This is used to reposition the node and associated links based on a fixed angle or fixed length step relative to another node
		float posXdif = (this.transform.localPosition.x - fromNode.transform.localPosition.x);
		float posYdif = (this.transform.localPosition.y - fromNode.transform.localPosition.y);
		
		float angle = Mathf.Atan2(posYdif,posXdif)*Mathf.Rad2Deg;
		if (angle < 0) angle += 360;
		
		float length = Mathf.Sqrt(Mathf.Pow(posYdif,2) + Mathf.Pow(posXdif,2));
		if (length < 0) length = 0;
		
		float newAngle = angle;
		if (fixAngle) {
			newAngle = 0;
			for (int i = 0; i < 360 / degreeStep; i++) {
				if (angle >= i*degreeStep - 0.5f*degreeStep && angle < (i+1)*degreeStep - 0.5f*degreeStep) {
					newAngle = i*degreeStep;
				}
			}
		}
		else {
			float mod = length % lengthStep;
			length -= mod;
			if (lengthStep - mod < lengthStep / 2) length += lengthStep;
		}
		
		this.transform.localPosition = new Vector3 (fromNode.transform.localPosition.x + length * Mathf.Cos(Mathf.Deg2Rad*(newAngle)), 
													fromNode.transform.localPosition.y + length * Mathf.Sin(Mathf.Deg2Rad*(newAngle)), 
													this.transform.localPosition.z);
		
		for (int i = 0; i < numLinks; i++) {
			WMG_Link theLink = links[i].GetComponent<WMG_Link>();
			theLink.Reposition();
		}
	}
Пример #5
0
    public List <GameObject> GenerateGraph()
    {
        GameObject fromN    = theGraph.CreateNode(nodePrefab, null);
        WMG_Node   fromNode = fromN.GetComponent <WMG_Node>();

        return(GenerateGraphFromNode(fromNode));
    }
Пример #6
0
    // Use this for initialization
    void Start()
    {
        // Convert to 3d
        this.transform.localPosition          = new Vector3(0, 300, 900);
        shieldTree.transform.localEulerAngles = new Vector3(0, 15, 0);
        weaponTree.transform.localEulerAngles = new Vector3(345, 0, 0);
        engineTree.transform.localEulerAngles = new Vector3(0, 345, 0);

        UIEventListener.Get(shieldTreeBackground).onHover += OnShieldTreeHover;
        UIEventListener.Get(engineTreeBackground).onHover += OnEngineTreeHover;
        UIEventListener.Get(weaponTreeBackground).onHover += OnWeaponTreeHover;
        UIEventListener.Get(shieldTreeBackground).onClick += OnShieldTreeClick;
        UIEventListener.Get(engineTreeBackground).onClick += OnEngineTreeClick;
        UIEventListener.Get(weaponTreeBackground).onClick += OnWeaponTreeClick;

        toolTipText1Label = toolTipText1.GetComponent <UILabel>();
        toolTipText2Label = toolTipText2.GetComponent <UILabel>();
        toolTipText3Label = toolTipText3.GetComponent <UILabel>();
        toolTipText4Label = toolTipText4.GetComponent <UILabel>();

        foreach (Transform child in shieldTree.transform)
        {
            WMG_Node aNode = child.GetComponent <WMG_Node>();
            if (aNode != null)
            {
                UIEventListener.Get(child.gameObject).onHover += OnSkillNodeHover;
                BoxCollider aCol = child.GetComponent <BoxCollider>();
                if (aCol != null)
                {
                    aCol.enabled = false;
                }
            }
        }
        foreach (Transform child in engineTree.transform)
        {
            WMG_Node aNode = child.GetComponent <WMG_Node>();
            if (aNode != null)
            {
                UIEventListener.Get(child.gameObject).onHover += OnSkillNodeHover;
                BoxCollider aCol = child.GetComponent <BoxCollider>();
                if (aCol != null)
                {
                    aCol.enabled = false;
                }
            }
        }
        foreach (Transform child in weaponTree.transform)
        {
            WMG_Node aNode = child.GetComponent <WMG_Node>();
            if (aNode != null)
            {
                UIEventListener.Get(child.gameObject).onHover += OnSkillNodeHover;
                BoxCollider aCol = child.GetComponent <BoxCollider>();
                if (aCol != null)
                {
                    aCol.enabled = false;
                }
            }
        }
    }
 public void CreateNodes()
 {
     // Create nodes based on numNodes
     for (int i = 0; i < numNodes; i++)
     {
         if (treeNodes.Count <= i)
         {
             Object nodePrefab = defaultNodePrefab;
             if (nodePrefabs.Count > i)
             {
                 nodePrefab = nodePrefabs[i];
             }
             WMG_Node curNode = CreateNode(nodePrefab, nodeParent).GetComponent <WMG_Node>();
             treeNodes.Add(curNode.gameObject);
         }
     }
     // Create invisible nodes
     for (int i = 0; i < numInvisibleNodes; i++)
     {
         if (treeInvisibleNodes.Count <= i)
         {
             WMG_Node curNode = CreateNode(invisibleNodePrefab, nodeParent).GetComponent <WMG_Node>();
             treeInvisibleNodes.Add(curNode.gameObject);
         }
     }
 }
Пример #8
0
    private string defaultTooltipLabeler(WMG_Series aSeries, WMG_Node aNode)
    {
        // Find out the point value data for this node
        Vector2 nodeData     = aSeries.getNodeValue(aNode);
        float   numberToMult = Mathf.Pow(10f, aSeries.theGraph.tooltipNumberDecimals);
        string  nodeX        = (Mathf.Round(nodeData.x * numberToMult) / numberToMult).ToString();
        string  nodeY        = (Mathf.Round(nodeData.y * numberToMult) / numberToMult).ToString();

        // Determine the tooltip text to display
        string textToSet;

        if (aSeries.seriesIsLine)
        {
            textToSet = "(" + nodeX + ", " + nodeY + ")";
        }
        else
        {
            textToSet = nodeY;
        }
        if (aSeries.theGraph.tooltipDisplaySeriesName)
        {
            textToSet = aSeries.seriesName + ": " + textToSet;
        }
        return(textToSet);
    }
Пример #9
0
    public GameObject CreateLinkNoRepos(WMG_Node fromNode, GameObject toNode, Object prefabLink, GameObject parent)
    {
        GameObject createdLink = fromNode.CreateLink(toNode, prefabLink, linksParent.Count, parent, false);

        linksParent.Add(createdLink);
        return(createdLink);
    }
Пример #10
0
 void ActivateNeighbors(WMG_Node fromNode)
 {
     for (int i = 0; i < fromNode.numLinks; i++)
     {
         WMG_Link aLink = fromNode.links[i].GetComponent <WMG_Link>();
         if (!theMap.activeInHierarchy(aLink.gameObject))
         {
             // Activate and animate links expanding from source node to end node
             activatingNodesStart = fromNode;
             theMap.SetActive(aLink.gameObject, true);
             UIWidget aLinkW    = aLink.objectToScale.GetComponent <UIWidget>();
             int      origScale = Mathf.RoundToInt(aLinkW.height);
             float    p1y       = fromNode.transform.localPosition.y + (fromNode.radius) * Mathf.Sin(Mathf.Deg2Rad * fromNode.linkAngles[i]);
             float    p1x       = fromNode.transform.localPosition.x + (fromNode.radius) * Mathf.Cos(Mathf.Deg2Rad * fromNode.linkAngles[i]);
             Vector3  origPos   = aLink.transform.localPosition;
             Vector3  newPos    = new Vector3(p1x, p1y, origPos.z);
             aLink.transform.localPosition = newPos;
             TweenPosition.Begin(aLink.gameObject, 1, origPos);
             aLinkW.height = 0;
             TweenHeight tSca = TweenHeight.Begin(aLinkW, 1, origScale);
             tSca.callWhenFinished = "endActivatingNeighbors";
             tSca.eventReceiver    = this.gameObject;
         }
     }
 }
Пример #11
0
    public GameObject ReplaceNodeWithNewPrefab(WMG_Node theNode, Object prefabNode)
    {
        // Used to swap prefabs of a node
        GameObject newNode  = CreateNode(prefabNode, theNode.transform.parent.gameObject);
        WMG_Node   newNode2 = newNode.GetComponent <WMG_Node>();

        newNode2.numLinks   = theNode.numLinks;
        newNode2.links      = theNode.links;
        newNode2.linkAngles = theNode.linkAngles;
        newNode2.SetID(theNode.id);
        newNode2.name = theNode.name;
        newNode.transform.position = theNode.transform.position;

        // Update link from / to node references
        for (int i = 0; i < theNode.numLinks; i++)
        {
            WMG_Link aLink = theNode.links[i].GetComponent <WMG_Link>();
            WMG_Node fromN = aLink.fromNode.GetComponent <WMG_Node>();
            if (fromN.id == theNode.id)
            {
                aLink.fromNode = newNode;
            }
            else
            {
                aLink.toNode = newNode;
            }
        }
        nodesParent.Remove(theNode.gameObject);
        Destroy(theNode.gameObject);

        return(newNode);
    }
Пример #12
0
    IEnumerator AnimateSpriteFill(int sliceNum, float animateDuration, float afterFill, float newAngle, int lastSliceNum, Color newSliceColor)
    {
        if (sliceNum == 0)
        {
            isAnimating = true;
        }
        WMG_Node pieSlice           = slices[sliceNum].GetComponent <WMG_Node>();
        UISprite sliceSprite        = pieSlice.objectToColor.GetComponent <UISprite>();
        float    t                  = 0f;
        float    beforeFill         = slicePercents[sliceNum];
        float    beforeRot          = sliceSprite.transform.localEulerAngles.z;
        float    fill               = beforeFill;
        float    rot                = beforeRot;
        float    beforeExplodeAngle = beforeRot * -1 + 0.5f * beforeFill * 360;
        float    afterExplodeAngle  = newAngle * -1 + 0.5f * afterFill * 360;
        float    explodeFromAngle   = beforeExplodeAngle;

        sliceSprite.color = newSliceColor;
        while (t < animateDuration)
        {
            float animationPercent = t / animateDuration;
            fill             = Mathf.Lerp(beforeFill, afterFill, animationPercent);
            rot              = Mathf.Lerp(beforeRot, newAngle, animationPercent);
            explodeFromAngle = Mathf.Lerp(beforeExplodeAngle, afterExplodeAngle, animationPercent);
            t += Time.deltaTime;
            sliceSprite.fillAmount = fill;
            sliceSprite.transform.localEulerAngles   = new Vector3(0, 0, rot);
            slices[sliceNum].transform.localPosition = new Vector3(explodeLength * Mathf.Sin(explodeFromAngle * Mathf.Deg2Rad),
                                                                   explodeLength * Mathf.Cos(explodeFromAngle * Mathf.Deg2Rad), slices[sliceNum].transform.localPosition.z);
            pieSlice.objectToLabel.transform.localPosition = new Vector3((explodeLength + sliceLabelExplodeLength + getSpriteWidth(pieSlice.objectToColor) / 4) * Mathf.Sin(explodeFromAngle * Mathf.Deg2Rad),
                                                                         (explodeLength + sliceLabelExplodeLength + getSpriteHeight(pieSlice.objectToColor) / 4) * Mathf.Cos(explodeFromAngle * Mathf.Deg2Rad),
                                                                         pieSlice.objectToLabel.transform.localPosition.z);
            yield return(null);
        }
        sliceExplodeAngles[sliceNum]             = afterExplodeAngle;
        slicePercents[sliceNum]                  = afterFill;
        slices[sliceNum].name                    = sliceLabels[sliceNum];
        sliceLegendEntries[sliceNum].name        = sliceLabels[sliceNum];
        sliceSprite.fillAmount                   = afterFill;
        sliceSprite.transform.localEulerAngles   = new Vector3(0, 0, newAngle);
        slices[sliceNum].transform.localPosition = new Vector3(explodeLength * Mathf.Sin(afterExplodeAngle * Mathf.Deg2Rad),
                                                               explodeLength * Mathf.Cos(afterExplodeAngle * Mathf.Deg2Rad), slices[sliceNum].transform.localPosition.z);
        pieSlice.objectToLabel.transform.localPosition = new Vector3((explodeLength + sliceLabelExplodeLength + getSpriteWidth(pieSlice.objectToColor) / 4) * Mathf.Sin(afterExplodeAngle * Mathf.Deg2Rad),
                                                                     (explodeLength + sliceLabelExplodeLength + getSpriteHeight(pieSlice.objectToColor) / 4) * Mathf.Cos(afterExplodeAngle * Mathf.Deg2Rad),
                                                                     pieSlice.objectToLabel.transform.localPosition.z);
        if (sliceNum == lastSliceNum)
        {
            isAnimating = false;
            bool wasASwap = false;
            if (sortBy != sortMethod.None)
            {
                wasASwap = sortData();
            }
            if (wasASwap)
            {
                isSortAnimating = true;
                shrinkSlices();
            }
        }
    }
Пример #13
0
    public WMG_Series seriesRef;     // Used for series legend event delegates

    public GameObject CreateLink(GameObject target, Object prefabLink, int linkId, GameObject parent, bool repos)
    {
        // Creating a link between two nodes populates all needed references and automatically repositions and scales the link based on the nodes
        GameObject objLink      = Instantiate(prefabLink) as GameObject;
        Vector3    linkLocalPos = objLink.transform.localPosition;
        GameObject theParent    = parent;

        if (parent == null)
        {
            theParent = target.transform.parent.gameObject;
        }
        changeSpriteParent(objLink, theParent);
//		objLink.transform.parent = target.transform.parent;
        objLink.transform.localScale    = Vector3.one;
        objLink.transform.localPosition = linkLocalPos;
        WMG_Link theLink = objLink.GetComponent <WMG_Link>();

        links.Add(objLink);
        linkAngles.Add(0);
        WMG_Node theTarget = target.GetComponent <WMG_Node>();

        theTarget.links.Add(objLink);
        theTarget.linkAngles.Add(0);
        theTarget.numLinks++;
        numLinks++;
        theLink.Setup(this.gameObject, target, linkId, repos);         // automatically repositions and scales the link based on the nodes
        return(objLink);
    }
Пример #14
0
 private void WMG_MouseEnter_2(GameObject go, bool state)
 {
     if (WMG_MouseEnter != null)
     {
         WMG_Node node = go.GetComponent <WMG_Node>();
         WMG_MouseEnter(node.seriesRef, node, state);
     }
 }
Пример #15
0
 private void WMG_Click_2(GameObject go, PointerEventData pointerEventData)
 {
     if (WMG_Click != null)
     {
         WMG_Node node = go.GetComponent <WMG_Node>();
         WMG_Click(node.seriesRef, node, pointerEventData);
     }
 }
Пример #16
0
    public void CreateLink(WMG_Node fromNode, WMG_Node toNode)
    {
        WMG_Link aLink = GetLink(fromNode, toNode);

        if (aLink == null)
        {
            CreateLink(fromNode, toNode.gameObject, this.LinkPrefab, this.gameObject);
        }
    }
Пример #17
0
	// Given two nodes return one or more shortest paths between the nodes based on the link weights (weighted), and also node radii if include radii is true
	public List<WMG_Link> FindShortestPathBetweenNodesWeighted(WMG_Node fromNode, WMG_Node toNode, bool includeRadii) {
		
		List<WMG_Link> linksBetweenToAndFrom = new List<WMG_Link>();
		List<WMG_Node> Dijkstra_nodes = new List<WMG_Node>();
		// Reset data needed for this algorithm
		foreach (GameObject node in nodesParent) {
			WMG_Node aNode = node.GetComponent<WMG_Node>();
			if (aNode != null) {
				if (aNode.id == fromNode.id) aNode.Dijkstra_depth = 0;
				else aNode.Dijkstra_depth = Mathf.Infinity;
				Dijkstra_nodes.Add(aNode);
			}
		}
		Dijkstra_nodes.Sort (delegate(WMG_Node x, WMG_Node y) { return x.Dijkstra_depth.CompareTo(y.Dijkstra_depth); });
		
		// This is exactly Dijkstra's algorithm
		while (Dijkstra_nodes.Count > 0) {
			WMG_Node temp = Dijkstra_nodes[0];
			Dijkstra_nodes.RemoveAt(0);
			if (toNode.id == temp.id) break; // Reached the target node so we are done
			if (temp.Dijkstra_depth == Mathf.Infinity) break;
			for (int i = 0; i < temp.numLinks; i++) {
				WMG_Link aLink = temp.links[i].GetComponent<WMG_Link>();
				WMG_Node temp2 = aLink.toNode.GetComponent<WMG_Node>();
				if (temp2.id == temp.id) temp2 = aLink.fromNode.GetComponent<WMG_Node>();
				float alt = temp.Dijkstra_depth + aLink.weight;
				if (includeRadii) alt += temp.radius + temp2.radius;
				if (alt < temp2.Dijkstra_depth) {
					temp2.Dijkstra_depth = alt;
					Dijkstra_nodes.Sort (delegate(WMG_Node x, WMG_Node y) { return x.Dijkstra_depth.CompareTo(y.Dijkstra_depth); });
				}
			}
		}
		
		// If all we cared about was the shortest distance between the two nodes we could end here, but we might also want the links themselves
		// This finds the shortest path of links between the starting and ending nodes using the previously calculated depths
		Queue<WMG_Node> mapSysQ = new Queue<WMG_Node>();
		mapSysQ.Enqueue(toNode);
		while (mapSysQ.Count > 0) {
			WMG_Node temp = mapSysQ.Dequeue();
			if (fromNode.id == temp.id) break;
			for (int i = 0; i < temp.numLinks; i++) {
				WMG_Link aLink = temp.links[i].GetComponent<WMG_Link>();
				WMG_Node temp2 = aLink.toNode.GetComponent<WMG_Node>();
				if (temp2.id == temp.id) temp2 = aLink.fromNode.GetComponent<WMG_Node>();
				float alt = temp2.Dijkstra_depth + aLink.weight;
				if (includeRadii) alt += temp.radius + temp2.radius;
				if (Mathf.Approximately(temp.Dijkstra_depth, alt)) {
					linksBetweenToAndFrom.Add(aLink);
					if (!mapSysQ.Contains(temp2)) mapSysQ.Enqueue(temp2);
				}
			}
		}
		return linksBetweenToAndFrom;
	}
Пример #18
0
	// Given two nodes return one or more shortest paths between the nodes based on the number of links (unweighted)
	public List<WMG_Link> FindShortestPathBetweenNodes(WMG_Node fromNode, WMG_Node toNode) {
		
		List<WMG_Link> linksBetweenToAndFrom = new List<WMG_Link>();
		
		// Reset BFS data needed for this algorithm
		foreach (GameObject node in nodesParent) {
			WMG_Node aNode = node.GetComponent<WMG_Node>();
			if (aNode != null) {
				aNode.BFS_mark = false;
				aNode.BFS_depth = 0;
			}
		}
		
		Queue<WMG_Node> mapSysQ = new Queue<WMG_Node>();
		
		// This calculates and stores the depth of every node between the starting and ending nodes
		// This is exactly the BFS (Breadth-first search) algorithm
		mapSysQ.Enqueue(fromNode);
		fromNode.BFS_mark =  true;
		while (mapSysQ.Count > 0) {
			WMG_Node temp = mapSysQ.Dequeue();
			if (toNode.id == temp.id) break; // Reached the target node so we are done
			// Add the current node neighbors to the queue if they haven't been added in the past and calculate the depth
			for (int i = 0; i < temp.numLinks; i++) {
				WMG_Link aLink = temp.links[i].GetComponent<WMG_Link>();
				WMG_Node temp2 = aLink.toNode.GetComponent<WMG_Node>();
				if (temp2.id == temp.id) temp2 = aLink.fromNode.GetComponent<WMG_Node>();
				if (!temp2.BFS_mark) {
					temp2.BFS_mark = true;
					temp2.BFS_depth = temp.BFS_depth + 1;
					mapSysQ.Enqueue(temp2);
				}
			}
		}
		
		// If all we cared about was the shortest distance between the two nodes we could end here, but we might also want the links themselves
		// This finds the shortest path of links between the starting and ending nodes using the previously calculated depths
		mapSysQ.Clear();
		mapSysQ.Enqueue(toNode);
		while (mapSysQ.Count > 0) {
			WMG_Node temp = mapSysQ.Dequeue();
			if (fromNode.id == temp.id) break;
			for (int i = 0; i < temp.numLinks; i++) {
				WMG_Link aLink = temp.links[i].GetComponent<WMG_Link>();
				WMG_Node temp2 = aLink.toNode.GetComponent<WMG_Node>();
				if (temp2.id == temp.id) temp2 = aLink.fromNode.GetComponent<WMG_Node>();
				if (temp.BFS_depth == temp2.BFS_depth + 1) {
					if (temp2.BFS_depth == 0 && temp2.id != fromNode.id) continue;
					linksBetweenToAndFrom.Add(aLink);
					if (!mapSysQ.Contains(temp2)) mapSysQ.Enqueue(temp2);
				}
			}
		}
		return linksBetweenToAndFrom;
	}
Пример #19
0
    public void Reposition()
    {
        float posXdif = getSpritePositionX(toNode) - getSpritePositionX(fromNode);
        float posYdif = getSpritePositionY(toNode) - getSpritePositionY(fromNode);

        float angle = Mathf.Atan2(posYdif, posXdif) * Mathf.Rad2Deg + 90;

        WMG_Node fromN = fromNode.GetComponent <WMG_Node>();
        WMG_Node toN   = toNode.GetComponent <WMG_Node>();

        SetNodeAngles(angle, fromN, toN);       // Set angles in node references, so they don't need to be calculated in various places

        float radiuses = fromN.radius + toN.radius;
        float length   = Mathf.Sqrt(Mathf.Pow(posYdif, 2) + Mathf.Pow(posXdif, 2)) - radiuses;

        if (length < 0)
        {
            length = 0;
        }

        if (weightIsLength)
        {
            weight = length;
        }
        if (updateLabelWithLength)
        {
            if (objectToLabel != null)
            {
                changeLabelText(objectToLabel, Mathf.Round(length).ToString());
                objectToLabel.transform.localEulerAngles = new Vector3(0, 0, 360 - angle);
            }
        }

        // NGUI
        this.transform.localPosition = new Vector3(getSpriteFactorY2(this.gameObject) * posXdif + fromNode.transform.localPosition.x,
                                                   getSpriteFactorY2(this.gameObject) * posYdif + fromNode.transform.localPosition.y,
                                                   this.transform.localPosition.z);

        // Daikon
//		changeSpritePositionRelativeToObjBy(this.gameObject, fromNode,
//											new Vector3(getSpriteFactorY(this.gameObject) * posXdif +
//														-getSpriteOffsetX(this.gameObject) +
//														Mathf.Cos(Mathf.Deg2Rad * angle) * 0.5f * getSpriteWidth(this.gameObject) +
//														Mathf.Cos(Mathf.Deg2Rad * angle) * (getSpriteFactorX(this.gameObject) - 1) * getSpriteWidth(this.gameObject) +
//														getSpriteOffsetX(fromNode),
//														getSpriteFactorY(this.gameObject) * posYdif +
//														getSpriteOffsetY(this.gameObject) +
//														-Mathf.Sin(Mathf.Deg2Rad * angle) * 0.5f * getSpriteWidth(this.gameObject) +
//														Mathf.Sin(Mathf.Deg2Rad * angle) * getSpriteFactorX(this.gameObject) * getSpriteWidth(this.gameObject) +
//														-getSpriteOffsetY(fromNode), 1));

        changeSpriteHeight(objectToScale, Mathf.RoundToInt(length));
        this.transform.localEulerAngles = new Vector3(0, 0, angle);
    }
Пример #20
0
 /// <summary>
 /// 点击计量条的方法,该方法内通过面板控制器打开对应弹出的面板
 /// </summary>
 /// <param name="aSeries">计量条所在的series</param>
 /// <param name="aNode">被点击的计量条</param>
 private void BarGraph_WMG_Click(WMG_Series aSeries, WMG_Node aNode)
 {
     if (nodesDic.ContainsKey(aNode))
     {
         //当字典中包含被点击的计量条时,将计量条所对应的产品id取出
         int        t   = nodesDic[aNode];
         MessageArg arg = new MessageArg(t);
         //调用面板控制器,传入产品产量明细, 和条目id
         SendMsg((int)MessageUIConst.OpenPassRateDetailPanel, ManagerID.SecondLevelPanel, arg);
     }
 }
Пример #21
0
 // Get Vector2 associated with a node in this series
 public Vector2 getNodeValue(WMG_Node aNode)
 {
     for (int i = 0; i < pointValues.Count; i++)           // TODO improve performance by mapping IDs to Vector2
     {
         if (points[i].GetComponent <WMG_Node>() == aNode)
         {
             return(pointValues[i]);
         }
     }
     return(Vector2.zero);
 }
Пример #22
0
    public void UpdateSeriesName()
    {
        if (seriesNameChanged)
        {
            // Series name
            WMG_Node cObj = legendEntryParent.GetComponent <WMG_Node>();
            theGraph.changeLabelText(cObj.objectToLabel, seriesName);

            // Legend font size
            cObj.objectToLabel.transform.localScale = new Vector3(legendEntryFontSize, legendEntryFontSize, 1);
        }
    }
Пример #23
0
    // Only Used in Editor -
    public void RepositionRelativeToNode(WMG_Node fromNode, bool fixAngle, int degreeStep, float lengthStep)
    {
        // This is used to reposition the node and associated links based on a fixed angle or fixed length step relative to another node
        float posXdif = (this.transform.localPosition.x - fromNode.transform.localPosition.x);
        float posYdif = (this.transform.localPosition.y - fromNode.transform.localPosition.y);

        float angle = Mathf.Atan2(posYdif, posXdif) * Mathf.Rad2Deg;

        if (angle < 0)
        {
            angle += 360;
        }

        float length = Mathf.Sqrt(Mathf.Pow(posYdif, 2) + Mathf.Pow(posXdif, 2));

        if (length < 0)
        {
            length = 0;
        }

        float newAngle = angle;

        if (fixAngle)
        {
            newAngle = 0;
            for (int i = 0; i < 360 / degreeStep; i++)
            {
                if (angle >= i * degreeStep - 0.5f * degreeStep && angle < (i + 1) * degreeStep - 0.5f * degreeStep)
                {
                    newAngle = i * degreeStep;
                }
            }
        }
        else
        {
            float mod = length % lengthStep;
            length -= mod;
            if (lengthStep - mod < lengthStep / 2)
            {
                length += lengthStep;
            }
        }

        this.transform.localPosition = new Vector3(fromNode.transform.localPosition.x + length * Mathf.Cos(Mathf.Deg2Rad * (newAngle)),
                                                   fromNode.transform.localPosition.y + length * Mathf.Sin(Mathf.Deg2Rad * (newAngle)),
                                                   this.transform.localPosition.z);

        for (int i = 0; i < numLinks; i++)
        {
            WMG_Link theLink = links[i].GetComponent <WMG_Link>();
            theLink.Reposition();
        }
    }
Пример #24
0
    public float weight;               // A link's weight, used in find shortest path weighted algorithms

    public void Setup(GameObject fromNode, GameObject toNode, int linkId)
    {
        // Setup references and give a default name of the link based on node IDs
        this.fromNode = fromNode;
        this.toNode   = toNode;
        SetId(linkId);
        WMG_Node fromN = fromNode.GetComponent <WMG_Node>();
        WMG_Node toN   = toNode.GetComponent <WMG_Node>();

        this.name = "WMG_Link_" + fromN.id + "_" + toN.id;
        Reposition();           // Update position and scale based on connected nodes
    }
Пример #25
0
    /// <summary>
    /// Reposition this link based on the positions of its from and to nodes.
    /// </summary>
    public virtual void Reposition()
    {
        float posXdif = getSpritePositionX(toNode) - getSpritePositionX(fromNode);
        float posYdif = getSpritePositionY(toNode) - getSpritePositionY(fromNode);

        float angle = Mathf.Atan2(posYdif, posXdif) * Mathf.Rad2Deg + 90;

        WMG_Node fromN = fromNode.GetComponent <WMG_Node>();
        WMG_Node toN   = toNode.GetComponent <WMG_Node>();

        SetNodeAngles(angle, fromN, toN);       // Set angles in node references, so they don't need to be calculated in various places

        float radii  = fromN.radius + toN.radius;
        float length = Mathf.Sqrt(Mathf.Pow(posYdif, 2) + Mathf.Pow(posXdif, 2)) - radii;

        if (length < 0)
        {
            length = 0;
        }

        // When the radii are different, need to offset the link position based on the difference of the radii
        float radiusDifPosX = (fromN.radius - toN.radius) / 2 * Mathf.Cos(Mathf.Deg2Rad * (angle - 90));
        float radiusDifPosY = (fromN.radius - toN.radius) / 2 * Mathf.Sin(Mathf.Deg2Rad * (angle - 90));

        // Handling cases when one or more of the from / to nodes are square instead of circle
        float squareLengthOffsetFrom = getSquareCircleOffsetLength(fromN, angle, true);
        float squareLengthOffsetTo   = getSquareCircleOffsetLength(toN, angle, false);

        length = length - squareLengthOffsetFrom - squareLengthOffsetTo;

        float squareDifPosX = (squareLengthOffsetFrom - squareLengthOffsetTo) / 2 * Mathf.Cos(Mathf.Deg2Rad * (angle - 90));
        float squareDifPosY = (squareLengthOffsetFrom - squareLengthOffsetTo) / 2 * Mathf.Sin(Mathf.Deg2Rad * (angle - 90));

        if (weightIsLength)
        {
            weight = length;
        }
        if (updateLabelWithLength)
        {
            if (objectToLabel != null)
            {
                changeLabelText(objectToLabel, Mathf.Round(length).ToString());
                objectToLabel.transform.localEulerAngles = new Vector3(0, 0, 360 - angle);
            }
        }

        changeSpritePositionTo(this.gameObject, new Vector3(getSpritePivotTopToBot(this.objectToScale) * posXdif + fromNode.transform.localPosition.x + radiusDifPosX + squareDifPosX,
                                                            getSpritePivotTopToBot(this.objectToScale) * posYdif + fromNode.transform.localPosition.y + radiusDifPosY + squareDifPosY,
                                                            this.transform.localPosition.z));

        changeSpriteHeightFloat(objectToScale, length);
        this.transform.localEulerAngles = new Vector3(0, 0, angle);
    }
Пример #26
0
    private void animateLinkCallback(WMG_Series aSeries, GameObject aGO)
    {
        WMG_Node aNode   = aGO.GetComponent <WMG_Node>();
        WMG_Link theLine = aNode.links[aNode.links.Count - 1].GetComponent <WMG_Link>();

        theLine.Reposition();
        if (aSeries.connectFirstToLast)           // One extra link to animate for circles / close loop series
        {
            aNode   = aSeries.getPoints()[0].GetComponent <WMG_Node>();
            theLine = aNode.links[0].GetComponent <WMG_Link>();
            theLine.Reposition();
        }
    }
Пример #27
0
 void ActivateNeighborNodes(WMG_Node fromNode)
 {
     for (int i = 0; i < fromNode.numLinks; i++)
     {
         WMG_Link aLink   = fromNode.links[i].GetComponent <WMG_Link>();
         WMG_Node aLinkTo = aLink.toNode.GetComponent <WMG_Node>();
         if (aLinkTo.id == fromNode.id)
         {
             aLinkTo = aLink.fromNode.GetComponent <WMG_Node>();
         }
         theMap.SetActive(aLinkTo.gameObject, true);
     }
 }
Пример #28
0
    string customTooltipLabeler(WMG_Series aSeries, WMG_Node aNode)
    {
        Vector2 nodeData = aSeries.getNodeValue(aNode);

        tooltipNumberFormatInfo.CurrencyDecimalDigits = aSeries.theGraph.tooltipNumberDecimals;
        string textToSet = nodeData.y.ToString("C", tooltipNumberFormatInfo);

        if (aSeries.theGraph.tooltipDisplaySeriesName)
        {
            textToSet = aSeries.seriesName + ": " + textToSet;
        }
        return(textToSet);
    }
Пример #29
0
 float getSquareCircleOffsetLength(WMG_Node theNode, float angle, bool isFrom)
 {
     if (theNode.isSquare)
     {
         int   angleOffset       = getSquareCircleOffsetAngle(angle, isFrom);
         float squareOffsetFromX = theNode.radius - theNode.radius * Mathf.Cos(Mathf.Deg2Rad * angleOffset);
         float squareOffsetFromY = squareOffsetFromX * Mathf.Tan(Mathf.Deg2Rad * angleOffset);
         return(Mathf.Sqrt(squareOffsetFromX * squareOffsetFromX + squareOffsetFromY * squareOffsetFromY));
     }
     else
     {
         return(0);
     }
 }
Пример #30
0
    void OnWeaponTreeClick(GameObject go)
    {
        if (!treeAnimating && !weaponClicked)
        {
            weaponClicked = !weaponClicked;
            treeAnimating = true;
            Quaternion newRot = weaponTree.transform.localRotation;
            newRot.eulerAngles = new Vector3(0, 0, 0);
            TweenRotation.Begin(weaponTree, treeClickAnimDuration, newRot);
            TweenPosition tpos = TweenPosition.Begin(weaponTree, treeClickAnimDuration, new Vector3(0, 100, -350));
            tpos.method = UITweener.Method.EaseIn;
            TweenAlpha.Begin(go, treeClickAnimDuration, 70 / 255f);

            TweenAlpha.Begin(shieldTree, treeClickAnimDuration, 0);
            TweenAlpha.Begin(engineTree, treeClickAnimDuration, 0);

            tpos.callWhenFinished = "endWeaponTreeClicked";
            tpos.eventReceiver    = this.gameObject;
        }
        if (!treeAnimating && weaponClicked)
        {
            weaponClicked = !weaponClicked;
            treeAnimating = true;
            Quaternion newRot = weaponTree.transform.localRotation;
            newRot.eulerAngles = new Vector3(345, 0, 0);
            TweenRotation.Begin(weaponTree, treeClickAnimDuration, newRot);
            TweenPosition tpos = TweenPosition.Begin(weaponTree, treeClickAnimDuration, new Vector3(0, -150, 0));
            TweenAlpha.Begin(go, treeClickAnimDuration, 100 / 255f);

            TweenAlpha.Begin(shieldTree, treeClickAnimDuration, 1);
            TweenAlpha.Begin(engineTree, treeClickAnimDuration, 1);

            tpos.callWhenFinished = "endTreeClickAnim";
            tpos.eventReceiver    = this.gameObject;

            foreach (Transform child in weaponTree.transform)
            {
                WMG_Node aNode = child.GetComponent <WMG_Node>();
                if (aNode != null)
                {
                    BoxCollider aCol = child.GetComponent <BoxCollider>();
                    if (aCol != null)
                    {
                        aCol.enabled = false;
                    }
                }
            }
        }
    }
Пример #31
0
    void updateIndicator()
    {
        if (series1.getPoints().Count == 0)
        {
            return;
        }
        WMG_Node lastPoint = series1.getLastPoint().GetComponent <WMG_Node>();

        graph.changeSpritePositionToY(indicatorGO, lastPoint.transform.localPosition.y);
        Vector2 nodeData = series1.getNodeValue(lastPoint);
        //indicatorLabelNumberFormatInfo.CurrencyDecimalDigits = indicatorNumDecimals;
        string textToSet = nodeData.y.ToString();

        graph.changeLabelText(indicatorGO.transform.GetChild(0).GetChild(0).gameObject, textToSet);
    }
Пример #32
0
	private void animateLinkCallback(WMG_Series aSeries, GameObject aGO, bool isLast) {
		WMG_Node aNode = aGO.GetComponent<WMG_Node>();
		if (aNode.links.Count != 0) {
			WMG_Link theLine = aNode.links[aNode.links.Count-1].GetComponent<WMG_Link>();
			theLine.Reposition();
		}
		if (isLast) {
			aSeries.updateAreaShading(null);
		}
		if (aSeries.connectFirstToLast) { // One extra link to animate for circles / close loop series
			aNode = aSeries.getPoints()[0].GetComponent<WMG_Node>();
			WMG_Link theLine = aNode.links[0].GetComponent<WMG_Link>();
			theLine.Reposition();
		}
	}
Пример #33
0
 private void TooltipLegendNodeMouseEnter(WMG_Series aSeries, WMG_Node aNode, bool state)
 {
     if (isTooltipObjectNull())
     {
         return;
     }
     if (state)
     {
         MouseEnterCommon(aSeries.seriesName, aNode.gameObject, new Vector3(2, 2, 1));
     }
     else
     {
         MouseExitCommon(aNode.gameObject);
     }
 }
Пример #34
0
    private string defaultTooltipLabeler(WMG_Series aSeries, WMG_Node aNode)
    {
        // Find out the point value data for this node
        Vector2 nodeData = aSeries.getNodeValue(aNode);
        float numberToMult = Mathf.Pow(10f, aSeries.theGraph.tooltipNumberDecimals);
        string nodeX = (Mathf.Round(nodeData.x*numberToMult)/numberToMult).ToString();
        string nodeY = (Mathf.Round(nodeData.y*numberToMult)/numberToMult).ToString();

        // Determine the tooltip text to display
        string textToSet;
        if (aSeries.seriesIsLine) {
            textToSet = "(" + nodeX + ", " + nodeY + ")";
        }
        else {
            textToSet = nodeY;
        }
        if (aSeries.theGraph.tooltipDisplaySeriesName) {
            textToSet = aSeries.seriesName + ": " + textToSet;
        }
        return textToSet;
    }
Пример #35
0
    private void TooltipNodeMouseEnter(WMG_Series aSeries, WMG_Node aNode, bool state)
    {
        if (isTooltipObjectNull()) return;
        if (state) {
            // Find out what point value data is for this node
            Vector2 nodeData = aSeries.getNodeValue(aNode);
            float numberToMult = Mathf.Pow(10f, theGraph.tooltipNumberDecimals);
            string nodeX = (Mathf.Round(nodeData.x*numberToMult)/numberToMult).ToString();
            string nodeY = (Mathf.Round(nodeData.y*numberToMult)/numberToMult).ToString();

            // Determine the tooltip to display and set the text
            string textToSet;
            if (theGraph.graphType != WMG_Axis_Graph.graphTypes.line) {
                textToSet = nodeY;
            }
            else {
                textToSet = "(" + nodeX + ", " + nodeY + ")";
            }
            if (theGraph.tooltipDisplaySeriesName) {
                textToSet = aSeries.seriesName + ": " + textToSet;
            }
            changeLabelText(theGraph.toolTipLabel, textToSet);

            // Resize this control to match the size of the contents
            changeSpriteWidth(theGraph.toolTipPanel, Mathf.RoundToInt(getSpriteWidth(theGraph.toolTipLabel)) + 24);

            // Ensure tooltip is in position before showing it so it doesn't appear to jump
            repositionTooltip();

            // Display the base panel
            showControl(theGraph.toolTipPanel);
            bringSpriteToFront(theGraph.toolTipPanel);

            Vector3 newVec = new Vector3(2,2,1);
            if (theGraph.graphType != WMG_Axis_Graph.graphTypes.line) {
                if (theGraph.orientationType == WMG_Axis_Graph.orientationTypes.vertical) {
                    newVec = new Vector3(1,1.1f,1);
                }
                else {
                    newVec = new Vector3(1.1f,1,1);
                }
            }

            performTooltipAnimation(aNode.transform, newVec);
        }
        else {
            hideControl(theGraph.toolTipPanel);
            sendSpriteToBack(theGraph.toolTipPanel);

            performTooltipAnimation(aNode.transform, new Vector3(1,1,1));
        }
    }
Пример #36
0
	string customTooltipLabeler(WMG_Series aSeries, WMG_Node aNode) {
		Vector2 nodeData = aSeries.getNodeValue(aNode);
		tooltipNumberFormatInfo.CurrencyDecimalDigits = aSeries.theGraph.tooltipNumberDecimals;
		string textToSet = nodeData.y.ToString("C", tooltipNumberFormatInfo);
		if (aSeries.theGraph.tooltipDisplaySeriesName) {
			textToSet = aSeries.seriesName + ": " + textToSet;
		}
		return textToSet;
	}
Пример #37
0
    public List<GameObject> GenerateGraphFromNode(WMG_Node fromNode)
    {
        // Given a starting node, generate a graph of nodes around the starting node
        // Returns the list of nodes and links composing the resulting graph
        List<GameObject> returnResults = new List<GameObject>();
        returnResults.Add(fromNode.gameObject);

        // Initialize various variables used in the algorithm
        GameObject[] nodes = new GameObject[numNodes];
        bool[] nodesProcessed = new bool[numNodes];
        GameObject curObj = fromNode.gameObject;
        int procNodeNum = 0;
        int numNodesProcessed = 0;
        int numNodesStarting = theGraph.NodesParent.Count - 1;
        nodes[procNodeNum] = curObj;

        // Each while loop processes a node by attempting to create neighbors and links to neighbors from the node.
        // The loop ends when all nodes have been processed or when the number of nodes specified have been created.
        // A node is processed if all of its neighbors were successfully created or if not all neighbors were created, but maxNeighborAttempts was reached.
        // maxNeighborAttempts (a failed neighbor creation attempt) can get incremented for the following reasons:
        // 1. When a randomly generated angle falls between existing neighbors that is less than minAngle.
        // 2. If noLinkIntersection is true, a randomly generated angle and length would create a link that would cross an existing link in this manager's links parent.
        // 3. If noNodeIntersection is true, a randomly generated angle and length would create a node that that would circle interesect an existing node in this manager's nodes parent.
        // 3 cont. The same as above but noNodeIntersectionRadiusPadding > 0, performs the circle intersections check with the nodes' radii increased by the specified padding.
        // 4. If noLinkNodeIntersection is true, a randomly generated node would intersect with an existing link or a randomly generated link would intersect with an existing node.
        // 4 cont. The same as above but noLinkNodeIntersectionRadiusPadding > 0, performas the circle - line intersections with the node radius increased by the specified padding.
        while (theGraph.NodesParent.Count - numNodesStarting < numNodes) {

            WMG_Node procNode = nodes[procNodeNum].GetComponent<WMG_Node>();
            int numNeighbors = Random.Range(minRandomNumberNeighbors,maxRandomNumberNeighbors);
            if (debugRandomGraph) Debug.Log("Processesing Node: " + procNode.id + " with " + numNeighbors + " neighbors.");
            // Attempt to create a neighbor for the specified random number of neighbors
            for (int i = 0; i < numNeighbors; i++) {
                int curNeighborAttempt = 0;
                // For each neighbor, attempt to create the neighbor based on the maxNeighborAttempts
                while (curNeighborAttempt < maxNeighborAttempts) {
                    // For this attempt, randomly generate an angle and length based on the specified parameters
                    float neighborAngle = Random.Range(minAngleRange,maxAngleRange);
                    float neighborLength = Random.Range(minRandomLinkLength,maxRandomLinkLength);
                    bool failedAttempt = false;

                    if (debugRandomGraph) Debug.Log("Neighbor: " + i + " Attempt: " + curNeighborAttempt + " angle: " + Mathf.Round(neighborAngle));

                    // Check to see that the randomly generated neighbor would not be too close to an existing neighbor (failure possibility #1)
                    if (minAngle > 0) {
                        for (int j = 0; j < procNode.numLinks; j++) {
                            float angleDif = Mathf.Abs(procNode.linkAngles[j] - neighborAngle);
                            if (angleDif > 180) angleDif = Mathf.Abs(angleDif - 360);
                            if (angleDif < minAngle) {
                                failedAttempt = true;
                                break;
                            }
                        }
                    }

                    if (failedAttempt) {
                        // Failed because random angle was smaller than the minAngle on either side of an existing neighbor
                        if (debugRandomGraph) Debug.Log("Failed: Angle within minAngle of existing neighbor");
                        curNeighborAttempt++;
                        continue;
                    }
                    // Check if the randomly generated link intersects an existing link (failure possibility #2)
                    if (noLinkIntersection) {
                        float p1y = procNode.transform.localPosition.y + (neighborLength + procNode.radius) * Mathf.Sin(Mathf.Deg2Rad*neighborAngle);
                        float p1x = procNode.transform.localPosition.x + (neighborLength + procNode.radius) * Mathf.Cos(Mathf.Deg2Rad*neighborAngle);
                        float p2y = procNode.transform.localPosition.y + procNode.radius * Mathf.Sin(Mathf.Deg2Rad*neighborAngle);
                        float p2x = procNode.transform.localPosition.x + procNode.radius * Mathf.Cos(Mathf.Deg2Rad*neighborAngle);
                        foreach (GameObject child in theGraph.LinksParent) {
                            WMG_Link childLink = child.GetComponent<WMG_Link>();
                            if (childLink.id == -1) continue; // Dummy editor link
                            WMG_Node childLinkFrom = childLink.fromNode.GetComponent<WMG_Node>();
                            WMG_Node childLinkTo = childLink.toNode.GetComponent<WMG_Node>();
                            float p3y = childLinkFrom.transform.localPosition.y;
                            float p3x = childLinkFrom.transform.localPosition.x;
                            float p4y = childLinkTo.transform.localPosition.y;
                            float p4x = childLinkTo.transform.localPosition.x;
                            if (PointInterArea(p1x, p1y, p2x, p2y, p3x, p3y) * PointInterArea(p1x, p1y, p2x, p2y, p4x, p4y) < 0 &&
                                PointInterArea(p3x, p3y, p4x, p4y, p1x, p1y) * PointInterArea(p3x, p3y, p4x, p4y, p2x, p2y) < 0) { // Links intersect
                                if (debugRandomGraph) Debug.Log("Failed: Link intersected with existing link: " + childLink.id);
                                failedAttempt = true;
                                break;
                            }
                        }
                    }
                    if (failedAttempt) {
                        // Failed because random link intersected an existing link
                        curNeighborAttempt++;
                        continue;
                    }
                    // Check if the randomly generated node intersects an existing node (failure possibility #3)
                    if (noNodeIntersection) {
                        float p1y = procNode.transform.localPosition.y + (neighborLength) * Mathf.Sin(Mathf.Deg2Rad*neighborAngle);
                        float p1x = procNode.transform.localPosition.x + (neighborLength) * Mathf.Cos(Mathf.Deg2Rad*neighborAngle);
                        foreach (GameObject child in theGraph.NodesParent) {
                            WMG_Node aNode = child.GetComponent<WMG_Node>();
                            if (aNode.id == -1) continue; // Dummy editor node
                            // Circles intersect if (R0-R1)^2 <= (x0-x1)^2+(y0-y1)^2 <= (R0+R1)^2
                            if (Mathf.Pow((p1x - child.transform.localPosition.x),2) + Mathf.Pow((p1y - child.transform.localPosition.y),2) <= Mathf.Pow(2*(procNode.radius + noNodeIntersectionRadiusPadding),2)) {
                                if (debugRandomGraph) Debug.Log("Failed: Node intersected with existing node: " + aNode.id);
                                failedAttempt = true;
                                break;
                            }
                        }
                    }
                    if (failedAttempt) {
                        // Failed because random node intersected an existing node
                        curNeighborAttempt++;
                        continue;
                    }
                    // Check if the randomly generated link intersects an existing node
                    if (noLinkNodeIntersection) {
                        float p1y = procNode.transform.localPosition.y + (neighborLength + procNode.radius) * Mathf.Sin(Mathf.Deg2Rad*neighborAngle);
                        float p1x = procNode.transform.localPosition.x + (neighborLength + procNode.radius) * Mathf.Cos(Mathf.Deg2Rad*neighborAngle);
                        float p2y = procNode.transform.localPosition.y + procNode.radius * Mathf.Sin(Mathf.Deg2Rad*neighborAngle);
                        float p2x = procNode.transform.localPosition.x + procNode.radius * Mathf.Cos(Mathf.Deg2Rad*neighborAngle);
                        foreach (GameObject child in theGraph.NodesParent) {
                            WMG_Node aNode = child.GetComponent<WMG_Node>();
                            if (procNode.id == aNode.id) continue; // Ignore the processesing node
                            if (LineInterCircle(p1x, p1y, p2x, p2y, child.transform.localPosition.x, child.transform.localPosition.y, aNode.radius + noLinkNodeIntersectionRadiusPadding)) {
                                if (debugRandomGraph) Debug.Log("Failed: Link intersected with existing node: " + aNode.id);
                                failedAttempt = true;
                                break;
                            }
                        }
                    }
                    if (failedAttempt) {
                        // Failed because random link intersected an existing node
                        curNeighborAttempt++;
                        continue;
                    }

                    // Check if the randomly generated node intersects an existing link
                    if (noLinkNodeIntersection) {
                        float cy = procNode.transform.localPosition.y + (neighborLength + 2 * procNode.radius) * Mathf.Sin(Mathf.Deg2Rad*neighborAngle);
                        float cx = procNode.transform.localPosition.x + (neighborLength + 2 * procNode.radius) * Mathf.Cos(Mathf.Deg2Rad*neighborAngle);
                        foreach (GameObject child in theGraph.LinksParent) {
                            WMG_Link childLink = child.GetComponent<WMG_Link>();
                            if (childLink.id == -1) continue; // Dummy editor link
                            WMG_Node childLinkFrom = childLink.fromNode.GetComponent<WMG_Node>();
                            WMG_Node childLinkTo = childLink.toNode.GetComponent<WMG_Node>();
                            float p1y = childLinkFrom.transform.localPosition.y;
                            float p1x = childLinkFrom.transform.localPosition.x;
                            float p2y = childLinkTo.transform.localPosition.y;
                            float p2x = childLinkTo.transform.localPosition.x;
                            if (LineInterCircle(p1x, p1y, p2x, p2y, cx, cy, procNode.radius + noLinkNodeIntersectionRadiusPadding)) {
                                if (debugRandomGraph) Debug.Log("Failed: Node intersected with existing link: " + childLink.id);
                                failedAttempt = true;
                                break;
                            }
                        }
                    }
                    if (failedAttempt) {
                        // Failed because random node intersected an existing link
                        curNeighborAttempt++;
                        continue;
                    }

                    // The attempt did not fail, so create the node and the link and break out of the while attempt < maxAttempts loop
                    curObj = theGraph.CreateNode(nodePrefab, fromNode.transform.parent.gameObject);
                    returnResults.Add(curObj);
                    nodes[theGraph.NodesParent.Count - numNodesStarting - 1] = curObj;

        //					curObj.transform.parent = fromNode.transform.parent;

                    float dx = Mathf.Cos(Mathf.Deg2Rad*neighborAngle)*neighborLength;
                    float dy = Mathf.Sin(Mathf.Deg2Rad*neighborAngle)*neighborLength;
                    curObj.transform.localPosition = new Vector3(procNode.transform.localPosition.x + dx, procNode.transform.localPosition.y + dy, 0);

                    returnResults.Add(theGraph.CreateLink(procNode, curObj, linkPrefab, null));
                    break;
                }
                if (theGraph.NodesParent.Count - numNodesStarting == numNodes) break; // Max number nodes specified was reached, we are done generating the graph
            }
            // Set the node as processed and increment the processed node counter
            nodesProcessed[procNodeNum] = true;
            numNodesProcessed++;
            // Process the oldest node added as the next node to process
            if (centerPropogate) {
                procNodeNum++;
            }
            // Pick a random node as the next node to process from the nodes that have been created from this algorithm
            else {
                int numPossibleProcNodes = theGraph.NodesParent.Count - numNodesStarting - numNodesProcessed;
                if (numPossibleProcNodes > 0) {
                    int[] possibleProcNodes = new int[numPossibleProcNodes];
                    int j = 0;
                    for (int i = 0; i < numNodes; i++) {
                        if (!nodesProcessed[i] && i < theGraph.NodesParent.Count - numNodesStarting) {
                            possibleProcNodes[j] = i;
                            j++;
                        }
                    }
                    procNodeNum = possibleProcNodes[Random.Range(0,j-1)];
                }
            }

            // This happens (algorithm ends prematurely) when maxNeighborAttempts was reached for the starting node or all the nodes created
            if (theGraph.NodesParent.Count - numNodesStarting == numNodesProcessed) { // Case where all nodes have been processed, but number nodes specfied were not created
                Debug.Log("WMG - Warning: Only generated " + (theGraph.NodesParent.Count - numNodesStarting - 1) + " nodes with the given parameters.");
                break;
            }
        }

        return returnResults;
    }
Пример #38
0
	private void TooltipNodeMouseEnter(WMG_Series aSeries, WMG_Node aNode, bool state) {
		if (isTooltipObjectNull()) return;
		if (state) {
			// Set tooltip text
			changeLabelText(theGraph.toolTipLabel, tooltipLabeler(aSeries, aNode));
			
			// Resize this control to match the size of the contents
			changeSpriteWidth(theGraph.toolTipPanel, Mathf.RoundToInt(getSpriteWidth(theGraph.toolTipLabel)) + 24);
			
			// Ensure tooltip is in position before showing it so it doesn't appear to jump
			repositionTooltip();
			
			// Display the base panel
			showControl(theGraph.toolTipPanel);
			bringSpriteToFront(theGraph.toolTipPanel);
			
			Vector3 newVec = new Vector3(2,2,1);
			if (!aSeries.seriesIsLine) {
				if (theGraph.orientationType == WMG_Axis_Graph.orientationTypes.vertical) {
					newVec = new Vector3(1,1.1f,1);
				}
				else {
					newVec = new Vector3(1.1f,1,1);
				}
			}
			
			performTooltipAnimation(aNode.transform, newVec);
		}
		else {
			hideControl(theGraph.toolTipPanel);
			sendSpriteToBack(theGraph.toolTipPanel);
			
			performTooltipAnimation(aNode.transform, new Vector3(1,1,1));
		}
	}
Пример #39
0
	void CreateOrDeleteLink(WMG_Node fromNode, WMG_Node toNode, bool noVertHoriz) {
		WMG_Link aLink = GetLink(fromNode, toNode);
		if (aLink == null) {
			if (createLinks && !noVertHoriz) {
				gridLinks.Add(CreateLink(fromNode, toNode.gameObject, linkPrefab, this.gameObject));
			}
		}
		else {
			if (!createLinks || noVertHoriz) {
				gridLinks.Remove(aLink.gameObject);
				DeleteLink(aLink);
			}
		}
	}
Пример #40
0
	private float getSquareCircleOffsetLength(WMG_Node theNode, float angle, bool isFrom) {
		if (theNode.isSquare) {
			int angleOffset = getSquareCircleOffsetAngle(angle, isFrom);
			float squareOffsetFromX = theNode.radius - theNode.radius * Mathf.Cos(Mathf.Deg2Rad * angleOffset);
			float squareOffsetFromY = squareOffsetFromX * Mathf.Tan(Mathf.Deg2Rad * angleOffset);
			return Mathf.Sqrt(squareOffsetFromX * squareOffsetFromX + squareOffsetFromY * squareOffsetFromY);
		}
		else return 0;
	}
Пример #41
0
	void SetNodeAngles(float angle, WMG_Node fromN, WMG_Node toN) {
		for (int i = 0; i < fromN.numLinks; i++) {
			WMG_Link fromNlink = fromN.links[i].GetComponent<WMG_Link>();
			if (fromNlink.id == this.id) {
				fromN.linkAngles[i] = angle - 90;
			}
		}
		for (int i = 0; i < toN.numLinks; i++) {
			WMG_Link toNlink = toN.links[i].GetComponent<WMG_Link>();
			if (toNlink.id == this.id) {
				toN.linkAngles[i] = angle + 90;
			}
		}
	}
Пример #42
0
 // Get Vector2 associated with a node in this series
 public Vector2 getNodeValue(WMG_Node aNode)
 {
     for (int i = 0; i < pointValues.Count; i++) {
         if (points[i].GetComponent<WMG_Node>() == aNode) return pointValues[i];
     }
     return Vector2.zero;
 }
Пример #43
0
 // Get Vector2 associated with a node in this series
 public Vector2 getNodeValue(WMG_Node aNode)
 {
     for (int i = 0; i < pointValues.Count; i++) { // TODO improve performance by mapping IDs to Vector2
         if (points[i].GetComponent<WMG_Node>() == aNode) return pointValues[i];
     }
     return Vector2.zero;
 }