public void WriteToBuffers(BetterList<Vector3> v, BetterList<Vector2> u, BetterList<Color32> c, BetterList<Vector3> n, BetterList<Vector4> t) { if ((this.mRtpVerts != null) && (this.mRtpVerts.size > 0)) { if (n == null) { for (int i = 0; i < this.mRtpVerts.size; i++) { v.Add(this.mRtpVerts.buffer[i]); u.Add(this.uvs.buffer[i]); c.Add(this.cols.buffer[i]); } } else { for (int j = 0; j < this.mRtpVerts.size; j++) { v.Add(this.mRtpVerts.buffer[j]); u.Add(this.uvs.buffer[j]); c.Add(this.cols.buffer[j]); n.Add(this.mRtpNormal); t.Add(this.mRtpTan); } } } }
public BetterList<ITMItem> getRandomItems(int aItemCount) { BetterList<ITMItem> r = new BetterList<ITMItem>(); while(aItemCount>0) { r.Add(randomLibrary().randomItem()); aItemCount--; } return r; }
/// <summary> /// Virtual function called by the UIScreen that fills the buffers. /// </summary> public override void OnFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color> cols) { verts.Add(new Vector3(1f, 0f, 0f)); verts.Add(new Vector3(1f, -1f, 0f)); verts.Add(new Vector3(0f, -1f, 0f)); verts.Add(new Vector3(0f, 0f, 0f)); uvs.Add(Vector2.one); uvs.Add(new Vector2(1f, 0f)); uvs.Add(Vector2.zero); uvs.Add(new Vector2(0f, 1f)); cols.Add(color); cols.Add(color); cols.Add(color); cols.Add(color); }
public BetterList<string> GetListOfSprites(string match) { if (this.mReplacement != null) { return this.mReplacement.GetListOfSprites(match); } if (string.IsNullOrEmpty(match)) { return this.GetListOfSprites(); } if (this.mSprites.Count == 0) { this.Upgrade(); } BetterList<string> list = new BetterList<string>(); int num = 0; int count = this.mSprites.Count; while (num < count) { UISpriteData data = this.mSprites[num]; if (((data != null) && !string.IsNullOrEmpty(data.name)) && string.Equals(match, data.name, StringComparison.OrdinalIgnoreCase)) { list.Add(data.name); return list; } num++; } char[] separator = new char[] { ' ' }; string[] strArray = match.Split(separator, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < strArray.Length; i++) { strArray[i] = strArray[i].ToLower(); } int num4 = 0; int num5 = this.mSprites.Count; while (num4 < num5) { UISpriteData data2 = this.mSprites[num4]; if ((data2 != null) && !string.IsNullOrEmpty(data2.name)) { string str = data2.name.ToLower(); int num6 = 0; for (int j = 0; j < strArray.Length; j++) { if (str.Contains(strArray[j])) { num6++; } } if (num6 == strArray.Length) { list.Add(data2.name); } } num4++; } return list; }
public override void OnFill (BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols) { base.OnFill (verts, uvs, cols); Vector2 uv0 = new Vector2(mOuterUV.xMin, mOuterUV.yMin); Vector2 uv1 = new Vector2(mOuterUV.xMax, mOuterUV.yMax); verts.Add(new Vector3(1f, 0f, 0f)); verts.Add(new Vector3(1f, 0f, extrusionDepth)); verts.Add(new Vector3(1f, -1f, extrusionDepth)); verts.Add(new Vector3(1f, -1f, 0f)); verts.Add(new Vector3(1f, 0f, 0f)); verts.Add(new Vector3(0f, 0f, 0f)); verts.Add(new Vector3(0f, 0f, extrusionDepth)); verts.Add(new Vector3(1f, 0f, extrusionDepth)); verts.Add(new Vector3(0f, -1f, 0f)); verts.Add(new Vector3(0f, -1f, extrusionDepth)); verts.Add(new Vector3(0f, 0f, extrusionDepth)); verts.Add(new Vector3(0f, 0f, 0f)); verts.Add(new Vector3(1f, -1f, extrusionDepth)); verts.Add(new Vector3(0f, -1f, extrusionDepth)); verts.Add(new Vector3(0f, -1f, 0f)); verts.Add(new Vector3(1f, -1f, 0f)); for( int i = 0 ; i < 4 ; i++ ) { uvs.Add(uv1); uvs.Add(new Vector2(uv1.x, uv0.y)); uvs.Add(uv0); uvs.Add(new Vector2(uv0.x, uv1.y)); } #if UNITY_3_5_4 Color col = color; #else Color32 col = color; #endif for( int i = 0 ; i < 16 ; i++ ) { cols.Add(col); } }
public override void OnFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols) { Color c = base.color; c.a *= base.mPanel.finalAlpha; Color32 item = !this.premultipliedAlpha ? c : NGUITools.ApplyPMA(c); Vector4 drawingDimensions = this.drawingDimensions; verts.Add(new Vector3(drawingDimensions.x, drawingDimensions.y)); verts.Add(new Vector3(drawingDimensions.x, drawingDimensions.w)); verts.Add(new Vector3(drawingDimensions.z, drawingDimensions.w)); verts.Add(new Vector3(drawingDimensions.z, drawingDimensions.y)); uvs.Add(new Vector2(this.mRect.xMin, this.mRect.yMin)); uvs.Add(new Vector2(this.mRect.xMin, this.mRect.yMax)); uvs.Add(new Vector2(this.mRect.xMax, this.mRect.yMax)); uvs.Add(new Vector2(this.mRect.xMax, this.mRect.yMin)); cols.Add(item); cols.Add(item); cols.Add(item); cols.Add(item); }
private BetterList<MoveTreeCompletionDataRow> getBranchByPower(EMoveBranch aMoveBranch,byte aMaxMoves) { BetterList<MoveTreeCompletionDataRow> r = new BetterList<MoveTreeCompletionDataRow>(); int i = _items.size; while(i>0&&r.size<aMaxMoves) { i--; if(_items[i].moveBranch==aMoveBranch&&_items[i].canBeSelected) { r.Add(_items[i]); } } return r; }
public BetterList<MoveTreeCompletionDataRow> getBranch(EMoveBranch aBranch) { BetterList<MoveTreeCompletionDataRow> r = new BetterList<MoveTreeCompletionDataRow>(); int i = _items.size; while(i>0) { i--; if(_items[i].moveBranch==aBranch) { r.Add(_items[i]); } } return r; }
public BetterList<MonsterLibraryRecord> getMonstersOfElement(ElementalType aElementalType) { BetterList<MonsterLibraryRecord> rec = new BetterList<MonsterLibraryRecord>(); for(int i = 0; i < list.size ; i++) { if((list[i].PrimaryElement==aElementalType)||(list[i].SecondaryElement==aElementalType)) { if(list[i].Name!="No Creature") rec.Add(list[i]); } } return rec; }
public BetterList<EStatusEffects> StatusEffectsAsList() { BetterList<EStatusEffects> r = new BetterList<EStatusEffects> (); if ((this._currentStatusEffects & EStatusEffects.Burn) == EStatusEffects.Burn) { r.Add(EStatusEffects.Burn); } if ((this._currentStatusEffects & EStatusEffects.Confusion) == EStatusEffects.Confusion) { r.Add(EStatusEffects.Confusion); } if ((this._currentStatusEffects & EStatusEffects.Flinch) == EStatusEffects.Flinch) { r.Add(EStatusEffects.Flinch); } if ((this._currentStatusEffects & EStatusEffects.Freeze) == EStatusEffects.Freeze) { r.Add(EStatusEffects.Freeze); } if ((this._currentStatusEffects & EStatusEffects.Paralyze) == EStatusEffects.Paralyze) { r.Add(EStatusEffects.Paralyze); } if ((this._currentStatusEffects & EStatusEffects.Poison) == EStatusEffects.Poison) { r.Add(EStatusEffects.Poison); } if ((this._currentStatusEffects & EStatusEffects.Sleep) == EStatusEffects.Sleep) { r.Add(EStatusEffects.Sleep); } return r; }
public static BetterList<NPCBattleMonstersRow> getMonstersForBattle(string aBattleName) { BetterList<NPCBattleMonstersRow> r = new BetterList<NPCBattleMonstersRow>(); List<NPCBattleMonstersRow> l = NPCBattleMonsters.Instance.Rows; for(int i = 0;i<l.Count&&r.size<3;i++) { if(l[i]._BattleName==aBattleName) { r.Add(l[i]); } } if(r.size==0) { Debug.LogError("Battle: "+aBattleName+" Had no monsters!"); } return r; }
void OnEnable () { Dictionary<string, string[]> dict = Localization.dictionary; if (dict.Count > 0) { mKeys = new BetterList<string>(); foreach (KeyValuePair<string, string[]> pair in dict) { if (pair.Key == "KEY") continue; mKeys.Add(pair.Key); } mKeys.Sort(delegate (string left, string right) { return left.CompareTo(right); }); } }
private void ApplyShadow(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols, int start, int end, float x, float y) { Color mEffectColor = this.mEffectColor; mEffectColor.a *= base.alpha * base.mPanel.finalAlpha; Color32 color2 = ((this.bitmapFont == null) || !this.bitmapFont.premultipliedAlpha) ? mEffectColor : NGUITools.ApplyPMA(mEffectColor); for (int i = start; i < end; i++) { verts.Add(verts.buffer[i]); uvs.Add(uvs.buffer[i]); cols.Add(cols.buffer[i]); Vector3 vector = verts.buffer[i]; vector.x += x; vector.y += y; verts.buffer[i] = vector; cols.buffer[i] = color2; } }
public float doAgilityChange(float aMultiplier,BetterList<string> aImprovedStatsArr,BetterList<string> aDecreasedStatsArr) { if(aMultiplier>1.0f&&this._agilityEffector<MAX_EFFECTOR_VALUE) { this._agilityEffector *= aMultiplier; aImprovedStatsArr.Add("Agility"); return delayPerItem; } else if(aMultiplier<1.0f&&this._agilityEffector>MIN_EFFECTOR_VALUE) { if((EMonsterStat.Agility&this.invulnerableToChanges)!=EMonsterStat.Agility) { this._agilityEffector *= aMultiplier; aDecreasedStatsArr.Add ("Agility"); } else { this.doCommentaryMessage(this.name+" is Invulnerable to Agility Changes",ECommentaryMessageType.StandardMessage); } return delayPerItem; } return 0; }
/// <summary> /// 负责显示内容,它的工作是填写如何显示,显示什么。就是把需要显示的内容存储在UIWidget /// </summary> /// <param name="verts"></param> /// <param name="uvs">显示的多边形形状</param> /// <param name="cols">颜色调配</param> public override void OnFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols) { // 开始画网格, 顶点, 矩形 Vector3[] arrVerts = localCorners; // 直接由4个角组成矩形吧 for (int i = 0; i < arrVerts.Length; i++) { verts.Add(arrVerts[i]); } // 贴图点 for (int i = 0; i < arrVerts.Length; i++) { uvs.Add(new Vector2(0, 0)); } // 顶点颜色 Color pmaColor = NGUITools.ApplyPMA(this.color); // NGUI PMA for (int i = 0; i < arrVerts.Length; i++) { cols.Add(pmaColor); } }
public BetterList<string> GetListOfSprites() { if (this.mReplacement != null) { return this.mReplacement.GetListOfSprites(); } if (this.mSprites.Count == 0) { this.Upgrade(); } BetterList<string> list = new BetterList<string>(); int num = 0; int count = this.mSprites.Count; while (num < count) { UISpriteData data = this.mSprites[num]; if ((data != null) && !string.IsNullOrEmpty(data.name)) { list.Add(data.name); } num++; } return list; }
public BetterList<MoveQueueItem> reviveMoveQueue() { BetterList<MoveQueueItem> returnList = new BetterList<MoveQueueItem>(); BetterList<BattleMonster> monsters = this.monstersAsBattleMonster; Debug.Log ("Monsters as battle monster was: "+this.monstersAsBattleMonster.size); for(int i = 0;i<monsters.size;i++) { if(monsters[i]!=null) { Debug.Log("Monster: "+i+" was "+monsters[i].name); monsters[i].monster.restingStatus = ERestingStatus.Awake; monsters[i].monster.hp =1f; monsters[i].hp = 1f; monsters[i].removeAllLingeringEffects(); ///iTween.FadeTo(monsters[i].gameObject,1f,0.5f); MoveQueueItem mq = new MoveQueueItem(float.MaxValue,MovesLib.REF.getMove("Full Revive"),this.teamPosition,this.positionForMonster(monsters[i]),this.positionForMonster(monsters[i])); mq.actioningMonster = (BattleMonsterWithMoves) monsters[i]; mq.actioningTeam = (BattleTeam) this; mq.timesToHit = 1; returnList.Add(mq); } } Debug.Log ("Revive Move queue was: "+returnList.size); return returnList; }
public void DoMeshRenderer() { if (m_SpriteManager == null) { return; } m_SpriteManager.PackSprites(); BetterList <DynamicSpriteData> sprite_datas = m_SpriteManager.GetDynamicSpriteDatas(); //Debug.LogWarning ("Do Mesh Renderer for dynamic atlas!"); int size = sprite_datas.size; for (int i = m_MeshRenderers.size; i < size; i++) { MeshRenderer mesh_renderer = InstantiateMeshRenderer(); m_MeshRenderers.Add(mesh_renderer); } int rt_width = m_Material.mainTexture.width; int rt_height = m_Material.mainTexture.height; float x_ratio = 2.0f / rt_width; float y_ratio = 2.0f / rt_height; Vector3 loc_pos = Vector3.zero; Vector3 loc_scale = Vector3.one; int counter = 0; for (int i = 0; i < size; i++) { ++counter; MeshRenderer mr = m_MeshRenderers[i]; if (sprite_datas[i] == null) { mr.enabled = false; continue; } loc_pos.x = (sprite_datas[i].x + (sprite_datas[i].width) / 2.0f) * x_ratio - 1.0f; loc_pos.y = (rt_height - sprite_datas[i].y - (sprite_datas[i].height) / 2.0f) * y_ratio - 1.0f; loc_scale.x = x_ratio * sprite_datas[i].width; loc_scale.z = x_ratio * sprite_datas[i].height; //不推荐的写法,因为对材质属性的修改会造成额外的材质创建,请使用材质属性块(MaterialPropertyBlock)来修改材质属性 //mr.material.mainTexture = sprite_datas[i].TextureReference; mr.GetPropertyBlock(_matPropBlock); _matPropBlock.SetTexture(_matTextureID, sprite_datas[i].TextureReference); mr.SetPropertyBlock(_matPropBlock); mr.transform.localPosition = loc_pos; mr.transform.localScale = loc_scale; mr.enabled = true; } for (int i = counter; i < m_MeshRenderers.size; ++i) { m_MeshRenderers[i].enabled = false; } ActiveRenderer(); }
private void FilledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (this.mFillAmount < 0.001f) { return; } Vector4 drawingDimensions = this.drawingDimensions; Vector4 drawingUVs = this.drawingUVs; Color32 drawingColor = this.drawingColor; if (this.mFillDirection == UIBasicSprite.FillDirection.Horizontal || this.mFillDirection == UIBasicSprite.FillDirection.Vertical) { if (this.mFillDirection == UIBasicSprite.FillDirection.Horizontal) { float num = (drawingUVs.z - drawingUVs.x) * this.mFillAmount; if (this.mInvert) { drawingDimensions.x = drawingDimensions.z - (drawingDimensions.z - drawingDimensions.x) * this.mFillAmount; drawingUVs.x = drawingUVs.z - num; } else { drawingDimensions.z = drawingDimensions.x + (drawingDimensions.z - drawingDimensions.x) * this.mFillAmount; drawingUVs.z = drawingUVs.x + num; } } else if (this.mFillDirection == UIBasicSprite.FillDirection.Vertical) { float num2 = (drawingUVs.w - drawingUVs.y) * this.mFillAmount; if (this.mInvert) { drawingDimensions.y = drawingDimensions.w - (drawingDimensions.w - drawingDimensions.y) * this.mFillAmount; drawingUVs.y = drawingUVs.w - num2; } else { drawingDimensions.w = drawingDimensions.y + (drawingDimensions.w - drawingDimensions.y) * this.mFillAmount; drawingUVs.w = drawingUVs.y + num2; } } } UIBasicSprite.mTempPos[0] = new Vector2(drawingDimensions.x, drawingDimensions.y); UIBasicSprite.mTempPos[1] = new Vector2(drawingDimensions.x, drawingDimensions.w); UIBasicSprite.mTempPos[2] = new Vector2(drawingDimensions.z, drawingDimensions.w); UIBasicSprite.mTempPos[3] = new Vector2(drawingDimensions.z, drawingDimensions.y); UIBasicSprite.mTempUVs[0] = new Vector2(drawingUVs.x, drawingUVs.y); UIBasicSprite.mTempUVs[1] = new Vector2(drawingUVs.x, drawingUVs.w); UIBasicSprite.mTempUVs[2] = new Vector2(drawingUVs.z, drawingUVs.w); UIBasicSprite.mTempUVs[3] = new Vector2(drawingUVs.z, drawingUVs.y); if (this.mFillAmount < 1f) { if (this.mFillDirection == UIBasicSprite.FillDirection.Radial90) { if (UIBasicSprite.RadialCut(UIBasicSprite.mTempPos, UIBasicSprite.mTempUVs, this.mFillAmount, this.mInvert, 0)) { for (int i = 0; i < 4; i++) { verts.Add(UIBasicSprite.mTempPos[i]); uvs.Add(UIBasicSprite.mTempUVs[i]); cols.Add(drawingColor); } } return; } if (this.mFillDirection == UIBasicSprite.FillDirection.Radial180) { for (int j = 0; j < 2; j++) { float t = 0f; float t2 = 1f; float t3; float t4; if (j == 0) { t3 = 0f; t4 = 0.5f; } else { t3 = 0.5f; t4 = 1f; } UIBasicSprite.mTempPos[0].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t3); UIBasicSprite.mTempPos[1].x = UIBasicSprite.mTempPos[0].x; UIBasicSprite.mTempPos[2].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t4); UIBasicSprite.mTempPos[3].x = UIBasicSprite.mTempPos[2].x; UIBasicSprite.mTempPos[0].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t); UIBasicSprite.mTempPos[1].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t2); UIBasicSprite.mTempPos[2].y = UIBasicSprite.mTempPos[1].y; UIBasicSprite.mTempPos[3].y = UIBasicSprite.mTempPos[0].y; UIBasicSprite.mTempUVs[0].x = Mathf.Lerp(drawingUVs.x, drawingUVs.z, t3); UIBasicSprite.mTempUVs[1].x = UIBasicSprite.mTempUVs[0].x; UIBasicSprite.mTempUVs[2].x = Mathf.Lerp(drawingUVs.x, drawingUVs.z, t4); UIBasicSprite.mTempUVs[3].x = UIBasicSprite.mTempUVs[2].x; UIBasicSprite.mTempUVs[0].y = Mathf.Lerp(drawingUVs.y, drawingUVs.w, t); UIBasicSprite.mTempUVs[1].y = Mathf.Lerp(drawingUVs.y, drawingUVs.w, t2); UIBasicSprite.mTempUVs[2].y = UIBasicSprite.mTempUVs[1].y; UIBasicSprite.mTempUVs[3].y = UIBasicSprite.mTempUVs[0].y; float value = this.mInvert ? (this.mFillAmount * 2f - (float)(1 - j)) : (this.fillAmount * 2f - (float)j); if (UIBasicSprite.RadialCut(UIBasicSprite.mTempPos, UIBasicSprite.mTempUVs, Mathf.Clamp01(value), !this.mInvert, NGUIMath.RepeatIndex(j + 3, 4))) { for (int k = 0; k < 4; k++) { verts.Add(UIBasicSprite.mTempPos[k]); uvs.Add(UIBasicSprite.mTempUVs[k]); cols.Add(drawingColor); } } } return; } if (this.mFillDirection == UIBasicSprite.FillDirection.Radial360) { for (int l = 0; l < 4; l++) { float t5; float t6; if (l < 2) { t5 = 0f; t6 = 0.5f; } else { t5 = 0.5f; t6 = 1f; } float t7; float t8; if (l == 0 || l == 3) { t7 = 0f; t8 = 0.5f; } else { t7 = 0.5f; t8 = 1f; } UIBasicSprite.mTempPos[0].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t5); UIBasicSprite.mTempPos[1].x = UIBasicSprite.mTempPos[0].x; UIBasicSprite.mTempPos[2].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t6); UIBasicSprite.mTempPos[3].x = UIBasicSprite.mTempPos[2].x; UIBasicSprite.mTempPos[0].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t7); UIBasicSprite.mTempPos[1].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t8); UIBasicSprite.mTempPos[2].y = UIBasicSprite.mTempPos[1].y; UIBasicSprite.mTempPos[3].y = UIBasicSprite.mTempPos[0].y; UIBasicSprite.mTempUVs[0].x = Mathf.Lerp(drawingUVs.x, drawingUVs.z, t5); UIBasicSprite.mTempUVs[1].x = UIBasicSprite.mTempUVs[0].x; UIBasicSprite.mTempUVs[2].x = Mathf.Lerp(drawingUVs.x, drawingUVs.z, t6); UIBasicSprite.mTempUVs[3].x = UIBasicSprite.mTempUVs[2].x; UIBasicSprite.mTempUVs[0].y = Mathf.Lerp(drawingUVs.y, drawingUVs.w, t7); UIBasicSprite.mTempUVs[1].y = Mathf.Lerp(drawingUVs.y, drawingUVs.w, t8); UIBasicSprite.mTempUVs[2].y = UIBasicSprite.mTempUVs[1].y; UIBasicSprite.mTempUVs[3].y = UIBasicSprite.mTempUVs[0].y; float value2 = (!this.mInvert) ? (this.mFillAmount * 4f - (float)(3 - NGUIMath.RepeatIndex(l + 2, 4))) : (this.mFillAmount * 4f - (float)NGUIMath.RepeatIndex(l + 2, 4)); if (UIBasicSprite.RadialCut(UIBasicSprite.mTempPos, UIBasicSprite.mTempUVs, Mathf.Clamp01(value2), this.mInvert, NGUIMath.RepeatIndex(l + 2, 4))) { for (int m = 0; m < 4; m++) { verts.Add(UIBasicSprite.mTempPos[m]); uvs.Add(UIBasicSprite.mTempUVs[m]); cols.Add(drawingColor); } } } return; } } for (int n = 0; n < 4; n++) { verts.Add(UIBasicSprite.mTempPos[n]); uvs.Add(UIBasicSprite.mTempUVs[n]); cols.Add(drawingColor); } }
public void RebuildLightsList(List <VisibleLight> visibleLights, CameraData cameraData, PipelineSettings pipelineSettings, ref RenderingData renderingData) { UnityEngine.Profiling.Profiler.BeginSample("RebuildLightsList"); lights.Clear(); var unityLights = visibleLights; VisibleLight = 0; LightsDataForShadow.Clear(); bool softShadow = false; int j = 0; int currentShadowIndex = 0; int maxShadowNum = pipelineSettings.MaxShadowLightsNum; for (int i = 0; i < unityLights.Count; ++i) { var ul = unityLights[i]; var pl = ul.light.GetComponent <ProjectorLight>(); if (pl == null) { continue; } lights.Add(pl); var ifLight = pl; if (ifLight.spritesAtlas != spritesAtlas) { spritesAtlas = ifLight.spritesAtlas; } //矩阵是从右向左乘的,view需要z取反 Matrix4x4 c2w = /*Camera.main*/ cameraData.camera.cameraToWorldMatrix * Matrix4x4.Scale(new Vector3(1, 1, -1));// Camera.main.transform.localToWorldMatrix; int shadowIndex = currentShadowIndex; if (currentShadowIndex >= maxShadowNum || !ifLight.lightParms_Shadow) { shadowIndex = -1; } LightDataInAll lightDataInAll = ifLight.GetLightData(c2w, shadowIndex); NativeLightsBoundList[i] = lightDataInAll.sFiniteLightBound; NativeLightsDataList[i] = lightDataInAll.lightData; ++VisibleLight; //for shadow // TODO frustum cull if (ifLight.lightParms_Shadow && currentShadowIndex < maxShadowNum) { LightDataForShadow lightDataForShadow = new LightDataForShadow(); lightDataForShadow.lightIndex = j++; lightDataForShadow.shadowData = lightDataInAll.shadowData; lightDataForShadow.visibleLight = ul; lightDataForShadow.projectorLight = ifLight; lightDataForShadow.unityLightIndex = i; //Matrix4x4 scaleMatrix = Matrix4x4.identity; ////scaleMatrix.m22 = -1.0f; //Matrix4x4 view = scaleMatrix * ul.localToWorld.inverse; //lightDataForShadow.shadowData.viewMatrix = view; LightsDataForShadow.Add(lightDataForShadow); softShadow |= ifLight.softShadow; ++currentShadowIndex; } } renderingData.shadowData.supportsSoftShadows = softShadow; culsterDataGenerator.Begin(pipelineSettings); culsterDataGenerator.Run(cameraData, pipelineSettings, this); lightLoopLightsData.LightsDatasBuf.SetData(LightsDataList); tileAndClusterData.itemsIDListBuf.SetData(culsterDataGenerator.ResultItemsIDList); tileAndClusterData.clusterNumItemsBuf.SetData(culsterDataGenerator.ResultClusterNumItems); culsterDataGenerator.End(); UnityEngine.Profiling.Profiler.EndSample(); }
/// <summary> /// Parse the symbol, if possible. Returns 'true' if the 'index' was adjusted. Advanced symbol support contributed by Rudy Pangestu. /// </summary> static public bool ParseSymbol(string text, ref int index, BetterList <Color> colors, bool premultiply, ref int sub, ref bool bold, ref bool italic, ref bool underline, ref bool strike) { int length = text.Length; if (index + 3 > length || text[index] != '[') { return(false); } if (text[index + 2] == ']') { if (text[index + 1] == '-') { if (colors != null && colors.size > 1) { colors.RemoveAt(colors.size - 1); } index += 3; return(true); } string sub3 = text.Substring(index, 3); switch (sub3) { case "[b]": bold = true; index += 3; return(true); case "[i]": italic = true; index += 3; return(true); case "[u]": underline = true; index += 3; return(true); } } if (index + 4 > length) { return(false); } if (text[index + 3] == ']') { string sub4 = text.Substring(index, 4); switch (sub4) { case "[/b]": bold = false; index += 4; return(true); case "[/i]": italic = false; index += 4; return(true); case "[/u]": underline = false; index += 4; return(true); case "[st]": strike = true; index += 4; return(true); } } if (index + 5 > length) { return(false); } if (text[index + 4] == ']') { string sub5 = text.Substring(index, 5); switch (sub5) { case "[sub]": sub = 1; index += 5; return(true); case "[sup]": sub = 2; index += 5; return(true); case "[/st]": strike = false; index += 5; return(true); } } if (index + 6 > length) { return(false); } if (text[index + 5] == ']') { string sub6 = text.Substring(index, 6); switch (sub6) { case "[/sub]": sub = 0; index += 6; return(true); case "[/sup]": sub = 0; index += 6; return(true); } } if (index + 8 > length) { return(false); } if (text[index + 7] == ']') { Color c = ParseColor(text, index + 1); if (EncodeColor(c) != text.Substring(index + 1, 6).ToUpper()) { return(false); } if (colors != null) { c.a = colors[colors.size - 1].a; if (premultiply && c.a != 1f) { c = Color.Lerp(mInvisible, c, c.a); } colors.Add(c); } index += 8; return(true); } return(false); }
/// <summary> /// Print character positions and indices into the specified buffer. Meant to be used with the "find closest vertex" calculations. /// </summary> static public void PrintCharacterPositions(string text, BetterList <Vector3> verts, BetterList <int> indices) { if (string.IsNullOrEmpty(text)) { text = " "; } Prepare(text); float x = 0f, y = 0f, maxX = 0f, halfSize = fontSize * fontScale * 0.5f; int textLength = text.Length, indexOffset = verts.size, ch = 0, prev = 0; for (int i = 0; i < textLength; ++i) { ch = text[i]; verts.Add(new Vector3(x, -y - halfSize)); indices.Add(i); if (ch == '\n') { if (x > maxX) { maxX = x; } if (alignment != TextAlignment.Left) { Align(verts, indexOffset, x - finalSpacingX); indexOffset = verts.size; } x = 0; y += finalLineHeight; prev = 0; continue; } else if (ch < ' ') { prev = 0; continue; } if (encoding && ParseSymbol(text, ref i)) { --i; continue; } // See if there is a symbol matching this text BMSymbol symbol = useSymbols ? GetSymbol(text, i, textLength) : null; if (symbol == null) { float w = GetGlyphWidth(ch, prev); if (w != 0f) { x += w + finalSpacingX; verts.Add(new Vector3(x, -y - halfSize)); indices.Add(i + 1); prev = ch; } } else { x += symbol.advance * fontScale + finalSpacingX; verts.Add(new Vector3(x, -y - halfSize)); indices.Add(i + 1); i += symbol.sequence.Length - 1; prev = 0; } } if (alignment != TextAlignment.Left && indexOffset < verts.size) { Align(verts, indexOffset, x - finalSpacingX); } }
/// <summary> /// Filled sprite fill function. /// </summary> protected void FilledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (mFillAmount < 0.001f) { return; } Color colF = color; colF.a *= mPanel.finalAlpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; Vector4 v = drawingDimensions; float tx0 = mOuterUV.xMin; float ty0 = mOuterUV.yMin; float tx1 = mOuterUV.xMax; float ty1 = mOuterUV.yMax; // Horizontal and vertical filled sprites are simple -- just end the sprite prematurely if (mFillDirection == FillDirection.Horizontal || mFillDirection == FillDirection.Vertical) { if (mFillDirection == FillDirection.Horizontal) { float fill = (tx1 - tx0) * mFillAmount; if (mInvert) { v.x = v.z - (v.z - v.x) * mFillAmount; tx0 = tx1 - fill; } else { v.z = v.x + (v.z - v.x) * mFillAmount; tx1 = tx0 + fill; } } else if (mFillDirection == FillDirection.Vertical) { float fill = (ty1 - ty0) * mFillAmount; if (mInvert) { v.y = v.w - (v.w - v.y) * mFillAmount; ty0 = ty1 - fill; } else { v.w = v.y + (v.w - v.y) * mFillAmount; ty1 = ty0 + fill; } } } mTemp1[0] = new Vector2(v.x, v.y); mTemp1[1] = new Vector2(v.x, v.w); mTemp1[2] = new Vector2(v.z, v.w); mTemp1[3] = new Vector2(v.z, v.y); mTemp2[0] = new Vector2(tx0, ty0); mTemp2[1] = new Vector2(tx0, ty1); mTemp2[2] = new Vector2(tx1, ty1); mTemp2[3] = new Vector2(tx1, ty0); if (mFillAmount < 1f) { if (mFillDirection == FillDirection.Radial90) { if (RadialCut(mTemp1, mTemp2, mFillAmount, mInvert, 0)) { for (int i = 0; i < 4; ++i) { verts.Add(mTemp1[i]); uvs.Add(mTemp2[i]); cols.Add(col); } } return; } if (mFillDirection == FillDirection.Radial180) { for (int side = 0; side < 2; ++side) { float fx0, fx1, fy0, fy1; fy0 = 0f; fy1 = 1f; if (side == 0) { fx0 = 0f; fx1 = 0.5f; } else { fx0 = 0.5f; fx1 = 1f; } mTemp1[0].x = Mathf.Lerp(v.x, v.z, fx0); mTemp1[1].x = mTemp1[0].x; mTemp1[2].x = Mathf.Lerp(v.x, v.z, fx1); mTemp1[3].x = mTemp1[2].x; mTemp1[0].y = Mathf.Lerp(v.y, v.w, fy0); mTemp1[1].y = Mathf.Lerp(v.y, v.w, fy1); mTemp1[2].y = mTemp1[1].y; mTemp1[3].y = mTemp1[0].y; mTemp2[0].x = Mathf.Lerp(tx0, tx1, fx0); mTemp2[1].x = mTemp2[0].x; mTemp2[2].x = Mathf.Lerp(tx0, tx1, fx1); mTemp2[3].x = mTemp2[2].x; mTemp2[0].y = Mathf.Lerp(ty0, ty1, fy0); mTemp2[1].y = Mathf.Lerp(ty0, ty1, fy1); mTemp2[2].y = mTemp2[1].y; mTemp2[3].y = mTemp2[0].y; float val = !mInvert ? fillAmount * 2f - side : mFillAmount * 2f - (1 - side); if (RadialCut(mTemp1, mTemp2, Mathf.Clamp01(val), !mInvert, NGUIMath.RepeatIndex(side + 3, 4))) { for (int i = 0; i < 4; ++i) { verts.Add(mTemp1[i]); uvs.Add(mTemp2[i]); cols.Add(col); } } } return; } if (mFillDirection == FillDirection.Radial360) { for (int corner = 0; corner < 4; ++corner) { float fx0, fx1, fy0, fy1; if (corner < 2) { fx0 = 0f; fx1 = 0.5f; } else { fx0 = 0.5f; fx1 = 1f; } if (corner == 0 || corner == 3) { fy0 = 0f; fy1 = 0.5f; } else { fy0 = 0.5f; fy1 = 1f; } mTemp1[0].x = Mathf.Lerp(v.x, v.z, fx0); mTemp1[1].x = mTemp1[0].x; mTemp1[2].x = Mathf.Lerp(v.x, v.z, fx1); mTemp1[3].x = mTemp1[2].x; mTemp1[0].y = Mathf.Lerp(v.y, v.w, fy0); mTemp1[1].y = Mathf.Lerp(v.y, v.w, fy1); mTemp1[2].y = mTemp1[1].y; mTemp1[3].y = mTemp1[0].y; mTemp2[0].x = Mathf.Lerp(tx0, tx1, fx0); mTemp2[1].x = mTemp2[0].x; mTemp2[2].x = Mathf.Lerp(tx0, tx1, fx1); mTemp2[3].x = mTemp2[2].x; mTemp2[0].y = Mathf.Lerp(ty0, ty1, fy0); mTemp2[1].y = Mathf.Lerp(ty0, ty1, fy1); mTemp2[2].y = mTemp2[1].y; mTemp2[3].y = mTemp2[0].y; float val = mInvert ? mFillAmount * 4f - NGUIMath.RepeatIndex(corner + 2, 4) : mFillAmount * 4f - (3 - NGUIMath.RepeatIndex(corner + 2, 4)); if (RadialCut(mTemp1, mTemp2, Mathf.Clamp01(val), mInvert, NGUIMath.RepeatIndex(corner + 2, 4))) { for (int i = 0; i < 4; ++i) { verts.Add(mTemp1[i]); uvs.Add(mTemp2[i]); cols.Add(col); } } } return; } } // Fill the buffer with the quad for the sprite for (int i = 0; i < 4; ++i) { verts.Add(mTemp1[i]); uvs.Add(mTemp2[i]); cols.Add(col); } }
/// <summary> /// Sliced sprite fill function is more complicated as it generates 9 quads instead of 1. /// </summary> protected void SlicedFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (mSprite == null) { return; } if (!mSprite.hasBorder) { SimpleFill(verts, uvs, cols); return; } Vector4 br = border * atlas.pixelSize; Vector2 po = pivotOffset; float fw = 1f / mWidth; float fh = 1f / mHeight; mTemp1[0].x = mSprite.paddingLeft * fw; mTemp1[0].y = mSprite.paddingBottom * fh; mTemp1[3].x = 1f - mSprite.paddingRight * fw; mTemp1[3].y = 1f - mSprite.paddingTop * fh; mTemp1[1].x = mTemp1[0].x + fw * br.x; mTemp1[1].y = mTemp1[0].y + fh * br.y; mTemp1[2].x = mTemp1[3].x - fw * br.z; mTemp1[2].y = mTemp1[3].y - fh * br.w; for (int i = 0; i < 4; ++i) { mTemp1[i].x -= po.x; mTemp1[i].y -= po.y; mTemp1[i].x *= mWidth; mTemp1[i].y *= mHeight; } mTemp2[0] = new Vector2(mOuterUV.xMin, mOuterUV.yMin); mTemp2[1] = new Vector2(mInnerUV.xMin, mInnerUV.yMin); mTemp2[2] = new Vector2(mInnerUV.xMax, mInnerUV.yMax); mTemp2[3] = new Vector2(mOuterUV.xMax, mOuterUV.yMax); Color colF = color; colF.a *= mPanel.finalAlpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; for (int x = 0; x < 3; ++x) { int x2 = x + 1; for (int y = 0; y < 3; ++y) { if (!mFillCenter && x == 1 && y == 1) { continue; } int y2 = y + 1; verts.Add(new Vector3(mTemp1[x].x, mTemp1[y].y)); verts.Add(new Vector3(mTemp1[x].x, mTemp1[y2].y)); verts.Add(new Vector3(mTemp1[x2].x, mTemp1[y2].y)); verts.Add(new Vector3(mTemp1[x2].x, mTemp1[y].y)); uvs.Add(new Vector2(mTemp2[x].x, mTemp2[y].y)); uvs.Add(new Vector2(mTemp2[x].x, mTemp2[y2].y)); uvs.Add(new Vector2(mTemp2[x2].x, mTemp2[y2].y)); uvs.Add(new Vector2(mTemp2[x2].x, mTemp2[y].y)); cols.Add(col); cols.Add(col); cols.Add(col); cols.Add(col); } } }
/// <summary> /// Regular sprite fill function is quite simple. /// </summary> protected void SimpleFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols) { Vector2 uv0 = new Vector2(mOuterUV.xMin, mOuterUV.yMin); Vector2 uv1 = new Vector2(mOuterUV.xMax, mOuterUV.yMax); verts.Add(new Vector3(1f, 0f, 0f)); verts.Add(new Vector3(1f, -1f, 0f)); verts.Add(new Vector3(0f, -1f, 0f)); verts.Add(new Vector3(0f, 0f, 0f)); uvs.Add(uv1); uvs.Add(new Vector2(uv1.x, uv0.y)); uvs.Add(uv0); uvs.Add(new Vector2(uv0.x, uv1.y)); Color colF = color; colF.a *= mPanel.alpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; cols.Add(col); cols.Add(col); cols.Add(col); cols.Add(col); }
/// <summary> /// Tiled sprite fill function. /// </summary> protected void TiledFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols) { Texture tex = material.mainTexture; if (tex == null) return; Rect rect = mInner; if (atlas.coordinates == UIAtlas.Coordinates.TexCoords) { rect = NGUIMath.ConvertToPixels(rect, tex.width, tex.height, true); } Vector2 scale = cachedTransform.localScale; float pixelSize = atlas.pixelSize; float width = Mathf.Abs(rect.width / scale.x) * pixelSize; float height = Mathf.Abs(rect.height / scale.y) * pixelSize; // Safety check. Useful so Unity doesn't run out of memory if the sprites are too small. if (width * height < 0.0001f) { Debug.LogWarning("The tiled sprite (" + NGUITools.GetHierarchy(gameObject) + ") is too small.\nConsider using a bigger one."); width = 0.01f; height = 0.01f; } Vector2 min = new Vector2(rect.xMin / tex.width, rect.yMin / tex.height); Vector2 max = new Vector2(rect.xMax / tex.width, rect.yMax / tex.height); Vector2 clipped = max; Color colF = color; colF.a *= mPanel.alpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; float y = 0f; while (y < 1f) { float x = 0f; clipped.x = max.x; float y2 = y + height; if (y2 > 1f) { clipped.y = min.y + (max.y - min.y) * (1f - y) / (y2 - y); y2 = 1f; } while (x < 1f) { float x2 = x + width; if (x2 > 1f) { clipped.x = min.x + (max.x - min.x) * (1f - x) / (x2 - x); x2 = 1f; } verts.Add(new Vector3(x2, -y, 0f)); verts.Add(new Vector3(x2, -y2, 0f)); verts.Add(new Vector3(x, -y2, 0f)); verts.Add(new Vector3(x, -y, 0f)); uvs.Add(new Vector2(clipped.x, 1f - min.y)); uvs.Add(new Vector2(clipped.x, 1f - clipped.y)); uvs.Add(new Vector2(min.x, 1f - clipped.y)); uvs.Add(new Vector2(min.x, 1f - min.y)); cols.Add(col); cols.Add(col); cols.Add(col); cols.Add(col); x += width; } y += height; } }
/// <summary> /// Draw the widget. /// </summary> override public void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color> cols) { if (mOuterUV == mInnerUV) { base.OnFill(verts, uvs, cols); return; } Vector2[] v = new Vector2[4]; Vector2[] uv = new Vector2[4]; Texture tex = mainTexture; v[0] = Vector2.zero; v[1] = Vector2.zero; v[2] = new Vector2(1f, -1f); v[3] = new Vector2(1f, -1f); if (tex != null) { float pixelSize = atlas.pixelSize; float borderLeft = (mInnerUV.xMin - mOuterUV.xMin) * pixelSize; float borderRight = (mOuterUV.xMax - mInnerUV.xMax) * pixelSize; float borderTop = (mInnerUV.yMax - mOuterUV.yMax) * pixelSize; float borderBottom = (mOuterUV.yMin - mInnerUV.yMin) * pixelSize; Vector3 scale = cachedTransform.localScale; scale.x = Mathf.Max(0f, scale.x); scale.y = Mathf.Max(0f, scale.y); Vector2 sz = new Vector2(scale.x / tex.width, scale.y / tex.height); Vector2 tl = new Vector2(borderLeft / sz.x, borderTop / sz.y); Vector2 br = new Vector2(borderRight / sz.x, borderBottom / sz.y); Pivot pv = pivot; // We don't want the sliced sprite to become smaller than the summed up border size if (pv == Pivot.Right || pv == Pivot.TopRight || pv == Pivot.BottomRight) { v[0].x = Mathf.Min(0f, 1f - (br.x + tl.x)); v[1].x = v[0].x + tl.x; v[2].x = v[0].x + Mathf.Max(tl.x, 1f - br.x); v[3].x = v[0].x + Mathf.Max(tl.x + br.x, 1f); } else { v[1].x = tl.x; v[2].x = Mathf.Max(tl.x, 1f - br.x); v[3].x = Mathf.Max(tl.x + br.x, 1f); } if (pv == Pivot.Bottom || pv == Pivot.BottomLeft || pv == Pivot.BottomRight) { v[0].y = Mathf.Max(0f, -1f - (br.y + tl.y)); v[1].y = v[0].y + tl.y; v[2].y = v[0].y + Mathf.Min(tl.y, -1f - br.y); v[3].y = v[0].y + Mathf.Min(tl.y + br.y, -1f); } else { v[1].y = tl.y; v[2].y = Mathf.Min(tl.y, -1f - br.y); v[3].y = Mathf.Min(tl.y + br.y, -1f); } uv[0] = new Vector2(mOuterUV.xMin, mOuterUV.yMax); uv[1] = new Vector2(mInnerUV.xMin, mInnerUV.yMax); uv[2] = new Vector2(mInnerUV.xMax, mInnerUV.yMin); uv[3] = new Vector2(mOuterUV.xMax, mOuterUV.yMin); } else { // No texture -- just use zeroed out texture coordinates for (int i = 0; i < 4; ++i) { uv[i] = Vector2.zero; } } for (int x = 0; x < 3; ++x) { int x2 = x + 1; for (int y = 0; y < 3; ++y) { if (!mFillCenter && x == 1 && y == 1) { continue; } int y2 = y + 1; verts.Add(new Vector3(v[x2].x, v[y].y, 0f)); verts.Add(new Vector3(v[x2].x, v[y2].y, 0f)); verts.Add(new Vector3(v[x].x, v[y2].y, 0f)); verts.Add(new Vector3(v[x].x, v[y].y, 0f)); uvs.Add(new Vector2(uv[x2].x, uv[y].y)); uvs.Add(new Vector2(uv[x2].x, uv[y2].y)); uvs.Add(new Vector2(uv[x].x, uv[y2].y)); uvs.Add(new Vector2(uv[x].x, uv[y].y)); cols.Add(color); cols.Add(color); cols.Add(color); cols.Add(color); } } }
/// <summary> /// Filled sprite fill function. /// </summary> void FilledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (mFillAmount < 0.001f) { return; } Vector4 v = drawingDimensions; Vector4 u = drawingUVs; Color32 c = drawingColor; // Horizontal and vertical filled sprites are simple -- just end the sprite prematurely if (mFillDirection == FillDirection.Horizontal || mFillDirection == FillDirection.Vertical) { if (mFillDirection == FillDirection.Horizontal) { float fill = (u.z - u.x) * mFillAmount; if (mInvert) { v.x = v.z - (v.z - v.x) * mFillAmount; u.x = u.z - fill; } else { v.z = v.x + (v.z - v.x) * mFillAmount; u.z = u.x + fill; } } else if (mFillDirection == FillDirection.Vertical) { float fill = (u.w - u.y) * mFillAmount; if (mInvert) { v.y = v.w - (v.w - v.y) * mFillAmount; u.y = u.w - fill; } else { v.w = v.y + (v.w - v.y) * mFillAmount; u.w = u.y + fill; } } } mTempPos[0] = new Vector2(v.x, v.y); mTempPos[1] = new Vector2(v.x, v.w); mTempPos[2] = new Vector2(v.z, v.w); mTempPos[3] = new Vector2(v.z, v.y); mTempUVs[0] = new Vector2(u.x, u.y); mTempUVs[1] = new Vector2(u.x, u.w); mTempUVs[2] = new Vector2(u.z, u.w); mTempUVs[3] = new Vector2(u.z, u.y); if (mFillAmount < 1f) { if (mFillDirection == FillDirection.Radial90) { if (RadialCut(mTempPos, mTempUVs, mFillAmount, mInvert, 0)) { for (int i = 0; i < 4; ++i) { verts.Add(mTempPos[i]); uvs.Add(mTempUVs[i]); cols.Add(c); } } return; } if (mFillDirection == FillDirection.Radial180) { for (int side = 0; side < 2; ++side) { float fx0, fx1, fy0, fy1; fy0 = 0f; fy1 = 1f; if (side == 0) { fx0 = 0f; fx1 = 0.5f; } else { fx0 = 0.5f; fx1 = 1f; } mTempPos[0].x = Mathf.Lerp(v.x, v.z, fx0); mTempPos[1].x = mTempPos[0].x; mTempPos[2].x = Mathf.Lerp(v.x, v.z, fx1); mTempPos[3].x = mTempPos[2].x; mTempPos[0].y = Mathf.Lerp(v.y, v.w, fy0); mTempPos[1].y = Mathf.Lerp(v.y, v.w, fy1); mTempPos[2].y = mTempPos[1].y; mTempPos[3].y = mTempPos[0].y; mTempUVs[0].x = Mathf.Lerp(u.x, u.z, fx0); mTempUVs[1].x = mTempUVs[0].x; mTempUVs[2].x = Mathf.Lerp(u.x, u.z, fx1); mTempUVs[3].x = mTempUVs[2].x; mTempUVs[0].y = Mathf.Lerp(u.y, u.w, fy0); mTempUVs[1].y = Mathf.Lerp(u.y, u.w, fy1); mTempUVs[2].y = mTempUVs[1].y; mTempUVs[3].y = mTempUVs[0].y; float val = !mInvert ? fillAmount * 2f - side : mFillAmount * 2f - (1 - side); if (RadialCut(mTempPos, mTempUVs, Mathf.Clamp01(val), !mInvert, NGUIMath.RepeatIndex(side + 3, 4))) { for (int i = 0; i < 4; ++i) { verts.Add(mTempPos[i]); uvs.Add(mTempUVs[i]); cols.Add(c); } } } return; } if (mFillDirection == FillDirection.Radial360) { for (int corner = 0; corner < 4; ++corner) { float fx0, fx1, fy0, fy1; if (corner < 2) { fx0 = 0f; fx1 = 0.5f; } else { fx0 = 0.5f; fx1 = 1f; } if (corner == 0 || corner == 3) { fy0 = 0f; fy1 = 0.5f; } else { fy0 = 0.5f; fy1 = 1f; } mTempPos[0].x = Mathf.Lerp(v.x, v.z, fx0); mTempPos[1].x = mTempPos[0].x; mTempPos[2].x = Mathf.Lerp(v.x, v.z, fx1); mTempPos[3].x = mTempPos[2].x; mTempPos[0].y = Mathf.Lerp(v.y, v.w, fy0); mTempPos[1].y = Mathf.Lerp(v.y, v.w, fy1); mTempPos[2].y = mTempPos[1].y; mTempPos[3].y = mTempPos[0].y; mTempUVs[0].x = Mathf.Lerp(u.x, u.z, fx0); mTempUVs[1].x = mTempUVs[0].x; mTempUVs[2].x = Mathf.Lerp(u.x, u.z, fx1); mTempUVs[3].x = mTempUVs[2].x; mTempUVs[0].y = Mathf.Lerp(u.y, u.w, fy0); mTempUVs[1].y = Mathf.Lerp(u.y, u.w, fy1); mTempUVs[2].y = mTempUVs[1].y; mTempUVs[3].y = mTempUVs[0].y; float val = mInvert ? mFillAmount * 4f - NGUIMath.RepeatIndex(corner + 2, 4) : mFillAmount * 4f - (3 - NGUIMath.RepeatIndex(corner + 2, 4)); if (RadialCut(mTempPos, mTempUVs, Mathf.Clamp01(val), mInvert, NGUIMath.RepeatIndex(corner + 2, 4))) { for (int i = 0; i < 4; ++i) { verts.Add(mTempPos[i]); uvs.Add(mTempUVs[i]); cols.Add(c); } } } return; } } // Fill the buffer with the quad for the sprite for (int i = 0; i < 4; ++i) { verts.Add(mTempPos[i]); uvs.Add(mTempUVs[i]); cols.Add(c); } }
/// <summary> /// Tiled sprite fill function. /// </summary> void TiledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { Texture tex = mainTexture; if (tex == null) { return; } Vector2 size = new Vector2(mInnerUV.width * tex.width, mInnerUV.height * tex.height); size *= pixelSize; if (tex == null || size.x < 2f || size.y < 2f) { return; } Color32 c = drawingColor; Vector4 v = drawingDimensions; Vector4 u; if (mFlip == Flip.Horizontally || mFlip == Flip.Both) { u.x = mInnerUV.xMax; u.z = mInnerUV.xMin; } else { u.x = mInnerUV.xMin; u.z = mInnerUV.xMax; } if (mFlip == Flip.Vertically || mFlip == Flip.Both) { u.y = mInnerUV.yMax; u.w = mInnerUV.yMin; } else { u.y = mInnerUV.yMin; u.w = mInnerUV.yMax; } float x0 = v.x; float y0 = v.y; float u0 = u.x; float v0 = u.y; while (y0 < v.w) { x0 = v.x; float y1 = y0 + size.y; float v1 = u.w; if (y1 > v.w) { v1 = Mathf.Lerp(u.y, u.w, (v.w - y0) / size.y); y1 = v.w; } while (x0 < v.z) { float x1 = x0 + size.x; float u1 = u.z; if (x1 > v.z) { u1 = Mathf.Lerp(u.x, u.z, (v.z - x0) / size.x); x1 = v.z; } verts.Add(new Vector3(x0, y0)); verts.Add(new Vector3(x0, y1)); verts.Add(new Vector3(x1, y1)); verts.Add(new Vector3(x1, y0)); uvs.Add(new Vector2(u0, v0)); uvs.Add(new Vector2(u0, v1)); uvs.Add(new Vector2(u1, v1)); uvs.Add(new Vector2(u1, v0)); cols.Add(c); cols.Add(c); cols.Add(c); cols.Add(c); x0 += size.x; } y0 += size.y; } }
/// <summary> /// Sliced sprite fill function is more complicated as it generates 9 quads instead of 1. /// </summary> void SlicedFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { Vector4 br = border * pixelSize; if (br.x == 0f && br.y == 0f && br.z == 0f && br.w == 0f) { SimpleFill(verts, uvs, cols); return; } Color32 c = drawingColor; Vector4 v = drawingDimensions; mTempPos[0].x = v.x; mTempPos[0].y = v.y; mTempPos[3].x = v.z; mTempPos[3].y = v.w; if (mFlip == Flip.Horizontally || mFlip == Flip.Both) { mTempPos[1].x = mTempPos[0].x + br.z; mTempPos[2].x = mTempPos[3].x - br.x; mTempUVs[3].x = mOuterUV.xMin; mTempUVs[2].x = mInnerUV.xMin; mTempUVs[1].x = mInnerUV.xMax; mTempUVs[0].x = mOuterUV.xMax; } else { mTempPos[1].x = mTempPos[0].x + br.x; mTempPos[2].x = mTempPos[3].x - br.z; mTempUVs[0].x = mOuterUV.xMin; mTempUVs[1].x = mInnerUV.xMin; mTempUVs[2].x = mInnerUV.xMax; mTempUVs[3].x = mOuterUV.xMax; } if (mFlip == Flip.Vertically || mFlip == Flip.Both) { mTempPos[1].y = mTempPos[0].y + br.w; mTempPos[2].y = mTempPos[3].y - br.y; mTempUVs[3].y = mOuterUV.yMin; mTempUVs[2].y = mInnerUV.yMin; mTempUVs[1].y = mInnerUV.yMax; mTempUVs[0].y = mOuterUV.yMax; } else { mTempPos[1].y = mTempPos[0].y + br.y; mTempPos[2].y = mTempPos[3].y - br.w; mTempUVs[0].y = mOuterUV.yMin; mTempUVs[1].y = mInnerUV.yMin; mTempUVs[2].y = mInnerUV.yMax; mTempUVs[3].y = mOuterUV.yMax; } for (int x = 0; x < 3; ++x) { int x2 = x + 1; for (int y = 0; y < 3; ++y) { if (centerType == AdvancedType.Invisible && x == 1 && y == 1) { continue; } int y2 = y + 1; verts.Add(new Vector3(mTempPos[x].x, mTempPos[y].y)); verts.Add(new Vector3(mTempPos[x].x, mTempPos[y2].y)); verts.Add(new Vector3(mTempPos[x2].x, mTempPos[y2].y)); verts.Add(new Vector3(mTempPos[x2].x, mTempPos[y].y)); uvs.Add(new Vector2(mTempUVs[x].x, mTempUVs[y].y)); uvs.Add(new Vector2(mTempUVs[x].x, mTempUVs[y2].y)); uvs.Add(new Vector2(mTempUVs[x2].x, mTempUVs[y2].y)); uvs.Add(new Vector2(mTempUVs[x2].x, mTempUVs[y].y)); cols.Add(c); cols.Add(c); cols.Add(c); cols.Add(c); } } }
/// <summary> /// Search the entire project for required assets. /// </summary> void Search() { mSearched = true; if (mExtensions != null) { string[] paths = AssetDatabase.GetAllAssetPaths(); bool isComponent = mType.IsSubclassOf(typeof(Component)); BetterList <Object> list = new BetterList <Object>(); for (int i = 0; i < mObjects.Length; ++i) { if (mObjects[i] != null) { list.Add(mObjects[i]); } } for (int i = 0; i < paths.Length; ++i) { string path = paths[i]; bool valid = false; for (int b = 0; b < mExtensions.Length; ++b) { if (path.EndsWith(mExtensions[b], System.StringComparison.OrdinalIgnoreCase)) { valid = true; break; } } if (!valid) { continue; } EditorUtility.DisplayProgressBar("Loading", "Searching assets, please wait...", (float)i / paths.Length); Object obj = AssetDatabase.LoadMainAssetAtPath(path); if (obj == null || list.Contains(obj)) { continue; } if (!isComponent) { System.Type t = obj.GetType(); if (t == mType || t.IsSubclassOf(mType) && !list.Contains(obj)) { list.Add(obj); } } else if (PrefabUtility.GetPrefabType(obj) == PrefabType.Prefab) { Object t = (obj as GameObject).GetComponent(mType); if (t != null && !list.Contains(t)) { list.Add(t); } } } list.Sort(delegate(Object a, Object b) { return(a.name.CompareTo(b.name)); }); mObjects = list.ToArray(); } EditorUtility.ClearProgressBar(); }
public void Print(string text, Color32 color, BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols, bool encoding, UIFont.SymbolStyle symbolStyle, UIFont.Alignment alignment, int lineWidth, bool premultiply) { if (this.mReplacement != null) { this.mReplacement.Print(text, color, verts, uvs, cols, encoding, symbolStyle, alignment, lineWidth, premultiply); } else if (text != null) { if (!this.isValid) { Debug.LogError("Attempting to print using an invalid font!"); return; } bool isDynamic = this.isDynamic; if (isDynamic) { this.mDynamicFont.textureRebuildCallback = new Font.FontTextureRebuildCallback(this.OnFontChanged); this.mDynamicFont.RequestCharactersInTexture(text, this.mDynamicFontSize, this.mDynamicFontStyle); this.mDynamicFont.textureRebuildCallback = null; } this.mColors.Clear(); this.mColors.Add(color); int size = this.size; Vector2 vector = (size <= 0) ? Vectors.v2one : new Vector2(1f / (float)size, 1f / (float)size); int size2 = verts.size; int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; int num5 = size + this.mSpacingY; Vector3 zero = Vectors.zero; Vector3 zero2 = Vectors.zero; Vector2 zero3 = Vectors.v2zero; Vector2 zero4 = Vectors.v2zero; float num6 = this.uvRect.width / (float)this.mFont.texWidth; float num7 = this.mUVRect.height / (float)this.mFont.texHeight; int length = text.Length; bool flag = encoding && symbolStyle != UIFont.SymbolStyle.None && this.hasSymbols && this.sprite != null; for (int i = 0; i < length; i++) { char c = text[i]; if (c == '\n') { if (num2 > num) { num = num2; } if (alignment != UIFont.Alignment.Left) { this.Align(verts, size2, alignment, num2, lineWidth); size2 = verts.size; } num2 = 0; num3 += num5; num4 = 0; } else if (c < ' ') { num4 = 0; } else { if (encoding && c == '[') { int num8 = NGUITools.ParseSymbol(text, i, this.mColors, premultiply); if (num8 > 0) { color = this.mColors[this.mColors.Count - 1]; i += num8 - 1; goto IL_96C; } } if (!isDynamic) { BMSymbol bmsymbol = (!flag) ? null : this.MatchSymbol(text, i, length); if (bmsymbol == null) { BMGlyph glyph = this.mFont.GetGlyph((int)c); if (glyph == null) { goto IL_96C; } if (num4 != 0) { num2 += glyph.GetKerning(num4); } if (c == ' ') { num2 += this.mSpacingX + glyph.advance; num4 = (int)c; goto IL_96C; } zero.x = vector.x * (float)(num2 + glyph.offsetX); zero.y = -vector.y * (float)(num3 + glyph.offsetY); zero2.x = zero.x + vector.x * (float)glyph.width; zero2.y = zero.y - vector.y * (float)glyph.height; zero3.x = this.mUVRect.xMin + num6 * (float)glyph.x; zero3.y = this.mUVRect.yMax - num7 * (float)glyph.y; zero4.x = zero3.x + num6 * (float)glyph.width; zero4.y = zero3.y - num7 * (float)glyph.height; num2 += this.mSpacingX + glyph.advance; num4 = (int)c; if (glyph.channel == 0 || glyph.channel == 15) { for (int j = 0; j < 4; j++) { cols.Add(color); } } else { Color color2 = color; color2 *= 0.49f; switch (glyph.channel) { case 1: color2.b += 0.51f; break; case 2: color2.g += 0.51f; break; case 4: color2.r += 0.51f; break; case 8: color2.a += 0.51f; break; } for (int k = 0; k < 4; k++) { cols.Add(color2); } } } else { zero.x = vector.x * (float)(num2 + bmsymbol.offsetX); zero.y = -vector.y * (float)(num3 + bmsymbol.offsetY); zero2.x = zero.x + vector.x * (float)bmsymbol.width; zero2.y = zero.y - vector.y * (float)bmsymbol.height; Rect uvRect = bmsymbol.uvRect; zero3.x = uvRect.xMin; zero3.y = uvRect.yMax; zero4.x = uvRect.xMax; zero4.y = uvRect.yMin; num2 += this.mSpacingX + bmsymbol.advance; i += bmsymbol.length - 1; num4 = 0; if (symbolStyle == UIFont.SymbolStyle.Colored) { for (int l = 0; l < 4; l++) { cols.Add(color); } } else { Color32 item = Color.white; item.a = color.a; for (int m = 0; m < 4; m++) { cols.Add(item); } } } verts.Add(new Vector3(zero2.x, zero.y)); verts.Add(new Vector3(zero2.x, zero2.y)); verts.Add(new Vector3(zero.x, zero2.y)); verts.Add(new Vector3(zero.x, zero.y)); uvs.Add(new Vector2(zero4.x, zero3.y)); uvs.Add(new Vector2(zero4.x, zero4.y)); uvs.Add(new Vector2(zero3.x, zero4.y)); uvs.Add(new Vector2(zero3.x, zero3.y)); } else if (this.mDynamicFont.GetCharacterInfo(c, out UIFont.mChar, this.mDynamicFontSize, this.mDynamicFontStyle)) { zero.x = vector.x * ((float)num2 + UIFont.mChar.vert.xMin); zero.y = -vector.y * ((float)num3 - UIFont.mChar.vert.yMax + this.mDynamicFontOffset); zero2.x = zero.x + vector.x * UIFont.mChar.vert.width; zero2.y = zero.y - vector.y * UIFont.mChar.vert.height; zero3.x = UIFont.mChar.uv.xMin; zero3.y = UIFont.mChar.uv.yMin; zero4.x = UIFont.mChar.uv.xMax; zero4.y = UIFont.mChar.uv.yMax; num2 += this.mSpacingX + (int)UIFont.mChar.width; for (int n = 0; n < 4; n++) { cols.Add(color); } if (UIFont.mChar.flipped) { uvs.Add(new Vector2(zero3.x, zero4.y)); uvs.Add(new Vector2(zero3.x, zero3.y)); uvs.Add(new Vector2(zero4.x, zero3.y)); uvs.Add(new Vector2(zero4.x, zero4.y)); } else { uvs.Add(new Vector2(zero4.x, zero3.y)); uvs.Add(new Vector2(zero3.x, zero3.y)); uvs.Add(new Vector2(zero3.x, zero4.y)); uvs.Add(new Vector2(zero4.x, zero4.y)); } verts.Add(new Vector3(zero2.x, zero.y)); verts.Add(new Vector3(zero.x, zero.y)); verts.Add(new Vector3(zero.x, zero2.y)); verts.Add(new Vector3(zero2.x, zero2.y)); } } IL_96C :; } if (alignment != UIFont.Alignment.Left && size2 < verts.size) { this.Align(verts, size2, alignment, num2, lineWidth); size2 = verts.size; } } }
//ToDo 之后需要这里添加判别回复类型,现在默认为文字 public static int newRequest(BGIRequestResult requestResult, RequestType inType, string url, int tag = 0, float inHttpTimeOut = 20f, bool nolimit = false, bool noCache = false) { reqid++; //Debug.Log(url); if (mInstance == null) { mInstance = new GameObject("_BGHTTP_AGENT"); GameObject.DontDestroyOnLoad(mInstance); UpdateManager.AddLateUpdate(null, 0, OnUpdate); } //构造requestResult if (requestResult == null) { } //队列尚有空余加之 //if(requests.size<ListLimit)mInstance = go.AddComponent<BGHttpRequest>(); if (noCache) { removeCache(url); } else if (inType == RequestType.IMAGE) { byte[] res = getCache(url); if (res != null) { //MonoBehaviour.print("cached::::"+url); Texture2D imgTexture = new Texture2D(256, 256, TextureFormat.ARGB32, false); // imgTexture.anisoLevel = 9; imgTexture.wrapMode = TextureWrapMode.Clamp; // imgTexture.filterMode = FilterMode.Trilinear; // imgTexture.anisoLevel = 3; imgTexture.LoadImage(res); requestResult.requestSuccessedTexture(imgTexture, tag); return(reqid); } // DownloadImgTest.DownloadTexture(requestResult,url,tag); // GameObject.Find("LoginSceneManager").GetComponent<LoginSceneManager>().DownloadTexture(requestResult,url,tag); // return reqid; } if (inType == RequestType.TEXT) { nolimit = true; } //add new if (requests.size < ListLimit || nolimit) { BGHttpRequest request = new BGHttpRequest(requestResult, inHttpTimeOut, inType); request.requestURLN(url, tag); request.taskid = reqid; requests.Add(request); } else { RequestTask task = new RequestTask(); task.inHttpTimeOut = inHttpTimeOut; task.inType = inType; task.requestResult = requestResult; task.tag = tag; task.url = url; task.taskid = reqid; tasks.Add(task); } return(reqid); }
public void Print(string text, Color32 color, BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols, bool encoding, SymbolStyle symbolStyle, Alignment alignment, int lineWidth, bool premultiply) { if (mReplacement != null) { mReplacement.Print(text, color, verts, uvs, cols, encoding, symbolStyle, alignment, lineWidth, premultiply); } else if (text != null) { if (!isValid) { Debug.LogError("Attempting to print using an invalid font!"); } else { var isDynamic = this.isDynamic; if (isDynamic) { mDynamicFont.textureRebuildCallback = OnFontChanged; mDynamicFont.RequestCharactersInTexture(text, mDynamicFontSize, mDynamicFontStyle); mDynamicFont.textureRebuildCallback = null; } mColors.Clear(); mColors.Add(color); var size = this.size; var vector = size <= 0 ? Vector2.one : new Vector2(1f / size, 1f / size); var indexOffset = verts.size; var num3 = 0; var x = 0; var num5 = 0; var previousChar = 0; var num7 = size + mSpacingY; var zero = Vector3.zero; var vector3 = Vector3.zero; var vector4 = Vector2.zero; var vector5 = Vector2.zero; var num8 = this.uvRect.width / mFont.texWidth; var num9 = mUVRect.height / mFont.texHeight; var length = text.Length; var flag2 = encoding && symbolStyle != SymbolStyle.None && hasSymbols && sprite != null; for (var i = 0; i < length; i++) { var index = text[i]; if (index == '\n') { if (x > num3) { num3 = x; } if (alignment != Alignment.Left) { Align(verts, indexOffset, alignment, x, lineWidth); indexOffset = verts.size; } x = 0; num5 += num7; previousChar = 0; continue; } if (index < ' ') { previousChar = 0; continue; } if (encoding && index == '[') { var num12 = NGUITools.ParseSymbol(text, i, mColors, premultiply); if (num12 > 0) { color = mColors[mColors.Count - 1]; i += num12 - 1; continue; } } if (!isDynamic) { var symbol = !flag2 ? null : MatchSymbol(text, i, length); if (symbol == null) { var glyph = mFont.GetGlyph(index); if (glyph == null) { continue; } if (previousChar != 0) { x += glyph.GetKerning(previousChar); } if (index == ' ') { x += mSpacingX + glyph.advance; previousChar = index; continue; } zero.x = vector.x * (x + glyph.offsetX); zero.y = -vector.y * (num5 + glyph.offsetY); vector3.x = zero.x + vector.x * glyph.width; vector3.y = zero.y - vector.y * glyph.height; vector4.x = mUVRect.xMin + num8 * glyph.x; vector4.y = mUVRect.yMax - num9 * glyph.y; vector5.x = vector4.x + num8 * glyph.width; vector5.y = vector4.y - num9 * glyph.height; x += mSpacingX + glyph.advance; previousChar = index; if (glyph.channel == 0 || glyph.channel == 15) { for (var j = 0; j < 4; j++) { cols.Add(color); } } else { Color item = color; item = item * 0.49f; switch (glyph.channel) { case 1: item.b += 0.51f; break; case 2: item.g += 0.51f; break; case 4: item.r += 0.51f; break; case 8: item.a += 0.51f; break; } for (var k = 0; k < 4; k++) { cols.Add(item); } } } else { zero.x = vector.x * (x + symbol.offsetX); zero.y = -vector.y * (num5 + symbol.offsetY); vector3.x = zero.x + vector.x * symbol.width; vector3.y = zero.y - vector.y * symbol.height; var uvRect = symbol.uvRect; vector4.x = uvRect.xMin; vector4.y = uvRect.yMax; vector5.x = uvRect.xMax; vector5.y = uvRect.yMin; x += mSpacingX + symbol.advance; i += symbol.length - 1; previousChar = 0; if (symbolStyle == SymbolStyle.Colored) { for (var m = 0; m < 4; m++) { cols.Add(color); } } else { Color32 white = Color.white; white.a = color.a; for (var n = 0; n < 4; n++) { cols.Add(white); } } } verts.Add(new Vector3(vector3.x, zero.y)); verts.Add(new Vector3(vector3.x, vector3.y)); verts.Add(new Vector3(zero.x, vector3.y)); verts.Add(new Vector3(zero.x, zero.y)); uvs.Add(new Vector2(vector5.x, vector4.y)); uvs.Add(new Vector2(vector5.x, vector5.y)); uvs.Add(new Vector2(vector4.x, vector5.y)); uvs.Add(new Vector2(vector4.x, vector4.y)); continue; } if (mDynamicFont.GetCharacterInfo(index, out mChar, mDynamicFontSize, mDynamicFontStyle)) { zero.x = vector.x * (x + mChar.vert.xMin); zero.y = -vector.y * (num5 - mChar.vert.yMax + mDynamicFontOffset); vector3.x = zero.x + vector.x * mChar.vert.width; vector3.y = zero.y - vector.y * mChar.vert.height; vector4.x = mChar.uv.xMin; vector4.y = mChar.uv.yMin; vector5.x = mChar.uv.xMax; vector5.y = mChar.uv.yMax; x += mSpacingX + (int)mChar.width; for (var num18 = 0; num18 < 4; num18++) { cols.Add(color); } if (mChar.flipped) { uvs.Add(new Vector2(vector4.x, vector5.y)); uvs.Add(new Vector2(vector4.x, vector4.y)); uvs.Add(new Vector2(vector5.x, vector4.y)); uvs.Add(new Vector2(vector5.x, vector5.y)); } else { uvs.Add(new Vector2(vector5.x, vector4.y)); uvs.Add(new Vector2(vector4.x, vector4.y)); uvs.Add(new Vector2(vector4.x, vector5.y)); uvs.Add(new Vector2(vector5.x, vector5.y)); } verts.Add(new Vector3(vector3.x, zero.y)); verts.Add(new Vector3(zero.x, zero.y)); verts.Add(new Vector3(zero.x, vector3.y)); verts.Add(new Vector3(vector3.x, vector3.y)); } } if (alignment != Alignment.Left && indexOffset < verts.size) { Align(verts, indexOffset, alignment, x, lineWidth); indexOffset = verts.size; } } } }
/// <summary> /// Tiled sprite fill function. /// </summary> protected void TiledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { Texture tex = material.mainTexture; if (tex == null) { return; } Vector2 size = new Vector2(mInnerUV.width * tex.width, mInnerUV.height * tex.height); size *= atlas.pixelSize; float width = Mathf.Abs(size.x / mWidth); float height = Mathf.Abs(size.y / mHeight); if (width * height < 0.0001f) { width = 0.01f; height = 0.01f; } Color colF = color; colF.a *= mPanel.finalAlpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; Vector2 pv = pivotOffset; Vector2 min = new Vector2(mInnerUV.xMin, mInnerUV.yMin); Vector2 max = new Vector2(mInnerUV.xMax, mInnerUV.yMax); Vector2 clipped = max; float y1 = 0f; while (y1 < 1f) { float x1 = 0f; clipped.x = max.x; float y2 = y1 + height; if (y2 > 1f) { clipped.y = min.y + (max.y - min.y) * (1f - y1) / (y2 - y1); y2 = 1f; } while (x1 < 1f) { float x2 = x1 + width; if (x2 > 1f) { clipped.x = min.x + (max.x - min.x) * (1f - x1) / (x2 - x1); x2 = 1f; } // Convert from normalized (0-1 range) coordinates to pixels float fx1 = (x1 - pv.x) * mWidth; float fx2 = (x2 - pv.x) * mWidth; float fy1 = (y1 - pv.y) * mHeight; float fy2 = (y2 - pv.y) * mHeight; verts.Add(new Vector3(fx1, fy1)); verts.Add(new Vector3(fx1, fy2)); verts.Add(new Vector3(fx2, fy2)); verts.Add(new Vector3(fx2, fy1)); uvs.Add(new Vector2(min.x, min.y)); uvs.Add(new Vector2(min.x, clipped.y)); uvs.Add(new Vector2(clipped.x, clipped.y)); uvs.Add(new Vector2(clipped.x, min.y)); cols.Add(col); cols.Add(col); cols.Add(col); cols.Add(col); x1 += width; } y1 += height; } }
/// <summary> /// Draw the widget. /// </summary> override public void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color> cols) { if (mOuterUV == mInnerUV) { base.OnFill(verts, uvs, cols); return; } Vector4 dr = drawingDimensions; if (dr.x == dr.z || dr.y == dr.w) { return; } Vector4 br = border * atlas.pixelSize; mTempPos[0].x = dr.x; mTempPos[0].y = dr.y; mTempPos[3].x = dr.z; mTempPos[3].y = dr.w; mTempPos[1].x = mTempPos[0].x + br.x; mTempPos[1].y = mTempPos[0].y + br.y; mTempPos[2].x = mTempPos[3].x - br.z; mTempPos[2].y = mTempPos[3].y - br.w; mTempUVs[0] = new Vector2(mOuterUV.xMin, mOuterUV.yMin); mTempUVs[1] = new Vector2(mInnerUV.xMin, mInnerUV.yMin); mTempUVs[2] = new Vector2(mInnerUV.xMax, mInnerUV.yMax); mTempUVs[3] = new Vector2(mOuterUV.xMax, mOuterUV.yMax); for (int x = 0; x < 3; ++x) { int x2 = x + 1; for (int y = 0; y < 3; ++y) { if (!mFillCenter && x == 1 && y == 1) { continue; } int y2 = y + 1; verts.Add(new Vector3(mTempPos[x].x, mTempPos[y].y)); verts.Add(new Vector3(mTempPos[x].x, mTempPos[y2].y)); verts.Add(new Vector3(mTempPos[x2].x, mTempPos[y2].y)); verts.Add(new Vector3(mTempPos[x2].x, mTempPos[y].y)); uvs.Add(new Vector2(mTempUVs[x].x, mTempUVs[y].y)); uvs.Add(new Vector2(mTempUVs[x].x, mTempUVs[y2].y)); uvs.Add(new Vector2(mTempUVs[x2].x, mTempUVs[y2].y)); uvs.Add(new Vector2(mTempUVs[x2].x, mTempUVs[y].y)); cols.Add(color); cols.Add(color); cols.Add(color); cols.Add(color); } } }
void OnEnable() { list.Add(this); }
private void TiledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { Texture mainTexture = this.mainTexture; if (mainTexture == null) { return; } Vector2 a = new Vector2(this.mInnerUV.width * (float)mainTexture.width, this.mInnerUV.height * (float)mainTexture.height); a *= this.pixelSize; if (mainTexture == null || a.x < 2f || a.y < 2f) { return; } Color32 drawingColor = this.drawingColor; Vector4 drawingDimensions = this.drawingDimensions; Vector4 vector; if (this.mFlip == UIBasicSprite.Flip.Horizontally || this.mFlip == UIBasicSprite.Flip.Both) { vector.x = this.mInnerUV.xMax; vector.z = this.mInnerUV.xMin; } else { vector.x = this.mInnerUV.xMin; vector.z = this.mInnerUV.xMax; } if (this.mFlip == UIBasicSprite.Flip.Vertically || this.mFlip == UIBasicSprite.Flip.Both) { vector.y = this.mInnerUV.yMax; vector.w = this.mInnerUV.yMin; } else { vector.y = this.mInnerUV.yMin; vector.w = this.mInnerUV.yMax; } float num = drawingDimensions.x; float num2 = drawingDimensions.y; float x = vector.x; float y = vector.y; while (num2 < drawingDimensions.w) { num = drawingDimensions.x; float num3 = num2 + a.y; float y2 = vector.w; if (num3 > drawingDimensions.w) { y2 = Mathf.Lerp(vector.y, vector.w, (drawingDimensions.w - num2) / a.y); num3 = drawingDimensions.w; } while (num < drawingDimensions.z) { float num4 = num + a.x; float x2 = vector.z; if (num4 > drawingDimensions.z) { x2 = Mathf.Lerp(vector.x, vector.z, (drawingDimensions.z - num) / a.x); num4 = drawingDimensions.z; } verts.Add(new Vector3(num, num2)); verts.Add(new Vector3(num, num3)); verts.Add(new Vector3(num4, num3)); verts.Add(new Vector3(num4, num2)); uvs.Add(new Vector2(x, y)); uvs.Add(new Vector2(x, y2)); uvs.Add(new Vector2(x2, y2)); uvs.Add(new Vector2(x2, y)); cols.Add(drawingColor); cols.Add(drawingColor); cols.Add(drawingColor); cols.Add(drawingColor); num += a.x; } num2 += a.y; } }
/// <summary> /// Print the caret and selection vertices. Note that it's expected that 'text' has been stripped clean of symbols. /// </summary> static public void PrintCaretAndSelection(string text, int start, int end, BetterList <Vector3> caret, BetterList <Vector3> highlight) { if (string.IsNullOrEmpty(text)) { text = " "; } Prepare(text); int caretPos = end; if (start > end) { end = start; start = caretPos; } float x = 0f, y = 0f, maxX = 0f, fs = fontSize * fontScale; int caretOffset = (caret != null) ? caret.size : 0; int highlightOffset = (highlight != null) ? highlight.size : 0; int textLength = text.Length, index = 0, ch = 0, prev = 0; bool highlighting = false, caretSet = false; Vector2 last0 = Vector2.zero; Vector2 last1 = Vector2.zero; for (; index < textLength; ++index) { // Print the caret if (caret != null && !caretSet && caretPos <= index) { caretSet = true; caret.Add(new Vector3(x - 1f, -y - fs)); caret.Add(new Vector3(x - 1f, -y)); caret.Add(new Vector3(x + 1f, -y)); caret.Add(new Vector3(x + 1f, -y - fs)); } ch = text[index]; if (ch == '\n') { // Used for alignment purposes if (x > maxX) { maxX = x; } // Align the caret if (caret != null && caretSet) { if (NGUIText.alignment != TextAlignment.Left) { NGUIText.Align(caret, caretOffset, x - finalSpacingX); } caret = null; } if (highlight != null) { if (highlighting) { // Close the selection on this line highlighting = false; highlight.Add(last1); highlight.Add(last0); } else if (start <= index && end > index) { // This must be an empty line. Add a narrow vertical highlight. highlight.Add(new Vector3(x, -y - fs)); highlight.Add(new Vector3(x, -y)); highlight.Add(new Vector3(x + 2f, -y)); highlight.Add(new Vector3(x + 2f, -y - fs)); } // Align the highlight if (NGUIText.alignment != TextAlignment.Left && highlightOffset < highlight.size) { NGUIText.Align(highlight, highlightOffset, x - finalSpacingX); highlightOffset = highlight.size; } } x = 0; y += finalLineHeight; prev = 0; continue; } else if (ch < ' ') { prev = 0; continue; } if (encoding && ParseSymbol(text, ref index)) { --index; continue; } // See if there is a symbol matching this text BMSymbol symbol = useSymbols ? GetSymbol(text, index, textLength) : null; float w = (symbol != null) ? symbol.advance * fontScale : GetGlyphWidth(ch, prev); if (w != 0f) { float v0x = x; float v1x = x + w; float v0y = -y - fs; float v1y = -y; x += w + finalSpacingX; // Print the highlight if (highlight != null) { if (start > index || end <= index) { if (highlighting) { // Finish the highlight highlighting = false; highlight.Add(last1); highlight.Add(last0); } } else if (!highlighting) { // Start the highlight highlighting = true; highlight.Add(new Vector3(v0x, v0y)); highlight.Add(new Vector3(v0x, v1y)); } } // Save what the character ended with last0 = new Vector2(v1x, v0y); last1 = new Vector2(v1x, v1y); prev = ch; } } // Ensure we always have a caret if (caret != null) { if (!caretSet) { caret.Add(new Vector3(x - 1f, -y - fs)); caret.Add(new Vector3(x - 1f, -y)); caret.Add(new Vector3(x + 1f, -y)); caret.Add(new Vector3(x + 1f, -y - fs)); } if (NGUIText.alignment != TextAlignment.Left) { NGUIText.Align(caret, caretOffset, x - finalSpacingX); } } // Close the selection if (highlight != null) { if (highlighting) { // Finish the highlight highlight.Add(last1); highlight.Add(last0); } else if (start < index && end == index) { // Happens when highlight ends on an empty line. Highlight it with a thin line. highlight.Add(new Vector3(x, -y - fs)); highlight.Add(new Vector3(x, -y)); highlight.Add(new Vector3(x + 2f, -y)); highlight.Add(new Vector3(x + 2f, -y - fs)); } // Align the highlight if (NGUIText.alignment != TextAlignment.Left && highlightOffset < highlight.size) { NGUIText.Align(highlight, highlightOffset, x - finalSpacingX); } } }
/// <summary> /// Parse an embedded symbol, such as [FFAA00] (set color) or [-] (undo color change). Returns whether the index was adjusted. /// </summary> static public bool ParseSymbol (string text, ref int index, BetterList<Color> colors, bool premultiply) { if (colors == null) return ParseSymbol(text, ref index); int length = text.Length; if (index + 2 < length && text[index] == '[') { if (text[index + 1] == '-') { if (text[index + 2] == ']') { if (colors != null && colors.size > 1) colors.RemoveAt(colors.size - 1); index += 3; return true; } } else if (index + 7 < length) { if (text[index + 7] == ']') { if (colors != null) { Color c = ParseColor(text, index + 1); if (EncodeColor(c) != text.Substring(index + 1, 6).ToUpper()) return false; c.a = colors[colors.size - 1].a; if (premultiply && c.a != 1f) c = Color.Lerp(mInvisible, c, c.a); colors.Add(c); } index += 8; return true; } } } return false; }
/// <summary> /// Convenience function that retrieves a list of all sprite names that contain the specified phrase /// </summary> public BetterList<string> GetListOfSprites(string match) { if (mReplacement != null) return mReplacement.GetListOfSprites(match); if (string.IsNullOrEmpty(match)) return GetListOfSprites(); if (mSprites.Count == 0) Upgrade(); BetterList<string> list = new BetterList<string>(); // First try to find an exact match for (int i = 0, imax = mSprites.Count; i < imax; ++i) { UISpriteData s = mSprites[i]; if (s != null && !string.IsNullOrEmpty(s.name) && string.Equals(match, s.name, StringComparison.OrdinalIgnoreCase)) { list.Add(s.name); return list; } } // No exact match found? Split up the search into space-separated components. string[] keywords = match.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < keywords.Length; ++i) keywords[i] = keywords[i].ToLower(); // Try to find all sprites where all keywords are present for (int i = 0, imax = mSprites.Count; i < imax; ++i) { UISpriteData s = mSprites[i]; if (s != null && !string.IsNullOrEmpty(s.name)) { string tl = s.name.ToLower(); int matches = 0; for (int b = 0; b < keywords.Length; ++b) { if (tl.Contains(keywords[b])) ++matches; } if (matches == keywords.Length) list.Add(s.name); } } return list; }
/// <summary> /// Tiled sprite fill function. /// </summary> protected void TiledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { Texture tex = material.mainTexture; if (tex == null) { return; } Vector4 v = drawingDimensions; Vector4 u; if (mFlip == Flip.Horizontally || mFlip == Flip.Both) { u.x = mInnerUV.xMax; u.z = mInnerUV.xMin; } else { u.x = mInnerUV.xMin; u.z = mInnerUV.xMax; } if (mFlip == Flip.Vertically || mFlip == Flip.Both) { u.y = mInnerUV.yMax; u.w = mInnerUV.yMin; } else { u.y = mInnerUV.yMin; u.w = mInnerUV.yMax; } Vector2 size = new Vector2(mInnerUV.width * tex.width, mInnerUV.height * tex.height); size *= atlas.pixelSize; Color colF = color; colF.a = finalAlpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; float x0 = v.x; float y0 = v.y; float u0 = u.x; float v0 = u.y; while (y0 < v.w) { x0 = v.x; float y1 = y0 + size.y; float v1 = u.w; if (y1 > v.w) { v1 = Mathf.Lerp(u.y, u.w, (v.w - y0) / size.y); y1 = v.w; } while (x0 < v.z) { float x1 = x0 + size.x; float u1 = u.z; if (x1 > v.z) { u1 = Mathf.Lerp(u.x, u.z, (v.z - x0) / size.x); x1 = v.z; } verts.Add(new Vector3(x0, y0)); verts.Add(new Vector3(x0, y1)); verts.Add(new Vector3(x1, y1)); verts.Add(new Vector3(x1, y0)); uvs.Add(new Vector2(u0, v0)); uvs.Add(new Vector2(u0, v1)); uvs.Add(new Vector2(u1, v1)); uvs.Add(new Vector2(u1, v0)); cols.Add(col); cols.Add(col); cols.Add(col); cols.Add(col); x0 += size.x; } y0 += size.y; } }
override public void OnFill (BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols) #endif { Vector2 uv0 = new Vector2(mOuterUV.xMin, mOuterUV.yMin); Vector2 uv1 = new Vector2(mOuterUV.xMax, mOuterUV.yMax); verts.Add(new Vector3(1f, 0f, 0f)); verts.Add(new Vector3(1f, -1f, 0f)); verts.Add(new Vector3(0f, -1f, 0f)); verts.Add(new Vector3(0f, 0f, 0f)); uvs.Add(uv1); uvs.Add(new Vector2(uv1.x, uv0.y)); uvs.Add(uv0); uvs.Add(new Vector2(uv0.x, uv1.y)); #if UNITY_3_5_4 Color col = color; #else Color32 col = color; #endif cols.Add(col); cols.Add(col); cols.Add(col); cols.Add(col); }
private void SlicedFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { Vector4 vector = this.border * this.pixelSize; if (vector.x == 0f && vector.y == 0f && vector.z == 0f && vector.w == 0f) { this.SimpleFill(verts, uvs, cols); return; } Color32 drawingColor = this.drawingColor; Vector4 drawingDimensions = this.drawingDimensions; UIBasicSprite.mTempPos[0].x = drawingDimensions.x; UIBasicSprite.mTempPos[0].y = drawingDimensions.y; UIBasicSprite.mTempPos[3].x = drawingDimensions.z; UIBasicSprite.mTempPos[3].y = drawingDimensions.w; if (this.mFlip == UIBasicSprite.Flip.Horizontally || this.mFlip == UIBasicSprite.Flip.Both) { UIBasicSprite.mTempPos[1].x = UIBasicSprite.mTempPos[0].x + vector.z; UIBasicSprite.mTempPos[2].x = UIBasicSprite.mTempPos[3].x - vector.x; UIBasicSprite.mTempUVs[3].x = this.mOuterUV.xMin; UIBasicSprite.mTempUVs[2].x = this.mInnerUV.xMin; UIBasicSprite.mTempUVs[1].x = this.mInnerUV.xMax; UIBasicSprite.mTempUVs[0].x = this.mOuterUV.xMax; } else { UIBasicSprite.mTempPos[1].x = UIBasicSprite.mTempPos[0].x + vector.x; UIBasicSprite.mTempPos[2].x = UIBasicSprite.mTempPos[3].x - vector.z; UIBasicSprite.mTempUVs[0].x = this.mOuterUV.xMin; UIBasicSprite.mTempUVs[1].x = this.mInnerUV.xMin; UIBasicSprite.mTempUVs[2].x = this.mInnerUV.xMax; UIBasicSprite.mTempUVs[3].x = this.mOuterUV.xMax; } if (this.mFlip == UIBasicSprite.Flip.Vertically || this.mFlip == UIBasicSprite.Flip.Both) { UIBasicSprite.mTempPos[1].y = UIBasicSprite.mTempPos[0].y + vector.w; UIBasicSprite.mTempPos[2].y = UIBasicSprite.mTempPos[3].y - vector.y; UIBasicSprite.mTempUVs[3].y = this.mOuterUV.yMin; UIBasicSprite.mTempUVs[2].y = this.mInnerUV.yMin; UIBasicSprite.mTempUVs[1].y = this.mInnerUV.yMax; UIBasicSprite.mTempUVs[0].y = this.mOuterUV.yMax; } else { UIBasicSprite.mTempPos[1].y = UIBasicSprite.mTempPos[0].y + vector.y; UIBasicSprite.mTempPos[2].y = UIBasicSprite.mTempPos[3].y - vector.w; UIBasicSprite.mTempUVs[0].y = this.mOuterUV.yMin; UIBasicSprite.mTempUVs[1].y = this.mInnerUV.yMin; UIBasicSprite.mTempUVs[2].y = this.mInnerUV.yMax; UIBasicSprite.mTempUVs[3].y = this.mOuterUV.yMax; } for (int i = 0; i < 3; i++) { int num = i + 1; for (int j = 0; j < 3; j++) { if (this.centerType != UIBasicSprite.AdvancedType.Invisible || i != 1 || j != 1) { int num2 = j + 1; verts.Add(new Vector3(UIBasicSprite.mTempPos[i].x, UIBasicSprite.mTempPos[j].y)); verts.Add(new Vector3(UIBasicSprite.mTempPos[i].x, UIBasicSprite.mTempPos[num2].y)); verts.Add(new Vector3(UIBasicSprite.mTempPos[num].x, UIBasicSprite.mTempPos[num2].y)); verts.Add(new Vector3(UIBasicSprite.mTempPos[num].x, UIBasicSprite.mTempPos[j].y)); uvs.Add(new Vector2(UIBasicSprite.mTempUVs[i].x, UIBasicSprite.mTempUVs[j].y)); uvs.Add(new Vector2(UIBasicSprite.mTempUVs[i].x, UIBasicSprite.mTempUVs[num2].y)); uvs.Add(new Vector2(UIBasicSprite.mTempUVs[num].x, UIBasicSprite.mTempUVs[num2].y)); uvs.Add(new Vector2(UIBasicSprite.mTempUVs[num].x, UIBasicSprite.mTempUVs[j].y)); cols.Add(drawingColor); cols.Add(drawingColor); cols.Add(drawingColor); cols.Add(drawingColor); } } } }
public void PushTitle(HUDTitleInfo title) { title.m_nBatcherIndex = m_ValidTitles.size; m_ValidTitles.Add(title); m_bNeedSort = true; }
/// <summary> /// It's often useful to be able to tell which keys are used in localization, and which are not. /// For this to work properly it's advised to play through the entire game and view all localized content before hitting the Stop button. /// </summary> void OnDisable () { string final = ""; BetterList<string> full = new BetterList<string>(); // Create a list of all the known keys foreach (KeyValuePair<string, string> pair in mDictionary) full.Add(pair.Key); // Sort the full list full.Sort(delegate(string s1, string s2) { return s1.CompareTo(s2); }); // Create the final string with the localization keys for (int i = 0; i < full.size; ++i) { string key = full[i]; string val = mDictionary[key].Replace("\n", "\\n"); if (mUsed.Contains(key)) final += key + " = " + val + "\n"; else final += "//" + key + " = " + val + "\n"; } // Show the final report in a format that makes it easy to copy/paste into the original localization file if (!string.IsNullOrEmpty(final)) Debug.Log("// Localization Report\n\n" + final); mLocalizationLoaded = false; mLanguageIndex = -1; mLocalization.Clear(); mDictionary.Clear(); }
/// <summary> /// Filled sprite fill function. /// </summary> protected void FilledFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols) { float x0 = 0f; float y0 = 0f; float x1 = 1f; float y1 = -1f; float u0 = mOuterUV.xMin; float v0 = mOuterUV.yMin; float u1 = mOuterUV.xMax; float v1 = mOuterUV.yMax; // Horizontal and vertical filled sprites are simple -- just end the sprite prematurely if (mFillDirection == FillDirection.Horizontal || mFillDirection == FillDirection.Vertical) { float du = (u1 - u0) * mFillAmount; float dv = (v1 - v0) * mFillAmount; if (fillDirection == FillDirection.Horizontal) { if (mInvert) { x0 = (1f - mFillAmount); u0 = u1 - du; } else { x1 *= mFillAmount; u1 = u0 + du; } } else if (fillDirection == FillDirection.Vertical) { if (mInvert) { y1 *= mFillAmount; v0 = v1 - dv; } else { y0 = -(1f - mFillAmount); v1 = v0 + dv; } } } // Starting AutoTargetImage for the sprite Vector2[] xy = new Vector2[4]; Vector2[] uv = new Vector2[4]; xy[0] = new Vector2(x1, y0); xy[1] = new Vector2(x1, y1); xy[2] = new Vector2(x0, y1); xy[3] = new Vector2(x0, y0); uv[0] = new Vector2(u1, v1); uv[1] = new Vector2(u1, v0); uv[2] = new Vector2(u0, v0); uv[3] = new Vector2(u0, v1); Color colF = color; colF.a *= mPanel.alpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; if (fillDirection == FillDirection.Radial90) { // Adjust the AutoTargetImage radially, and if 'false' is returned (it's not visible), just exit if (!AdjustRadial(xy, uv, mFillAmount, mInvert)) return; } else if (fillDirection == FillDirection.Radial180) { // Working in 0-1 coordinates is easier Vector2[] oxy = new Vector2[4]; Vector2[] ouv = new Vector2[4]; for (int i = 0; i < 2; ++i) { oxy[0] = new Vector2(0f, 0f); oxy[1] = new Vector2(0f, 1f); oxy[2] = new Vector2(1f, 1f); oxy[3] = new Vector2(1f, 0f); ouv[0] = new Vector2(0f, 0f); ouv[1] = new Vector2(0f, 1f); ouv[2] = new Vector2(1f, 1f); ouv[3] = new Vector2(1f, 0f); // Each half must be rotated 90 degrees clockwise in order for it to fill properly if (mInvert) { if (i > 0) { Rotate(oxy, i); Rotate(ouv, i); } } else if (i < 1) { Rotate(oxy, 1 - i); Rotate(ouv, 1 - i); } // Each half must fill in only a part of the space float x, y; if (i == 1) { x = mInvert ? 0.5f : 1f; y = mInvert ? 1f : 0.5f; } else { x = mInvert ? 1f : 0.5f; y = mInvert ? 0.5f : 1f; } oxy[1].y = Mathf.Lerp(x, y, oxy[1].y); oxy[2].y = Mathf.Lerp(x, y, oxy[2].y); ouv[1].y = Mathf.Lerp(x, y, ouv[1].y); ouv[2].y = Mathf.Lerp(x, y, ouv[2].y); float amount = (mFillAmount) * 2 - i; bool odd = (i % 2) == 1; if (AdjustRadial(oxy, ouv, amount, !odd)) { if (mInvert) odd = !odd; // Add every other side in reverse order so they don't come out backface-culled due to rotation if (odd) { for (int b = 0; b < 4; ++b) { x = Mathf.Lerp(xy[0].x, xy[2].x, oxy[b].x); y = Mathf.Lerp(xy[0].y, xy[2].y, oxy[b].y); float u = Mathf.Lerp(uv[0].x, uv[2].x, ouv[b].x); float v = Mathf.Lerp(uv[0].y, uv[2].y, ouv[b].y); verts.Add(new Vector3(x, y, 0f)); uvs.Add(new Vector2(u, v)); cols.Add(col); } } else { for (int b = 3; b > -1; --b) { x = Mathf.Lerp(xy[0].x, xy[2].x, oxy[b].x); y = Mathf.Lerp(xy[0].y, xy[2].y, oxy[b].y); float u = Mathf.Lerp(uv[0].x, uv[2].x, ouv[b].x); float v = Mathf.Lerp(uv[0].y, uv[2].y, ouv[b].y); verts.Add(new Vector3(x, y, 0f)); uvs.Add(new Vector2(u, v)); cols.Add(col); } } } } return; } else if (fillDirection == FillDirection.Radial360) { float[] matrix = new float[] { // x0 y0 x1 y1 0.5f, 1f, 0f, 0.5f, // AutoTargetImagerant 0 0.5f, 1f, 0.5f, 1f, // AutoTargetImagerant 1 0f, 0.5f, 0.5f, 1f, // AutoTargetImagerant 2 0f, 0.5f, 0f, 0.5f, // AutoTargetImagerant 3 }; Vector2[] oxy = new Vector2[4]; Vector2[] ouv = new Vector2[4]; for (int i = 0; i < 4; ++i) { oxy[0] = new Vector2(0f, 0f); oxy[1] = new Vector2(0f, 1f); oxy[2] = new Vector2(1f, 1f); oxy[3] = new Vector2(1f, 0f); ouv[0] = new Vector2(0f, 0f); ouv[1] = new Vector2(0f, 1f); ouv[2] = new Vector2(1f, 1f); ouv[3] = new Vector2(1f, 0f); // Each AutoTargetImagerant must be rotated 90 degrees clockwise in order for it to fill properly if (mInvert) { if (i > 0) { Rotate(oxy, i); Rotate(ouv, i); } } else if (i < 3) { Rotate(oxy, 3 - i); Rotate(ouv, 3 - i); } // Each AutoTargetImagerant must fill in only a quarter of the space for (int b = 0; b < 4; ++b) { int index = (mInvert) ? (3 - i) * 4 : i * 4; float fx0 = matrix[index]; float fy0 = matrix[index + 1]; float fx1 = matrix[index + 2]; float fy1 = matrix[index + 3]; oxy[b].x = Mathf.Lerp(fx0, fy0, oxy[b].x); oxy[b].y = Mathf.Lerp(fx1, fy1, oxy[b].y); ouv[b].x = Mathf.Lerp(fx0, fy0, ouv[b].x); ouv[b].y = Mathf.Lerp(fx1, fy1, ouv[b].y); } float amount = (mFillAmount) * 4 - i; bool odd = (i % 2) == 1; if (AdjustRadial(oxy, ouv, amount, !odd)) { if (mInvert) odd = !odd; // Add every other side in reverse order so they don't come out backface-culled due to rotation if (odd) { for (int b = 0; b < 4; ++b) { float x = Mathf.Lerp(xy[0].x, xy[2].x, oxy[b].x); float y = Mathf.Lerp(xy[0].y, xy[2].y, oxy[b].y); float u = Mathf.Lerp(uv[0].x, uv[2].x, ouv[b].x); float v = Mathf.Lerp(uv[0].y, uv[2].y, ouv[b].y); verts.Add(new Vector3(x, y, 0f)); uvs.Add(new Vector2(u, v)); cols.Add(col); } } else { for (int b = 3; b > -1; --b) { float x = Mathf.Lerp(xy[0].x, xy[2].x, oxy[b].x); float y = Mathf.Lerp(xy[0].y, xy[2].y, oxy[b].y); float u = Mathf.Lerp(uv[0].x, uv[2].x, ouv[b].x); float v = Mathf.Lerp(uv[0].y, uv[2].y, ouv[b].y); verts.Add(new Vector3(x, y, 0f)); uvs.Add(new Vector2(u, v)); cols.Add(col); } } } } return; } // Fill the buffer with the AutoTargetImage for the sprite for (int i = 0; i < 4; ++i) { verts.Add(xy[i]); uvs.Add(uv[i]); cols.Add(col); } }
/// <summary> /// Sliced sprite fill function is more complicated as it generates 9 quads instead of 1. /// </summary> protected void SlicedFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (!mSprite.hasBorder) { SimpleFill(verts, uvs, cols); return; } Vector4 dr = drawingDimensions; Vector4 br = border * atlas.pixelSize; mTempPos[0].x = dr.x; mTempPos[0].y = dr.y; mTempPos[3].x = dr.z; mTempPos[3].y = dr.w; mTempPos[1].x = mTempPos[0].x + br.x; mTempPos[1].y = mTempPos[0].y + br.y; mTempPos[2].x = mTempPos[3].x - br.z; mTempPos[2].y = mTempPos[3].y - br.w; mTempUVs[0] = new Vector2(mOuterUV.xMin, mOuterUV.yMin); mTempUVs[1] = new Vector2(mInnerUV.xMin, mInnerUV.yMin); mTempUVs[2] = new Vector2(mInnerUV.xMax, mInnerUV.yMax); mTempUVs[3] = new Vector2(mOuterUV.xMax, mOuterUV.yMax); Color colF = color; colF.a = finalAlpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; for (int x = 0; x < 3; ++x) { int x2 = x + 1; for (int y = 0; y < 3; ++y) { if (centerType == AdvancedType.Invisible && x == 1 && y == 1) { continue; } int y2 = y + 1; verts.Add(new Vector3(mTempPos[x].x, mTempPos[y].y)); verts.Add(new Vector3(mTempPos[x].x, mTempPos[y2].y)); verts.Add(new Vector3(mTempPos[x2].x, mTempPos[y2].y)); verts.Add(new Vector3(mTempPos[x2].x, mTempPos[y].y)); uvs.Add(new Vector2(mTempUVs[x].x, mTempUVs[y].y)); uvs.Add(new Vector2(mTempUVs[x].x, mTempUVs[y2].y)); uvs.Add(new Vector2(mTempUVs[x2].x, mTempUVs[y2].y)); uvs.Add(new Vector2(mTempUVs[x2].x, mTempUVs[y].y)); cols.Add(col); cols.Add(col); cols.Add(col); cols.Add(col); } } }
/// <summary> /// Sliced sprite fill function is more complicated as it generates 9 AutoTargetImages instead of 1. /// </summary> protected void SlicedFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols) { if (mOuterUV == mInnerUV) { SimpleFill(verts, uvs, cols); return; } Vector2[] v = new Vector2[4]; Vector2[] uv = new Vector2[4]; Texture tex = mainTexture; v[0] = Vector2.zero; v[1] = Vector2.zero; v[2] = new Vector2(1f, -1f); v[3] = new Vector2(1f, -1f); if (tex != null) { float pixelSize = atlas.pixelSize; float borderLeft = (mInnerUV.xMin - mOuterUV.xMin) * pixelSize; float borderRight = (mOuterUV.xMax - mInnerUV.xMax) * pixelSize; float borderTop = (mInnerUV.yMax - mOuterUV.yMax) * pixelSize; float borderBottom = (mOuterUV.yMin - mInnerUV.yMin) * pixelSize; Vector3 scale = cachedTransform.localScale; scale.x = Mathf.Max(0f, scale.x); scale.y = Mathf.Max(0f, scale.y); Vector2 sz = new Vector2(scale.x / tex.width, scale.y / tex.height); Vector2 tl = new Vector2(borderLeft / sz.x, borderTop / sz.y); Vector2 br = new Vector2(borderRight / sz.x, borderBottom / sz.y); Pivot pv = pivot; // We don't want the sliced sprite to become smaller than the summed up border size if (pv == Pivot.Right || pv == Pivot.TopRight || pv == Pivot.BottomRight) { v[0].x = Mathf.Min(0f, 1f - (br.x + tl.x)); v[1].x = v[0].x + tl.x; v[2].x = v[0].x + Mathf.Max(tl.x, 1f - br.x); v[3].x = v[0].x + Mathf.Max(tl.x + br.x, 1f); } else { v[1].x = tl.x; v[2].x = Mathf.Max(tl.x, 1f - br.x); v[3].x = Mathf.Max(tl.x + br.x, 1f); } if (pv == Pivot.Bottom || pv == Pivot.BottomLeft || pv == Pivot.BottomRight) { v[0].y = Mathf.Max(0f, -1f - (br.y + tl.y)); v[1].y = v[0].y + tl.y; v[2].y = v[0].y + Mathf.Min(tl.y, -1f - br.y); v[3].y = v[0].y + Mathf.Min(tl.y + br.y, -1f); } else { v[1].y = tl.y; v[2].y = Mathf.Min(tl.y, -1f - br.y); v[3].y = Mathf.Min(tl.y + br.y, -1f); } uv[0] = new Vector2(mOuterUV.xMin, mOuterUV.yMax); uv[1] = new Vector2(mInnerUV.xMin, mInnerUV.yMax); uv[2] = new Vector2(mInnerUV.xMax, mInnerUV.yMin); uv[3] = new Vector2(mOuterUV.xMax, mOuterUV.yMin); } else { // No texture -- just use zeroed out texture coordinates for (int i = 0; i < 4; ++i) uv[i] = Vector2.zero; } Color colF = color; colF.a *= mPanel.alpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; for (int x = 0; x < 3; ++x) { int x2 = x + 1; for (int y = 0; y < 3; ++y) { if (!mFillCenter && x == 1 && y == 1) continue; int y2 = y + 1; verts.Add(new Vector3(v[x2].x, v[y].y, 0f)); verts.Add(new Vector3(v[x2].x, v[y2].y, 0f)); verts.Add(new Vector3(v[x].x, v[y2].y, 0f)); verts.Add(new Vector3(v[x].x, v[y].y, 0f)); uvs.Add(new Vector2(uv[x2].x, uv[y].y)); uvs.Add(new Vector2(uv[x2].x, uv[y2].y)); uvs.Add(new Vector2(uv[x].x, uv[y2].y)); uvs.Add(new Vector2(uv[x].x, uv[y].y)); cols.Add(col); cols.Add(col); cols.Add(col); cols.Add(col); } } }
/// <summary> /// Tiled sprite fill function. /// </summary> protected void TiledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { Texture tex = material.mainTexture; if (tex == null) { return; } Vector4 dr = drawingDimensions; Vector2 size = new Vector2(mInnerUV.width * tex.width, mInnerUV.height * tex.height); size *= atlas.pixelSize; Color colF = color; colF.a = finalAlpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; float x0 = dr.x; float y0 = dr.y; float u0 = mInnerUV.xMin; float v0 = mInnerUV.yMin; while (y0 < dr.w) { x0 = dr.x; float y1 = y0 + size.y; float v1 = mInnerUV.yMax; if (y1 > dr.w) { v1 = Mathf.Lerp(mInnerUV.yMin, mInnerUV.yMax, (dr.w - y0) / size.y); y1 = dr.w; } while (x0 < dr.z) { float x1 = x0 + size.x; float u1 = mInnerUV.xMax; if (x1 > dr.z) { u1 = Mathf.Lerp(mInnerUV.xMin, mInnerUV.xMax, (dr.z - x0) / size.x); x1 = dr.z; } verts.Add(new Vector3(x0, y0)); verts.Add(new Vector3(x0, y1)); verts.Add(new Vector3(x1, y1)); verts.Add(new Vector3(x1, y0)); uvs.Add(new Vector2(u0, v0)); uvs.Add(new Vector2(u0, v1)); uvs.Add(new Vector2(u1, v1)); uvs.Add(new Vector2(u1, v0)); cols.Add(col); cols.Add(col); cols.Add(col); cols.Add(col); x0 += size.x; } y0 += size.y; } }
void ApplyShadow (BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols, int start, int end, float x, float y) #endif { #if UNITY_3_5_4 Color c = mEffectColor; c.a = c.a * color.a; Color col = c; #else Color c = mEffectColor; c.a = c.a * color.a; Color32 col = c; #endif for (int i = start; i < end; ++i) { verts.Add(verts.buffer[i]); uvs.Add(uvs.buffer[i]); cols.Add(cols.buffer[i]); Vector3 v = verts.buffer[i]; v.x += x; v.y += y; verts.buffer[i] = v; cols.buffer[i] = col; } }
/// <summary> /// Delete the specified revealer. /// </summary> static public void DeleteRevealer(Revealer rev) { lock (mRemoved) mRemoved.Add(rev); }
/// <summary> /// Convenience function that retrieves a list of all sprite names. /// </summary> public BetterList<string> GetListOfSprites() { if (mReplacement != null) return mReplacement.GetListOfSprites(); if (mSprites.Count == 0) Upgrade(); BetterList<string> list = new BetterList<string>(); for (int i = 0, imax = mSprites.Count; i < imax; ++i) { UISpriteData s = mSprites[i]; if (s != null && !string.IsNullOrEmpty(s.name)) list.Add(s.name); } return list; }
/// <summary> /// Update the fog of war's visibility. /// </summary> void UpdateBuffer() { // Add all items scheduled to be added if (mAdded.size > 0) { lock (mAdded) { while (mAdded.size > 0) { int index = mAdded.size - 1; mRevealers.Add(mAdded.buffer[index]); mAdded.RemoveAt(index); } } } // Remove all items scheduled for removal if (mRemoved.size > 0) { lock (mRemoved) { while (mRemoved.size > 0) { int index = mRemoved.size - 1; mRevealers.Remove(mRemoved.buffer[index]); mRemoved.RemoveAt(index); } } } // Use the texture blend time, thus estimating the time this update will finish // Doing so helps avoid visible changes in blending caused by the blended result being X milliseconds behind. float factor = (textureBlendTime > 0f) ? Mathf.Clamp01(mBlendFactor + mElapsed / textureBlendTime) : 1f; // Clear the buffer's red channel (channel used for current visibility -- it's updated right after) for (int i = 0, imax = mBuffer0.Length; i < imax; ++i) { mBuffer0[i] = Color32.Lerp(mBuffer0[i], mBuffer1[i], factor); mBuffer1[i].r = 0; } // For conversion from world coordinates to texture coordinates float worldToTex = (float)textureSize / worldSize; // Update the visibility buffer, one revealer at a time for (int i = 0; i < mRevealers.size; ++i) { Revealer rev = mRevealers[i]; if (!rev.mIsActive) { continue; } if (rev.mLos == LOSChecks.None) { RevealUsingRadius(rev, worldToTex); } else if (rev.mLos == LOSChecks.OnlyOnce) { RevealUsingCache(rev, worldToTex); } else { RevealUsingLOS(rev, worldToTex); } } // Blur the final visibility data for (int i = 0; i < blurIterations; ++i) { BlurVisibility(); } // Reveal the map based on what's currently visible RevealMap(); }
/// <summary> /// Apply a shadow effect to the buffer. /// </summary> void ApplyShadow (BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols, int start, int end, float x, float y) { Color c = mEffectColor; c.a *= alpha * mPanel.alpha; Color32 col = (font.premultipliedAlpha) ? NGUITools.ApplyPMA(c) : c; for (int i = start; i < end; ++i) { verts.Add(verts.buffer[i]); uvs.Add(uvs.buffer[i]); cols.Add(cols.buffer[i]); Vector3 v = verts.buffer[i]; v.x += x; v.y += y; verts.buffer[i] = v; cols.buffer[i] = col; } }
/// <summary> /// Register the font texture change listener. /// </summary> protected override void OnInit() { base.OnInit(); mList.Add(this); SetActiveFont(trueTypeFont); }
/// <summary> /// Clear all active press states when the application gets paused. /// </summary> void OnApplicationPause () { MouseOrTouch prev = currentTouch; if (useTouch) { BetterList<int> ids = new BetterList<int>(); foreach (KeyValuePair<int, MouseOrTouch> pair in mTouches) { if (pair.Value != null && pair.Value.pressed) { currentTouch = pair.Value; currentTouchID = pair.Key; currentScheme = ControlScheme.Touch; currentTouch.clickNotification = ClickNotification.None; ProcessTouch(false, true); ids.Add(currentTouchID); } } for (int i = 0; i < ids.size; ++i) RemoveTouch(ids[i]); } if (useMouse) { for (int i = 0; i < 3; ++i) { if (mMouse[i].pressed) { currentTouch = mMouse[i]; currentTouchID = -1 - i; currentKey = KeyCode.Mouse0 + i; currentScheme = ControlScheme.Mouse; currentTouch.clickNotification = ClickNotification.None; ProcessTouch(false, true); } } } if (useController) { if (controller.pressed) { currentTouch = controller; currentTouchID = -100; currentScheme = ControlScheme.Controller; currentTouch.last = currentTouch.current; currentTouch.current = mCurrentSelection; currentTouch.clickNotification = ClickNotification.None; ProcessTouch(false, true); currentTouch.last = null; } } currentTouch = prev; }
/// <summary> /// Read a single line of Comma-Separated Values from the file. /// </summary> public BetterList <string> ReadCSV() { mTemp.Clear(); string line = ""; bool insideQuotes = false; int wordStart = 0; while (canRead) { if (insideQuotes) { string s = ReadLine(false); if (s == null) { return(null); } s = s.Replace("\\n", "\n"); line += "\n" + s; } else { line = ReadLine(true); if (line == null) { return(null); } line = line.Replace("\\n", "\n"); wordStart = 0; } for (int i = wordStart, imax = line.Length; i < imax; ++i) { char ch = line[i]; if (ch == ',') { if (!insideQuotes) { mTemp.Add(line.Substring(wordStart, i - wordStart)); wordStart = i + 1; } } else if (ch == '"') { if (insideQuotes) { if (i + 1 >= imax) { mTemp.Add(line.Substring(wordStart, i - wordStart).Replace("\"\"", "\"")); return(mTemp); } if (line[i + 1] != '"') { mTemp.Add(line.Substring(wordStart, i - wordStart).Replace("\"\"", "\"")); insideQuotes = false; if (line[i + 1] == ',') { ++i; wordStart = i + 1; } } else { ++i; } } else { wordStart = i + 1; insideQuotes = true; } } } if (wordStart < line.Length) { if (insideQuotes) { continue; } mTemp.Add(line.Substring(wordStart, line.Length - wordStart)); } return(mTemp); } return(null); }
/// <summary> /// Print the specified text into the buffers. /// </summary> static public void Print (Font font, string text, BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols) { if (font == null || string.IsNullOrEmpty(text)) return; int size = current.finalSize; int indexOffset = verts.size; float lineHeight = size + current.finalSpacingY; // We need to know the baseline first float baseline = 0f; font.RequestCharactersInTexture("j", size, current.style); font.GetCharacterInfo('j', out mTempChar, size, current.style); baseline = size + mTempChar.vert.yMax; // Ensure that the text we're about to print exists in the font's texture font.RequestCharactersInTexture(text, size, current.style); // Start with the white tint mColors.Add(Color.white); float x = 0f; float y = 0f; float maxX = 0f; float spacingX = current.finalSpacingX; float pixelSize = 1f / current.pixelDensity; float sizeF = size; Vector3 v0 = Vector3.zero, v1 = Vector3.zero; Vector2 u0 = Vector2.zero, u1 = Vector2.zero; Color gb = current.tint * current.gradientBottom; Color gt = current.tint * current.gradientTop; Color32 uc = current.tint; int textLength = text.Length; for (int i = 0; i < textLength; ++i) { char c = text[i]; if (c == '\n') { if (x > maxX) maxX = x; if (current.alignment != TextAlignment.Left) { Align(verts, indexOffset, x - spacingX); indexOffset = verts.size; } x = 0; y += lineHeight; continue; } if (c < ' ') continue; // Color changing symbol if (current.encoding && ParseSymbol(text, ref i, mColors, current.premultiply)) { Color fc = current.tint * mColors[mColors.size - 1]; uc = fc; if (current.gradient) { gb = current.gradientBottom * fc; gt = current.gradientTop * fc; } --i; continue; } if (!font.GetCharacterInfo(c, out mTempChar, size, current.style)) continue; v0.x = (x + mTempChar.vert.xMin); v0.y = -(y - mTempChar.vert.yMax + baseline); v1.x = v0.x + mTempChar.vert.width; v1.y = v0.y - mTempChar.vert.height; if (pixelSize != 1f) { v0 *= pixelSize; v1 *= pixelSize; } u0.x = mTempChar.uv.xMin; u0.y = mTempChar.uv.yMin; u1.x = mTempChar.uv.xMax; u1.y = mTempChar.uv.yMax; x += (mTempChar.width + spacingX); verts.Add(new Vector3(v1.x, v0.y)); verts.Add(new Vector3(v0.x, v0.y)); verts.Add(new Vector3(v0.x, v1.y)); verts.Add(new Vector3(v1.x, v1.y)); if (mTempChar.flipped) { uvs.Add(new Vector2(u0.x, u1.y)); uvs.Add(new Vector2(u0.x, u0.y)); uvs.Add(new Vector2(u1.x, u0.y)); uvs.Add(new Vector2(u1.x, u1.y)); } else { uvs.Add(new Vector2(u1.x, u0.y)); uvs.Add(new Vector2(u0.x, u0.y)); uvs.Add(new Vector2(u0.x, u1.y)); uvs.Add(new Vector2(u1.x, u1.y)); } if (current.gradient) { float min = sizeF - (-mTempChar.vert.yMax + baseline); float max = min - (mTempChar.vert.height); min /= sizeF; max /= sizeF; s_c0 = Color.Lerp(gb, gt, min); s_c1 = Color.Lerp(gb, gt, max); cols.Add(s_c0); cols.Add(s_c0); cols.Add(s_c1); cols.Add(s_c1); } else for (int b = 0; b < 4; ++b) cols.Add(uc); } if (current.alignment != TextAlignment.Left && indexOffset < verts.size) { Align(verts, indexOffset, x - spacingX); indexOffset = verts.size; } mColors.Clear(); }
/// <summary> /// Draw the custom wizard. /// </summary> void OnGUI() { Event currentEvent = Event.current; EventType type = currentEvent.type; int x = cellPadding, y = cellPadding; int width = Screen.width - cellPadding; int spacingX = cellSize + cellPadding; int spacingY = spacingX; if (mMode == Mode.DetailedMode) { spacingY += 32; } GameObject dragged = draggedObject; bool isDragging = (dragged != null); int indexUnderMouse = GetCellUnderMouse(spacingX, spacingY); Item selection = isDragging ? FindItem(dragged) : null; string searchFilter = NGUISettings.searchField; int newTab = mTab; GUILayout.BeginHorizontal(); if (GUILayout.Toggle(newTab == 0, "1", "ButtonLeft")) { newTab = 0; } if (GUILayout.Toggle(newTab == 1, "2", "ButtonMid")) { newTab = 1; } if (GUILayout.Toggle(newTab == 2, "3", "ButtonMid")) { newTab = 2; } if (GUILayout.Toggle(newTab == 3, "4", "ButtonMid")) { newTab = 3; } if (GUILayout.Toggle(newTab == 4, "5", "ButtonRight")) { newTab = 4; } GUILayout.EndHorizontal(); if (mTab != newTab) { Save(); mTab = newTab; mReset = true; NGUISettings.SetInt("NGUI Prefab Tab", mTab); Load(); } if (mReset && type == EventType.Repaint) { mReset = false; foreach (Item item in mItems) { GeneratePreview(item, null); } RectivateLights(); } // Search field GUILayout.BeginHorizontal(); { string after = EditorGUILayout.TextField("", searchFilter, "SearchTextField", GUILayout.Width(Screen.width - 20f)); if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f))) { after = ""; GUIUtility.keyboardControl = 0; } if (searchFilter != after) { NGUISettings.searchField = after; searchFilter = after; } } GUILayout.EndHorizontal(); bool eligibleToDrag = (currentEvent.mousePosition.y < Screen.height - 40); if (type == EventType.MouseDown) { mMouseIsInside = true; } else if (type == EventType.MouseDrag) { mMouseIsInside = true; if (indexUnderMouse != -1 && eligibleToDrag) { // Drag operation begins if (draggedObjectIsOurs) { DragAndDrop.StartDrag("Prefab Tool"); } currentEvent.Use(); } } else if (type == EventType.MouseUp) { DragAndDrop.PrepareStartDrag(); mMouseIsInside = false; Repaint(); } else if (type == EventType.DragUpdated) { // Something dragged into the window mMouseIsInside = true; UpdateVisual(); currentEvent.Use(); } else if (type == EventType.DragPerform) { // We've dropped a new object into the window if (dragged != null) { if (selection != null) { DestroyTexture(selection); mItems.Remove(selection); } AddItem(dragged, indexUnderMouse); draggedObject = null; } mMouseIsInside = false; currentEvent.Use(); } else if (type == EventType.DragExited || type == EventType.Ignore) { mMouseIsInside = false; } // If the mouse is not inside the window, clear the selection and dragged object if (!mMouseIsInside) { selection = null; dragged = null; } // Create a list of indices, inserting an entry of '-1' underneath the dragged object BetterList <int> indices = new BetterList <int>(); for (int i = 0; i < mItems.size;) { if (dragged != null && indices.size == indexUnderMouse) { indices.Add(-1); } if (mItems[i] != selection) { if (string.IsNullOrEmpty(searchFilter) || mItems[i].prefab.name.IndexOf(searchFilter, System.StringComparison.CurrentCultureIgnoreCase) != -1) { indices.Add(i); } } ++i; } // There must always be '-1' (Add/Move slot) present if (!indices.Contains(-1)) { indices.Add(-1); } // We want to start dragging something from within the window if (eligibleToDrag && type == EventType.MouseDown && indexUnderMouse > -1) { GUIUtility.keyboardControl = 0; if (currentEvent.button == 0 && indexUnderMouse < indices.size) { int index = indices[indexUnderMouse]; if (index != -1 && index < mItems.size) { selection = mItems[index]; draggedObject = selection.prefab; dragged = selection.prefab; currentEvent.Use(); } } } //else if (type == EventType.MouseUp && currentEvent.button == 1 && indexUnderMouse > mItems.size) //{ // NGUIContextMenu.AddItem("Reset", false, RemoveItem, index); // NGUIContextMenu.Show(); //} // Draw the scroll view with prefabs mPos = GUILayout.BeginScrollView(mPos); { Color normal = new Color(1f, 1f, 1f, 0.5f); for (int i = 0; i < indices.size; ++i) { int index = indices[i]; Item ent = (index != -1) ? mItems[index] : selection; if (ent != null && ent.prefab == null) { mItems.RemoveAt(index); continue; } Rect rect = new Rect(x, y, cellSize, cellSize); Rect inner = rect; inner.xMin += 2f; inner.xMax -= 2f; inner.yMin += 2f; inner.yMax -= 2f; rect.yMax -= 1f; // Button seems to be mis-shaped. It's height is larger than its width by a single pixel. if (!isDragging && (mMode == Mode.CompactMode || (ent == null || ent.tex != null))) { mContent.tooltip = (ent != null) ? ent.prefab.name : "Click to add"; } else { mContent.tooltip = ""; } //if (ent == selection) { GUI.color = normal; NGUIEditorTools.DrawTiledTexture(inner, NGUIEditorTools.backdropTexture); } GUI.color = Color.white; GUI.backgroundColor = normal; if (GUI.Button(rect, mContent, "Button")) { if (ent == null || currentEvent.button == 0) { string path = EditorUtility.OpenFilePanel("Add a prefab", NGUISettings.currentPath, "prefab"); if (!string.IsNullOrEmpty(path)) { NGUISettings.currentPath = System.IO.Path.GetDirectoryName(path); Item newEnt = CreateItemByPath(path); if (newEnt != null) { mItems.Add(newEnt); Save(); } } } else if (currentEvent.button == 1) { NGUIContextMenu.AddItem("Delete", false, RemoveItem, index); NGUIContextMenu.Show(); } } string caption = (ent == null) ? "" : ent.prefab.name.Replace("Control - ", ""); if (ent != null) { if (ent.tex != null) { GUI.DrawTexture(inner, ent.tex); } else if (mMode != Mode.DetailedMode) { GUI.Label(inner, caption, mStyle); caption = ""; } } else { GUI.Label(inner, "Add", mStyle); } if (mMode == Mode.DetailedMode) { GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f); GUI.contentColor = new Color(1f, 1f, 1f, 0.7f); GUI.Label(new Rect(rect.x, rect.y + rect.height, rect.width, 32f), caption, "ProgressBarBack"); GUI.contentColor = Color.white; GUI.backgroundColor = Color.white; } x += spacingX; if (x + spacingX > width) { y += spacingY; x = cellPadding; } } GUILayout.Space(y); } GUILayout.EndScrollView(); // Mode Mode modeAfter = (Mode)EditorGUILayout.EnumPopup(mMode); if (modeAfter != mMode) { mMode = modeAfter; mReset = true; NGUISettings.SetEnum("NGUI Prefab Mode", mMode); } }