/// <summary> /// 添加可选控件 /// </summary> private void OnAddOptional() { var mainLayerDefine = controlDic[layerInfo.type]; var options = mainLayerDefine.runtimeSubControls.ToArray(); var optionNames = new string[options.Length]; for (int i = 0; i < options.Length; i++) { optionNames[i] = mainLayerDefine.GetSubControlName(options[i]); } var count = controlItemCreater.CreatedItems.Count; PopOption.Instence.ShowPop(optionNames, (id) => { var key = options[id]; if (!layerInfo.subResourceDic.ContainsKey(key)) { var subType = mainLayerDefine.GetSubControlType(key); if (!string.IsNullOrEmpty(subType)) { var dic = new ResourceDic(); var ctrlItem = controlItemCreater.AddItem(); layerInfo.subResourceDic.Add(key, dic); var layerDefine = controlDic[subType]; InitCtrlItem(count, ctrlItem, layerDefine, dic, key); SetLastScroll(); } } }); }
public void SetPropertys(ResourceDic propertyDic, ILayerDefine layerDic) { this.layerDefine = layerDic; this.propertyDic = propertyDic; CopyDictionary(propertyDic, propertyCatchedDic); this.dicHash = propertyDic.GetHashCode(); UpdateView(); }
protected void Awake() { m_add.onClick.AddListener(AddOnePropertyItem); m_delete.onClick.AddListener(OnDeleteThis); m_option.onClick.AddListener(OnOptionClicked); m_check.onValueChanged.AddListener(OnSwitchActive); propertyCatchedDic = new ResourceDic(); propertyItemCreater = new ListItemCreater <PropertyItem>(propertyItemParent, propertyItemPrefab); }
public static string GetString(string key, string culture) { var str = key; if (ResourceDic.ContainsKey(key)) { str = culture == "en" ? ResourceDic[key].English : ResourceDic[key].French; } return(str); }
public void SetAcitveKey(ResourceDic dic, string key) { if (key == "rect") { dic.Remove("padding"); } else if (key == "padding") { dic.Remove("rect"); } }
private void CopyDictionary(ResourceDic source, ResourceDic target) { using (var enumerator = source.GetEnumerator()) { while (enumerator.MoveNext()) { target[enumerator.Current.Key] = enumerator.Current.Value; SetAcitveKey(target, enumerator.Current.Key); } } }
/// <summary> /// 添加图片 /// </summary> private void OnAddRawImage() { if (controlDic != null) { var count = controlItemCreater.CreatedItems.Count; var dic = new ResourceDic(); layerInfo.sub_rawImages.Add(dic); var ctrlItem = controlItemCreater.AddItem(); var layerDefine = controlDic[ParamAnalysisTool.rawImage_art_key]; InitCtrlItem(count, ctrlItem, layerDefine, dic, key_RawImage_Name); SetLastScroll(); } }
/// <summary> /// 添加文字控件 /// </summary> private void OnAddText() { if (controlDic != null) { var count = controlItemCreater.CreatedItems.Count; var textDic = new ResourceDic(); layerInfo.sub_texts.Add(textDic); var ctrlItem = controlItemCreater.AddItem(); var layerDefine = controlDic[ParamAnalysisTool.text_art_key]; InitCtrlItem(count, ctrlItem, layerDefine, textDic, key_Text_Name); SetLastScroll(); } }
/// <summary> /// 更新资源字典 /// </summary> /// <param name="resourceDic"></param> /// <param name="newResourceDic"></param> private void UpdateResourceDic(ResourceDic resourceDic, ResourceDic newResourceDic) { if (newResourceDic.Count == 0) { return; } using (var enumerator = newResourceDic.GetEnumerator()) { while (enumerator.MoveNext()) { var current = enumerator.Current; resourceDic[current.Key] = current.Value; } } }
public static void AnalysisLayerInfo(PsdLayer layer, LayerInfo layerInfo) { ResourceDic dic = new ResourceDic(); Rect parentRect = layerInfo.rect; Rect innerRect = GetSubRectFromLayer(layer, parentRect); dic.Add("name", layer.Name); switch (layer.LayerType) { case LayerType.Normal: case LayerType.Color: layerInfo.sub_images.Add(dic); dic.Add("sprite", layer.Name + ".png"); dic.Add("rect", ParamAnalysisTool.RectToString(innerRect)); CreatePNGFile(layer); break; case LayerType.Text: layerInfo.sub_texts.Add(dic); var textInfo = layer.Records.TextInfo; var color = new Color(textInfo.color[0], textInfo.color[1], textInfo.color[2], textInfo.color[3]); dic.Add("rect", ParamAnalysisTool.RectToString(GetMarginRect(innerRect, 1.2f))); dic.Add("color", ParamAnalysisTool.ColorToString(color)); dic.Add("text", textInfo.text); if (!string.IsNullOrEmpty(textInfo.fontName)) { dic.Add("font", textInfo.fontName); } dic.Add("fontSize", textInfo.fontSize.ToString()); break; case LayerType.Complex: Debug.Log("目标层解析能正常,请修改为智能对象! layer --> " + layer.Name); layerInfo.sub_images.Add(dic); dic.Add("sprite", layer.Name + ".png"); dic.Add("rect", ParamAnalysisTool.RectToString(innerRect)); CreatePNGFile(layer); break; default: break; } }
/// <summary> /// 置为主控件 /// </summary> /// <param name="ctrlItem"></param> private void OnMainCtrlItem(Control_Item ctrlItem) { var mainLayerDefine = controlDic[layerInfo.type]; if (ctrlItem.layerDefine != mainLayerDefine) { var @continue = DialogHelper.ShowDialog("小提示", "注意到与目标类型不一致!", "继续", "取消"); if (!@continue) { return; } } var tempDic = new ResourceDic(layerInfo.resourceDic); ctrlItem.CopyToDic(layerInfo.resourceDic); var typeName = ctrlItem.layerDefine.type.Name; layerInfo.type = typeName; var id = controlTypes.IndexOf(typeName); if (m_controlTypes.value != id) { layerInfo.type = controlTypes[id]; m_controlTypes.onValueChanged.RemoveListener(OnControlTypeChanged); m_controlTypes.value = id; m_controlTypes.onValueChanged.AddListener(OnControlTypeChanged); } var keep = tempDic.Count > 0 && DialogHelper.ShowDialog("小提示", "原有主控件信息不为空,是否保留信息继续编辑!", "保留", "删除"); if (keep) { ctrlItem.CopyFromDic(tempDic); } else { OnDeleteCtrlItem(ctrlItem); } UpdateListView(); }
public void CopyToDic(ResourceDic target) { target.Clear(); CopyDictionary(propertyDic, target); }
public void CopyFromDic(ResourceDic tempDic) { propertyDic.Clear(); CopyDictionary(tempDic, propertyDic); UpdateView(); }
/// <summary> /// 初始化CtrlItem /// </summary> /// <param name="ctrlItem"></param> /// <param name="layerDefine"></param> /// <param name="dic"></param> /// <param name="name"></param> private void InitCtrlItem(int index, Control_Item ctrlItem, ILayerDefine layerDefine, ResourceDic dic, string name) { var mainLayerDefine = controlDic[layerInfo.type]; var controlName = name; if (index != 0) { controlName = mainLayerDefine.GetSubControlName(name); } ctrlItem.onDelete = OnDeleteCtrlItem; ctrlItem.onMainControl = OnMainCtrlItem; ctrlItem.onGenInstenceControl = OnGenInstenceControl; ctrlItem.SetIndex(index); ctrlItem.SetTitle(controlName); UpdateCtrlItemState(index, ctrlItem); ctrlItem.SetPropertys(dic, layerDefine); }