private void loadLevel() { if (currentLevel >= levels.Length) { // Winner! NextLevelController nextLevelController = GameObject.FindObjectOfType <NextLevelController>(); nextLevelController.loadScene(); return; } clear(); LevelPanelManager.instance.loadLevel(levels[currentLevel]); if (inputLoader == null) { inputLoader = GameObject.Instantiate(inputPref, inputPos.position, Quaternion.identity).GetComponent <LevelInputLoader>(); } if (outputLoader == null) { outputLoader = GameObject.Instantiate(outputPref, outputPos.position, Quaternion.identity).GetComponent <LevelOutputLoader>(); } inputLoader.gate = levels[currentLevel].input; inputLoader.load(); inputGate = inputLoader.gameObject.GetComponent <GateInstance>(); outputLoader.gate = levels[currentLevel].output; outputLoader.load(); outputGate = outputLoader.gameObject.GetComponent <GateInstance>(); stepFails = new List <int>(); step = 0; }
public ServiceHandler(GateInstance gate, RelayClient relayClient, BinTables tables, IDbContextFactory <ItemContext> itemFactory, IDbContextFactory <AccountContext> accountFactory, IDbContextFactory <CharacterContext> characterFactory) { _gate = gate; _relayClient = relayClient; _tables = tables; _itemFactory = itemFactory; _accountFactory = accountFactory; _characterFactory = characterFactory; }
/// <summary> /// Update is called every frame, if the MonoBehaviour is enabled. /// </summary> void Update() { if (playing) { if (Time.time - lastTickTime >= TICK_TIME) { LevelLoader.tick(); lastTickTime = Time.time; } if (selected != null) { selected = null; } } if (selected != null) { if (selected.GetType().IsSubclassOf(typeof(Port))) { if (wireInstance == null) { wireInstance = GameObject.Instantiate(wirePrefab, Vector3.zero, Quaternion.identity); wireInstance.SetPosition(0, ((Port)selected).transform.position); } Plane p = new Plane(Vector3.back, Vector3.up); Ray ray = Camera.main.ScreenPointToRay(mousePos); float enter; if (p.Raycast(ray, out enter)) { wireInstance.SetPosition(1, ray.GetPoint(enter)); } } else if (selected.GetType().IsAssignableFrom(typeof(GateInstance))) { GateInstance selectedGate = (GateInstance)selected; Plane p = new Plane(Vector3.back, Vector3.up); Ray ray = Camera.main.ScreenPointToRay(mousePos); float enter; if (p.Raycast(ray, out enter)) { selectedGate.transform.position = ray.GetPoint(enter); } selectedGate.updateWires(); } } else { if (wireInstance != null) { Destroy(wireInstance); } } }
private void Start() { Instance = this; }
// Only Ports and Gates should be selected! public void select() { if (playing) { return; } if (Time.time - lastSelectionTime <= ACTION_COOLDOWN) { return; } lastSelectionTime = Time.time; Ray ray = Camera.main.ScreenPointToRay(mousePos); PointerEventData pointerData = new PointerEventData(EventSystem.current); pointerData.position = mousePos; List <RaycastResult> results = new List <RaycastResult>(); EventSystem.current.RaycastAll(pointerData, results); for (int i = 0; i < results.Count; i++) { if (results[i].gameObject == null) { continue; } if (selected != null) { // Handle what happens when port is selected if (selected.GetType().IsSubclassOf(typeof(Port))) { Port hitPort = results[i].gameObject.GetComponent <Port>(); if (hitPort != null) { // Both are ports, make sure they aren't the same type if (!selected.GetType().Equals(hitPort.GetType())) { if (selected.GetType().Equals(typeof(InputPort))) { ((OutputPort)hitPort).addNext((InputPort)selected); audioSource.PlayOneShot(wireConnectSound); deselect(); return; } else { ((OutputPort)selected).addNext((InputPort)hitPort); audioSource.PlayOneShot(wireConnectSound); deselect(); return; } } } } } else // Selected null, select what we clicked on { Port hitPort = results[i].gameObject.GetComponent <Port>(); GateInstance gateInstance = results[i].gameObject.GetComponent <GateInstance>(); GateDrawerLoader gateDrawerItem = results[i].gameObject.GetComponent <GateDrawerLoader>(); if (hitPort != null) { selected = hitPort; audioSource.PlayOneShot(wireConnectSound); return; } else if (gateInstance != null) { selected = gateInstance; audioSource.PlayOneShot(gatePickupSound); return; } else if (gateDrawerItem != null) { GateLoader loader = GameObject.Instantiate(gatePrefab, Vector3.zero, Quaternion.identity).GetComponent <GateLoader>(); loader.gate = gateDrawerItem.gate; loader.load(); selected = loader.Instance; audioSource.PlayOneShot(gatePickupSound); return; } } } RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, 100); if (selected != null) { // Handle what happens when port is selected if (selected.GetType().IsSubclassOf(typeof(Port))) { if (hit.collider != null) { Port hitPort = hit.collider.GetComponent <Port>(); if (hitPort != null) { // Both are ports, make sure they aren't the same type if (!selected.GetType().Equals(hitPort.GetType())) { if (selected.GetType().Equals(typeof(InputPort))) { ((OutputPort)hitPort).addNext((InputPort)selected); audioSource.PlayOneShot(wireConnectSound); deselect(); return; } else { ((OutputPort)selected).addNext((InputPort)hitPort); audioSource.PlayOneShot(wireConnectSound); deselect(); return; } } } } else { removeSelected(); return; } } else if (selected.GetType().IsAssignableFrom(typeof(GateInstance))) { deselect(); audioSource.PlayOneShot(gateDropSound); return; } } else if (hit.collider != null) // Selected null, select what we clicked on { Port hitPort = hit.collider.GetComponent <Port>(); GateInstance gateInstance = hit.collider.GetComponent <GateInstance>(); if (hitPort != null) { selected = hitPort; audioSource.PlayOneShot(wireConnectSound); return; } else if (gateInstance != null) { selected = gateInstance; audioSource.PlayOneShot(gatePickupSound); return; } } if (selected != null) { removeSelected(); } }