public void OnClicked() { ColorChange(); Color color = gameObject.GetComponent <UnityEngine.UI.Image>().color; PixelGridManager.Instance().SelectColor(colorNumber); }
public void MouseEnter() { if (Input.GetMouseButton(0)) { PixelGridManager.Instance().ButtonClicked(this); } }
public void LoadByPathOrName(string pathOrName) { if (SpriteManager.Instance().SpriteNameIsGood(pathOrName)) { string vesselDir = System.IO.Path.Combine(UnityEngine.Application.persistentDataPath, "Vessels"); string buildStringPath = GameStringsHelper.VesselNameToPath(pathOrName); string spriteName = pathOrName; bool buildStringExists = System.IO.File.Exists(buildStringPath); if (buildStringExists) { string buildString = System.IO.File.ReadAllText(buildStringPath); spriteName = buildString.Split(' ')[1]; } Sprite sprite = SpriteManager.Instance().SpriteFromName(spriteName); PixelGridManager.Instance().LoadTexture(sprite.texture); if (buildStringExists) { string buildString = System.IO.File.ReadAllText(buildStringPath); LoadVesselParts(buildString); } } else { byte[] data = System.IO.File.ReadAllBytes(pathOrName); Texture2D texture = new Texture2D(SpriteManager.SPRITE_SIZE, SpriteManager.SPRITE_SIZE); texture.LoadImage(data); PixelGridManager.Instance().LoadTexture(texture); } }
public void LoadVesselParts(string buildString) { List <VesselPart> parts = GameStringsHelper.PartsListFromBuildString(buildString); foreach (VesselPart part in parts) { PixelGridButton button = PixelGridManager.Instance().ButtonFromRelativePosition(part.position); PartPlacementManager.Instance().PlacePart(button, part); } }
public void Save() { string name = input.text; PixelGridManager.Instance().SaveTexture(name); string buildstring = "build "; buildstring += name + " "; buildstring += sizeSlider.value.ToString() + " "; buildstring += qualitySlider.value.ToString() + " "; foreach (VesselPart part in PartPlacementManager.Instance().GetListOfParts()) { if (part.partType == VesselPartType.Bay) { buildstring += "-bay "; } else if (part.partType == VesselPartType.Engine) { buildstring += "-engine "; } else if (part.partType == VesselPartType.Launcher) { buildstring += "-launcher "; } buildstring += part.size.ToString() + " "; buildstring += part.quality1.ToString() + " "; buildstring += part.quality2.ToString() + " "; Vector2 positionInRelativeForm = PixelGridManager.Instance().GetRelativeForm(part.position); buildstring += positionInRelativeForm.x.ToString() + " "; buildstring += positionInRelativeForm.y.ToString() + " "; buildstring += part.facing.ToString() + " "; } string vesselDir = GameStringsHelper.VesselDirectory(); if (!System.IO.Directory.Exists(vesselDir)) { System.IO.Directory.CreateDirectory(vesselDir); } string path = GameStringsHelper.VesselNameToPath(name); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } System.IO.File.WriteAllText(path, buildstring); }
public void ColorChange() { PixelGridManager.Instance().SetColor(colorNumber, gameObject.GetComponent <UnityEngine.UI.Image>().color); }
public void OnClicked() { PixelGridManager.Instance().ButtonClicked(this); }
public void PlacePart(PixelGridButton button, VesselPart partToPlace) { if (buttonToPlacedPart.ContainsKey(button)) { Debug.Log("Dictionary already contains key " + button.ToString()); Debug.Log("There is already a part there."); return; } button.gameObject.transform.SetSiblingIndex(button.transform.parent.childCount - 1); GameObject placedPart = new GameObject("Placed Part"); RectTransform rectTransform = placedPart.AddComponent <RectTransform>(); placedPart.transform.SetParent(button.transform); rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.zero; float halfsize = partToPlace.size * Vessel.partSizeFactor * SpriteManager.SPRITE_SIZE * PixelGridManager.Instance().GetSizeFactor() / 2; rectTransform.offsetMin = Vector2.one * -1 * halfsize; rectTransform.offsetMax = Vector2.one * halfsize; rectTransform.eulerAngles = new Vector3(0, 0, partToPlace.facing); UnityEngine.UI.Image image = placedPart.AddComponent <UnityEngine.UI.Image>(); string spriteName; if (partToPlace.partType == VesselPartType.Bay) { spriteName = "square"; } else if (partToPlace.partType == VesselPartType.Engine) { spriteName = "halfcircle"; } else //(partInProgress.partType == VesselPartType.Launcher) { spriteName = "triangle"; } image.sprite = SpriteManager.Instance().SpriteFromName(spriteName); image.color = Color.white * GetPartColor(); image.raycastTarget = false; partToPlace.position = button.GetPosition(); VesselPart newPart = partToPlace; buttonToPlacedPart[button] = newPart; GameObject deleter = new GameObject("Deleter"); rectTransform = deleter.AddComponent <RectTransform>(); deleter.transform.SetParent(button.transform); rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.one; rectTransform.offsetMin = Vector2.zero; rectTransform.offsetMax = Vector2.zero; image = deleter.AddComponent <UnityEngine.UI.Image>(); image.sprite = SpriteManager.Instance().SpriteFromName("X"); image.color = new Color(0.75f, 0, 0); image.raycastTarget = false; }
public void SelectLauncher() { partInProgress.partType = VesselPartType.Launcher; demoImage.sprite = SpriteManager.Instance().SpriteFromName("triangle"); PixelGridManager.Instance().SetPartPlacing(); }
public void SelectEngine() { partInProgress.partType = VesselPartType.Engine; demoImage.sprite = SpriteManager.Instance().SpriteFromName("halfcircle"); PixelGridManager.Instance().SetPartPlacing(); }
public void SelectBay() { partInProgress.partType = VesselPartType.Bay; demoImage.sprite = SpriteManager.Instance().SpriteFromName("square"); PixelGridManager.Instance().SetPartPlacing(); }
public void Submit() { PixelGridManager.Instance().SpawnButtons(i); }