// Use this for initialization void Start() { UIEventListener.Get(background).onDrag += OnMapBackgroundDragged; UIEventListener.Get(background).onScroll += OnMapBackgroundScrolled; theMap = MapManagerObject.GetComponent <WMG_Graph_Manager>(); theMapGenerator = MapManagerObject.GetComponent <WMG_Random_Graph>(); theMapGenerator.nodePrefab = NodePrefab; theMapGenerator.linkPrefab = LinkPrefab; CurrentNode = theMap.CreateNode(NodePrefab, PanParentObject); // CurrentNode.transform.parent = PanParentObject.transform; WMG_Node_World_Map startNode = CurrentNode.GetComponent <WMG_Node_World_Map>(); theMap.SetActive(startNode.SelectionObject, true); theMapGenerator.GenerateGraphFromNode(startNode); foreach (GameObject child in theMap.LinksParent) { theMap.SetActive(child, false); } foreach (GameObject child in theMap.NodesParent) { UIEventListener.Get(child).onClick += OnNodeClick; UIEventListener.Get(child).onHover += OnNodeHover; WMG_Node_World_Map aNode = child.GetComponent <WMG_Node_World_Map>(); AnimateSelection(aNode); if (aNode.id != startNode.id) { theMap.SetActive(child, false); } } ActivateNeighbors(startNode); }
void AnimateSelection(WMG_Node_World_Map theNode) { float duration = 0.4f; TweenPosition tPos; tPos = TweenPosition.Begin(theNode.SelTopRight, duration, new Vector3(20, 20, 0)); tPos.style = UITweener.Style.PingPong; tPos = TweenPosition.Begin(theNode.SelBotLeft, duration, new Vector3(-20, -20, 0)); tPos.style = UITweener.Style.PingPong; tPos = TweenPosition.Begin(theNode.SelBotRight, duration, new Vector3(20, -20, 0)); tPos.style = UITweener.Style.PingPong; tPos = TweenPosition.Begin(theNode.SelTopLeft, duration, new Vector3(-20, 20, 0)); tPos.style = UITweener.Style.PingPong; }
void OnNodeClick(GameObject go) { if (CurrentNode != go) { WMG_Node_World_Map cNode = CurrentNode.GetComponent <WMG_Node_World_Map>(); WMG_Node_World_Map newNode = go.GetComponent <WMG_Node_World_Map>(); theMap.SetActive(cNode.SelectionObject, false); theMap.SetActive(newNode.SelectionObject, true); ActivateNeighbors(newNode); AnimatePath(false, theMap.FindShortestPathBetweenNodes(cNode, newNode)); CurrentNode = go; } }
void OnNodeHover(GameObject go, bool hover) { WMG_Node_World_Map tNode = go.GetComponent <WMG_Node_World_Map>(); if (hover) { if (tNode.hoverState) { return; // Since click events send out hover true events } tNode.hoverState = true; } else { tNode.hoverState = false; } if (CurrentNode != go) { WMG_Node_World_Map fNode = CurrentNode.GetComponent <WMG_Node_World_Map>(); AnimatePath(hover, theMap.FindShortestPathBetweenNodes(fNode, tNode)); } }