// 绘引用 private void DrawAsset() { GUI.backgroundColor = Color.black; GUILayout.BeginVertical(new GUIStyle(EditorStyles.textField), GUILayout.Width(250), GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true)); GUI.backgroundColor = m_defaultBgClr; GUILayout.Label("资源管理", m_styleTittle, GUILayout.Width(250), GUILayout.Height(40)); m_assetScroPos = GUILayout.BeginScrollView(m_assetScroPos, true, false, GUILayout.ExpandWidth(true)); // true, false, GUILayout.Width(200), GUILayout.Height(100)); for (int i = 0; i < m_effectData.aA.Length; ++i) { EffectAssetData assData = m_effectData.aA[i]; DrawAssetItem(assData); } GUILayout.FlexibleSpace(); GUILayout.EndScrollView(); // +按钮 if (GUILayout.Button("+", GUILayout.Height(40), GUILayout.Width(245))) { List <EffectAssetData> listAsset = new List <EffectAssetData>(m_effectData.aA); listAsset.Add(new EffectAssetData()); m_effectData.aA = listAsset.ToArray(); } GUILayout.EndVertical(); }
// 检测资源数据是否有效 // @assetData:资源数据 // return:有效返回ture;否则false private bool CheckAssetIsValid(EffectAssetData assetData) { if (string.IsNullOrEmpty(assetData.n)) { return(false); } return(CheckImgIsValid(assetData.i)); }
// 绘制资源图标 // @assetData:资源数据 private void DrawAssetItem(EffectAssetData assetData) { if (CheckAssetIsValid(assetData)) { GUI.backgroundColor = Color.green; } else { GUI.backgroundColor = Color.red; } GUILayout.BeginVertical(new GUIStyle(EditorStyles.textField), GUILayout.Width(250), GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true)); GUI.backgroundColor = m_defaultBgClr; GUILayout.BeginHorizontal(); GUILayout.Label("资源id:", GUILayout.Width(55)); assetData.i = EditorGUILayout.IntField(assetData.i, GUILayout.Width(100)); if (GUILayout.Button("-", GUILayout.Width(20))) { List <EffectAssetData> listData = new List <EffectAssetData>(m_effectData.aA); listData.Remove(assetData); m_effectData.aA = listData.ToArray(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("资源:", GUILayout.Width(55)); Texture2D tx2D = null; if (!string.IsNullOrEmpty(assetData.n)) { tx2D = Resources.Load <Texture2D>("EffectRaw/" + assetData.n); } Texture2D nTx2D = (Texture2D)EditorGUILayout.ObjectField(tx2D, typeof(Texture2D), false, GUILayout.Width(120)); if (nTx2D != null) { assetData.n = nTx2D.name; assetData.w = nTx2D.width; assetData.h = nTx2D.height; } else { assetData.n = null; } GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
// 获取特效的资源数据 // 加载特效图片资源 // @effData:特效数据 // @id:图片id // return:资源数据 private EffectAssetData GetEffectImgAssetData(EffectData effData, int id) { for (int i = 0; i < effData.aA.Length; ++i) { EffectAssetData assetData = effData.aA[i]; if (assetData.i == id) { return(assetData); } } return(null); }
// 模拟帧数据 //private void SimulateFrameData() //{ // int defFrameNum = m_effectData.aF.Length; // for (int i = 0; i < defFrameNum - 1; ++i) // { // EffectFrameData frame1 = m_effectData.aF[i]; // EffectFrameData frame2 = m_effectData.aF[i + 1]; // m_listFrameData.Add(frame1); // for (int j = frame1.n + 1; j < frame2.n; ++j) // { // EffectFrameData nFrameData = new EffectFrameData(); // nFrameData.n = j; // m_listFrameData.Add(nFrameData); // List<EffectImageData> listImgData = new List<EffectImageData>(); // for (int k = 0; k < frame1.aI.Length; ++k) // { // EffectImageData imgData1 = frame1.aI[k]; // EffectImageData imgData2 = GetImgDataFromFrame(frame2, imgData1.i); // if(imgData2 != null) // { // EffectImageData nImgData = new EffectImageData(); // nImgData.i = imgData1.i; // nImgData.sX = EffectEditorUtil.EvaluteInperpolation(imgData1.sX, imgData2.sX, frame1.n, frame2.n, j); // nImgData.sY = EffectEditorUtil.EvaluteInperpolation(imgData1.sY, imgData2.sY, frame1.n, frame2.n, j); // nImgData.pX = EffectEditorUtil.EvaluteInperpolation(imgData1.pX, imgData2.pX, frame1.n, frame2.n, j); // nImgData.pY = EffectEditorUtil.EvaluteInperpolation(imgData1.pY, imgData2.pY, frame1.n, frame2.n, j); // nImgData.r = EffectEditorUtil.EvaluteInperpolation(imgData1.r, imgData2.r, frame1.n, frame2.n, j); // nImgData.c[0] = (int)EffectEditorUtil.EvaluteInperpolation(imgData1.c[0], imgData2.c[0], frame1.n, frame2.n, j); // nImgData.c[1] = (int)EffectEditorUtil.EvaluteInperpolation(imgData1.c[1], imgData2.c[1], frame1.n, frame2.n, j); // nImgData.c[2] = (int)EffectEditorUtil.EvaluteInperpolation(imgData1.c[2], imgData2.c[2], frame1.n, frame2.n, j); // nImgData.c[3] = (int)EffectEditorUtil.EvaluteInperpolation(imgData1.c[3], imgData2.c[3], frame1.n, frame2.n, j); // listImgData.Add(nImgData); // } // else // { // listImgData.Add(imgData1); // } // nFrameData.aI = listImgData.ToArray(); // } // } // } // m_listFrameData.Add(m_effectData.aF[defFrameNum - 1]); //} //// 从帧数据里面获取指定id的图片数据 //private EffectImageData GetImgDataFromFrame(EffectFrameData frameData, int imgId) //{ // for(int i =0; i < frameData.aI.Length; ++i) // { // EffectImageData imgData = frameData.aI[i]; // if (imgData.i == imgId) // return imgData; // } // return null; //} // 根据指定的帧更新显示 // @effData:特效数据 // @frameData:帧数据 public void UpdateByFrame(EffectData effData, EffectFrameData frameData) { // 先创建足够的图片资源 if (m_listImg.Count < frameData.aI.Length) { for (int i = m_listImg.Count; i < frameData.aI.Length; ++i) { Image img = Image.Instantiate(m_imgTemplate); img.transform.SetParent(transform); img.hideFlags = HideFlags.HideInHierarchy; m_listImg.Add(img); } } for (int i = 0; i < frameData.aI.Length; ++i) { Image img = m_listImg[i]; EffectImageData imgData = frameData.aI[i]; EffectAssetData assetData = GetEffectImgAssetData(effData, imgData.i); if (assetData == null) { continue; } img.gameObject.SetActive(true); img.sprite = Resources.Load <Sprite>("EffectRaw/" + assetData.n); img.rectTransform.sizeDelta = new Vector2(assetData.w, assetData.h); img.transform.localPosition = new Vector3(imgData.pX, imgData.pY, 0); img.transform.localRotation = Quaternion.Euler(0, 0, imgData.r); img.transform.localScale = new Vector2(imgData.sX, imgData.sY); img.color = new Color32((byte)imgData.c[0], (byte)imgData.c[1], (byte)imgData.c[2], (byte)imgData.c[3]); } for (int i = frameData.aI.Length; i < m_listImg.Count; ++i) { Image img = m_listImg[i]; img.gameObject.SetActive(false); } }
// 检测特效数据是否有效 // return:有效返回true;否则false private bool CheckEffectDataIsValid() { for (int i = 0; i < m_effectData.aA.Length; ++i) { EffectAssetData assetData = m_effectData.aA[i]; if (!CheckImgIsValid(assetData.i)) { return(false); } } for (int i = 0; i < m_effectData.aF.Length; ++i) { EffectFrameData frameData = m_effectData.aF[i]; if (!CheckFrameIsValid(frameData)) { return(false); } } return(true); }
private void OnGUI() { GUILayout.BeginHorizontal(); DrawMenu(); GUILayout.EndHorizontal(); if (m_effectData == null) { return; } m_dicAssetNum.Clear(); for (int i = 0; i < m_effectData.aA.Length; ++i) { EffectAssetData assetData = m_effectData.aA[i]; if (m_dicAssetNum.ContainsKey(assetData.i)) { m_dicAssetNum[assetData.i]++; } else { m_dicAssetNum.Add(assetData.i, 1); } } m_dicFrameNum.Clear(); for (int i = 0; i < m_effectData.aF.Length; ++i) { EffectFrameData frameData = m_effectData.aF[i]; if (m_dicFrameNum.ContainsKey(frameData.n)) { m_dicFrameNum[frameData.n]++; } else { m_dicFrameNum.Add(frameData.n, 1); } } GUILayout.BeginVertical(); DrawSetting(); GUILayout.BeginHorizontal(); DrawAsset(); DrawFrame(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); ResortFrame(); if (EffectEditorUI.Inst != null) { if (m_frameData != null && !EffectEditorUI.Inst.IsPlay) { PlayCurrentFrame(); } } }