private void UpdateExistingEdgeGoData(GameObject edgeExistingGo, CdmEdgeBtc edgeNewBtc) { Msg.Log("GraphFactory.UpdateExistingEdgeGoData is refreshing edge data"); // TODO What might need updated? Since Cdm handles merges, it seems safe enough to overwrite whole object. GraphEdgeBrain blb = edgeExistingGo.GetComponent <GraphEdgeBrain>(); if (blb != null) { blb.CdmEdgeBtc = edgeNewBtc; // TODO plus propogate any values across the edge GO ? } }
/// <summary> /// Create game object for edge /// Terrible code, needs refactored /// </summary> private GameObject InstantiateEdge(string id, string idFriendly, int edgeNumSource, int edgeNumTarget, GameObject source, GameObject target, EdgeType edgeType, bool valueIsKnown, float valueMBtc, float valueMBtcAdditional) { if (source == null || target == null || (source == target)) { Msg.LogWarning("GraphFactory.InstantiateEdge: source or target do not exist, or are identical. Edge not created."); return(null); } // an entirely new link GraphEdgeBrain linkObject = Instantiate(LinkPrefab, new Vector3(0, 0, 0), Quaternion.identity, ParentFolder) as GraphEdgeBrain; linkObject.id = id; linkObject.edgeNumInSource = edgeNumSource; linkObject.edgeNumInTarget = edgeNumTarget; linkObject.name = idFriendly + "--" + edgeNumSource + "--" + edgeNumTarget; // Game Object name linkObject.source = source; linkObject.target = target; //linkObject.SetBitLinkValue(valueIsKnown, valueMBtc); //linkObject.SetBitLinkType(linkType); EdgeType linkType = EdgeType.Input; if (edgeType == EdgeType.Input) { linkType = EdgeType.Input; linkObject.SetBitLinkTypeAndValue_Initial(linkType, valueIsKnown, valueMBtc, edgeType); } else if (edgeType == EdgeType.Output) { linkType = EdgeType.Output; linkObject.SetBitLinkTypeAndValue_Initial(linkType, valueIsKnown, valueMBtcAdditional, edgeType); } else { // TODO Horrible and needs refactored, this is hangover from proof of concept // We are now a mixed link, the method SetBitLinkTypeAndValue_Additional() will handle setting the type to Mixed itself Msg.Log("GraphFactory.InstantiateEdge: Link between source " + source.name + " and target " + target.name + " being PROMOTED TO MIXED"); linkObject.SetBitLinkTypeAndValue_Initial(EdgeType.Input, valueIsKnown, valueMBtc, edgeType); linkObject.SetBitLinkTypeAndValue_Additional(EdgeType.Output, valueIsKnown, valueMBtcAdditional, edgeType); // this counts towards our link counters of course UpdateLinkCountersOnSourceAndTarget(source, target); } linkCount++; // Update link counters UpdateLinkCountersOnSourceAndTarget(source, target); return(linkObject.gameObject); }
/// <summary> /// Create a new edge game object, or update an existing one. New edges get added to _graphIndex list. /// </summary> void IGraphFactory.CreateOrUpdateEdge(CdmEdge edgeNew) { CdmEdgeBtc edgeNewBtc = edgeNew as CdmEdgeBtc; // Do we exist already? GameObject edgeExistingGo; if (_graphIndex.TryGetValue(edgeNewBtc.EdgeId, out edgeExistingGo)) { UpdateExistingEdgeGoData(edgeExistingGo, edgeNewBtc); return; } // We are new. Do necessary nodes exist? GameObject sourceGo; bool sourceExists = _graphIndex.TryGetValue(edgeNewBtc.NodeSourceId, out sourceGo); GameObject targetGo; bool targetExists = _graphIndex.TryGetValue(edgeNewBtc.NodeTargetId, out targetGo); if (!sourceExists || !targetExists) { Msg.LogWarning("GraphFactory.CreateEdge cannot create edge because source or target GameObject dont exist yet"); return; } // Do it GameObject createdEdge = null; //Msg.Log("GraphFactory.CreateEdge: Edge about to be created: " + edgeNewBtc.EdgeId); createdEdge = InstantiateEdge(edgeNewBtc.EdgeId, edgeNewBtc.EdgeIdFriendly, edgeNewBtc.EdgeNumberInSource, edgeNewBtc.EdgeNumberInTarget, sourceGo, targetGo, edgeNewBtc.EdgeType, true, edgeNewBtc.ValueInSource, edgeNewBtc.ValueInTarget); if (createdEdge == null) { Msg.LogWarning("GraphFactory.CreateEdge: Edge not created."); } else { Msg.Log("GraphFactory.GenerateEdge: Edge created: " + createdEdge.gameObject.name); GraphEdgeBrain geb = createdEdge.GetComponent <GraphEdgeBrain>(); if (geb != null) { geb.CdmEdgeBtc = edgeNewBtc; } // index it _graphIndex.Add(edgeNewBtc.EdgeId, createdEdge); } }
// Update is called once per frame void Update() { // Free up the mouse if (Input.GetKeyDown(KeyCode.Escape)) { if (Screen.fullScreen) { // if we are full screen, first Esc press takes to window Screen.fullScreen = !Screen.fullScreen; } else if (Cursor.lockState == CursorLockMode.Locked) { // second Esc press frees cursor Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } else if (Cursor.lockState == CursorLockMode.None) { // third Esc toggle cursor back into window Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } } // Mouse recapture also possible with a left click in the Window if (Input.GetMouseButton(0)) { if (Cursor.lockState == CursorLockMode.None) { // Recapture mouse Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } } // Toggle labels if (Input.GetKeyDown(KeyCode.L)) { GlobalData.Instance.IsGlobalLinkLabelActive = !GlobalData.Instance.IsGlobalLinkLabelActive; foreach (GameObject linkGo in GameObject.FindGameObjectsWithTag("edge")) { //Debug.Log("UiInputController: Toggle Labels: examine label: " + linkGo.name); GraphEdgeBrain edgeBrain = linkGo.GetComponent <GraphEdgeBrain>(); if (GlobalData.Instance.IsGlobalLinkLabelActive) { edgeBrain.CanvasEnable(); } else { edgeBrain.CanvasDisable(); } } } // Toggle Physics if (Input.GetKeyDown(KeyCode.P)) { GraphFactoryBtc.Instance.AllStatic = !GraphFactoryBtc.Instance.AllStatic; } // Toggle Auto Grow if (Input.GetKeyDown(KeyCode.G)) { GraphFactorySprout.Instance.IsAutoGrowActive = !GraphFactorySprout.Instance.IsAutoGrowActive; } // Toggle Mouse if (Input.GetKeyDown(KeyCode.M)) { if (GlobalData.Instance.FlipMouseYAxis < 0f) { GlobalData.Instance.FlipMouseYAxis = 1f; } else { GlobalData.Instance.FlipMouseYAxis = -1f; } } }