public static ConnectionInfo[] setElementIndexes(PageElementEventTrigger peet) { ConnectionInfo[] connections = new ConnectionInfo[peet.connections.Count]; peet.connections.Values.CopyTo(connections, 0); for (int i = 0; i < connections.Length; i++) { connections[i].connectedElementIndex = -1; //-1 should be default value Page connectedPage = peet.connections[i].connectedPage; if (connectedPage == null) { continue; } GameObject currentElement = peet.connections[i].connectedElement; if (currentElement != null) { //Debug.Log("Current element is not null: " + currentElement); GameObject[] connectedPageElements = connectedPage.getElements(); //loop through the elements in this list to find the index that corresponds with the connectedElement for (int j = 0; j < connectedPageElements.Length; j++) { // Debug.Log("looping through elements in connected page: " + connectedPageElements[j]); if (connectedPageElements[j].Equals(currentElement)) { connections[i].connectedElementIndex = j; break; } } } } return(connections); }
public BackgroundData(GameObject background) { name = background.name; rtd = new RectTransformData(background.GetComponent <RectTransform>()); image = new ImageData(background.GetComponent <Image>()); //Fill the connection arrays PageElementEventTrigger peet = background.GetComponent <PageElementEventTrigger>(); connections = XMLSerializationManager.setElementIndexes(peet); }
public ButtonData(GameObject button) { name = button.name; rtd = new RectTransformData(button.GetComponent <RectTransform>()); image = new ImageData(button.GetComponent <Image>()); etd = new EventTriggerData(button.GetComponent <EventTrigger>()); text = new TextData(button.GetComponentInChildren <Text>()); PageElementEventTrigger peet = button.GetComponent <PageElementEventTrigger>(); connections = XMLSerializationManager.setElementIndexes(peet); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); PageElementEventTrigger peet = (PageElementEventTrigger)target; GUILayout.Label("Connection size: " + peet.connections.Count); GUILayout.Label("[Key|connectedPageName|connectedElementIndex \n|connectedObjectName|Object|Action] \n" + "----------------------------"); foreach (KeyValuePair <int, ConnectionInfo> connection in peet.connections) { GUILayout.Label("[" + connection.Key + " | " + connection.Value.connectedPageName + "|" + connection.Value.connectedElementIndex + "\n | " + connection.Value.connectedPage.getName() + " | " + connection.Value.connectedElement + " | " + connection.Value.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 }); }
public override GameObject toPrefab(Canvas canvas) { GameObject bg = GameObject.Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/PageElements/BackgroundImage.prefab"), canvas.transform); bg.name = name; rtd.copyToRectTransform(bg.GetComponent <RectTransform>()); image.copyToImage(bg.GetComponent <Image>()); PageElementEventTrigger peet = bg.GetComponent <PageElementEventTrigger>(); foreach (ConnectionInfo connection in connections) { peet.AddConnection(connection); } return(bg); }
public override GameObject toPrefab(Canvas canvas) //Decide if I need to return something based on how I add to element list in page { GameObject sa = GameObject.Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/PageElements/ScrollArea.prefab"), canvas.transform); sa.name = name; rtd_SA.copyToRectTransform(sa.GetComponent <RectTransform>()); image_SA.copyToImage(sa.GetComponent <Image>()); PageElementEventTrigger peet = sa.GetComponent <PageElementEventTrigger>(); foreach (ConnectionInfo connection in connections) { peet.AddConnection(connection); } GameObject tb = sa.transform.GetChild(0).gameObject; rtd_TB.copyToRectTransform(tb.GetComponent <RectTransform>()); srd_TB.copyToScrollRect(tb.GetComponent <ScrollRect>()); GameObject sb = tb.transform.GetChild(0).gameObject; rtd_SB.copyToRectTransform(sb.GetComponent <RectTransform>()); image_SB.copyToImage(sb.GetComponent <Image>()); sb_SB.copyToScrollbar(sb.GetComponent <Scrollbar>()); GameObject sla = sb.transform.GetChild(0).gameObject; rtd_SlA.copyToRectTransform(sla.GetComponent <RectTransform>()); GameObject h = sla.transform.GetChild(0).gameObject; rtd_H.copyToRectTransform(h.GetComponent <RectTransform>()); image_H.copyToImage(h.GetComponent <Image>()); GameObject t = tb.transform.GetChild(1).gameObject; //should be getchild(1) rtd_T.copyToRectTransform(t.GetComponent <RectTransform>()); text_T.copyToText(t.GetComponent <Text>()); //Now that all items are instantiated they need each other's references ScrollRect scrollRect = tb.GetComponent <ScrollRect>(); scrollRect.verticalScrollbar = sb.GetComponent <Scrollbar>(); scrollRect.content = t.GetComponent <RectTransform>(); sb.GetComponent <Scrollbar>().handleRect = h.GetComponent <RectTransform>(); return(sa); }
//removes connections to this Page or pageElement; public static void removeConnectionsTo(Story currentStory, Page removePage) { foreach (Page page in currentStory.getPages()) { foreach (GameObject element in page.getElements()) { PageElementEventTrigger peet = element.GetComponent <PageElementEventTrigger>(); foreach (KeyValuePair <int, ConnectionInfo> connection in peet.connections) { if (connection.Value.connectedPage.Equals(removePage)) { peet.connections.Remove(connection.Key); } } } } }
public override GameObject toPrefab(Canvas canvas) { GameObject button = GameObject.Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/PageElements/Button.prefab"), canvas.transform); button.name = name; rtd.copyToRectTransform(button.GetComponent <RectTransform>()); image.copyToImage(button.GetComponent <Image>()); etd.copyToEventTrigger(button.GetComponent <EventTrigger>()); text.copyToText(button.GetComponentInChildren <Text>()); PageElementEventTrigger peet = button.GetComponent <PageElementEventTrigger>(); foreach (ConnectionInfo connection in connections) { peet.AddConnection(connection); } return(button); }
public new void OnBeginDrag(PointerEventData data) { //clear any references to next page or next element since previous curve is replaced so the link has been broken PageElementEventTrigger peet = GetComponentInParent <ElementNodeGraphicManager>().associatedElement.GetComponent <PageElementEventTrigger>(); //peet.AddConnection(null, null, PageElementEventTrigger.Action.None); //shouldn't need this with current implementation if (curve != null) { curve.breakLink(); } curve = GameObject.Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/StoryEditor/CurveRenderer.prefab") , contentWindow).GetComponent <BezierCurve4PointRenderer>(); curve.setAction(GetComponentInParent <SelectionConnectorManager>().getDropdownSelection()); curve.originConnector = gameObject; //Give reference to this connector's game object to the curve lastDraggedCurve = curve.gameObject; dragging = true; }
public ScrollAreaData(GameObject scrollArea) { name = scrollArea.name; //SA fields rtd_SA = new RectTransformData(scrollArea.GetComponent <RectTransform>()); image_SA = new ImageData(scrollArea.GetComponent <Image>()); //TB fields GameObject textBox = scrollArea.transform.GetChild(0).gameObject; rtd_TB = new RectTransformData(textBox.GetComponent <RectTransform>()); srd_TB = new ScrollRectData(textBox.GetComponent <ScrollRect>()); //SB fields GameObject scrollbar = textBox.transform.GetChild(0).gameObject; rtd_SB = new RectTransformData(scrollbar.GetComponent <RectTransform>()); image_SB = new ImageData(scrollbar.GetComponent <Image>()); sb_SB = new ScrollbarData(scrollbar.GetComponent <Scrollbar>()); //SlA fields GameObject slidingArea = scrollbar.transform.GetChild(0).gameObject; rtd_SlA = new RectTransformData(slidingArea.GetComponent <RectTransform>()); //Handle fields GameObject handle = slidingArea.transform.GetChild(0).gameObject; rtd_H = new RectTransformData(handle.GetComponent <RectTransform>()); image_H = new ImageData(handle.GetComponent <Image>()); //TextFields GameObject text = textBox.transform.GetChild(1).gameObject; rtd_T = new RectTransformData(text.GetComponent <RectTransform>()); text_T = new TextData(text.GetComponent <Text>()); //EventTrigger fields PageElementEventTrigger peet = scrollArea.GetComponent <PageElementEventTrigger>(); connections = XMLSerializationManager.setElementIndexes(peet); }
//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; } } }
//Loops through every element in a story and gives it reference to the element/page that it is connected to public static void makeActionConnections(Story story) { foreach (Page page in story.getPages()) { foreach (GameObject element in page.getElements()) { PageElementEventTrigger peet = element.GetComponent <PageElementEventTrigger>(); for (int i = 0; i < peet.connections.Count; i++) { if (peet.connections[i].connectedPageName != null && !peet.connections[i].connectedPageName.Equals("")) //if there is a connected page { peet.connections[i].connectedPage = story.getPage(peet.connections[i].connectedPageName); //set the connected page if (peet.connections[i].connectedElementIndex != -1) { peet.connections[i].connectedElement = peet.connections[i].connectedPage.getElements()[peet.connections[i].connectedElementIndex]; //set the connected element } } } } } }
public new void OnPointerClick(PointerEventData data) { if (editingFunction == EditingFunction.Delete) { if (appliedToPage) //This is a page { PageNodeGraphicManager pngm = GetComponentInParent <PageNodeGraphicManager>(); pngm.page.storyRef.removePage(pngm.page.name); GameObject.Destroy(pngm.gameObject); } else //This is an element { Debug.Log("Deleting Element"); PageElementEventTrigger peet = GetComponentInParent <PageElementEventTrigger>(); Page pageRef = peet.pageRef; GameObject element = peet.gameObject; pageRef.removePageElement(element); } } else if (editingFunction == EditingFunction.EditProperties) { //Implement EditProperties here if (appliedToPage) { //Go to editPage Mode for this page gm.changeMode(GameManager.Mode.EditPage, GetComponentInParent <PageNodeGraphicManager>().page); } else { //open options based on what type of PageElement this is: such as a photo selector for image } } else if (editingFunction == EditingFunction.Play) { gm.changeMode(GameManager.Mode.Play, GetComponentInParent <PageNodeGraphicManager>().page); } //Resizing handles don't do anything when clicked }