public void AddJigsaw(int index_, JigsawDataJson data_) { JigsawGameData gameData = new JigsawGameData { M_game_template_id = data_.M_template_id, M_game_dimention = data_.M_dimention, M_game_chips = new Dictionary <string, JigsawChipJson>(), }; foreach (var item in data_.M_chips) { gameData.M_game_chips.Add(item.M_chip_name, item); } if (!this.m_dict.ContainsKey(index_)) { m_dict.Add(index_, gameData); } else { this.m_dict[index_] = gameData; } }
private static List <JigsawDataJson> FindAllTemlates() { List <JigsawDataJson> ret = new List <JigsawDataJson>(); string temp_path = string.Format("{0}{1}", Application.dataPath, C_TEMPLATE_PATH); string[] fileNames = Directory.GetFiles(temp_path, "*.prefab"); Comparison <int> comparison = (x, y) => { if (x > y) { return(-1); } else if (x == y) { return(0); } else { return(1); } }; foreach (var fileName in fileNames) { string only_file_anme = Path.GetFileName(fileName); if (only_file_anme.Contains(C_TEMPLATE_NAME)) { string asset_file_path = string.Format("{0}{1}{2}", "Assets", C_TEMPLATE_PATH, only_file_anme); UnityEngine.Object ui_prefab = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(asset_file_path); GameObject template = PrefabUtility.InstantiatePrefab(ui_prefab) as GameObject; string[] template_words = template.name.Split('_'); int template_id = int.Parse(template_words[2]); GameObject chip_root = template.transform.Find("Panel").gameObject; List <int> chip_ids = new List <int>(); List <JigsawChipJson> chips = new List <JigsawChipJson>(); foreach (Transform child in chip_root.transform) { if (!child.gameObject.activeSelf) { continue; } int chip_id = int.Parse(child.name); chip_ids.Add(chip_id); RectTransform rect = child.Find("RawImage").GetComponent <RectTransform>(); RawImage image = child.Find("RawImage").GetComponent <RawImage>(); string tex_name = System.IO.Path.GetFileName(AssetDatabase.GetAssetPath(image.texture)); RectJson rect_j = new RectJson(rect.anchoredPosition.x, rect.anchoredPosition.y, rect.sizeDelta.x, rect.sizeDelta.y); JigsawChipJson chip_j = new JigsawChipJson { M_chip_name = child.name, M_tex_anme = tex_name, M_tex_size = rect_j }; chips.Add(chip_j); } GameObject.DestroyImmediate(template); //Resources.UnloadAsset(ui_prefab); chip_ids.Sort(comparison); int matrix_index = chip_ids[0]; int row = matrix_index / 10; int col = matrix_index % 10; int dimension = row > col ? row : col; dimension += 1; JigsawDataJson data = new JigsawDataJson() { M_chips = chips, M_dimention = dimension, M_template_id = template_id }; ret.Add(data); //Resources.UnloadAsset(template); } } return(ret); }