//动画表情:重新计算uv private bool RecaculateAnimSpriteMesh(URichTextSpriteMeshInfo meshInfo) { int spriteID = 0; if (mainTexture == null) { return(false); } Data.AnimSpriteConfig.SSchemeAnimFrameData frameData = Data.AnimSpriteConfig.AnimSpriteConfig.Instance.GetData(meshInfo.animKey); Rect newSpriteRect = frameData.GetFrameRect(meshInfo.spriteIndex);//sInfo.rect; //由于位置不变,改变uv即可 //由于uv原点在左下角,但一般算sprite 坐标时按左上角,所以翻转一下 Vector2 newTexSize = new Vector2(m_mainTexture.width, m_mainTexture.height); meshInfo.uvs[3] = new Vector2(newSpriteRect.x / newTexSize.x, 1 - (newSpriteRect.y + newSpriteRect.height) / newTexSize.y); //new Vector2(newSpriteRect.x / newTexSize.x, newSpriteRect.y / newTexSize.y); meshInfo.uvs[1] = new Vector2((newSpriteRect.x + newSpriteRect.width) / newTexSize.x, 1 - newSpriteRect.y / newTexSize.y); //new Vector2((newSpriteRect.x + newSpriteRect.width) / newTexSize.x, (newSpriteRect.y + newSpriteRect.height) / newTexSize.y); meshInfo.uvs[2] = new Vector2((newSpriteRect.x + newSpriteRect.width) / newTexSize.x, 1 - (newSpriteRect.y + newSpriteRect.height) / newTexSize.y); //new Vector2((newSpriteRect.x + newSpriteRect.width) / newTexSize.x, newSpriteRect.y / newTexSize.y); meshInfo.uvs[0] = new Vector2(newSpriteRect.x / newTexSize.x, 1 - newSpriteRect.y / newTexSize.y); //new Vector2(newSpriteRect.x / newTexSize.x, (newSpriteRect.y + newSpriteRect.height) / newTexSize.y); return(true); }
public Sprite GetAnimSprite(string _strAnimName) { Data.AnimSpriteConfig.SSchemeAnimFrameData configData = Data.AnimSpriteConfig.AnimSpriteConfig.Instance.GetData(_strAnimName); if (configData == null) { return(DefaultSprite); } //WndID写个整个游戏进程都会有的UI return(GetSprite(ESpriteType.EST_AnimSprite, configData.strAssetName, USpeedUI.WndID.WND_ID_TOOLTIPS)); }
public void Load(string strPath) { m_dicAnimSpriteConfig = new Dictionary <string, SSchemeAnimFrameData>(); ScpReader reader = new ScpReader(strPath, true); for (int i = 0; i < reader.GetRecordCount(); i++) { SSchemeAnimFrameData sConfig = new SSchemeAnimFrameData(); sConfig.strAssetName = reader.GetString(i, (int)EAnimSpriteConfig.EASC_AssetName, string.Empty); sConfig.strAnimName = reader.GetString(i, (int)EAnimSpriteConfig.EASC_AnimName, string.Empty); sConfig.nAnimFrame = reader.GetInt(i, (int)EAnimSpriteConfig.EASC_AnimFrame, 1); string tmpAnimStartPos = reader.GetString(i, (int)EAnimSpriteConfig.EASC_AnimStartPos, "0;0"); sConfig.vec2AnimStartPos = new Vector2(float.Parse(tmpAnimStartPos.Split(';')[0]), float.Parse(tmpAnimStartPos.Split(';')[1])); string tmpAnimFrameSize = reader.GetString(i, (int)EAnimSpriteConfig.EASC_AnimFrameSize, "32;32"); sConfig.vec2AnimFrameSize = new List <Vector2>(); if (tmpAnimFrameSize.Contains("|")) { string[] sizeArray = tmpAnimFrameSize.Split('|'); if (sizeArray.Length != sConfig.nAnimFrame) { Trace.LogWarning("动画帧尺寸不一致,且尺寸数量与帧数不符,所有帧都用第一帧尺寸使用"); string tmpSize = sizeArray[0]; sConfig.vec2AnimFrameSize.Add(new Vector2(float.Parse(tmpSize.Split(';')[0]), float.Parse(tmpSize.Split(';')[1]))); } else { foreach (var strSize in sizeArray) { sConfig.vec2AnimFrameSize.Add(new Vector2(float.Parse(strSize.Split(';')[0]), float.Parse(strSize.Split(';')[1]))); } } } else { sConfig.vec2AnimFrameSize.Add(new Vector2(float.Parse(tmpAnimFrameSize.Split(';')[0]), float.Parse(tmpAnimFrameSize.Split(';')[1]))); } if (m_dicAnimSpriteConfig.ContainsKey(sConfig.strAnimName)) { Trace.LogWarning("有相同的动画名称:" + sConfig.strAnimName + "在表第" + i + "行."); } else { m_dicAnimSpriteConfig.Add(sConfig.strAnimName, sConfig); } } reader.Dispose(); reader = null; }