void PollControls() { if (Input.GetMouseButtonUp(0)) { if (changingSpawnPoint) { changingSpawnPoint = false; } else if (spawnPoint.GetComponent <SpriteRenderer>().bounds.Contains(GetMousePos())) { changingSpawnPoint = true; } } if (changingSpawnPoint) { spawnPoint.position = CalcSpawnPos(); } if (Input.GetKeyUp(KeyCode.T)) { if (taskInterface.GetActive()) { taskInterface.GetComponentInChildren <NodeEditorFramework.Standard.RTNodeEditor>().AutoSave(); } taskInterface.ToggleActive(); } if (Input.GetKeyDown(KeyCode.C) && !system.IsPointerOverGameObject()) { ActivateCharacterHandler(); } }
public void OnPointerClick(PointerEventData eventData) { if (window) { window.ToggleActive(); field.text = (builder as IBuilderInterface).GetCurrentJSON(); } }
public void PromptMigrate(int index) { switch (saves[index].version) { case "Alpha 2.1.0": indexToMigrate = index; migratePrompt.transform.Find("Background").GetComponentInChildren <Text>().text = "This will reset your task progress, reputation and place you in the " + "Spawning Grounds. Backup first! (Below save icon delete button)"; migratePrompt.ToggleActive(); break; default: indexToMigrate = index; migratePrompt.transform.Find("Background").GetComponentInChildren <Text>().text = "This will simply add Sukrat to your party list. Regardless, backup first! (Below save icon delete button)"; migratePrompt.ToggleActive(); break; } }
public void OnPointerClick(PointerEventData eventData) { #if UNITY_EDITOR Debug.Log(builder.GetCurrentJSON()); #endif if (window) { window.ToggleActive(); field.text = builder.GetCurrentJSON(); } }
public void PromptDelete(int index) { indexToDelete = index; deletePrompt.ToggleActive(); }
public void FromJSON() { string path = GameObject.Find("JSONPath").GetComponentInChildren <InputField>().text; if (System.IO.File.Exists(path)) { SectorData data = JsonUtility.FromJson <SectorData>(System.IO.File.ReadAllText(path)); Sector sectorDataWrapper = ScriptableObject.CreateInstance <Sector>(); JsonUtility.FromJsonOverwrite(data.sectorjson, sectorDataWrapper); LandPlatform platformDataWrapper = ScriptableObject.CreateInstance <LandPlatform>(); JsonUtility.FromJsonOverwrite(data.platformjson, platformDataWrapper); type = sectorDataWrapper.type; currentColor = sectorDataWrapper.backgroundColor; sctName = sectorDataWrapper.sectorName; UpdateColors(); int cols = platformDataWrapper.columns; int rows = platformDataWrapper.rows; x = sectorDataWrapper.bounds.x; y = sectorDataWrapper.bounds.y; width = sectorDataWrapper.bounds.w; height = sectorDataWrapper.bounds.h; sectorProps.ToggleActive(); sectorProps.transform.Find("Beginning X").GetComponentInChildren <InputField>().text = x.ToString(); sectorProps.transform.Find("Beginning Y").GetComponentInChildren <InputField>().text = y.ToString(); sectorProps.transform.Find("Height").GetComponentInChildren <InputField>().text = height.ToString(); sectorProps.transform.Find("Width").GetComponentInChildren <InputField>().text = width.ToString(); sectorProps.transform.Find("Sector Name").GetComponentInChildren <InputField>().text = sctName; sectorProps.transform.Find("Sector Type").GetComponent <Dropdown>().value = (int)sectorDataWrapper.type; sectorProps.ToggleActive(); var rend = GameObject.Find("SectorBorders").GetComponent <LineRenderer>(); rend.SetPositions(new Vector3[] { new Vector3(x, y, 0), new Vector3(x + width, y, 0), new Vector3(x + width, y + height, 0), new Vector3(x, y + height, 0) }); center = new Vector3 { x = this.x + width / 2F, y = this.y + height / 2F }; Vector2 offset = new Vector2 { x = center.x - tileSize * (cols - 1) / 2, y = center.y + tileSize * (rows - 1) / 2 }; for (int i = 0; i < platformDataWrapper.tilemap.Length; i++) { switch (platformDataWrapper.tilemap[i]) { case -1: break; default: PlaceableObject obj = new PlaceableObject(); obj.type = ObjectTypes.Platform; obj.placeablesIndex = platformDataWrapper.tilemap[i]; obj.rotation = platformDataWrapper.rotations[i]; Vector3 pos = new Vector3 { x = offset.x + (i % cols) * tileSize, y = offset.y - (i / cols) * tileSize, z = 0 }; obj.pos = pos; obj.obj = Instantiate(placeables[platformDataWrapper.tilemap[i]].obj, pos, Quaternion.identity); obj.obj.transform.localEulerAngles = new Vector3(0, 0, 90 * platformDataWrapper.rotations[i]); objects.Add(obj); break; } } foreach (Sector.LevelEntity ent in sectorDataWrapper.entities) { PlaceableObject obj = new PlaceableObject(); obj.pos = ent.position; obj.faction = ent.faction; obj.shellcoreJSON = ent.blueprintJSON; obj.ID = ent.ID; obj.assetID = ent.assetID; obj.type = ObjectTypes.Other; obj.vendingID = ent.vendingID; for (int i = 0; i < placeables.Length; i++) { if (placeables[i].assetID == obj.assetID) { obj.placeablesIndex = i; break; } } obj.obj = Instantiate(placeables[obj.placeablesIndex].obj, obj.pos, Quaternion.identity); obj.obj.name = ent.name; if (GetIsFactable(obj)) { foreach (SpriteRenderer renderer in obj.obj.GetComponentsInChildren <SpriteRenderer>()) { renderer.color = FactionManager.GetFactionColor(obj.faction); } if (obj.obj.GetComponentsInChildren <SpriteRenderer>().Length > 1) { obj.obj.GetComponent <SpriteRenderer>().color = Color.white; } } objects.Add(obj); } } else { Debug.Log($"File {path} doesn't exist."); } }
public void ToJSON() { if (string.IsNullOrEmpty(sctName)) { Debug.Log("Name your damn sector!"); return; } Sector sct = ScriptableObject.CreateInstance <Sector>(); sct.sectorName = sctName; sct.type = type; sct.backgroundColor = currentColor; LandPlatform platform = ScriptableObject.CreateInstance <LandPlatform>(); Vector3 firstTilePos = new Vector3 { x = center.x, y = center.y }; Vector3 lastTilePos = new Vector3 { x = center.x, y = center.y }; foreach (PlaceableObject ojs in objects) { if (ojs.type == ObjectTypes.Platform) { Vector3 tilePos = ojs.obj.transform.position; if (tilePos.x < firstTilePos.x) { firstTilePos.x = tilePos.x; } if (tilePos.y > firstTilePos.y) { firstTilePos.y = tilePos.y; } if (tilePos.x > lastTilePos.x) { lastTilePos.x = tilePos.x; } if (tilePos.y < lastTilePos.y) { lastTilePos.y = tilePos.y; } } } int columns = Mathf.CeilToInt(Mathf.Max(Mathf.Abs(firstTilePos.x - center.x) + 1, Mathf.Abs(lastTilePos.x - center.x) + 1) / tileSize) * 2; int rows = Mathf.CeilToInt(Mathf.Max(Mathf.Abs(firstTilePos.y - center.y) + 1, Mathf.Abs(lastTilePos.y - center.y) + 1) / tileSize) * 2; if (Mathf.RoundToInt(center.x - cursorOffset.x) % Mathf.RoundToInt(tileSize) == 0) { columns++; } if (Mathf.RoundToInt(center.y - cursorOffset.y) % Mathf.RoundToInt(tileSize) == 0) { rows++; } Vector2 offset = new Vector2 { x = center.x + -(columns - 1) * tileSize / 2, y = center.y + (rows - 1) * tileSize / 2 }; platform.rows = rows; platform.columns = columns; platform.tilemap = new int[rows * columns]; platform.rotations = new int[rows * columns]; platform.prefabs = new string[] { "4 Entry", "3 Entry", "2 Entry", "1 Entry", "0 Entry", "Junction" }; for (int i = 0; i < platform.tilemap.Length; i++) { platform.tilemap[i] = -1; } IntRect rect = new IntRect(); List <string> targetIDS = new List <string>(); List <Sector.LevelEntity> ents = new List <Sector.LevelEntity>(); rect.x = x; rect.y = y; rect.w = width; rect.h = height; sct.bounds = rect; int ID = 0; foreach (PlaceableObject oj in objects) { if (oj.type != ObjectTypes.Platform) { Sector.LevelEntity ent = new Sector.LevelEntity(); ent.ID = (ID++).ToString(); ent.faction = oj.faction; ent.position = oj.obj.transform.position; ent.assetID = oj.assetID; ent.vendingID = oj.vendingID; if (oj.isTarget) { targetIDS.Add(ent.ID); } ent.name = oj.obj.name; if (ent.assetID == "shellcore_blueprint") { targetIDS.Add(ent.ID); ent.blueprintJSON = oj.shellcoreJSON; } ents.Add(ent); } else if (oj.type == ObjectTypes.Platform) { int[] coordinates = new int[2]; coordinates[1] = Mathf.RoundToInt((oj.obj.transform.position.x - offset.x) / tileSize); coordinates[0] = -Mathf.RoundToInt((oj.obj.transform.position.y - offset.y) / tileSize); platform.tilemap[coordinates[1] + platform.columns * coordinates[0]] = oj.placeablesIndex; platform.rotations[coordinates[1] + platform.columns * coordinates[0]] = oj.rotation; } } sct.entities = ents.ToArray(); sct.targets = targetIDS.ToArray(); sct.backgroundColor = currentColor; SectorData data = new SectorData(); data.sectorjson = JsonUtility.ToJson(sct); data.platformjson = JsonUtility.ToJson(platform); string output = JsonUtility.ToJson(data); var sectorsDir = System.IO.Path.Combine(Application.streamingAssetsPath, "Sectors"); if (!System.IO.Directory.Exists(sectorsDir)) { System.IO.Directory.CreateDirectory(sectorsDir); } string path = System.IO.Path.Combine(sectorsDir, sct.sectorName); System.IO.File.WriteAllText(path, output); System.IO.Path.ChangeExtension(path, ".json"); mainMenu.ToggleActive(); successBox.ToggleActive(); Debug.Log("JSON written to location: " + path); }
void FixedUpdate() { CalculateWindowEnabled(); Vector3 mousePos = Input.mousePosition; mousePos.z -= Camera.main.transform.position.z; mousePos = Camera.main.ScreenToWorldPoint(mousePos); if (cursor.type == ObjectTypes.Platform) { mousePos.x = cursorOffset.x + tileSize * (int)((mousePos.x - cursorOffset.x) / tileSize + (mousePos.x / 2 > 0 ? 0.5F : -0.5F)); mousePos.y = cursorOffset.y + tileSize * (int)((mousePos.y - cursorOffset.y) / tileSize + (mousePos.y / 2 > 0 ? 0.5F : -0.5F)); } else { mousePos.x = 0.5F * tileSize * Mathf.RoundToInt((mousePos.x) / (0.5F * tileSize)); mousePos.y = 0.5F * tileSize * Mathf.RoundToInt((mousePos.y) / (0.5F * tileSize)); } if (Input.GetKeyDown("g") && !windowEnabled) { mainMenu.ToggleActive(); if (mainMenu.gameObject.activeSelf) { coreEditor.gameObject.SetActive(false); } } else { /*if(Input.GetKeyDown("g") && sectorProps.gameObject.activeSelf && !sectorProps.transform.Find("Sector Name").GetComponent<InputField>().isFocused) { * sectorProps.ToggleActive(); * } * if(Input.GetKeyDown("g") && hotkeyList.gameObject.activeSelf) { * hotkeyList.ToggleActive(); * } * if(Input.GetKeyDown("g") && readFile.gameObject.activeSelf && !readFile.transform.Find("JSONPath").GetComponent<InputField>().isFocused) { * readFile.ToggleActive(); * }*/ } if (Input.GetKeyDown("t") && (!windowEnabled || nodeEditor.transform.parent.gameObject.activeSelf)) { nodeEditor.ToggleActive(); } if (!windowEnabled) { if (Input.GetKeyDown("space")) { Command com = new Command(); com.position = Camera.main.transform.position; com.type = CommandTypes.Center; undoStack.Push(com); redoStack.Clear(); Vector3 pos = center; pos.z = Camera.main.transform.position.z; Camera.main.transform.position = pos; } if (Input.GetKeyDown("k")) { GetPlatformIndex(mousePos); } #if UNITY_EDITOR if (Input.GetKeyDown("z")) { Undo(); } if (Input.GetKeyDown("y")) { Redo(); } #else if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown("z")) { Undo(); } if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown("y")) { Redo(); } #endif if (Input.GetKeyDown("q") || (Input.GetAxis("Mouse ScrollWheel") < 0 && !Input.GetKey(KeyCode.LeftControl))) { Destroy(cursor.obj); if (--cursorCount < 0) { cursorCount = placeables.Length - 1; } cursor = placeables[cursorCount % placeables.Length]; cursor.obj = Instantiate(placeables[cursorCount % placeables.Length].obj, cursor.obj.transform.position, Quaternion.identity); } if (Input.GetKeyDown("c")) { Command com = new Command(); List <PlaceableObject> oldList = new List <PlaceableObject>(); foreach (PlaceableObject placeable in objects) { oldList.Add(placeable); Destroy(placeable.obj); } com.type = CommandTypes.Clear; com.clearedList = oldList; undoStack.Push(com); redoStack.Clear(); objects.Clear(); } if (Input.GetKeyDown("e") || (Input.GetAxis("Mouse ScrollWheel") > 0 && !Input.GetKey(KeyCode.LeftControl))) { Destroy(cursor.obj); cursor = placeables[++cursorCount % placeables.Length]; cursor.obj = Instantiate(placeables[cursorCount % placeables.Length].obj, cursor.obj.transform.position, Quaternion.identity); } if (Input.GetKeyDown("r") || Input.GetMouseButtonDown(1)) { DeleteObject(); } if (Input.GetMouseButtonDown(0) || Input.GetKeyDown("f")) { Command com = new Command(); bool found = false; foreach (PlaceableObject obj in objects) { if (obj.pos == cursor.obj.transform.position && cursor.type == obj.type) { if (GetIsFactable(cursor)) { com.type = CommandTypes.ChangeFaction; com.position = cursor.obj.transform.position; var newObj = obj; if (obj.type == ObjectTypes.Other) { mainMenu.CloseUI(); coreEditor.Initialize(newObj, this); } else { newObj.faction = (obj.faction + 1) % numberOfFactions; com.obj = newObj; undoStack.Push(com); } objects.Remove(obj); objects.Add(newObj); UpdateColors(); } else if (obj.type == ObjectTypes.Platform) { objects.Remove(obj); PlaceableObject newObj = obj; newObj.rotation = (newObj.rotation + 1) % 4; Vector3 rot = newObj.obj.transform.localEulerAngles; rot.z = 90 * newObj.rotation; newObj.obj.transform.localEulerAngles = rot; objects.Add(newObj); } else if (obj.assetID == "flag") { coreEditor.Initialize(obj, this); } else { com.type = CommandTypes.Remove; com.position = cursor.obj.transform.position; com.obj = obj; undoStack.Push(com); objects.Remove(obj); Destroy(obj.obj); } redoStack.Clear(); found = true; break; } } if (!found) { com.type = CommandTypes.Place; PlaceableObject newo = cursor; newo.pos = cursor.obj.transform.position; com.position = newo.pos; newo.obj = Instantiate(cursor.obj, newo.pos, Quaternion.identity); com.obj = newo; undoStack.Push(com); redoStack.Clear(); objects.Add(newo); } } cursor.obj.transform.position = new Vector3(mousePos.x, mousePos.y, 0); } }
void Update() { current.pos = CalcPos(current.type); if (current.obj) { current.obj.transform.position = current.pos; } UpdateEntityAppearances(); VisualizeMouseInSector(); if (Input.GetKeyDown(KeyCode.Z) && (int)mode < 3) { ShiftMode(1); } if (Input.GetKeyDown(KeyCode.M) && !system.IsPointerOverGameObject()) { manual.ToggleActive(); } switch (mode) { case WCCursorMode.Item: RemovePendingSector(); current.obj.SetActive(true); modeText.text = "Item Mode"; PollItems(); break; case WCCursorMode.Sector: current.obj.SetActive(false); modeText.text = "Sector Mode"; if (!system.IsPointerOverGameObject()) { PollSectors(); } break; case WCCursorMode.Control: RemovePendingSector(); current.obj.SetActive(false); modeText.text = "Control Mode"; if (!system.IsPointerOverGameObject()) { PollControls(); } break; case WCCursorMode.SelectEntity: modeText.text = "Select Entity Mode"; // change only when mode changes? current.obj.SetActive(false); // same PollEntitySelection(); break; case WCCursorMode.DrawPath: modeText.text = "Draw Path Mode"; current.obj.SetActive(false); pathCreator.PollPathDrawing(); break; default: break; } modeText.color = Camera.main.backgroundColor = modeColors[(int)mode]; modeText.color += Color.gray; modeText.text = modeText.text.ToUpper(); }