예제 #1
0
        //void CreateClueAnchorsAndBGTex(ScanJsonData data_)
        //{
        //    if (!this.Visible)
        //        return;

        //    m_anchors_grid.EnsureSize<ClueAnchorItemView>(data_.M_anchors.Count);

        //    for (int i = 0; i < m_anchors_grid.ChildCount; ++i)
        //    {
        //        var clue_anchor_item_view = m_anchors_grid.GetChild<ClueAnchorItemView>(i);

        //        var clue_anchor_data = data_.M_anchors[i];

        //        clue_anchor_item_view.Refresh(clue_anchor_data.M_clue_id, clue_anchor_data.M_x, clue_anchor_data.M_y);
        //        clue_anchor_item_view.Visible = true;
        //    }
        //}



        void CreateClueAnchorsAndBGTex(ScanJsonData data_)
        {
            if (!this.Visible)
            {
                return;
            }
            m_input_tex.TextureName             = data_.M_tex_name;
            m_input_tex.Widget.anchoredPosition = new Vector2(data_.M_tex_x, data_.M_tex_y);
            m_input_tex.Widget.sizeDelta        = new Vector2(data_.M_tex_w, data_.M_tex_h);

            m_special_grid.EnsureSize <SpecialItemView>(data_.M_anchors.Count);

            for (int i = 0; i < m_special_grid.ChildCount; ++i)
            {
                var clue_anchor_item_view = m_special_grid.GetChild <SpecialItemView>(i);

                var clue_anchor_data = data_.M_anchors[i];

                clue_anchor_item_view.RefreshClueID(clue_anchor_data.M_clue_id, clue_anchor_data.M_w, clue_anchor_data.M_h);
                clue_anchor_item_view.Refresh(i);
                clue_anchor_item_view.Widget.anchoredPosition = new Vector2(clue_anchor_data.M_x, clue_anchor_data.M_y);
                //clue_anchor_item_view.Widget.sizeDelta = new Vector2(clue_anchor_data.M_w, clue_anchor_data.M_h);
                clue_anchor_item_view.Visible = true;
            }
        }
예제 #2
0
        public void GetScanData(long scan_id_, Action <ScanJsonData> onLoad_)
        {
            if (m_dict.ContainsKey(scan_id_))
            {
                onLoad_(m_dict[scan_id_]);
                return;
            }

            EngineCoreEvents.ResourceEvent.GetAssetEvent.SafeInvoke($"Scan{scan_id_}.json", (assetName, assetObject) =>
            {
                ScanJsonData data = Utf8Json.JsonSerializer.Deserialize <ScanJsonData>(assetObject.ToString());

                m_dict.Add(scan_id_, data);
                onLoad_(m_dict[scan_id_]);

                EngineCoreEvents.ResourceEvent.ReleaseAssetEvent.SafeInvoke(assetName, assetObject);
            }, LoadPriority.HighPrior);
        }
예제 #3
0
    private static List <ScanJsonData> FindAllTemlates()
    {
        List <ScanJsonData> ret = new List <ScanJsonData>();

        string temp_path = string.Format("{0}{1}", Application.dataPath, C_TEMPLATE_PATH);

        string[] fileNames = Directory.GetFiles(temp_path, "*.prefab");

        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;

                //>尸检id
                string[] template_words = template.name.Split('_');
                int      template_id    = int.Parse(template_words[2]);
                //>

                //<尸检图片名
                RawImage r_img    = template.transform.Find("Tex").GetComponent <RawImage>();
                string   tex_name = System.IO.Path.GetFileName(AssetDatabase.GetAssetPath(r_img.texture));
                Rect     tex_rect = new Rect(r_img.rectTransform.anchoredPosition.x, r_img.rectTransform.anchoredPosition.y, r_img.rectTransform.sizeDelta.x, r_img.rectTransform.sizeDelta.y);
                //>

                //<线索id,以及位置
                GameObject anchors_root = template.transform.Find("Anchors").gameObject;
                List <ScanAnchorJsonData> anchor_datas = new List <ScanAnchorJsonData>();


                foreach (Transform child in anchors_root.transform)
                {
                    if (!child.gameObject.activeSelf)
                    {
                        continue;
                    }

                    int clue_id;

                    if (!int.TryParse(child.name, out clue_id))
                    {
                        Debug.LogError($"Scan Temp {only_file_anme} child {child.name} is not int");
                        continue;
                    }

                    RectTransform rect = child.GetComponent <RectTransform>();

                    ScanAnchorJsonData anchor_data = new ScanAnchorJsonData
                    {
                        M_clue_id = clue_id,
                        M_x       = rect.anchoredPosition.x,
                        M_y       = rect.anchoredPosition.y,
                        M_w       = rect.sizeDelta.x,
                        M_h       = rect.sizeDelta.y,
                    };

                    anchor_datas.Add(anchor_data);
                }
                //>

                GameObject.DestroyImmediate(template);


                ScanJsonData data = new ScanJsonData()
                {
                    M_id       = template_id,
                    M_tex_name = tex_name,
                    M_tex_x    = tex_rect.x,
                    M_tex_y    = tex_rect.y,
                    M_tex_w    = tex_rect.width,
                    M_tex_h    = tex_rect.height,
                    M_anchors  = new List <ScanAnchorJsonData>(anchor_datas),
                };

                ret.Add(data);

                Resources.UnloadAsset(ui_prefab);
            }
        }

        return(ret);
    }