public static Texture2D CreatePreviewIcon(string jsonData) { Build.BuildSave buildSave = JsonUtility.FromJson <Build.BuildSave>(jsonData); Vector2 zero = Vector2.zero; PartGrid.CenterToPositon(buildSave.parts, Build.main.partDatabase, ref zero, new Vector2(0f, -200f)); List <GameObject> list = new List <GameObject>(); foreach (Build.BuildSave.PlacedPartSave placedPartSave in buildSave.parts) { PartData partByName = Build.main.partDatabase.GetPartByName(placedPartSave.partName); if (partByName != null) { list.Add(PartGrid.LoadIcon(Build.main.buildGrid.iconPrefab, partByName.prefab, placedPartSave.position, partByName.prefab.localScale, null, 0, placedPartSave.orientation, Color.white, true).gameObject); } } Build.main.previewIconCamera.transform.position = new Vector3(0f, -200f, Mathf.Clamp(-Mathf.Max(zero.x, zero.y), -100f, -1f) * 0.52f); Build.main.previewIconCamera.Render(); while (list.Count > 0) { UnityEngine.Object.DestroyImmediate(list[0]); list.RemoveAt(0); } Texture2D texture2D = new Texture2D(Build.main.previewIconCamera.targetTexture.width, Build.main.previewIconCamera.targetTexture.height, TextureFormat.RGB24, false); RenderTexture.active = Build.main.previewIconCamera.targetTexture; texture2D.ReadPixels(new Rect(0f, 0f, (float)Build.main.previewIconCamera.targetTexture.width, (float)Build.main.previewIconCamera.targetTexture.height), 0, 0); texture2D.Apply(); return(texture2D); }
public void LoadSave(Build.BuildSave buildSaveToLoad) { this.buildGrid.DeleteAllIcons(); Camera.main.transform.position = buildSaveToLoad.cameraPosition; this.buildGrid.parts = Build.BuildSave.PlacedPartSave.FromSave(buildSaveToLoad.parts, this.partDatabase); this.buildGrid.LoadAllIcons(); }
public static void AddQuicksave(Build.BuildSave newSave) { MyVesselSavedHook myVesselSavedHook = new MyVesselSavedHook(newSave); myVesselSavedHook = MyHookSystem.executeHook <MyVesselSavedHook>(myVesselSavedHook); if (myVesselSavedHook.isCanceled()) { return; } Build.BuildQuicksaves buildQuicksaves = Build.BuildQuicksaves.LoadBuildQuicksaves(); buildQuicksaves.buildSaves.Add(newSave); Build.BuildQuicksaves.SaveBuildQuicksaves(buildQuicksaves); }
public void LoadSave(Build.BuildSave buildSaveToLoad) { MyVesselLoadedHook myVesselLoadedHook = new MyVesselLoadedHook(Build.BuildSave.PlacedPartSave.FromSave(buildSaveToLoad.parts, this.partDatabase)); myVesselLoadedHook = MyHookSystem.executeHook <MyVesselLoadedHook>(myVesselLoadedHook); if (myVesselLoadedHook.isCanceled()) { return; } this.buildGrid.DeleteAllIcons(); Camera.main.transform.position = buildSaveToLoad.cameraPosition; this.buildGrid.parts = myVesselLoadedHook.parts; this.buildGrid.LoadAllIcons(); this.MoveCamera(Vector3.zero); }
public static void AddQuicksave(Build.BuildSave newSave) { Build.BuildQuicksaves buildQuicksaves = Build.BuildQuicksaves.LoadBuildQuicksaves(); buildQuicksaves.buildSaves.Add(newSave); Build.BuildQuicksaves.SaveBuildQuicksaves(buildQuicksaves); }