public void LoadStamps() { int stampK = PlayerPrefs.GetInt("stampK " + ImageOrder.imageSet + InstantiateImages.imageNumber); Debug.Log(stampK); string[] stampArray; for (int i = 0; i < stampK; i++) { StampData stampData = SaveSystem.LoadStamp(ImageOrder.imageSet, InstantiateImages.imageNumber, i); GameObject stampImg = new GameObject("Stamp"); string stampString = stampData.stampArray[0].ToString(); stampArray = stampString.Split('('); int spriteNr = int.Parse(stampArray[0].ToString()); float xCoord = float.Parse(stampArray[1].ToString()); float yCoord = float.Parse(stampArray[2].ToString()); stampImg.AddComponent <SpriteRenderer>().sprite = sprites[spriteNr]; stampImg.GetComponent <SpriteRenderer>().material = mat[4]; stampImg.AddComponent <RectTransform>().localScale = new Vector3(0.64f, 0.64f, 0.64f); stampImg.GetComponent <RectTransform>().localPosition = new Vector3(xCoord, yCoord, 0f); stampImg.layer = 9; stampImg.transform.SetParent(InstantiateImages.drawArray[ImageOrder.imageSet, InstantiateImages.imageNumber].transform); } }
public static void SaveStamp(SaveManager saveManager, int SetNumber, int ImageNumber, int index) { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/Stamp-" + SetNumber + "-" + ImageNumber + "-" + index + ".fun"; FileStream stream = new FileStream(path, FileMode.Create); StampData data = new StampData(saveManager); formatter.Serialize(stream, data); stream.Close(); }
static void StartStamping() { Init(); Object obj = Selection.activeObject; if (obj.GetType() == typeof(TextAsset)) { // instance.Stamp = Serializer.Deserialize<StampData>((Selection.activeObject as TextAsset).text); // EasyJson plugin instance.Stamp = JsonUtility.FromJson <StampData>((Selection.activeObject as TextAsset).text); } else { // we will generate a stamp from this single prefab StampData singleStamp = new StampData(); StampChild singleChild = new StampChild(); singleChild.PrefabPath = AssetDatabase.GetAssetPath(obj); singleStamp.prefabs.Add(singleChild); instance.Stamp = singleStamp; } currentStampName = Selection.activeObject.name; }
public async Task <IDataAccessDataResponse> GetResponseAsync(HttpContext httpContext, XDocument xml) { XElement data = xml.Element("Params"); if (data != null) { uint[] stampIds = ((string)data.Element("p_stamp_array") ?? throw new DataAccessProcedureMissingData()).Split(',').Select((b) => uint.Parse(b)).ToArray(); if (stampIds.Length > 0) { DataAccessGetManyStampsResponse response = new(); IList <StampData> stamps = await StampManager.GetStampsAsync(stampIds); foreach (StampData block in stamps) { response.AddStamp(block); } if (stamps.Count != stampIds.Length) { foreach (uint blockId in stampIds) { if (!stamps.Any((b) => b.Id == blockId)) { response.AddStamp(StampData.GetDeletedStamp(blockId)); } } } return(response); } else { return(new DataAccessGetManyStampsResponse()); } } else { throw new DataAccessProcedureMissingData(); } }
public static StampData LoadStamp(int SetNumber, int ImageNumber, int index) { string path = Application.persistentDataPath + "/Stamp-" + SetNumber + "-" + ImageNumber + "-" + index + ".fun"; if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); StampData data = formatter.Deserialize(stream) as StampData; stream.Close(); return(data); } else { Debug.Log("Save file not found in " + path); return(null); } }
static void CreateStamp() { if (Selection.gameObjects.Length == 0) { return; } // extra check: selected objects must be in scene if (Selection.activeGameObject.activeInHierarchy == true) { // In Hierarchy, ok } else { // In Project View, cannot use Debug.LogError("Select prefabbed objects from scene/hierarcy, not from the project folder.."); return; } foreach (GameObject go in Selection.gameObjects) { if (!go.activeInHierarchy) { continue; } GameObject parentPrefab = PrefabUtility.GetPrefabParent(go) as GameObject; if (parentPrefab == null || string.IsNullOrEmpty(AssetDatabase.GetAssetPath(parentPrefab))) { Debug.LogError("All selected GameObjects must be prefabs to make a stamp."); return; } } StampData stampData = new StampData(); Vector3 center = Vector3.zero; Bounds bounds = new Bounds(); foreach (GameObject go in Selection.gameObjects) { if (!go.activeInHierarchy) { continue; } StampChild sc = new StampChild(); sc.PrefabPath = AssetDatabase.GetAssetPath(PrefabUtility.GetPrefabParent(go)); sc.position = go.transform.position; sc.eulerAngles = go.transform.eulerAngles; sc.scale = go.transform.localScale; center += sc.position; // get bounds from all children foreach (Transform child in go.transform) { var mf = child.GetComponent <MeshFilter>(); bounds.Encapsulate(mf.sharedMesh.bounds); } stampData.prefabs.Add(sc); } stampData.center = center / stampData.prefabs.Count; stampData.bounds = bounds; // string jsonString = Serializer.Serialize(stampData, true); // EasyJSON plugin string jsonString = JsonUtility.ToJson(stampData, true); string assetPath = stampDataFolder + "new stamp.JSON"; string fullPath = Application.dataPath + assetPath; if (Directory.Exists(Path.GetDirectoryName(fullPath)) == true) { StreamWriter stream = File.CreateText(fullPath); stream.WriteLine(jsonString); stream.Close(); Debug.Log("Created new stamp at " + fullPath); AssetDatabase.Refresh(); } else { Debug.LogError("Missing stamp data folder: " + fullPath); } }
public void UpdateStampViewer(StampData selectedStamp) { viewedStamp = selectedStamp; stampViewer.GetComponent <SpriteRenderer>().sprite = Sprite.Create(selectedStamp.tex, new Rect(0, 0, selectedStamp.tex.width, selectedStamp.tex.height), new Vector2(0.5f, 0.5f)); }