private string createStatChangeString(BetterList<string> aStatNames) { string r = this.name+" "+aStatNames[0]; aStatNames.RemoveAt(0); while(aStatNames.size>1) { r+= ", "+aStatNames[0]; aStatNames.RemoveAt(0); } if(aStatNames.size>0) { r += " and "+aStatNames[0]; } return r; }
/// <summary> /// Add a new paragraph. /// </summary> protected void Add(string text, bool updateVisible) { Paragraph ce = null; if (mParagraphs.size < paragraphHistory) { ce = new Paragraph(); } else { ce = mParagraphs[0]; mParagraphs.RemoveAt(0); } ce.text = text; mParagraphs.Add(ce); Rebuild(); }
public AssetBundle PopDelayUnloadAssetBundle(string name) { int i = 0; for (int size = delayUnloadAssetBundles.size; i < size; i++) { DelayUnloadAssetBundle obj = delayUnloadAssetBundles[i]; if (obj.name == name) { delayUnloadAssetBundles.RemoveAt(i); AssetBundle assetBundle = obj.assetBundle; obj.assetBundle = null; DelayUnloadAssetBundle.Release(ref obj); return(assetBundle); } } return(null); }
float time; //curTime from runing start void showPopValue() { time = Time.time; for (int i = 0; i < mList.size;) { mPopEntryV2 ent = mList.buffer[i]; ent.curRuningTime = time - ent.curStartTimePoint; if (ent.curRuningTime > ent.totalRuningTime) { PopEntrySceneTest2.value -= ent.list.size; mList.RemoveAt(i); ent.OnClose(); continue; } i++; } }
private static void TrimDrawCalls(PrefabStage prefabStage, StageHandle stageHandleMain, BetterList <UIDrawCall> list, string identifier) { for (int i = list.size - 1; i >= 0; --i) { UIDrawCall dc = list[i]; if (dc == null || !dc.gameObject.BelongsToCurrentStage(prefabStage, stageHandleMain)) { list.RemoveAt(i); if (dc != null) { UIDrawCall.Destroy(dc); } if (log) { Debug.Log(string.Format("Removing {0} entry {1} from the {2} draw call list", dc == null ? "a null" : "an out of stage", i, identifier)); } } } }
public void UndoLastMove() { if (!CanUndo) { return; } if (DataManager.Instance.Coins < costForUndoLastMove) { // TODO: Add method to purchase coins. return; } DataManager.Instance.Coins -= costForUndoLastMove; if (waste[0].Type == CardType.Wild) { // TODO: Warn player that they'll lose their Wild card. GameObject.Destroy(waste.TakeTopCard().gameObject); } Action action = undoHistory[undoHistory.size - 1]; undoHistory.RemoveAt(undoHistory.size - 1); if (action.move == Action.Move.RevealNextCard) { if (waste.Size > 0) { ReturnCardFromWaste(); } } else if (action.move == Action.Move.RemoveCardFromSlot) { if (waste.Size > 0) { ReturnCardToSlot(action.slot); RefreshBoard(); } } }
public void Update() { time = RealTime.time; for (int i = 0; i < mList.size;) { mPopEntry ent = mList.buffer[i]; ent.curRuningTime = time - ent.curStartTimePoint; if (ent.curRuningTime > ent.totalRuningTime) { mList.RemoveAt(i); ent.OnClose(); continue; } else { ent.Update(); } i++; } }
protected void UpdateRevealers(int deltaMS) { // Add all items scheduled to be added if (revealersAdded.size > 0) { lock (revealersAdded) { while (revealersAdded.size > 0) { int index = revealersAdded.size - 1; revealers.Add(revealersAdded.buffer[index]); revealersAdded.RemoveAt(index); } } } // Remove all items scheduled for removal if (revealersRemoved.size > 0) { lock (revealersRemoved) { while (revealersRemoved.size > 0) { int index = revealersRemoved.size - 1; revealers.Remove(revealersRemoved.buffer[index]); revealersRemoved.RemoveAt(index); } } } for (int i = revealers.size - 1; i >= 0; i--) { IMangoFogRevealer revealer = revealers[i]; revealer.Update(deltaMS); if (!revealer.IsValid()) { revealer.Release(); } } }
/// <summary> /// Call all coroutine update functions and destroy all delayed destroy objects. /// </summary> bool CoroutineUpdate() { float time = Time.realtimeSinceStartup; float delta = time - mTime; if (delta < 0.001f) { return(true); } mTime = time; UpdateList(mOnCoro, delta); bool appIsPlaying = Application.isPlaying; for (int i = mDest.size; i > 0;) { DestroyEntry de = mDest.buffer[--i]; if (!appIsPlaying || de.time < mTime) { if (de.obj != null) { NGUITools.Destroy(de.obj); de.obj = null; } mDest.RemoveAt(i); } } // Nothing left to update? Destroy this game object. if (mOnUpdate.Count == 0 && mOnLate.Count == 0 && mOnCoro.Count == 0 && mDest.size == 0) { NGUITools.Destroy(gameObject); return(false); } return(true); }
/// <summary> /// Call all coroutine update functions and destroy all delayed destroy objects. /// </summary> bool CoroutineUpdate() { double time = Frontiers.WorldClock.RealTime; double delta = time - mTime; if (delta < 0.001) { return(true); } mTime = time; UpdateList(mOnCoro, (float)delta); bool appIsPlaying = Application.isPlaying; for (int i = mDest.size; i > 0;) { DestroyEntry de = mDest.buffer[--i]; if (!appIsPlaying || de.time < mTime) { if (de.obj != null) { NGUITools.Destroy(de.obj); de.obj = null; } mDest.RemoveAt(i); } } // Nothing left to update? Destroy this game object. if (mOnUpdate.Count == 0 && mOnLate.Count == 0 && mOnCoro.Count == 0 && mDest.size == 0) { NGUITools.Destroy(gameObject); return(false); } return(true); }
/// <summary> /// Fill the geometry for the specified draw call. /// </summary> bool FillDrawCall (UIDrawCall dc) { if (dc != null) { dc.isDirty = false; for (int i = 0; i < widgets.size; ) { UIWidget w = widgets[i]; if (w == null) { #if UNITY_EDITOR Debug.LogError("This should never happen"); #endif widgets.RemoveAt(i); continue; } if (w.drawCall == dc) { if (w.isVisible && w.hasVertices) { if (generateNormals) w.WriteToBuffers(dc.verts, dc.uvs, dc.cols, dc.norms, dc.tans); else w.WriteToBuffers(dc.verts, dc.uvs, dc.cols, null, null); } else w.drawCall = null; } ++i; } if (dc.verts.size != 0) { dc.UpdateGeometry(); return true; } } return false; }
/// <summary> /// Create a new draw call, reusing an old one if possible. /// </summary> static UIDrawCall Create(string name) { #if SHOW_HIDDEN_OBJECTS && UNITY_EDITOR name = (name != null) ? "_UIDrawCall [" + name + "]" : "DrawCall"; #endif if (mInactiveList.size > 0) { UIDrawCall dc = mInactiveList[mInactiveList.size - 1]; mInactiveList.RemoveAt(mInactiveList.size - 1); mActiveList.Add(dc); if (name != null) { dc.name = name; } NGUITools.SetActive(dc.gameObject, true); return(dc); } #if UNITY_EDITOR // If we're in the editor, create the game object with hide flags set right away GameObject go = UnityEditor.EditorUtility.CreateGameObjectWithHideFlags(name, #if SHOW_HIDDEN_OBJECTS HideFlags.DontSave | HideFlags.NotEditable, typeof(UIDrawCall)); #else HideFlags.HideAndDontSave, typeof(UIDrawCall)); #endif UIDrawCall newDC = go.GetComponent <UIDrawCall>(); #else GameObject go = new GameObject(name); DontDestroyOnLoad(go); UIDrawCall newDC = go.AddComponent <UIDrawCall>(); #endif // Create the draw call mActiveList.Add(newDC); return(newDC); }
/// <summary> /// Update the panel, all of its widgets and draw calls. /// </summary> void UpdateSelf () { mUpdateTime = RealTime.time; UpdateTransformMatrix(); UpdateLayers(); UpdateWidgets(); if (mRebuild) { mRebuild = false; FillAllDrawCalls(); } else { for (int i = 0; i < drawCalls.size; ) { UIDrawCall dc = drawCalls.buffer[i]; if (dc.isDirty && !FillDrawCall(dc)) { UIDrawCall.Destroy(dc); drawCalls.RemoveAt(i); continue; } ++i; } } if (mUpdateScroll) { mUpdateScroll = false; UIScrollView sv = GetComponent<UIScrollView>(); if (sv != null) sv.UpdateScrollbars(); } }
public PackageObject GetCachedPackage(string package_name) { PackageObject packageObject = packageCaches.Get(package_name); if (packageObject == null) { packageObject = systemPackageCaches.Get(package_name); } if (packageObject == null) { int i = 0; for (int size = deletePackageObjects.size; i < size; i++) { if (deletePackageObjects[i].name == package_name) { packageObject = deletePackageObjects[i]; deletePackageObjects.RemoveAt(i); packageCaches.Add(package_name, packageObject); break; } } } return(packageObject); }
/// <summary> /// Do the actual fading of panels. /// </summary> void Update() { // Fade out the previous window for (int i = mFading.size; i > 0;) { UIPanel p = mFading[--i]; if (p != null) { p.alpha = Mathf.Clamp01(p.alpha - RealTime.deltaTime * 6f); //p.SetAlphaRecursive(Mathf.Clamp01(p.alpha - RealTime.deltaTime * 6f), false); p.transform.localScale = Vector3.Lerp(Vector3.one * 0.9f, Vector3.one, p.alpha); if (p.alpha > 0f) { continue; } } mFading.RemoveAt(i); p.gameObject.SetActive(false); } // Only fade in the new window after the previous has faded out if (mFading.size == 0 && mActive != null && mActive.alpha < 1f) { mActive.alpha = Mathf.Clamp01(mActive.alpha + RealTime.deltaTime * 6f); //mActive.SetAlphaRecursive(Mathf.Clamp01(mActive.alpha + RealTime.deltaTime * 6f), false); Transform t = mActive.transform; t.localScale = Vector3.Lerp(Vector3.one * 0.9f, Vector3.one, mActive.alpha); // 3D layer if (mActive.gameObject.layer == 10) { t.localRotation = Quaternion.Euler(0f, -18f + mActive.alpha * 24f, 0f); } } }
public static void cancelRequest(int handlerid) { for (int i = 0; i < tasks.size; i++) { if (tasks[i].taskid == handlerid) { tasks.RemoveAt(i); return; } } for (int i = 0; i < requests.size; i++) { if (requests[i].taskid == handlerid) { requests[i].requestBody = null; if (requests[i].client != null) { requests[i].client.CancelAsync(); } requests[i].dispose(); return; } } }
/// <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. //使用纹理混合时间,从而估计此更新将完成的时间 //这样做有助于避免由于混合结果落后X毫秒而导致混合中的可见变化。 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) { IFOWRevealer rev = mRevealers[i]; if (rev.IsValid()) { RevealUsingRadius(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(); // Merge two buffer to one MergeBuffer(); }
protected void onMoveQueueCreated(BetterList<MoveQueueItem> aMoveQueue) { if(countdownTimer!=null) { countdownTimer.stop(); countdownTimer.text = ""; } this.easyTarget.gameObject.SetActive(false); _moveQueue = aMoveQueue; this.FadeBlackScreen(0.0f,0.1f); topLabel.gameObject.SetActive(false); Debug.Log ("Move Queue Size is: "+_moveQueue.size); for(int i = 0;i<_moveQueue.size;i++) { if((_moveQueue[i].moveData==null)&&(_moveQueue[i].baitItem==null)&&(_moveQueue[i].usedItem==null)) { _moveQueue.RemoveAt(i); i--; } else _moveQueue[i].setTimesToHit(); } processMoveQueue(); }
public static 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, ref bool ignoreColor) { 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 text2 = text.Substring(index, 3); string text3 = text2; switch (text3) { case "[b]": bold = true; index += 3; return true; case "[i]": italic = true; index += 3; return true; case "[u]": underline = true; index += 3; return true; case "[s]": strike = true; index += 3; return true; case "[c]": ignoreColor = true; index += 3; return true; } } if (index + 4 > length) { return false; } if (text[index + 3] == ']') { string text4 = text.Substring(index, 4); string text3 = text4; switch (text3) { 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 "[/s]": strike = false; index += 4; return true; case "[/c]": ignoreColor = false; index += 4; return true; } char ch = text[index + 1]; char ch2 = text[index + 2]; if (NGUIText.IsHex(ch) && NGUIText.IsHex(ch2)) { int num2 = NGUIMath.HexToDecimal(ch) << 4 | NGUIMath.HexToDecimal(ch2); NGUIText.mAlpha = (float)num2 / 255f; index += 4; return true; } } if (index + 5 > length) { return false; } if (text[index + 4] == ']') { string text5 = text.Substring(index, 5); string text3 = text5; if (text3 != null) { if (NGUIText.<>f__switch$mapE == null) { NGUIText.<>f__switch$mapE = new Dictionary<string, int>(2) { { "[sub]", 0 }, { "[sup]", 1 } }; } int num; if (NGUIText.<>f__switch$mapE.TryGetValue(text3, out num)) { if (num == 0) { sub = 1; index += 5; return true; } if (num == 1) { sub = 2; index += 5; return true; } } } } if (index + 6 > length) { return false; } if (text[index + 5] == ']') { string text6 = text.Substring(index, 6); string text3 = text6; switch (text3) { case "[/sub]": sub = 0; index += 6; return true; case "[/sup]": sub = 0; index += 6; return true; case "[/url]": index += 6; return true; } } if (text[index + 1] == 'u' && text[index + 2] == 'r' && text[index + 3] == 'l' && text[index + 4] == '=') { int num3 = text.IndexOf(']', index + 4); if (num3 != -1) { index = num3 + 1; return true; } index = text.Length; return true; } else { if (index + 8 > length) { return false; } if (text[index + 7] == ']') { Color color = NGUIText.ParseColor24(text, index + 1); if (NGUIText.EncodeColor24(color) != text.Substring(index + 1, 6).ToUpper()) { return false; } if (colors != null) { color.a = colors[colors.size - 1].a; if (premultiply && color.a != 1f) { color = Color.Lerp(NGUIText.mInvisible, color, color.a); } colors.Add(color); } index += 8; return true; } else { if (index + 10 > length) { return false; } if (text[index + 9] != ']') { return false; } Color color2 = NGUIText.ParseColor32(text, index + 1); if (NGUIText.EncodeColor32(color2) != text.Substring(index + 1, 8).ToUpper()) { return false; } if (colors != null) { if (premultiply && color2.a != 1f) { color2 = Color.Lerp(NGUIText.mInvisible, color2, color2.a); } colors.Add(color2); } index += 10; return true; } } }
public float applyPassiveEffectToMonsters(EWhenToApply aWhen,PassiveEffect aEffect,BattleMonster aPassiveEffectOwner,EMonsterPos aEffectOwnerPosition,MoveQueueItem aMoveQueueItem) { float delayAmount = 0f; if(aEffect.applyAt==aWhen) { if(this.containsMonster(aPassiveEffectOwner)) { // Check Splash on this passive effect BetterList<BattleMonster> monsters = new BetterList<BattleMonster>(); if(aMoveQueueItem!=null) monsters = this.getBoostTargetsForMove(positionForMonster(aPassiveEffectOwner),aEffect.moveRef,(BattleMonster) aMoveQueueItem.actioningMonster); else monsters = this.getBoostTargetsForMove(positionForMonster(aPassiveEffectOwner),aEffect.moveRef,aPassiveEffectOwner); if(aEffect.moveRef==null) { Debug.LogError("Passive effect for: "+aPassiveEffectOwner.name+" is "+aEffect.moveRef+" passive effect is: "+aPassiveEffectOwner.monster.passiveEffect.name); return 0f; } if(aEffect.moveRef.elementType!=ElementalLibrary.REF.getElement("Normal")) { // This passive effect can only be applied to monsters of type: aEffect.moveRef.elementType for(int i = 0;i<monsters.size;i++) { if(monsters[i].monster.elementType!=aEffect.moveRef.elementType) { monsters.RemoveAt(i); i--; } } for(int i = 0;i<monsters.size;i++) { monsters[i].applyStatEffectsFromMove(aEffect.moveRef,null,aEffect); delayAmount += monsters[i].applyStatusEffectsForMove(aEffect.moveRef,1,aEffect); this.applyHPBoostsToTeam(aEffect,aPassiveEffectOwner,aMoveQueueItem,this._position); if(aEffect.moveRef.decisiveBlowsImmunity>0f) { monsters[i].criticalHitImmune = true; } if(aEffect.moveRef.oneHitKillInvulnerable>0f) { monsters[i].oneHitKOImmune = true; } } } } else { BetterList<BattleMonster> monsters = this.getTargetsForMove(EMonsterPos.Unset,aEffect.moveRef); for(int i = 0;i<monsters.size;i++) { monsters[i].applyStatEffectsFromMove(aEffect.moveRef,null,aEffect); delayAmount += monsters[i].applyStatusEffectsForMove(aEffect.moveRef,1,aEffect); applyHPEffectToTeam(aEffect,aPassiveEffectOwner,aEffectOwnerPosition); } } } return delayAmount; }
/// <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> /// Animate the status bar. /// </summary> void Update() { if (mAlpha == 0f) { if (mEntries.size > 0) { // We have something to show -- let's start fading it in mCurrent = mEntries[0]; mEntries.RemoveAt(0); mFadingIn = true; mForceFadeOut = false; UpdateText(); } else if (!mFadingIn) { return; } } float time = Time.realtimeSinceStartup; // If the current entry is persistent and we have nothing more to show, keep updating the time if (mCurrent.persistent && mEntries.size == 0) { mShownTime = time; } // Calculate this entry's expiration time if (mEntries.size > 0) { mForceFadeOut = true; } float expireTime = mForceFadeOut ? mShownTime : mShownTime + shownDuration; if (mFadingIn) { mAlpha += RealTime.deltaTime / fadeInTime; if (mAlpha > 1f) { // We're done fading in mTrans.localScale = Vector3.one; background.color = mBackColor; label.color = mCurrent.color; mShownTime = time; mFadingIn = false; } else { // Still fading in float amount = curve.Evaluate(mAlpha); mTrans.localScale = new Vector3(0.2f + 0.8f * amount, 1f, 1f); background.color = Color.Lerp(mInvisible, mBackColor, amount); label.color = Color.Lerp(mInvisible, mCurrent.color, amount * amount); } } else if (expireTime < time) { mAlpha -= RealTime.deltaTime / (mForceFadeOut ? transitionTime : fadeOutTime); if (mAlpha < 0.01f) { // We're done fading out label.enabled = false; background.enabled = false; mAlpha = 0f; } else { // Still fading out background.color = Color.Lerp(mInvisible, mBackColor, mAlpha); label.color = Color.Lerp(mInvisible, mCurrent.color, mAlpha * mAlpha); } } }
/// <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> /// 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; case "[s]": strike = 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 "[/s]": strike = false; 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; } } 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> /// Load the specified CSV file. /// </summary> static bool LoadCSV(byte[] bytes, TextAsset asset, bool merge = false) { if (bytes == null) { return(false); } ByteReader reader = new ByteReader(bytes); // The first line should contain "KEY", followed by languages. BetterList <string> header = reader.ReadCSV(); // There must be at least two columns in a valid CSV file if (header.size < 2) { return(false); } header.RemoveAt(0); string[] languagesToAdd = null; if (string.IsNullOrEmpty(mLanguage)) { localizationHasBeenSet = false; } // Clear the dictionary if (!localizationHasBeenSet || (!merge && !mMerging) || mLanguages == null || mLanguages.Length == 0) { mDictionary.Clear(); mLanguages = new string[header.size]; if (!localizationHasBeenSet) { mLanguage = PlayerPrefs.GetString("Language", header[0]); localizationHasBeenSet = true; } for (int i = 0; i < header.size; ++i) { mLanguages[i] = header[i]; if (mLanguages[i] == mLanguage) { mLanguageIndex = i; } } } else { languagesToAdd = new string[header.size]; for (int i = 0; i < header.size; ++i) { languagesToAdd[i] = header[i]; } // Automatically resize the existing languages and add the new language to the mix for (int i = 0; i < header.size; ++i) { if (!HasLanguage(header[i])) { int newSize = mLanguages.Length + 1; #if UNITY_FLASH string[] temp = new string[newSize]; for (int b = 0, bmax = arr.Length; b < bmax; ++b) { temp[b] = mLanguages[b]; } mLanguages = temp; #else System.Array.Resize(ref mLanguages, newSize); #endif mLanguages[newSize - 1] = header[i]; Dictionary <string, string[]> newDict = new Dictionary <string, string[]>(); foreach (KeyValuePair <string, string[]> pair in mDictionary) { string[] arr = pair.Value; #if UNITY_FLASH temp = new string[newSize]; for (int b = 0, bmax = arr.Length; b < bmax; ++b) { temp[b] = arr[b]; } arr = temp; #else System.Array.Resize(ref arr, newSize); #endif arr[newSize - 1] = arr[0]; newDict.Add(pair.Key, arr); } mDictionary = newDict; } } } Dictionary <string, int> languageIndices = new Dictionary <string, int>(); for (int i = 0; i < mLanguages.Length; ++i) { languageIndices.Add(mLanguages[i], i); } // Read the entire CSV file into memory for (;;) { BetterList <string> temp = reader.ReadCSV(); if (temp == null || temp.size == 0) { break; } if (string.IsNullOrEmpty(temp[0])) { continue; } AddCSV(temp, languagesToAdd, languageIndices); } if (!mMerging && onLocalize != null) { mMerging = true; OnLocalizeNotification note = onLocalize; onLocalize = null; note(); onLocalize = note; mMerging = false; } return(true); }
/// <summary> /// Convenience function that figures out the panel's correct change flag by searching the parents. /// </summary> int GetChangeFlag(UINode start) { int flag = start.changeFlag; if (flag == -1) { Transform trans = start.trans.parent; UINode sub; // Keep going until we find a set flag for (;;) { // Check the parent's flag #if UNITY_FLASH if (trans != null && mChildren.TryGetValue(trans, out sub)) { #else if (trans != null && mChildren.Contains(trans)) { sub = (UINode)mChildren[trans]; #endif flag = sub.changeFlag; trans = trans.parent; // If the flag hasn't been set either, add this child to the hierarchy if (flag == -1) { mHierarchy.Add(sub); } else { break; } } else { flag = 0; break; } } // Update the parent flags for (int i = 0, imax = mHierarchy.size; i < imax; ++i) { UINode pc = mHierarchy.buffer[i]; pc.changeFlag = flag; } mHierarchy.Clear(); } return(flag); } /// <summary> /// Update the world-to-local transform matrix as well as clipping bounds. /// </summary> void UpdateTransformMatrix() { float time = Time.realtimeSinceStartup; if (time == 0f || mMatrixTime != time) { mMatrixTime = time; mWorldToLocal = cachedTransform.worldToLocalMatrix; if (mClipping != UIDrawCall.Clipping.None) { Vector2 size = new Vector2(mClipRange.z, mClipRange.w); if (size.x == 0f) { size.x = mScreenSize.x; } if (size.y == 0f) { size.y = mScreenSize.y; } size *= 0.5f; mMin.x = mClipRange.x - size.x; mMin.y = mClipRange.y - size.y; mMax.x = mClipRange.x + size.x; mMax.y = mClipRange.y + size.y; } } } /// <summary> /// Run through all managed transforms and see if they've changed. /// </summary> void UpdateTransforms() { mChangedLastFrame = false; bool transformsChanged = false; #if UNITY_EDITOR bool shouldCull = !Application.isPlaying || Time.realtimeSinceStartup > mCullTime; if (!Application.isPlaying || !widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled) #else bool shouldCull = Time.realtimeSinceStartup > mCullTime; if (!widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled) #endif { #if UNITY_FLASH foreach (KeyValuePair <Transform, UINode> child in mChildren) { UINode node = child.Value; #else for (int i = 0, imax = mChildren.Count; i < imax; ++i) { UINode node = (UINode)mChildren[i]; #endif if (node.trans == null) { mRemoved.Add(node.trans); continue; } if (node.HasChanged()) { node.changeFlag = 1; transformsChanged = true; } else { node.changeFlag = -1; } } // Clean up the deleted transforms for (int i = 0, imax = mRemoved.Count; i < imax; ++i) { mChildren.Remove(mRemoved[i]); } mRemoved.Clear(); } // If the children weren't culled but should be, check their visibility if (!mCulled && shouldCull) { mCheckVisibility = true; } // If something has changed, propagate the changes *down* the tree hierarchy (to children). // An alternative (but slower) approach would be to do a pc.trans.GetComponentsInChildren<UIWidget>() // in the loop above, and mark each one as dirty. if (mCheckVisibility || transformsChanged || mRebuildAll) { #if UNITY_FLASH foreach (KeyValuePair <Transform, UINode> child in mChildren) { UINode pc = child.Value; #else for (int i = 0, imax = mChildren.Count; i < imax; ++i) { UINode pc = (UINode)mChildren[i]; #endif if (pc.widget != null) { int visibleFlag = 1; // No sense in checking the visibility if we're not culling anything (as the visibility is always 'true') if (shouldCull || transformsChanged) { // If the change flag has not yet been determined... if (pc.changeFlag == -1) { pc.changeFlag = GetChangeFlag(pc); } // Is the widget visible? if (shouldCull) { visibleFlag = (mCheckVisibility || pc.changeFlag == 1) ? (IsVisible(pc.widget) ? 1 : 0) : pc.visibleFlag; } } // If visibility changed, mark the node as changed as well if (pc.visibleFlag != visibleFlag) { pc.changeFlag = 1; } // If the node has changed and the widget is visible (or was visible before) if (pc.changeFlag == 1 && (visibleFlag == 1 || pc.visibleFlag != 0)) { // Update the visibility flag pc.visibleFlag = visibleFlag; Material mat = pc.widget.material; // Add this material to the list of changed materials if (!mChanged.Contains(mat)) { mChanged.Add(mat); mChangedLastFrame = true; } } } } } mCulled = shouldCull; mCheckVisibility = false; mWidgetsAdded = false; } /// <summary> /// Update all widgets and rebuild their geometry if necessary. /// </summary> void UpdateWidgets() { #if UNITY_FLASH foreach (KeyValuePair <Transform, UINode> c in mChildren) { UINode pc = c.Value; #else for (int i = 0, imax = mChildren.Count; i < imax; ++i) { UINode pc = (UINode)mChildren[i]; #endif UIWidget w = pc.widget; // If the widget is visible, update it if (pc.visibleFlag == 1 && w != null && w.UpdateGeometry(ref mWorldToLocal, (pc.changeFlag == 1), generateNormals)) { // We will need to refill this buffer if (!mChanged.Contains(w.material)) { mChanged.Add(w.material); mChangedLastFrame = true; } } pc.changeFlag = 0; } } /// <summary> /// Update the clipping rect in the shaders and draw calls' positions. /// </summary> public void UpdateDrawcalls() { Vector4 range = Vector4.zero; if (mClipping != UIDrawCall.Clipping.None) { range = new Vector4(mClipRange.x, mClipRange.y, mClipRange.z * 0.5f, mClipRange.w * 0.5f); } if (range.z == 0f) { range.z = mScreenSize.x * 0.5f; } if (range.w == 0f) { range.w = mScreenSize.y * 0.5f; } RuntimePlatform platform = Application.platform; if (platform == RuntimePlatform.WindowsPlayer || platform == RuntimePlatform.WindowsWebPlayer || platform == RuntimePlatform.WindowsEditor) { range.x -= 0.5f; range.y += 0.5f; } Transform t = cachedTransform; for (int i = 0, imax = mDrawCalls.size; i < imax; ++i) { UIDrawCall dc = mDrawCalls.buffer[i]; dc.clipping = mClipping; dc.clipRange = range; dc.clipSoftness = mClipSoftness; dc.depthPass = depthPass; // Set the draw call's transform to match the panel's. // Note that parenting directly to the panel causes unity to crash as soon as you hit Play. Transform dt = dc.transform; dt.position = t.position; dt.rotation = t.rotation; dt.localScale = t.lossyScale; } } /// <summary> /// Set the draw call's geometry responsible for the specified material. /// </summary> void Fill(Material mat) { // Cleanup deleted widgets for (int i = mWidgets.size; i > 0;) { if (mWidgets[--i] == null) { mWidgets.RemoveAt(i); } } // Fill the buffers for the specified material for (int i = 0, imax = mWidgets.size; i < imax; ++i) { UIWidget w = mWidgets.buffer[i]; if (w.visibleFlag == 1 && w.material == mat) { UINode node = GetNode(w.cachedTransform); if (node != null) { if (generateNormals) { w.WriteToBuffers(mVerts, mUvs, mCols, mNorms, mTans); } else { w.WriteToBuffers(mVerts, mUvs, mCols, null, null); } } else { Debug.LogError("No transform found for " + NGUITools.GetHierarchy(w.gameObject), this); } } } if (mVerts.size > 0) { // Rebuild the draw call's mesh UIDrawCall dc = GetDrawCall(mat, true); dc.depthPass = depthPass; dc.Set(mVerts, generateNormals ? mNorms : null, generateNormals ? mTans : null, mUvs, mCols); } else { // There is nothing to draw for this material -- eliminate the draw call UIDrawCall dc = GetDrawCall(mat, false); if (dc != null) { mDrawCalls.Remove(dc); NGUITools.DestroyImmediate(dc.gameObject); } } // Cleanup mVerts.Clear(); mNorms.Clear(); mTans.Clear(); mUvs.Clear(); mCols.Clear(); } /// <summary> /// Main update function /// </summary> void LateUpdate() { UpdateTransformMatrix(); UpdateTransforms(); // Always move widgets to the panel's layer if (mLayer != gameObject.layer) { mLayer = gameObject.layer; UICamera uic = UICamera.FindCameraForLayer(mLayer); mCam = (uic != null) ? uic.cachedCamera : NGUITools.FindCameraForLayer(mLayer); SetChildLayer(cachedTransform, mLayer); for (int i = 0, imax = drawCalls.size; i < imax; ++i) { mDrawCalls.buffer[i].gameObject.layer = mLayer; } } UpdateWidgets(); // If the depth has changed, we need to re-sort the widgets if (mDepthChanged) { mDepthChanged = false; mWidgets.Sort(UIWidget.CompareFunc); } // Fill the draw calls for all of the changed materials for (int i = 0, imax = mChanged.size; i < imax; ++i) { Fill(mChanged.buffer[i]); } // Update the clipping rects UpdateDrawcalls(); mChanged.Clear(); mRebuildAll = false; #if UNITY_EDITOR mScreenSize = new Vector2(Screen.width, Screen.height); UIRoot root = NGUITools.FindInParents <UIRoot>(gameObject); if (root != null) { mScreenSize *= root.GetPixelSizeAdjustment(Screen.height); } #endif }
void UpdateMoveToDest() { Vector3 move = Vector3.zero; if (mWalkMode == EWalkMode.EWM_Dst) { // 开始移动时,需要先同步一次位置 if (mWalkToPoint == false) { mWalkToPoint = true; if (OnWalkToPointChange != null) { OnWalkToPointChange(mDst); } } Vector3 d = mDst; d.y = 0.0f; Vector3 p = mOwnerTrans.position; p.y = 0.0f; Vector3 vec = d - p; float ds = MoveSpeed * Time.deltaTime; if (vec.magnitude <= ds) { move = vec; mOwner.MoveImplement.Move(move, true); if (mDestList.size <= 0) { TurnDirImmediate(move); ReachDst();//TODO @hzb 跳转进副本后,如果角色没有进一步动作,此处会不停调用 return; } else { // 到达目标位置后,从mDestList中移除第一个点 mDestList.RemoveAt(0); if (mDestList.size <= 0) { TurnDirImmediate(move); ReachDst(); return; } mDst = mDestList[0]; if (OnWalkToPointChange != null) { OnWalkToPointChange(mDst); } return; } } mDir = vec.normalized; move.x = mDir.x * MoveSpeed * Time.deltaTime; move.z = mDir.z * MoveSpeed * Time.deltaTime; } else { move.x = mDir.x * MoveSpeed * Time.deltaTime; move.z = mDir.z * MoveSpeed * Time.deltaTime; } //if (!IsGrounded()) // move.y = -Time.deltaTime * 0.3f; TurnDirSmooth(move); mOwner.MoveImplement.Move(move, true); }
private static bool LoadCSV(byte[] bytes, TextAsset asset, bool merge = false) { if (bytes == null) { return(false); } ByteReader byteReader = new ByteReader(bytes); BetterList <string> betterList = byteReader.ReadCSV(); if (betterList.size < 2) { return(false); } betterList.RemoveAt(0); string[] array = null; if (string.IsNullOrEmpty(Localization.mLanguage)) { Localization.localizationHasBeenSet = false; } if (!Localization.localizationHasBeenSet || (!merge && !Localization.mMerging) || Localization.mLanguages == null || Localization.mLanguages.Length == 0) { Localization.mDictionary.Clear(); Localization.mLanguages = new string[betterList.size]; if (!Localization.localizationHasBeenSet) { Localization.mLanguage = PlayerPrefs.GetString("Language", betterList[0]); Localization.localizationHasBeenSet = true; } for (int i = 0; i < betterList.size; i++) { Localization.mLanguages[i] = betterList[i]; if (Localization.mLanguages[i] == Localization.mLanguage) { Localization.mLanguageIndex = i; } } } else { array = new string[betterList.size]; for (int j = 0; j < betterList.size; j++) { array[j] = betterList[j]; } for (int k = 0; k < betterList.size; k++) { if (!Localization.HasLanguage(betterList[k])) { int num = Localization.mLanguages.Length + 1; Array.Resize <string>(ref Localization.mLanguages, num); Localization.mLanguages[num - 1] = betterList[k]; Dictionary <string, string[]> dictionary = new Dictionary <string, string[]>(); foreach (KeyValuePair <string, string[]> current in Localization.mDictionary) { string[] value = current.Value; Array.Resize <string>(ref value, num); value[num - 1] = value[0]; dictionary.Add(current.Key, value); } Localization.mDictionary = dictionary; } } } Dictionary <string, int> dictionary2 = new Dictionary <string, int>(); for (int l = 0; l < Localization.mLanguages.Length; l++) { dictionary2.Add(Localization.mLanguages[l], l); } while (true) { BetterList <string> betterList2 = byteReader.ReadCSV(); if (betterList2 == null || betterList2.size == 0) { break; } if (!string.IsNullOrEmpty(betterList2[0])) { Localization.AddCSV(betterList2, array, dictionary2); } } if (!Localization.mMerging && Localization.onLocalize != null) { Localization.mMerging = true; Localization.OnLocalizeNotification onLocalizeNotification = Localization.onLocalize; Localization.onLocalize = null; onLocalizeNotification(); Localization.onLocalize = onLocalizeNotification; Localization.mMerging = false; } if (merge) { if (Localization.onLocalize != null) { Localization.onLocalize(); } UIRoot.Broadcast("OnLocalize"); } return(true); }
private static bool LoadCSV(byte[] bytes, TextAsset asset, bool merge = false) { if (bytes == null) { return(false); } ByteReader byteReader = new ByteReader(bytes); BetterList <string> betterList = byteReader.ReadCSV(); if (betterList.size < 2) { return(false); } betterList.RemoveAt(0); string[] array = null; if (string.IsNullOrEmpty(mLanguage)) { localizationHasBeenSet = false; } if (!localizationHasBeenSet || (!merge && !mMerging) || mLanguages == null || mLanguages.Length == 0) { mDictionary.Clear(); mLanguages = new string[betterList.size]; if (!localizationHasBeenSet) { mLanguage = PlayerPrefs.GetString("Language", betterList[0]); localizationHasBeenSet = true; } for (int i = 0; i < betterList.size; i++) { mLanguages[i] = betterList[i]; if (mLanguages[i] == mLanguage) { mLanguageIndex = i; } } } else { array = new string[betterList.size]; for (int j = 0; j < betterList.size; j++) { array[j] = betterList[j]; } for (int k = 0; k < betterList.size; k++) { if (!HasLanguage(betterList[k])) { int num = mLanguages.Length + 1; Array.Resize(ref mLanguages, num); mLanguages[num - 1] = betterList[k]; Dictionary <string, string[]> dictionary = new Dictionary <string, string[]>(); foreach (KeyValuePair <string, string[]> item in mDictionary) { string[] array2 = item.Value; Array.Resize(ref array2, num); array2[num - 1] = array2[0]; dictionary.Add(item.Key, array2); } mDictionary = dictionary; } } } Dictionary <string, int> dictionary2 = new Dictionary <string, int>(); for (int l = 0; l < mLanguages.Length; l++) { dictionary2.Add(mLanguages[l], l); } while (true) { BetterList <string> betterList2 = byteReader.ReadCSV(); if (betterList2 == null || betterList2.size == 0) { break; } if (!string.IsNullOrEmpty(betterList2[0])) { AddCSV(betterList2, array, dictionary2); } } if (!mMerging && onLocalize != null) { mMerging = true; OnLocalizeNotification onLocalizeNotification = onLocalize; onLocalize = null; onLocalizeNotification(); onLocalize = onLocalizeNotification; mMerging = false; } return(true); }
public static bool LoadCSV(byte[] bytes) { if (bytes == null) { return(false); } ByteReader reader = new ByteReader(bytes); // The first line should contain "KEY", followed by languages. BetterList <string> header = reader.ReadCSV(); // There must be at least two columns in a valid CSV file if (header.size < 2) { return(false); } header.RemoveAt(0); _langIndex = 0; _langs = new string[header.size]; for (int i = 0; i < header.size; i++) { _langs[i] = header[i]; } _langMap = new Dictionary <string, string[]>(); _langKeys = new List <string>(); for (; ;) { BetterList <string> temp = reader.ReadCSV(); if (temp == null || temp.size == 0) { break; } string key = temp[0]; if (string.IsNullOrEmpty(key)) { continue; } var fields = new string[_langs.Length]; for (int i = 1; i < temp.size; i++) { try { fields[i - 1] = temp[i]; } catch (Exception) { Debug.LogErrorFormat("当前key解析出错:{0}", key, string.Join("|", temp.ToArray())); throw; } } if (_langMap.ContainsKey(key)) { Debug.LogErrorFormat("存在重复ID,请检查配置表:<{0}> 行号:{1}", key, _langKeys.Count + 2); } else { _langMap.Add(key, fields); _langKeys.Add(key); } } UIRoot.BroadcastMessage("OnLocalize", SendMessageOptions.DontRequireReceiver); Debug.LogFormat("Load Localization csv success! langs:{0} key:{1}", _langs.Length, _langMap.Count); return(true); }
private void Update() { if (!mActive) { return; } if (mReset) { mCurrentOffset = 0; mReset = false; mLabel = GetComponent <UILabel>(); mFullText = mLabel.processedText; mFade.Clear(); if (keepFullDimensions && scrollView != null) { scrollView.UpdatePosition(); } } while (mCurrentOffset < mFullText.Length && mNextChar <= RealTime.time) { int num = mCurrentOffset; charsPerSecond = Mathf.Max(1, charsPerSecond); while (NGUIText.ParseSymbol(mFullText, ref mCurrentOffset)) { } mCurrentOffset++; if (mCurrentOffset > mFullText.Length) { break; } float num2 = 1f / (float)charsPerSecond; char c = (num >= mFullText.Length) ? '\n' : mFullText[num]; if (c == '\n') { num2 += delayOnNewLine; } else if (num + 1 == mFullText.Length || mFullText[num + 1] <= ' ') { switch (c) { case '.': if (num + 2 < mFullText.Length && mFullText[num + 1] == '.' && mFullText[num + 2] == '.') { num2 += delayOnPeriod * 3f; num += 2; } else { num2 += delayOnPeriod; } break; case '!': case '?': num2 += delayOnPeriod; break; } } if (mNextChar == 0f) { mNextChar = RealTime.time + num2; } else { mNextChar += num2; } if (fadeInTime != 0f) { FadeEntry item = default(FadeEntry); item.index = num; item.alpha = 0f; item.text = mFullText.Substring(num, mCurrentOffset - num); mFade.Add(item); } else { mLabel.text = ((!keepFullDimensions) ? mFullText.Substring(0, mCurrentOffset) : (mFullText.Substring(0, mCurrentOffset) + "[00]" + mFullText.Substring(mCurrentOffset))); if (!keepFullDimensions && scrollView != null) { scrollView.UpdatePosition(); } } } if (mFade.size != 0) { int num3 = 0; while (num3 < mFade.size) { FadeEntry value = mFade[num3]; value.alpha += RealTime.deltaTime / fadeInTime; if (value.alpha < 1f) { mFade[num3] = value; num3++; } else { mFade.RemoveAt(num3); } } if (mFade.size == 0) { if (keepFullDimensions) { mLabel.text = mFullText.Substring(0, mCurrentOffset) + "[00]" + mFullText.Substring(mCurrentOffset); } else { mLabel.text = mFullText.Substring(0, mCurrentOffset); } return; } StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < mFade.size; i++) { FadeEntry fadeEntry = mFade[i]; if (i == 0) { stringBuilder.Append(mFullText.Substring(0, fadeEntry.index)); } stringBuilder.Append('['); stringBuilder.Append(NGUIText.EncodeAlpha(fadeEntry.alpha)); stringBuilder.Append(']'); stringBuilder.Append(fadeEntry.text); } if (keepFullDimensions) { stringBuilder.Append("[00]"); stringBuilder.Append(mFullText.Substring(mCurrentOffset)); } mLabel.text = stringBuilder.ToString(); } else if (mCurrentOffset == mFullText.Length) { current = this; EventDelegate.Execute(onFinished); current = null; mActive = false; } }
/// <summary> /// Get a draw call at the specified index position. /// </summary> UIDrawCall GetDrawCall(int index, Material mat, Texture tex, Shader shader) { if (index < UIDrawCall.list.size) { UIDrawCall dc = UIDrawCall.list.buffer[index]; // If the material and texture match, keep using the same draw call if (dc != null && dc.manager == this && dc.baseMaterial == mat && dc.mainTexture == tex && dc.shader == shader) { return(dc); } // Otherwise we need to destroy all the draw calls that follow for (int i = UIDrawCall.list.size; i > index;) { UIDrawCall rem = UIDrawCall.list.buffer[--i]; if (rem != null) { UIDrawCall.list.RemoveAt(i); NGUITools.DestroyImmediate(rem.gameObject); } } } #if UNITY_EDITOR string name; if (tex != null) { name = tex.name; } else if (shader != null) { name = shader.name; } else if (mat != null) { name = mat.name; } else { name = ""; } // If we're in the editor, create the game object with hide flags set right away GameObject go = UnityEditor.EditorUtility.CreateGameObjectWithHideFlags("_UIDrawCall [" + name + "]", //HideFlags.DontSave | HideFlags.NotEditable); HideFlags.HideAndDontSave); #else GameObject go = new GameObject(); DontDestroyOnLoad(go); #endif go.layer = cachedGameObject.layer; // Create the draw call UIDrawCall drawCall = go.AddComponent <UIDrawCall>(); drawCall.baseMaterial = mat; drawCall.mainTexture = tex; drawCall.shader = shader; drawCall.renderQueue = UIDrawCall.list.size; drawCall.manager = this; //Debug.Log("Added DC " + mat.name + " as " + UIDrawCall.list.size); for (int i = mDrawCalls.size; i > 0;) { if (!mDrawCalls.buffer[--i]) { mDrawCalls.RemoveAt(i); } } mDrawCalls.Add(drawCall); UIDrawCall.list.Add(drawCall); return(drawCall); }
/// <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; case "[s]": strike = 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 "[/s]": strike = false; index += 4; return true; default: int a = (NGUIMath.HexToDecimal(text[index + 1]) << 4) | NGUIMath.HexToDecimal(text[index + 2]); mAlpha = a / 255f; 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; } } 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; case "[/url]": index += 6; return true; } } if (text[index + 1] == 'u' && text[index + 2] == 'r' && text[index + 3] == 'l' && text[index + 4] == '=') { int closingBracket = text.IndexOf(']', index + 4); if (closingBracket != -1) { index = closingBracket + 1; return true; } else { index = text.Length; return true; } } if (index + 8 > length) return false; if (text[index + 7] == ']') { Color c = ParseColor24(text, index + 1); if (EncodeColor24(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; } if (index + 10 > length) return false; if (text[index + 9] == ']') { Color c = ParseColor32(text, index + 1); if (EncodeColor32(c) != text.Substring(index + 1, 8).ToUpper()) return false; if (colors != null) { if (premultiply && c.a != 1f) c = Color.Lerp(mInvisible, c, c.a); colors.Add(c); } index += 10; return true; } return false; }
/// <summary> /// Convenience function that figures out the panel's correct change flag by searching the parents. /// </summary> int GetChangeFlag(UINode start) { int flag = start.changeFlag; if (flag == -1) { Transform trans = start.trans.parent; UINode sub; // Keep going until we find a set flag for (;;) { // Check the parent's flag #if USE_SIMPLE_DICTIONARY if (trans != null && mChildren.TryGetValue(trans, out sub)) { #else if (trans != null && mChildren.Contains(trans)) { sub = (UINode)mChildren[trans]; #endif flag = sub.changeFlag; trans = trans.parent; // If the flag hasn't been set either, add this child to the hierarchy if (flag == -1) { mHierarchy.Add(sub); } else { break; } } else { flag = 0; break; } } // Update the parent flags for (int i = 0, imax = mHierarchy.size; i < imax; ++i) { UINode pc = mHierarchy.buffer[i]; pc.changeFlag = flag; } mHierarchy.Clear(); } return(flag); } /// <summary> /// Update the world-to-local transform matrix as well as clipping bounds. /// </summary> void UpdateTransformMatrix() { if (mUpdateTime == 0f || mMatrixTime != mUpdateTime) { mMatrixTime = mUpdateTime; mWorldToLocal = cachedTransform.worldToLocalMatrix; if (mClipping != UIDrawCall.Clipping.None) { Vector2 size = new Vector2(mClipRange.z, mClipRange.w); if (size.x == 0f) { size.x = (mCam == null) ? Screen.width : mCam.pixelWidth; } if (size.y == 0f) { size.y = (mCam == null) ? Screen.height : mCam.pixelHeight; } size *= 0.5f; mMin.x = mClipRange.x - size.x; mMin.y = mClipRange.y - size.y; mMax.x = mClipRange.x + size.x; mMax.y = mClipRange.y + size.y; } } } /// <summary> /// Run through all managed transforms and see if they've changed. /// </summary> void UpdateTransforms() { mChangedLastFrame = false; bool transformsChanged = false; bool shouldCull = false; #if UNITY_EDITOR shouldCull = (clipping != UIDrawCall.Clipping.None) && (!Application.isPlaying || mUpdateTime > mCullTime); if (!Application.isPlaying || !widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled) #else shouldCull = (clipping != UIDrawCall.Clipping.None) && (mUpdateTime > mCullTime); if (!widgetsAreStatic || mWidgetsAdded || shouldCull != mCulled) #endif { #if USE_SIMPLE_DICTIONARY foreach (KeyValuePair <Transform, UINode> child in mChildren) { UINode node = child.Value; #else for (int i = 0, imax = mChildren.Count; i < imax; ++i) { UINode node = (UINode)mChildren[i]; #endif if (node.trans == null) { mRemoved.Add(node.trans); continue; } if (node.HasChanged()) { node.changeFlag = 1; transformsChanged = true; #if UNITY_EDITOR Vector3 s = node.trans.lossyScale; float min = Mathf.Abs(Mathf.Min(s.x, s.y)); if (min == 0f) { Debug.LogError("Scale of 0 is invalid! Zero cannot be divided by, which causes problems. Use a small value instead, such as 0.01\n" + node.trans.lossyScale, node.trans); } #endif } else { node.changeFlag = -1; } } // Clean up the deleted transforms for (int i = 0, imax = mRemoved.Count; i < imax; ++i) { mChildren.Remove(mRemoved[i]); } mRemoved.Clear(); } // If the children weren't culled but should be, check their visibility if (!mCulled && shouldCull) { mCheckVisibility = true; } // If something has changed, propagate the changes *down* the tree hierarchy (to children). // An alternative (but slower) approach would be to do a pc.trans.GetComponentsInChildren<UIWidget>() // in the loop above, and mark each one as dirty. if (mCheckVisibility || transformsChanged || mRebuildAll) { #if USE_SIMPLE_DICTIONARY foreach (KeyValuePair <Transform, UINode> child in mChildren) { UINode pc = child.Value; #else for (int i = 0, imax = mChildren.Count; i < imax; ++i) { UINode pc = (UINode)mChildren[i]; #endif if (pc.widget != null) { int visibleFlag = 1; // No sense in checking the visibility if we're not culling anything (as the visibility is always 'true') if (shouldCull || transformsChanged) { // If the change flag has not yet been determined... if (pc.changeFlag == -1) { pc.changeFlag = GetChangeFlag(pc); } // Is the widget visible? if (shouldCull) { visibleFlag = (mCheckVisibility || pc.changeFlag == 1) ? (IsVisible(pc.widget) ? 1 : 0) : pc.visibleFlag; } } // If visibility changed, mark the node as changed as well if (pc.visibleFlag != visibleFlag) { pc.changeFlag = 1; } // If the node has changed and the widget is visible (or was visible before) if (pc.changeFlag == 1 && (visibleFlag == 1 || pc.visibleFlag != 0)) { // Update the visibility flag pc.visibleFlag = visibleFlag; Material mat = pc.widget.material; // Add this material to the list of changed materials if (!mChanged.Contains(mat)) { mChanged.Add(mat); mChangedLastFrame = true; } } } } } mCulled = shouldCull; mCheckVisibility = false; mWidgetsAdded = false; } /// <summary> /// Update all widgets and rebuild their geometry if necessary. /// </summary> void UpdateWidgets() { #if USE_SIMPLE_DICTIONARY foreach (KeyValuePair <Transform, UINode> c in mChildren) { UINode pc = c.Value; #else for (int i = 0, imax = mChildren.Count; i < imax; ++i) { UINode pc = (UINode)mChildren[i]; #endif UIWidget w = pc.widget; // If the widget is visible, update it if (pc.visibleFlag == 1 && w != null && w.UpdateGeometry(ref mWorldToLocal, (pc.changeFlag == 1), generateNormals)) { // We will need to refill this buffer if (!mChanged.Contains(w.material)) { mChanged.Add(w.material); mChangedLastFrame = true; } } pc.changeFlag = 0; } } /// <summary> /// Update the clipping rect in the shaders and draw calls' positions. /// </summary> bool nestingClip = false; Vector4 newClipRange = Vector4.zero; public void UpdateDrawcalls() { Vector4 range = Vector4.zero; if (mClipping != UIDrawCall.Clipping.None) { UIDraggablePanel dragPanel = gameObject.GetComponent <UIDraggablePanel>(); if (dragPanel != null && gameObject.transform.parent != null) { UIPanel parentPanel = NGUITools.FindInParents <UIPanel>(gameObject.transform.parent.gameObject); if (parentPanel != null && parentPanel.transform.parent != null && parentPanel.clipping != UIDrawCall.Clipping.None) { Vector3 worldPos = transform.TransformPoint(Vector3.zero); Vector3 localPos = parentPanel.transform.parent.InverseTransformPoint(worldPos); newClipRange = mClipRange; Vector4 parentRect = new Vector4(-localPos.x - parentPanel.clipRange.z / 2 , -localPos.y - parentPanel.clipRange.w / 2 , -localPos.x + parentPanel.clipRange.z / 2 , -localPos.y + parentPanel.clipRange.w / 2); Vector4 selfRect = new Vector4(newClipRange.x - newClipRange.z / 2 , newClipRange.y - newClipRange.w / 2 , newClipRange.x + newClipRange.z / 2 , newClipRange.y + newClipRange.w / 2 ); if (selfRect.x < parentRect.x) { selfRect.x = parentRect.x; nestingClip = true; } if (selfRect.y < parentRect.y) { selfRect.y = parentRect.y; nestingClip = true; } if (selfRect.z > parentRect.z) { selfRect.z = parentRect.z; nestingClip = true; } if (selfRect.w > parentRect.w) { selfRect.w = parentRect.w; nestingClip = true; } float xLength = selfRect.z - selfRect.x; if (xLength < 0) { xLength = 0.0001f; } float yLength = selfRect.w - selfRect.y; if (yLength < 0) { yLength = 0.0001f; } newClipRange = new Vector4(selfRect.x + xLength / 2 , selfRect.y + yLength / 2 , xLength , yLength); //if (newClipRange.x < -localPos.x - Mathf.Abs(parentPanel.clipRange.z - newClipRange.z)/2) //{ // float offset = -localPos.x - Mathf.Abs(parentPanel.clipRange.z - newClipRange.z)/2; // newClipRange.x = offset / 2; // newClipRange.z -= offset; // nestingClip = true; //} //else if (newClipRange.x > -localPos.x + Mathf.Abs(parentPanel.clipRange.z - newClipRange.z)/2) //{ // float offset = localPos.x + Mathf.Abs(parentPanel.clipRange.z - newClipRange.z)/2; // newClipRange.x -= offset / 2; // newClipRange.z = offset; // nestingClip = true; //} //else //{ // nestingClip = false; //} //if (newClipRange.y < -localPos.y) //{ // newClipRange.y = -localPos.y; // newClipRange.w = parentPanel.clipRange.w; //} } } if (nestingClip) { range = new Vector4(newClipRange.x, newClipRange.y, newClipRange.z * 0.5f, newClipRange.w * 0.5f); } else { range = new Vector4(mClipRange.x, mClipRange.y, mClipRange.z * 0.5f, mClipRange.w * 0.5f); } } if (range.z == 0f) { range.z = Screen.width * 0.5f; } if (range.w == 0f) { range.w = Screen.height * 0.5f; } RuntimePlatform platform = Application.platform; if (platform == RuntimePlatform.WindowsPlayer || platform == RuntimePlatform.WindowsWebPlayer || platform == RuntimePlatform.WindowsEditor) { range.x -= 0.5f; range.y += 0.5f; } Transform t = cachedTransform; for (int i = 0, imax = mDrawCalls.size; i < imax; ++i) { UIDrawCall dc = mDrawCalls.buffer[i]; dc.clipping = mClipping; dc.clipRange = range; dc.clipSoftness = mClipSoftness; dc.depthPass = depthPass; // Set the draw call's transform to match the panel's. // Note that parenting directly to the panel causes unity to crash as soon as you hit Play. Transform dt = dc.transform; dt.position = t.position; dt.rotation = t.rotation; dt.localScale = t.lossyScale; } } /// <summary> /// Set the draw call's geometry responsible for the specified material. /// </summary> void Fill(Material mat) { // Cleanup deleted widgets for (int i = mWidgets.size; i > 0;) { if (mWidgets[--i] == null) { mWidgets.RemoveAt(i); } } // Fill the buffers for the specified material for (int i = 0, imax = mWidgets.size; i < imax; ++i) { UIWidget w = mWidgets.buffer[i]; if (w.visibleFlag == 1 && w.material == mat) { UINode node = GetNode(w.cachedTransform); if (node != null) { if (generateNormals) { w.WriteToBuffers(mVerts, mUvs, mCols, mNorms, mTans); } else { w.WriteToBuffers(mVerts, mUvs, mCols, null, null); } } else { Debug.LogError("No transform found for " + NGUITools.GetHierarchy(w.gameObject), this); } } } if (mVerts.size > 0) { // Rebuild the draw call's mesh UIDrawCall dc = GetDrawCall(mat, true); dc.depthPass = depthPass; dc.Set(mVerts, generateNormals ? mNorms : null, generateNormals ? mTans : null, mUvs, mCols); } else { // There is nothing to draw for this material -- eliminate the draw call UIDrawCall dc = GetDrawCall(mat, false); if (dc != null) { mDrawCalls.Remove(dc); NGUITools.DestroyImmediate(dc.gameObject); } } // Cleanup mVerts.Clear(); mNorms.Clear(); mTans.Clear(); mUvs.Clear(); mCols.Clear(); }
void Update() { if (!mActive) { return; } if (mReset) { mCurrentOffset = 0; mReset = false; mLabel = GetComponent <UILabel>(); mFullText = mLabel.processedText; mFade.Clear(); if (keepFullDimensions && scrollView != null) { scrollView.UpdatePosition(); } } while (mCurrentOffset < mFullText.Length && mNextChar <= RealTime.time) { int lastOffset = mCurrentOffset; charsPerSecond = Mathf.Max(1, charsPerSecond); // Automatically skip all symbols while (NGUIText.ParseSymbol(mFullText, ref mCurrentOffset)) { } ++mCurrentOffset; // Reached the end? We're done. if (mCurrentOffset > mFullText.Length) { break; } // Periods and end-of-line characters should pause for a longer time. float delay = 1f / charsPerSecond; char c = (lastOffset < mFullText.Length) ? mFullText[lastOffset] : '\n'; if (c == '\n') { delay += delayOnNewLine; } else if (lastOffset + 1 == mFullText.Length || mFullText[lastOffset + 1] <= ' ') { if (c == '.') { if (lastOffset + 2 < mFullText.Length && mFullText[lastOffset + 1] == '.' && mFullText[lastOffset + 2] == '.') { delay += delayOnPeriod * 3f; lastOffset += 2; } else { delay += delayOnPeriod; } } else if (c == '!' || c == '?') { delay += delayOnPeriod; } } if (mNextChar == 0f) { mNextChar = RealTime.time + delay; } else { mNextChar += delay; } if (fadeInTime != 0f) { // There is smooth fading involved FadeEntry fe = new FadeEntry(); fe.index = lastOffset; fe.alpha = 0f; fe.text = mFullText.Substring(lastOffset, mCurrentOffset - lastOffset); mFade.Add(fe); } else { // No smooth fading necessary mLabel.text = keepFullDimensions ? mFullText.Substring(0, mCurrentOffset) + "[00]" + mFullText.Substring(mCurrentOffset) : mFullText.Substring(0, mCurrentOffset); // If a scroll view was specified, update its position if (!keepFullDimensions && scrollView != null) { scrollView.UpdatePosition(); } } } // Alpha-based fading if (mFade.size != 0) { for (int i = 0; i < mFade.size;) { FadeEntry fe = mFade[i]; fe.alpha += RealTime.deltaTime / fadeInTime; if (fe.alpha < 1f) { mFade[i] = fe; ++i; } else { mFade.RemoveAt(i); } } if (mFade.size == 0) { if (keepFullDimensions) { mLabel.text = mFullText.Substring(0, mCurrentOffset) + "[00]" + mFullText.Substring(mCurrentOffset); } else { mLabel.text = mFullText.Substring(0, mCurrentOffset); } } else { StringBuilder sb = new StringBuilder(); for (int i = 0; i < mFade.size; ++i) { FadeEntry fe = mFade[i]; if (i == 0) { sb.Append(mFullText.Substring(0, fe.index)); } sb.Append('['); sb.Append(NGUIText.EncodeAlpha(fe.alpha)); sb.Append(']'); sb.Append(fe.text); } if (keepFullDimensions) { sb.Append("[00]"); sb.Append(mFullText.Substring(mCurrentOffset)); } mLabel.text = sb.ToString(); } } else if (mCurrentOffset == mFullText.Length) { current = this; EventDelegate.Execute(onFinished); current = null; mActive = false; } }
public static List <T> LoadImportData <T>(string fileName) { #if UNITY_EDITOR object obj = Resources.Load("Data/" + fileName); if (obj == null) { obj = BundleManager.LoadTable(fileName); if (obj == null) { Debug.LogWarning("not found file :" + fileName); return(null); } } #else object obj = BundleManager.LoadTable(fileName); if (obj == null) { obj = Resources.Load("Data/" + fileName); if (obj == null) { return(null); } } #endif ByteReader reader = new ByteReader(GetBytes(obj)); BetterList <string> keyList = reader.ReadCSV(); while (keyList != null) { if (keyList[0].Contains("*")) { keyList.RemoveAt(0); break; } keyList = reader.ReadCSV(); } List <T> mDataList = new List <T>(); int nameLen = keyList.size; FieldInfo[] fieldInfo = new FieldInfo[nameLen]; for (int i = 0; i < nameLen; i++) { fieldInfo[i] = typeof(T).GetField(keyList[i]); } BetterList <string> temp; temp = reader.ReadCSV(); while (temp != null) { if (string.IsNullOrEmpty(temp[0]) || !temp[0].Contains("*")) { temp = reader.ReadCSV(); continue; } temp.RemoveAt(0); { T t = (default(T) == null) ? Activator.CreateInstance <T>() : default(T); for (int j = 0; j < temp.size; j++) { object v = null; string s = temp[j]; if (string.IsNullOrEmpty(s) || fieldInfo[j] == null) { continue; } if (fieldInfo[j].FieldType.IsEnum) { try { v = Enum.Parse(fieldInfo[j].FieldType, s); } catch (Exception ex) { Debug.Log("error datafile=" + fileName + " fieldinfo=" + fieldInfo[j].Name + " fieldinfoValue=" + s); } } else { try { v = Convert.ChangeType(s, fieldInfo[j].FieldType); } catch (Exception ex) { Debug.Log("error datafile=" + fileName + " fieldinfo=" + fieldInfo[j].Name + " fieldinfoValue=" + s + " ID " + temp[0]); } } fieldInfo[j].SetValue(t, v); } mDataList.Add(t); } temp = reader.ReadCSV(); } return(mDataList); }
/// <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; }
private BetterList<BattleMonster> cleanReturnTargets(BetterList<BattleMonster> aReturns) { // Remove those with no HP left for(byte c = 0;c<aReturns.size;c++) { if(aReturns[c]==null||aReturns[c].monster.restingStatus!=ERestingStatus.Awake) { aReturns.RemoveAt(c); c--; } } return aReturns; }