//Sets the action field and changes the color of the line public void setAction(PageElementEventTrigger.Action action) { //Set line color to coincide with the function it is providing. (find AssociatedElementRef so it searches sibling components and only the parent has AER) this.action = action; LineRenderer line = this.GetComponent <LineRenderer>(); switch (this.action) { case PageElementEventTrigger.Action.Change: line.startColor = new Color(0.7253471f, 0.9433962f, 0.9433962f); line.endColor = new Color(0.2569865f, 0.75472f, 0.6981435f); break; case PageElementEventTrigger.Action.Show: line.startColor = new Color(.74f, .98f, .69f); line.endColor = new Color(.20f, .67f, .04f); break; case PageElementEventTrigger.Action.Hide: line.startColor = new Color(0.9811321f, 0.6895692f, 0.6895692f); line.endColor = new Color(0.7921569f, 0, 0); break; case PageElementEventTrigger.Action.None: Debug.LogError("Line was drawn but has no action"); break; } }
public void buildFromPage(Page content) { page = content; nodeParts = new List <GameObject>(); // float heightOfRect = titleHeight + footerHeight; //Starts at height of title since that will always be the minimum height of title foreach (GameObject element in content.getElements()) { GameObject body = GameObject.Instantiate(elementNodePrefab, this.transform); body.GetComponentInChildren <InputField>().text = element.name; body.name = "ElementNode_" + element.name; try { body.GetComponentInChildren <Image>().sprite = element.GetComponent <Image>().sprite; } catch (Exception) { }//in case this element doesn't have a sprite body.GetComponent <ElementNodeGraphicManager>().associatedElement = element; //add dropdowns and set them to reflect their actions int numberOfDropdowns = element.GetComponent <PageElementEventTrigger>().connections.Count; ElementNodeGraphicManager engm = body.GetComponent <ElementNodeGraphicManager>(); engm.addSelectionConnectors(numberOfDropdowns); for (int i = 0; i < numberOfDropdowns; i++) { ConnectionInfo connection = element.GetComponent <PageElementEventTrigger>().connections[i]; PageElementEventTrigger.Action action = connection.action; Dropdown dropdown = engm.selectionConnectors[i].GetComponentInChildren <Dropdown>(); if (dropdown != null) { if (action == PageElementEventTrigger.Action.Change) { dropdown.value = 0; } else if (action == PageElementEventTrigger.Action.Show) { dropdown.value = 1; } else if (action == PageElementEventTrigger.Action.Hide) { dropdown.value = 2; } } else { Debug.Log("No dropdown found in selection connector"); } //set the connection key in ManipulateNodeLines for this selection connector dropdown.GetComponentInParent <SelectionConnectorManager>().GetComponentInChildren <ManipulateNodeLines>() .connectionKey = connection.connectionKey; } nodeParts.Add(body); } drawElementNodes(); GetComponentInChildren <InputField>().text = page.getName(); //set title of node graphic to page name name = "NodeGraphic_" + page.getName(); this.GetComponent <RectTransform>().anchoredPosition = content.nodeGraphicLocation; }
public ConnectionInfo(Page page, GameObject element, PageElementEventTrigger.Action action) { connectedPage = page; if (page != null) { connectedPageName = page.getName(); } connectedElement = element; this.action = action; }
private PageElementEventTrigger peet; //The peet this element is associated with void Start() { peet = GetComponentInParent <ElementNodeGraphicManager>().associatedElement.GetComponent <PageElementEventTrigger>(); connectionKey = GetComponentInChildren <ManipulateNodeLines>().connectionKey; dropdown = GetComponentInChildren <Dropdown>(); dropdown.onValueChanged.AddListener(delegate { //Check to see if the change is still valid to the connector it is connected to (Can call hide and show both on an element but not on a page) //If valid, change action and color of curve, otherwise break the link try { connectionKey = GetComponentInChildren <ManipulateNodeLines>().connectionKey; PageElementEventTrigger.Action selection = getDropdownSelection(); if (selection == PageElementEventTrigger.Action.Change || selection == PageElementEventTrigger.Action.Edit) //These can only be connected to page connectors { BezierCurve4PointRenderer curve = GetComponentInChildren <ManipulateNodeLines>().curve; if (peet.connections[connectionKey].connectedElement != null) //if the connected receiver is from an Element then it cannot be page changed to { Debug.Log("Breaking link because trying to Change to Element"); curve.breakLink(); } else { Debug.Log("Changing old selection to Change"); peet.connections[connectionKey].action = selection; curve.setAction(selection); } } else { BezierCurve4PointRenderer curve = GetComponentInChildren <ManipulateNodeLines>().curve; if (peet.connections[connectionKey].connectedElement == null) //if the connected receiver is from an page then it cannot have an element function applied { Debug.Log("Breaking link because trying to " + selection + " to Page"); curve.breakLink(); } else { Debug.Log("Changing old selection to " + selection); peet.connections[connectionKey].action = selection; curve.setAction(selection); } } } catch (KeyNotFoundException) { } //If key wasn't found then there wasn't a connection already made catch (NullReferenceException) { } //if curve wasn't found then there wasnt a connection already made }); }
//Triggers when a button is pressed on a Page. //Needs only the element that the event is called from since PageElementEventTrigger stores the action and connectedPage or connectedElement public void buttonActions(GameObject element) { for (int i = 0; i < element.GetComponent <PageElementEventTrigger>().connections.Count; i++) { PageElementEventTrigger peet = element.GetComponent <PageElementEventTrigger>(); PageElementEventTrigger.Action action = peet.connections[i].action; if (action == PageElementEventTrigger.Action.Change) { storyRef.changePage(peet.connections[i].connectedPage); } if (action == PageElementEventTrigger.Action.Show) { peet.connections[i].connectedElement.GetComponent <PrefabInfo>().activeWithPage = true; } if (action == PageElementEventTrigger.Action.Hide) { peet.connections[i].connectedElement.GetComponent <PrefabInfo>().activeWithPage = false; } } }