public void OpenEditor(GameObject editable) { //break out? gameInfo = GameObject.FindObjectOfType <GameInfo>(); if (gameInfo.currentlyMouseAiming) { Close(); return; } if (!metaInventory) { metaInventory = GameObject.FindObjectOfType <MetaInventory>(); } //activate cursor Cursor.visible = true; //get editable obj = editable.transform.parent.gameObject; if (editable.GetComponent <EditRotation>()) { //activate mouseaim if... mouseAimButton.SetActive(true); eRot = editable.GetComponent <EditRotation>(); elements[4].SetActive(true); } else { mouseAimButton.SetActive(false); eRot = null; //so that you never end up doing it for something else } //make the title of the ui the obj name string objName = obj.name; //if it has a (, remove everything after that ( if (objName.Contains("(")) { int loc = objName.IndexOf("("); //substring does the trick objName = objName.Substring(0, loc); name.text = objName; } else { name.text = objName; } if (obj.GetComponent <Miner>()) { //set type typeSelected = 1; //set up layout for miner obj miner = obj.GetComponent <Miner>(); s1.gameObject.SetActive(true); s1.maxValue = 1000; s1.value = miner.launchForce; s1T.text = "Launch Force: " + s1.value.ToString(); } if (obj.GetComponent <LauncherController>()) { //set type typeSelected = 2; //set up layout for launcher obj launcher = obj.GetComponent <LauncherController>(); s1.gameObject.SetActive(true); s1.maxValue = 1000; s1.value = launcher.launchForce; s1T.text = "Launch Force: " + s1.value.ToString(); //set up second slider for interval s2.gameObject.SetActive(true); s2.maxValue = 2; s2.minValue = 0.25f; s2.value = launcher.coolDown; s2T.text = "Fire Interval: " + s2.value.ToString(); } if (obj.GetComponent <OreController>()) { typeSelected = 3; ore = obj.GetComponent <OreController>(); MidInfoT.gameObject.SetActive(true); if (ore.eternal) { MidInfoT.text = "Quantity: Eternal" + " Hardness: " + ore.hardness; } else { MidInfoT.text = "Quantity: " + ore.currentQuantity.ToString() + System.Environment.NewLine + "Hardness: " + ore.hardness; } MidInfoT.color = ore.GetComponent <SpriteRenderer>().color; bottomButton.gameObject.SetActive(true); if (ore.eternal) { print("ore is eternal"); bottomButton.interactable = true; bottomButtonText.text = "Destroy Ore"; } else if (metaInventory.eternalizers > 0) { bottomButton.interactable = true; bottomButtonText.text = "Mount MOED"; } else { bottomButton.interactable = false; bottomButtonText.text = "No MOED's"; } } if (obj.GetComponent <Crafting>()) { //set up crafter ui typeSelected = 4; crafterPanel.SetActive(true); craft = obj.GetComponent <Crafting>(); MidInfoT.gameObject.SetActive(true); UIButtonArray car = crafterPanel.GetComponent <UIButtonArray>(); foreach (Button b in car.buttons) { ///THIS ///MEANS ///THAT ///ALL ///BUTTONS ///MUST BE NAMED ///P R O P E R L Y !!! //print(b.name + " : " + craft.recipe.name); if (b.name == craft.recipe.name) { car.BClick(b); } } } if (obj.GetComponent <UnPackager>()) { typeSelected = 5; } if (obj.GetComponent <Packager>()) { Packager pack = obj.GetComponent <Packager>(); typeSelected = 6; s1.gameObject.SetActive(true); s1.maxValue = 100; s1.minValue = 10; s1.value = pack.maxItems; s1T.text = "Maximum Items: " + Mathf.RoundToInt(s1.value).ToString(); } else if (obj.GetComponent <Splitter>()) { split = obj.GetComponent <Splitter>(); typeSelected = 7; MidInfoT.gameObject.SetActive(true); MidInfoT.text = "Set a filter ->"; MidInfoT.color = new Color(0, 255, 255, 255); filterPanel.gameObject.SetActive(true); //setup filter panel UIButtonArray ar = filterPanel.GetComponent <UIButtonArray>(); foreach (Button b in ar.buttons) { ///THIS ///MEANS ///THAT ///ALL ///BUTTONS ///MUST BE NAMED ///P R O P E R L Y !!! if (b.name == split.typeName) { ar.BClick(b); } else { if (b.name == "Empty filter" && split.typeName == "") { ar.BClick(b); } } } } else if (obj.GetComponent <Pump>()) { pump = obj.GetComponent <Pump>(); MidInfoT.gameObject.SetActive(true); typeSelected = 8; } else if (obj.GetComponent <Core>()) { typeSelected = 9; core = obj.GetComponent <Core>(); int lv = core.level; MidInfoT.gameObject.SetActive(true); MidInfoT.text = "Level " + lv.ToString(); } else if (obj.GetComponent <RocketBase>()) { typeSelected = 10; rocket = obj.GetComponent <RocketBase>(); MidInfoT.gameObject.SetActive(true); rocketPanel.SetActive(true); rIronSlider.slider.maxValue = rocket.maxIron; rCopSlider.slider.maxValue = rocket.maxCopper; rFuelSlider.slider.maxValue = rocket.maxFuel; MidInfoT.text = "Needs rocket fuel"; //set max rIronSlider.SetSliderParameters(rocket.maxIron); rCopSlider.SetSliderParameters(rocket.maxCopper); rFuelSlider.SetSliderParameters(rocket.maxFuel); } }
void Update() { //help //input if (Input.anyKeyDown) { if (Input.GetKeyDown(KeyCode.Alpha1)) { SetIndex(4); } else if (Input.GetKeyDown(KeyCode.Alpha2)) { SetIndex(2); } else if (Input.GetKeyDown(KeyCode.Alpha3)) { SetIndex(3); } if (core.level > 0) { if (Input.GetKeyDown(KeyCode.Alpha4)) { SetIndex(0); } else if (Input.GetKeyDown(KeyCode.Alpha5)) { SetIndex(6); } else if (Input.GetKeyDown(KeyCode.Alpha6)) { SetIndex(7); } } if (core.level > 1) { //third tier items if (Input.GetKeyDown(KeyCode.Alpha7)) { SetIndex(9); } else if (Input.GetKeyDown(KeyCode.Alpha8)) { SetIndex(8); } else if (Input.GetKeyDown(KeyCode.Alpha9)) { SetIndex(10); } else if (Input.GetKeyDown(KeyCode.Alpha0)) { SetIndex(11); } } if (Input.GetKeyDown(KeyCode.X) || Input.GetKeyDown(KeyCode.Alpha0)) { SetIndex(5); } else if (Input.GetKeyDown(KeyCode.Escape)) { //open pause men if hupcont isnt open if (!UIOpened) { if (escMenuOpen) { escMenu.SetActive(false); Cursor.visible = false; escMenu.GetComponent <PauseMenu>().FreezeTime(false); escMenuOpen = false; settingsMenu.SetActive(false); } else { escMenu.SetActive(true); escMenu.GetComponent <PauseMenu>().FreezeTime(true); escMenuOpen = true; } } } else if (Input.GetKeyDown(KeyCode.F)) { //activate mouse aim if (eRot) { eRot.StartMouseAim(); } } } overUI = EventSystem.current.IsPointerOverGameObject(); //place the placable when able to if (((Input.GetKeyDown(KeyCode.Space) && canPlace) || (Input.GetMouseButtonDown(0) && canPlace)) && !overUI) { if (placeables[placeableIndex].GetComponent <Placeable>()) { Place(placeables[placeableIndex].GetComponent <Placeable>().RealObject); } editCoolDown = 4; } //lower cooldown so that editing is eventually re-enabled if (editCoolDown > -1) { editCoolDown -= 1; } //check if an object is placable or not using an overlap circle if (!(placeableIndex == 2) && !(placeableIndex == 10)) { //if u dont have the miner selected do this if (placeableIndex != 11) { canPlace = !Physics2D.OverlapCircle(transform.position, overlapRadius, overlapLayerMask); } else { //this means you are placing a core, make canplace radius way larger canPlace = !Physics2D.OverlapCircle(transform.position, overlapRadius * 4, overlapLayerMask); } } else if (placeableIndex == 2) { //if you have a miner, u need an ore. U can no longer stack miners gg ez if (Physics2D.OverlapCircle(transform.position, 1, oreMask)) { //also if u arent over a hardcollider if (!Physics2D.OverlapCircle(transform.position, 0.5f, groundLayerMask)) { canPlace = Physics2D.OverlapCircle(transform.position, 1, oreMask).GetComponent <OreController>(); } else { canPlace = false; } } else { canPlace = false; } } else if (placeableIndex == 10) //Special circumstances apply for the pump just like the miner { //With pump one must have water if (Physics2D.OverlapCircle(transform.position, 0.25f, holeMask)) { //also if u arent over a hardcollider if (!Physics2D.OverlapCircle(transform.position, 0.5f, groundLayerMask)) { canPlace = true; //hopefully } else { canPlace = false; } } else { canPlace = false; } } if (Physics2D.OverlapCircle(transform.position, 0.5f, editingLayerMask)) { Collider2D[] overlappedEditors = Physics2D.OverlapCircleAll(transform.position, 0.5f, editingLayerMask); float closestDistanceSqr = Mathf.Infinity; Transform closestTrans = null; foreach (Collider2D editor in overlappedEditors) { Transform edit = editor.transform; Vector3 direction = edit.position - transform.position; float dSqrToTarget = direction.sqrMagnitude; if (dSqrToTarget < closestDistanceSqr) { closestDistanceSqr = dSqrToTarget; closestTrans = edit; } } //now you have the closest one editingObject = closestTrans.gameObject; if (editingObject.GetComponent <EditRotation>()) { eRot = editingObject.GetComponent <EditRotation>(); } //now, hupcont logic ///we already know we are over a valid col, so ///but only open the hupcont if the editing index is active, ie if index is 1 ///in fact, dont even rotate if index isnt one if ((Input.GetMouseButtonDown(0) && editCoolDown < 0 || Input.GetKeyDown(KeyCode.Space) && editCoolDown < 0) && !overUI && placeableIndex == 1) { UIOpened = true; HUP.SetActive(true); if (editingObject.GetComponent <EditorValues>().hasPanel) { HUP.GetComponent <HUPCONT>().OpenEditor(editingObject); } } } else { //not over any colliders, cant be an erot eRot = null; } //now rotate the rotatable (only if Lshift isnt held because that is for moving the camera) ///also only if index is one because thats the editing index if (eRot && !Input.GetKey(KeyCode.LeftShift) && placeableIndex == 1) { eRot.rotateable.Rotate(new Vector3(0, 0, Input.mouseScrollDelta.y * rotSpeed)); if (Input.GetKey(KeyCode.Q)) { eRot.rotateable.Rotate(new Vector3(0, 0, 0.1f * rotSpeed)); } else if (Input.GetKey(KeyCode.E)) { eRot.rotateable.Rotate(new Vector3(0, 0, -0.1f * rotSpeed)); } //eRot.rotateable.Rotate(new Vector3(0, 0, Input.GetAxis("Horizontal") * -rotSpeed)); } //make the ""cursor"" follow the "cursor" if that makes any sense whatsoever if (!UIOpened && !freezeMovement) { Vector2 mPos = cam.ScreenToWorldPoint(Input.mousePosition); transform.position = mPos; //if not in edit mode and right click, select empty cursor if (!canEdit && Input.GetMouseButtonDown(1)) { SetIndex(1); } } //make the placable follow the cursor placeables[placeableIndex].transform.position = gameObject.transform.position; //rotate cursor with mouse or h axis if (!canEdit && !Input.GetKey(KeyCode.LeftShift)) { transform.Rotate(new Vector3(0, 0, Input.mouseScrollDelta.y * rotSpeed)); if (Input.GetKey(KeyCode.Q)) { transform.Rotate(new Vector3(0, 0, 0.1f * rotSpeed)); } else if (Input.GetKey(KeyCode.E)) { transform.Rotate(new Vector3(0, 0, -0.1f * rotSpeed)); } //transform.Rotate(new Vector3(0, 0, Input.GetAxis("Horizontal") * -rotSpeed)); } //if you are in editing mode however, instead find the rotatable launcher bit and rotate that too //if you are editing and over an object and rightclick, destroy it. if ((canEdit && Input.GetMouseButtonDown(1)) || (canEdit && Input.GetKeyDown(KeyCode.Backspace))) { //note requires the mouse collider to be a direct child of the parent. Keep that in mind when creating prefabs. //it also requires that the hard collider of the object be the only obj tagged ground. keep that in mind as well //make sure it is actually destructible. ALL EDITORS NEED AN EDITORVALUES SCRIPT EditorValues eVals = Physics2D.OverlapCircle(transform.position, 0.5f, editingLayerMask).GetComponent <EditorValues>(); if (eVals.canBeDestroyed) { Destroy(Physics2D.OverlapCircle(transform.position, 0.5f, editingLayerMask).transform.parent.transform.gameObject); } //destroy parent } //if the same is true and you left click, select it //if you hover over the ui element, set cursor to visible bool onUI = EventSystem.current.IsPointerOverGameObject(); if (onUI || freezeMovement) { Cursor.visible = true; } else if (!UIOpened) { Cursor.visible = false; } }