private static void Swap(List <TreeWindSfxManager.TreeInfo> trees, int a, int b) { if (a != b) { TreeWindSfxManager.TreeInfo value = trees[a]; trees[a] = trees[b]; trees[b] = value; } }
private static TreeWindSfxManager.TreeInfo GetTreeInfo(TreeWindSfx tree) { TreeWindSfxManager.TreeInfo treeInfo; if (TreeWindSfxManager.sTreeInfoListPool.Count > 0) { treeInfo = TreeWindSfxManager.sTreeInfoListPool.Dequeue(); treeInfo.Init(tree); } else { treeInfo = new TreeWindSfxManager.TreeInfo(tree); } return(treeInfo); }
public static void Remove(TreeWindSfx tree) { if (TreeWindSfxManager.sTrees.Contains(tree)) { TreeWindSfxManager.sTrees.Remove(tree); for (int i = 0; i < TreeWindSfxManager.sTreeInfoList.Count; i++) { TreeWindSfxManager.TreeInfo treeInfo = TreeWindSfxManager.sTreeInfoList[i]; if (treeInfo.tree == tree) { treeInfo.Clear(); TreeWindSfxManager.sTreeInfoListPool.Enqueue(treeInfo); TreeWindSfxManager.sTreeInfoList.RemoveAt(i); break; } } } }
private void UpdateVirtualisation() { if (TreeWindSfxManager.sTrees.Count <= this.TargetActiveCount) { foreach (TreeWindSfx treeWindSfx in TreeWindSfxManager.sTrees) { treeWindSfx.Activate(); } } else { List <TreeWindSfxManager.TreeInfo> list = TreeWindSfxManager.sTreeInfoList; if (LocalPlayer.Transform != null) { Vector3 position = LocalPlayer.Transform.position; for (int i = 0; i < list.Count; i++) { TreeWindSfxManager.TreeInfo treeInfo = list[i]; Vector3 vector = treeInfo.position - position; treeInfo.sqrDistance = vector.sqrMagnitude; treeInfo.direction = Mathf.Atan2(vector.z, vector.x); } } for (int j = 0; j < this.TargetActiveCount; j++) { int num = j; for (int k = j + 1; k < list.Count; k++) { if (list[k].sqrDistance < list[num].sqrDistance) { num = k; } } TreeWindSfxManager.Swap(list, j, num); list[j].tree.Activate(); TreeWindSfxManager.OccludeTrees(list[j], this.TreeOcclusionWidth, list, j + 1); } for (int l = this.TargetActiveCount; l < list.Count; l++) { list[l].tree.Deactivate(this.TreePersistTime); } } }
private static void OccludeTrees(TreeWindSfxManager.TreeInfo occluder, float occlusionWidth, List <TreeWindSfxManager.TreeInfo> trees, int startIndex) { if (startIndex < trees.Count) { float num; if (occluder.sqrDistance > 0f) { num = Mathf.Atan(occlusionWidth / 2f / Mathf.Sqrt(occluder.sqrDistance)); } else { num = 3.14159274f; } float num2 = occluder.direction - num; float num3 = occluder.direction + num; if (num2 < 0f) { num2 += 6.28318548f; num3 += 6.28318548f; } for (int i = startIndex; i < trees.Count; i++) { float num4 = trees[i].direction; if (num4 < num2) { num4 += 6.28318548f; } if (num2 <= num4 && num4 <= num3) { float num5 = (num4 - num2) / num; num5 -= 1f; num5 = 3f - 2f * Math.Abs(num5); trees[i].sqrDistance *= num5 * num5; } } } }
private static void DrawDebug() { if (TreeWindSfxManager.activeTexture == null) { TreeWindSfxManager.CreateDebugTextures(); } List <TreeWindSfxManager.TreeInfo> list = TreeWindSfxManager.sTreeInfoList; float num = 0f; int num2 = 0; for (int i = 0; i < list.Count; i++) { TreeWindSfxManager.TreeInfo treeInfo = list[i]; TreeWindSfx tree = treeInfo.tree; Vector3 vector = LocalPlayer.Transform.InverseTransformPoint(tree.transform.position); num = Math.Max(num, vector.sqrMagnitude); if (tree.IsActive) { num2++; } treeInfo.sqrDistance = vector.sqrMagnitude; treeInfo.direction = Mathf.Atan2(vector.z, vector.x); } num = Mathf.Sqrt(num); Vector2 vector2 = new Vector2(110f, (float)(Camera.main.pixelHeight - 110)); GUI.Box(new Rect(vector2.x - 105f, vector2.y - 105f - 35f, 210f, 245f), string.Format("Active trees: {0} Total trees: {1}", num2, list.Count)); foreach (TreeWindSfxManager.TreeInfo treeInfo2 in list) { float num3 = Mathf.Sqrt(treeInfo2.sqrDistance) / num * 100f; float num4 = vector2.x + num3 * Mathf.Cos(treeInfo2.direction); float num5 = vector2.y - num3 * Mathf.Sin(treeInfo2.direction); Texture2D image = (!treeInfo2.tree.IsActive) ? TreeWindSfxManager.inactiveTexture : TreeWindSfxManager.activeTexture; GUI.DrawTexture(new Rect(num4 - 5f, num5 - 5f, 10f, 10f), image); } GUI.DrawTexture(new Rect(vector2.x - 5f, vector2.y - 5f, 10f, 10f), TreeWindSfxManager.playerTexture); }