/// <summary> /// 弹出框回调 /// </summary> void PaintTipsResponse() { TipsType type = PaintTips.GetInstance().PaintTipsType; switch (type) { case TipsType.DELETE: string delName = CheckDeleteOpetion(); //进行删除操作 if (delName != string.Empty) { print("name:" + delName); string imagFullPath = m_strSaveImagePath + delName; if (File.Exists(imagFullPath)) { File.Delete(imagFullPath); } InitSaveImageList(); //删除后重新设置背景 m_PaintPanel.GetComponent <Image>().sprite = m_CurrentBgSp; } break; case TipsType.SAVE: string texName = PaintTips.GetInstance().GetSaveName(); //判断名称是否为空 if (texName == string.Empty) { CommonMesTips.GetInstance().AlertTips("输入的名称不能为空!"); return; } //检测是否该文件是否已经存在 string tempPath = m_strSaveImagePath + texName + ".png"; //不能进行保存 if (File.Exists(tempPath)) { PaintTips.GetInstance().Show(TipsType.COVER); return; } else { StartCoroutine(CaptureByRect(new Rect(130, 0, Screen.width - 260, Screen.height), tempPath)); } break; //进行清空操作 case TipsType.CLEAN: m_BackBtn.interactable = false; for (int i = 0; i < m_LineHistoryObjList.Count; i++) { Destroy(m_LineHistoryObjList[i]); } m_LineHistoryObjList.RemoveRange(0, m_LineHistoryObjList.Count); break; case TipsType.COVER: string texName2 = PaintTips.GetInstance().GetSaveName(); //检测是否该文件是否已经存在 string tempPath2 = m_strSaveImagePath + texName2 + ".png"; StartCoroutine(CaptureByRect(new Rect(130, 0, 1074, 750), tempPath2)); break; default: break; } }
// Use this for initialization void Start() { m_LineObjContent = GameObject.Find("PaintObjs").transform; m_strSaveImagePath = Application.persistentDataPath + "/ScreenShot/"; if (!Directory.Exists(m_strSaveImagePath)) { Directory.CreateDirectory(m_strSaveImagePath); } m_BgItemPrefab = Resources.Load("Prefabs/BgItemPrefab", typeof(GameObject)) as GameObject; m_ColorItemPrefab = Resources.Load("Prefabs/ColorItem", typeof(GameObject)) as GameObject; TextAsset colorAsset = Resources.Load("Json/Color", typeof(TextAsset)) as TextAsset; m_ColorListData = JSONNode.Parse(colorAsset.text); TextAsset bgAsset = Resources.Load("Json/Bg", typeof(TextAsset)) as TextAsset; m_BgListData = JSONNode.Parse(bgAsset.text); m_PaintPanel = transform.Find("paintPanel"); m_CurrentBgSp = m_PaintPanel.GetComponent <Image>().sprite; m_UIEventFileter = m_PaintPanel.GetComponent <UIEventFilter>(); m_ColorPanel = transform.Find("ColorContent").gameObject; m_BgPanel = transform.Find("BgList").gameObject; if (null != m_BgPanel) { m_BgContent = m_BgPanel.transform.Find("content"); } m_SaveImagePanel = transform.Find("SaveContent").gameObject; if (null != m_SaveImagePanel) { m_SaveImageContent = m_SaveImagePanel.transform.Find("content"); m_SaveImageToggleGroup = m_SaveImageContent.GetComponent <ToggleGroup>(); } //左侧面板 Transform leftFunctionPanel = transform.Find("LeftFunctionPanel"); if (null != leftFunctionPanel) { m_LeftFunctionBtnToggleGroup = leftFunctionPanel.GetComponent <ToggleGroup>(); GameObject colorListBtn = leftFunctionPanel.Find("ColorListBtn").gameObject; m_LeftFuntionBtnPanelDict.Add(colorListBtn, m_ColorPanel); GameObject bgListBtn = leftFunctionPanel.Find("bgListBtn").gameObject; m_LeftFuntionBtnPanelDict.Add(bgListBtn, m_BgPanel); GameObject saveImgListBtn = leftFunctionPanel.Find("saveImglistBtn").gameObject; m_LeftFuntionBtnPanelDict.Add(saveImgListBtn, m_SaveImagePanel); m_PaintWidthSlider = leftFunctionPanel.Find("Slider").GetComponent <Slider>(); m_PaintWidthSlider.onValueChanged.AddListener(PaintWidthChanged); m_PaintWidthSlider.value = m_nCurrentLineWidth; //注册回调 foreach (GameObject funtionBtn in m_LeftFuntionBtnPanelDict.Keys) { funtionBtn.GetComponent <Toggle>().onValueChanged.AddListener(delegate(bool isOn) { FunctionBtnClick(funtionBtn, isOn); }); } } //右侧面板 Transform rightFunctionPanel = transform.Find("RightFuntionBtnPanel"); if (null != rightFunctionPanel) { //删除按钮 rightFunctionPanel.Find("delBtn").GetComponent <Button>().onClick.AddListener(delegate() { string delName = CheckDeleteOpetion(); //删除操作 if (delName != string.Empty) { PaintTips.GetInstance().Show(TipsType.DELETE); } //清除操作 else { PaintTips.GetInstance().Show(TipsType.CLEAN); } }); //返回按钮 m_BackBtn = rightFunctionPanel.Find("backBtn").GetComponent <Button>(); m_BackBtn.onClick.AddListener(delegate() { if (m_LineHistoryObjList.Count > 0) { m_BackBtn.interactable = true; Destroy(m_LineHistoryObjList[m_LineHistoryObjList.Count - 1]); m_LineHistoryObjList.RemoveAt(m_LineHistoryObjList.Count - 1); } else { m_BackBtn.interactable = false; } }); //保存按钮 rightFunctionPanel.Find("saveBtn").GetComponent <Button>().onClick.AddListener(delegate() { PaintTips.GetInstance().Show(TipsType.SAVE); m_LeftFunctionBtnToggleGroup.SetAllTogglesOff(); }); } //初始化颜色列表 InitColorList(); //初始化背景列表 InitBgList(); //初始化保存图片列表 InitSaveImageList(); }
private void Awake() { m_Instance = this; }