public LogicGraphController displayLogicGraph(LogicChip graph, Vector3 bottomLeft) { GameObject graphPrefab = (GameObject)SceneResouces.SceneObjects["Default"][typeof(GameObject)]["Graph"]; GameObject go = Instantiate(graphPrefab).gameObject; Vector3 offset = new Vector3(graph.LightGraph.Width / 2, graph.LightGraph.Height / 2, 0); go.transform.position = bottomLeft + offset; LogicGraphController lgc = go.GetComponent <LogicGraphController>(); lgc.setUp(graph, bottomLeft, this); this.graphControllers.Add(lgc); return(lgc); }
public override void spawnContents(WindowController windowController, Transform contentPanel, Canvas canvas) { CameraManager cameraManager = GameObject.Find("CameraManager").GetComponent <CameraManager>(); Camera cam = cameraManager.makeNewCamera(false); this.camera = cam; Vector2 graphPosition = this.camera.transform.position; this.logicGraphController = this.logicGraphManager.displayLogicGraph(this.graph, graphPosition); GameObject image = GameObject.Instantiate((GameObject)SceneResouces.SceneObjects["Default"][typeof(GameObject)]["GraphEditor"]); this.rawImage = image.GetComponent <RawImage>(); image.transform.SetParent(contentPanel.transform, false); this.rawImageRect = image.GetComponent <RectTransform>(); //only for testing this.mouseObject = new GameObject("Mouse Graph Position"); this.mouseObject.transform.position = new Vector3(this.camera.transform.position.x, this.camera.transform.position.y, 0); this.renderTexture = new RenderTexture(512, 512, 16); this.rawImage.texture = this.renderTexture; this.camera.targetTexture = this.renderTexture; this.renderTexture.Create(); LogicGraphCameraController lgcc = this.camera.gameObject.AddComponent <LogicGraphCameraController>(); lgcc.setUp(graphPosition, this.logicGraphController.Graph, this.inputs, this.rawImage); #region GUIButtons Transform basePanel = image.transform.Find("Panel"); Button andButton = basePanel.Find("AndButton").GetComponent <Button>(); Button orButton = basePanel.Find("OrButton").GetComponent <Button>(); Button notButton = basePanel.Find("NotButton").GetComponent <Button>(); Button bufferButton = basePanel.Find("BufferButton").GetComponent <Button>(); Button nandButton = basePanel.Find("NandButton").GetComponent <Button>(); Button norButton = basePanel.Find("NorButton").GetComponent <Button>(); Button xorButton = basePanel.Find("XorButton").GetComponent <Button>(); Button xnorButton = basePanel.Find("XnorButton").GetComponent <Button>(); Button reflector = basePanel.Find("ReflectorButton").GetComponent <Button>(); Button splitterButton = basePanel.Find("SplitterButton").GetComponent <Button>(); Button sendBridgeButton = basePanel.Find("SendBridgeButton").GetComponent <Button>(); Button receiveBridgeButton = basePanel.Find("ReceiveBridgeButton").GetComponent <Button>(); Button deleteButton = basePanel.Find("DeleteButton").GetComponent <Button>(); //adds the component to the button andButton.onClick.AddListener(() => { this.component = new AndGate(this.previousGridPosition, this.rotation, this.flipped); this.changeComponent(); }); orButton.onClick.AddListener(() => { this.component = new OrGate(this.previousGridPosition, this.rotation, this.flipped); this.changeComponent(); }); notButton.onClick.AddListener(() => { this.component = new NotGate(this.previousGridPosition, this.rotation, this.flipped); this.changeComponent(); }); bufferButton.onClick.AddListener(() => { this.component = new BufferGate(this.previousGridPosition, this.rotation, this.flipped); this.changeComponent(); }); norButton.onClick.AddListener(() => { this.component = new NorGate(this.previousGridPosition, this.rotation, this.flipped); this.changeComponent(); }); xorButton.onClick.AddListener(() => { this.component = new XorGate(this.previousGridPosition, this.rotation, this.flipped); this.changeComponent(); }); xnorButton.onClick.AddListener(() => { this.component = new XnorGate(this.previousGridPosition, this.rotation, this.flipped); this.changeComponent(); }); nandButton.onClick.AddListener(() => { this.component = new NandGate(this.previousGridPosition, this.rotation, this.flipped); this.changeComponent(); }); splitterButton.onClick.AddListener(() => { this.component = new Splitter(this.previousGridPosition, this.rotation, this.flipped); this.changeComponent(); }); reflector.onClick.AddListener(() => { this.component = new Reflector(this.previousGridPosition, this.rotation, this.flipped); this.changeComponent(); }); sendBridgeButton.onClick.AddListener(() => { this.component = new GraphOutput(this.previousGridPosition, this.rotation, this.flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.SEND)); this.changeComponent(); }); receiveBridgeButton.onClick.AddListener(() => { this.component = new GraphInput(this.previousGridPosition, this.rotation, this.flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.RECEIVE)); this.changeComponent(); }); deleteButton.onClick.AddListener(() => { this.currentState = EditorState.DeleteComponent; this.destroyMouseChildren(); GameObject xSprite = this.makeX().gameObject; xSprite.transform.SetParent(this.mouseObject.transform); xSprite.transform.localPosition = new Vector2(.5f, .5f); }); //selects the first button andButton.onClick.Invoke(); andButton.Select(); #endregion #region KeyboardInputs //rotations this.inputs.addInput(new KeyCombination(KeyCode.Q, KeyStatus.Down), () => { this.rotation = (rotation + 1) % 4; this.changeComponent(); }); this.inputs.addInput(new KeyCombination(KeyCode.E, KeyStatus.Down), () => { this.rotation = this.rotation - 1; if (this.rotation < 0) { rotation = 3; } this.changeComponent(); }); //flip this.inputs.addInput(new KeyCombination(KeyCode.F, KeyStatus.Down), () => { this.flipped = !flipped; this.changeComponent(); }); //mouse rest this.inputs.addInput(new KeyCombination(KeyCode.Mouse0, KeyStatus.Rest), () => { if (this.logicGraphController.BottomLeftWorld != this.previousGridPosition) { Vector2Int currentMousePos = this.getMouseLocalGridPosition(); if (!this.previousGridPosition.Equals(currentMousePos)) { this.previousGridPosition = currentMousePos; if (this.currentState == EditorState.AddCompoent) { this.component.Position = this.previousGridPosition; bool canPlace = this.logicGraphController.Graph.LightGraph.canPlace(this.component); this.mouseObject.transform.Find("X").gameObject.SetActive(!canPlace); Vector2 worldMousePosition = this.getMouseWorldGridPosition(); this.mouseObject.transform.position = worldMousePosition; } else if (this.currentState == EditorState.DeleteComponent) { Vector2 worldMousePosition = this.getMouseWorldGridPosition(); this.mouseObject.transform.position = worldMousePosition; GraphComponent graphComp = this.logicGraphController.Graph.LightGraph.getComponentAt( this.previousGridPosition.x, this.previousGridPosition.y); SpriteRenderer rend = this.mouseObject.transform.GetChild(0).GetComponent <SpriteRenderer>(); if (graphComp != null) { rend.color = Color.red; } else { rend.color = Color.gray; } } } } }); //mouse down this.inputs.addInput(new KeyCombination(KeyCode.Mouse0, KeyStatus.Down), () => { if (this.currentState == EditorState.AddCompoent) { //adds the component LightComponent comp = this.duplicateAt(this.component.GetType(), this.previousGridPosition, this.rotation, this.flipped); if (this.logicGraphController.Graph.LightGraph.canPlace(comp) && this.inputs.CurrentFrameData.RaycastResults.Count != 0 && this.inputs.CurrentFrameData.RaycastResults[0].gameObject.Equals(this.rawImage.gameObject)) { if (comp.GetType().IsSubclassOf(typeof(LinkComponent))) { EnterTextContent etc = new EnterTextContent( "Type in a unique name for the Bridge." + " The name can not be the same as another bridge on this Graph", (string inputFieldText) => { //confrim ((LinkComponent)comp).getExtensionConnection().Name = inputFieldText; addComponentToGraph(comp); }, () => {}, 15); //names exits etc.addErrorCheck((string value) => { bool result = true; int counter = 0; ExtensionNode[] checkBridges = this.logicGraphController.Graph.AllBridges(); while (result && counter < checkBridges.Length) { if (value.Equals(checkBridges[counter].Name)) { result = false; } counter++; } return(result); }, "Name Already Exits"); //can place component after entering value etc.addErrorCheck((string value) => { return(this.logicGraphController.Graph.LightGraph.canPlace(comp)); }, "Can not Place there"); this.spawnChildWindow(new Window(comp.GetType() + " Name", 200, 200, etc)); } else { this.addComponentToGraph(comp); } } } else if (currentState == EditorState.DeleteComponent) { //removes the component Vector2Int gridPosition = this.getMouseLocalGridPosition(); LightComponent hitComponent = this.graph.LightGraph.getComponentAt(gridPosition.x, gridPosition.y); if (hitComponent != null) { bool removedGOState = this.logicGraphController.ComponentManager.removeComponent(hitComponent); bool removeDataState = this.graph.LightGraph.removeComponent(hitComponent); if (removedGOState && removeDataState) { this.logicGraphController.ComponentManager.reconnectRays(); } else { throw new System.Exception("ComponentNotFound: GameObjectRemoval:" + removedGOState + " DataRemoval" + removeDataState); } } } }); #endregion }
public bool removeGraphController(LogicGraphController controller) { return(this.graphControllers.Remove(controller)); }