public static GameObject GenObject(this BackgroundPlane plane, GameObject parent = null) { GameObject obj = new GameObject(plane.TextureName); if (parent != null) { obj.transform.parent = parent.transform; } obj.transform.localPosition = plane.Position; obj.transform.rotation = plane.Rotation; obj.transform.localScale = new Vector3( plane.Size.x * plane.Scale.x, plane.Size.y * plane.Scale.y, plane.Size.z * plane.Scale.z ); FezUnityBackgroundPlane fezHolder = obj.AddComponent <FezUnityBackgroundPlane>(); fezHolder.Fill(plane); obj.isStatic = true; // Fix Unity / Trixel Engine Z direction conflict obj.FezZ(); return(obj); }
private void SwapOpened() { this.LevelManager.RemovePlane(this.WaterfallPlane); this.LevelManager.RemovePlane(this.SplashPlane); Vector3 position1 = this.SplashPlane.Position; Vector3 scale1 = this.SplashPlane.Scale; Quaternion rotation1 = this.SplashPlane.Rotation; this.SplashPlane = new BackgroundPlane(this.LevelMaterializer.AnimatedPlanesMesh, this.OpenSplash) { Doublesided = true }; this.LevelManager.AddPlane(this.SplashPlane); this.SplashPlane.Timing.Restart(); this.WaterfallPlane.Timing.Loop = true; this.SplashPlane.Position = position1; this.SplashPlane.Scale = scale1; this.SplashPlane.Rotation = rotation1; Vector3 position2 = this.WaterfallPlane.Position; Vector3 scale2 = this.WaterfallPlane.Scale; Quaternion rotation2 = this.WaterfallPlane.Rotation; this.WaterfallPlane = new BackgroundPlane(this.LevelMaterializer.AnimatedPlanesMesh, this.OpenWaterfall) { Doublesided = true }; this.LevelManager.AddPlane(this.WaterfallPlane); this.WaterfallPlane.Timing.Restart(); this.WaterfallPlane.Timing.Loop = true; this.WaterfallPlane.YTextureRepeat = true; this.WaterfallPlane.Position = position2; this.WaterfallPlane.Scale = scale2; this.WaterfallPlane.Rotation = rotation2; }
public void AddPlane(BackgroundPlane plane) { int key = IdentifierPool.FirstAvailable <BackgroundPlane>(this.BackgroundPlanes); plane.Id = key; this.BackgroundPlanes.Add(key, plane); }
private void InitBitPlanes() { if (this.lastBits == this.GameState.SaveData.CubeShards + this.GameState.SaveData.SecretCubes) { return; } foreach (BackgroundPlane plane in this.BitPlanes) { this.LevelManager.RemovePlane(plane); } this.BitPlanes.Clear(); if (this.AoInstance.Rotation == new Quaternion(0.0f, 0.0f, 0.0f, -1f)) { this.AoInstance.Rotation = Quaternion.Identity; } int bitCount = ActorTypeExtensions.GetBitCount(this.AoInstance.ArtObject.ActorType); for (int index = 0; index < bitCount; ++index) { BackgroundPlane plane = new BackgroundPlane(this.LevelMaterializer.StaticPlanesMesh, index < this.GameState.SaveData.CubeShards ? (Texture)this.BitTexture : (Texture)this.AntiBitTexture) { Rotation = this.AoInstance.Rotation, Opacity = 0.0f, Fullbright = true }; this.BitPlanes.Add(plane); this.LevelManager.AddPlane(plane); } this.lastBits = this.GameState.SaveData.CubeShards + this.GameState.SaveData.SecretCubes; }
public void SetBackground(int newBackgroundID) { BackgroundPlane[] planesToLoad = null; BackgroundPlane plane = null; if (newBackgroundID != currentBackgroundID) { ClearPlanes(); currentBackgroundID = newBackgroundID; if (backgroundDatabase != null) { planesToLoad = backgroundDatabase.GetBackgroundPlanes(currentBackgroundID); if (planesToLoad != null) { for (int i = 0; i < planesToLoad.Length; i++) { plane = planesToLoad[i]; if (plane != null) { AddPlane(plane.planeSprite, plane.planeCameraConnection, plane.planeContinuity, plane.planeIndependentSpeed); } } } } } }
private void TryInitialize() { this.CodeMachineAO = (ArtObjectInstance)null; this.BitPlanes = (BackgroundPlane[])null; this.BitStates = (CodeMachineHost.BitState[])null; this.Enabled = false; this.Input.Clear(); CodeMachineHost codeMachineHost1 = this; CodeMachineHost codeMachineHost2 = this; ICollection <ArtObjectInstance> values = this.LevelManager.ArtObjects.Values; Func <ArtObjectInstance, bool> predicate = (Func <ArtObjectInstance, bool>)(x => x.ArtObject.ActorType == ActorType.CodeMachine); ArtObjectInstance artObjectInstance1; ArtObjectInstance artObjectInstance2 = artObjectInstance1 = Enumerable.FirstOrDefault <ArtObjectInstance>((IEnumerable <ArtObjectInstance>)values, predicate); codeMachineHost2.CodeMachineAO = artObjectInstance1; int num1 = artObjectInstance2 != null ? 1 : 0; codeMachineHost1.Enabled = num1 != 0; if (!this.Enabled) { return; } this.BitPlanes = new BackgroundPlane[144]; this.BitStates = new CodeMachineHost.BitState[144]; Texture2D texture2D = this.CMProvider.CurrentLevel.Load <Texture2D>("Other Textures/glow/code_machine_glowbit"); for (int index1 = 0; index1 < 36; ++index1) { BackgroundPlane backgroundPlane1 = new BackgroundPlane(this.LevelMaterializer.StaticPlanesMesh, (Texture)texture2D) { Fullbright = true, Opacity = 0.0f, Rotation = Quaternion.Identity }; this.BitPlanes[index1 * 4] = backgroundPlane1; BackgroundPlane backgroundPlane2 = backgroundPlane1.Clone(); backgroundPlane2.Rotation = Quaternion.CreateFromAxisAngle(Vector3.Up, 1.570796f); this.BitPlanes[index1 * 4 + 1] = backgroundPlane2; BackgroundPlane backgroundPlane3 = backgroundPlane1.Clone(); backgroundPlane3.Rotation = Quaternion.CreateFromAxisAngle(Vector3.Up, 3.141593f); this.BitPlanes[index1 * 4 + 2] = backgroundPlane3; BackgroundPlane backgroundPlane4 = backgroundPlane1.Clone(); backgroundPlane4.Rotation = Quaternion.CreateFromAxisAngle(Vector3.Up, 4.712389f); this.BitPlanes[index1 * 4 + 3] = backgroundPlane4; int num2 = index1 % 6; int num3 = index1 / 6; for (int index2 = 0; index2 < 4; ++index2) { BackgroundPlane plane = this.BitPlanes[index1 * 4 + index2]; this.BitStates[index1 * 4 + index2] = new CodeMachineHost.BitState(); Vector3 vector3_1 = Vector3.Transform(Vector3.UnitZ, plane.Rotation); Vector3 vector3_2 = Vector3.Transform(Vector3.Right, plane.Rotation); plane.Position = this.CodeMachineAO.Position + vector3_1 * 1.5f + vector3_2 * (float)(num2 * 8 - 20) / 16f + Vector3.Up * (float)(35 - num3 * 8) / 16f; this.LevelManager.AddPlane(plane); } } }
public void Render(TimeSpan elapsedGameTime) { PegPhysicsManager.Client().Render(); BackgroundPlane.Render(); CannonPlane.Client().Render(); ChutesPlane.Client().Render(); PegsPlane.Client().Render(); OverlaysPlane.Render(); CannonBallPlane.Client().Render(); }
/// <summary> /// Turns off the markers visuals, executed on the mobile /// </summary> private void TurnOffMarker() { foreach (Transform tr in CodeContainer.transform) { Destroy(tr.gameObject); } CodeContainer.transform.localScale = Vector3.one; BackgroundPlane.GetComponent <Renderer>().sharedMaterial.color = Color.white; gameObject.SetActive(false); }
private void SpawnDust(TrileInstance instance, float opacity, AnimatedTexture animation, bool onRight, bool onLeft) { float num1 = (float)((double)instance.Center.Y - (double)instance.TransformedSize.Y / 2.0 * (double)Math.Sign(this.CollisionManager.GravityFactor) + (double)animation.FrameHeight / 32.0 * (double)Math.Sign(this.CollisionManager.GravityFactor)); float num2 = (float)((double)FezMath.Dot(instance.TransformedSize, FezMath.SideMask(this.CameraManager.Viewpoint)) / 2.0 + (double)animation.FrameWidth / 32.0 * 2.0 / 3.0); if (ActorTypeExtensions.IsBomb(instance.Trile.ActorSettings.Type)) { num2 -= 0.25f; } opacity = 1f; Vector3 vector3_1 = FezMath.RightVector(this.CameraManager.Viewpoint); Vector3 vector3_2 = FezMath.ForwardVector(this.CameraManager.Viewpoint); bool b = (double)this.CollisionManager.GravityFactor < 0.0; if (onRight) { BackgroundPlane backgroundPlane; this.LevelManager.AddPlane(backgroundPlane = new BackgroundPlane(this.LevelMaterializer.AnimatedPlanesMesh, animation) { OriginalRotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, (float)FezMath.AsNumeric(b) * 3.141593f), Doublesided = true, Loop = false, Opacity = opacity, Timing = { Step = 0.0f } }); backgroundPlane.Position = instance.Center * FezMath.XZMask + vector3_1 * num2 + num1 * Vector3.UnitY - vector3_2; backgroundPlane.Billboard = true; } if (!onLeft) { return; } BackgroundPlane backgroundPlane1; this.LevelManager.AddPlane(backgroundPlane1 = new BackgroundPlane(this.LevelMaterializer.AnimatedPlanesMesh, animation) { OriginalRotation = Quaternion.CreateFromAxisAngle(Vector3.Up, 3.141593f) * Quaternion.CreateFromAxisAngle(Vector3.UnitX, (float)FezMath.AsNumeric(b) * 3.141593f), Doublesided = true, Loop = false, Opacity = opacity, Timing = { Step = 0.0f } }); backgroundPlane1.Position = instance.Center * FezMath.XZMask - vector3_1 * num2 + num1 * Vector3.UnitY - vector3_2; backgroundPlane1.Billboard = true; }
public override void Update(GameTime gameTime) { if (this.GameState.Loading || this.GameState.InMap || (this.GameState.InMenuCube || this.GameState.Paused)) { return; } bool flag1 = !FezMath.IsOrthographic(this.CameraManager.Viewpoint); Vector3 forward = this.CameraManager.InverseView.Forward; BoundingFrustum frustum = this.CameraManager.Frustum; foreach (FlickeringNeon.NeonState neonState in this.NeonPlanes) { neonState.Time -= (float)gameTime.ElapsedGameTime.TotalSeconds; if ((double)neonState.Time <= 0.0) { if (neonState.FlickersLeft == 0) { neonState.FlickersLeft = RandomHelper.Random.Next(4, 18); } BackgroundPlane backgroundPlane = neonState.Neon; bool flag2 = backgroundPlane.Visible = !backgroundPlane.Hidden && (flag1 || backgroundPlane.Doublesided || (backgroundPlane.Crosshatch || backgroundPlane.Billboard) || (double)FezMath.Dot(forward, backgroundPlane.Forward) > 0.0) && frustum.Contains(backgroundPlane.Bounds) != ContainmentType.Disjoint; neonState.Enabled = !neonState.Enabled; neonState.Neon.Hidden = neonState.Enabled; neonState.Neon.Visible = !neonState.Neon.Hidden; neonState.Neon.Update(); if (flag2 && RandomHelper.Probability(0.5)) { SoundEffectExtensions.EmitAt(RandomHelper.InList <SoundEffect>(this.Glitches), neonState.Neon.Position, false, RandomHelper.Centered(0.100000001490116), RandomHelper.Between(0.0, 1.0), false); } neonState.Time = Easing.EaseIn((double)RandomHelper.Between(0.0, 0.449999988079071), EasingType.Quadratic); --neonState.FlickersLeft; if (neonState.FlickersLeft == 0) { neonState.Enabled = true; neonState.Neon.Hidden = false; neonState.Neon.Visible = true; neonState.Neon.Update(); neonState.Time = RandomHelper.Between(3.0, 8.0); } } } }
public WaterfallState(BackgroundPlane plane, PlaneParticleSystem ps, WaterfallsHost host) { WaterfallsHost.WaterfallState waterfallState = this; ServiceHelper.InjectServices((object)this); this.Host = host; this.Plane = plane; this.ParticleSystem = ps; bool flag = plane.ActorType == ActorType.Trickle; this.Splash = new BackgroundPlane(this.LevelMaterializer.AnimatedPlanesMesh, this.LevelManager.WaterType != LiquidType.Sewer ? (this.LevelManager.WaterType != LiquidType.Purple ? this.CMProvider.CurrentLevel.Load <AnimatedTexture>("Background Planes/water/" + (flag ? "water_small_splash" : "water_large_splash")) : this.CMProvider.CurrentLevel.Load <AnimatedTexture>("Background Planes/waterPink/" + (flag ? "water_small_splash" : "water_large_splash"))) : this.CMProvider.CurrentLevel.Load <AnimatedTexture>("Background Planes/sewer/" + (flag ? "sewer_small_splash" : "sewer_large_splash"))) { Doublesided = true, Crosshatch = true }; this.LevelManager.AddPlane(this.Splash); this.Top = FezMath.Dot(this.Plane.Position + this.Plane.Scale * this.Plane.Size / 2f, Vector3.UnitY); this.TerminalPosition = this.Plane.Position - this.Plane.Scale * this.Plane.Size / 2f * Vector3.UnitY + Vector3.Transform(Vector3.UnitZ, plane.Rotation) / 16f; foreach (BackgroundPlane backgroundPlane in Enumerable.Where <BackgroundPlane>((IEnumerable <BackgroundPlane>) this.LevelManager.BackgroundPlanes.Values, (Func <BackgroundPlane, bool>)(x => { int?local_0 = x.AttachedPlane; int local_1 = plane.Id; if ((local_0.GetValueOrDefault() != local_1 ? 0 : (local_0.HasValue ? 1 : 0)) != 0) { return(FezMath.AlmostEqual(Vector3.Transform(Vector3.UnitZ, plane.Rotation).Y, 0.0f)); } else { return(false); } }))) { this.AttachedPlanes.Add(backgroundPlane); } Vector3 position = this.LevelManager.WaterType == LiquidType.None ? this.Top * Vector3.UnitY + this.Plane.Position * FezMath.XZMask : this.TerminalPosition * FezMath.XZMask + this.LevelManager.WaterHeight * Vector3.UnitY; Waiters.Wait((double)RandomHelper.Between(0.0, 1.0), (Action)(() => waterfallState.BubblingEmitter = SoundEffectExtensions.EmitAt(waterfallState.Host.SewageFallSound, position, true, RandomHelper.Centered(0.025), 0.0f))); }
private void UpdateBits(TimeSpan elapsed) { for (int index1 = 0; index1 < 36; ++index1) { int num1 = index1 % 6; int num2 = index1 / 6; for (int index2 = 0; index2 < 4; ++index2) { BackgroundPlane backgroundPlane = this.BitPlanes[index1 * 4 + index2]; CodeMachineHost.BitState bitState = this.BitStates[index1 * 4 + index2]; TimeSpan timeSpan = TimeSpan.FromTicks(CodeMachineHost.Delay.Ticks * (long)(num1 + num2)); if (bitState.On) { if (bitState.SinceOn < CodeMachineHost.FadeInDuration) { bitState.SinceOn += elapsed; backgroundPlane.Opacity = FezMath.Saturate((float)bitState.SinceOn.Ticks / (float)CodeMachineHost.FadeInDuration.Ticks); bitState.SinceOff = TimeSpan.FromSeconds((1.0 - (double)backgroundPlane.Opacity) * CodeMachineHost.FadeOutDuration.TotalSeconds) - timeSpan; } else if (bitState.SinceIdle < CodeMachineHost.TimeOut) { bitState.SinceIdle += elapsed; } else { bitState.On = false; } } else if (bitState.SinceOff < CodeMachineHost.FadeOutDuration) { bitState.SinceOff += elapsed; backgroundPlane.Opacity = FezMath.Saturate((float)(1.0 - (double)bitState.SinceOff.Ticks / (double)CodeMachineHost.FadeOutDuration.Ticks)); bitState.SinceOn = TimeSpan.FromSeconds((double)backgroundPlane.Opacity * CodeMachineHost.FadeInDuration.TotalSeconds) - timeSpan; } } } }
public GeyserState(TrileGroup group, GeysersHost host) { ServiceHelper.InjectServices((object)this); this.Host = host; this.Group = group; this.SinceStateChange = TimeSpan.FromSeconds(-(double)group.GeyserOffset); Vector3 position = Enumerable.Aggregate <TrileInstance, Vector3>((IEnumerable <TrileInstance>) this.Group.Triles, Vector3.Zero, (Func <Vector3, TrileInstance, Vector3>)((a, b) => a + b.Center)) / (float)group.Triles.Count; int key1 = IdentifierPool.FirstAvailable <BackgroundPlane>(this.LevelManager.BackgroundPlanes); this.TopPlane = new BackgroundPlane(this.LevelMaterializer.AnimatedPlanesMesh, "sewer/sewer_geyser_top", true) { Id = key1, Position = position, YTextureRepeat = true, Crosshatch = true, Doublesided = true }; this.LevelManager.BackgroundPlanes.Add(key1, this.TopPlane); int key2 = IdentifierPool.FirstAvailable <BackgroundPlane>(this.LevelManager.BackgroundPlanes); this.TilePlane = new BackgroundPlane(this.LevelMaterializer.AnimatedPlanesMesh, "sewer/sewer_geyser_tile", true) { Id = key2, Position = position, YTextureRepeat = true, Billboard = true }; this.LevelManager.BackgroundPlanes.Add(key2, this.TilePlane); this.TopPlane.Timing.Step = this.TilePlane.Timing.Step; this.loopEmitter = SoundEffectExtensions.EmitAt(this.Host.LoopSound, position, true, 0.0f, 0.0f); foreach (TrileInstance trileInstance in group.Triles) { trileInstance.PhysicsState.IgnoreCollision = true; trileInstance.PhysicsState.IgnoreClampToWater = true; } }
public override void Initialize() { base.Initialize(); this.LevelManager.AddPlane(this.Plane = new BackgroundPlane(this.LevelMaterializer.StaticPlanesMesh, (Texture)this.CMProvider.CurrentLevel.Load <Texture2D>("Other Textures/CAPSULE")) { Rotation = this.CameraManager.Rotation, Loop = false }); if (this.NpcId.HasValue) { this.Npc = this.LevelManager.NonPlayerCharacters[this.NpcId.Value]; this.OldPosition = this.Npc.Position; this.Npc.Position = new Vector3(487.0 / 16.0, 49f, 10f); this.OldDestinationOffset = this.Npc.DestinationOffset; this.Npc.DestinationOffset = new Vector3(-63.0 / 16.0, 0.0f, 0.0f); this.Npc.State.Scripted = true; this.Npc.State.LookingDirection = HorizontalDirection.Left; this.Npc.State.WalkStep = 0.0f; this.Npc.State.CurrentAction = NpcAction.Idle; this.Npc.State.UpdateAction(); this.Npc.State.SyncTextureMatrix(); this.Npc.Group.Position = this.LevelManager.NonPlayerCharacters[this.NpcId.Value].Position; this.CameraManager.Constrained = true; this.CameraManager.Center = new Vector3(32.5f, 50.5f, 16.5f); this.CameraManager.SnapInterpolation(); this.Plane.Position = this.Npc.Group.Position + new Vector3((float)(FezMath.Sign(this.Npc.State.LookingDirection) * 4) / 16f, 0.375f, 0.0f); this.sLetterInsert = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/MiscActors/LetterTubeInsert"); } else { this.Plane.Position = new Vector3(20.5f, 20.75f, 23.5f); this.Enabled = false; this.GomezService.ReadMail += new Action(this.Destroy); } this.LevelManager.LevelChanged += new Action(this.TryDestroy); }
IEnumerator LoadLevelCoroutine() { System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); yield return(new WaitForEndOfFrame()); //Calculate level visibility foreach (KeyValuePair <TrileEmplacement, TrileInstance> kvp in loaded.Triles) { TrileEmplacement currP = kvp.Key; if (kvp.Value.TrileId < 0) { visibility.Add(currP, false); continue; } if (kvp.Value.ForceSeeThrough || s.Triles[kvp.Value.TrileId].SeeThrough) { visibility.Add(currP, true); continue; } TrileEmplacement[] checkPos = new TrileEmplacement[6]; checkPos[0] = new TrileEmplacement(currP.X, currP.Y, currP.Z + 1); checkPos[1] = new TrileEmplacement(currP.X, currP.Y, currP.Z - 1); checkPos[2] = new TrileEmplacement(currP.X, currP.Y + 1, currP.Z); checkPos[3] = new TrileEmplacement(currP.X, currP.Y - 1, currP.Z); checkPos[4] = new TrileEmplacement(currP.X + 1, currP.Y, currP.Z); checkPos[5] = new TrileEmplacement(currP.X - 1, currP.Y, currP.Z); bool isVisible = false; foreach (TrileEmplacement pos in checkPos) { if (!loaded.Triles.ContainsKey(pos)) { visibility.Add(currP, true); isVisible = true; break; } else if (loaded.Triles[pos].TrileId < 0) { visibility.Add(currP, true); isVisible = true; break; } else if (loaded.Triles[pos].ForceSeeThrough || s.Triles[loaded.Triles[pos].TrileId].SeeThrough) { visibility.Add(currP, true); isVisible = true; break; } } if (!isVisible) { visibility.Add(currP, false); } } int index = 0; //Generate triles { foreach (KeyValuePair <TrileEmplacement, TrileInstance> kvp in loaded.Triles) { if (!visibility[kvp.Key]) { continue; } GameObject g = NewTrileObject(kvp.Key); index++; if (index > 50) { index = 0; if (loadOverFrames) { yield return(new WaitForEndOfFrame()); } } } //Generate Planes { foreach (KeyValuePair <int, BackgroundPlane> kvp in loaded.BackgroundPlanes) { BackgroundPlane b = kvp.Value; if (b.Hidden || b.Animated || !b.Visible) { continue; } GameObject newPlane; if (planeObjectCache.Count > 0) { newPlane = planeObjectCache[0]; planeObjectCache.RemoveAt(0); newPlane.gameObject.SetActive(true); } else { newPlane = Instantiate(planePrefab); } newPlane.transform.rotation = b.Rotation; newPlane.transform.position = b.Position - (Vector3.one / 2); newPlane.transform.localScale = new Vector3(-b.Size.x, -b.Size.y, b.Size.z); MeshRenderer mr = newPlane.GetComponent <MeshRenderer>(); try { Texture2D tex = FmbUtil.ReadObject <Texture2D>(OutputPath.OutputPathDir + "background planes/" + b.TextureName.ToLower() + ".xnb"); if (tex != null) { //tex.alphaIsTransparency=true; mr.material.mainTexture = tex; mr.material.mainTexture.filterMode = FilterMode.Point; } else { Debug.Log("Tex Null!"); } } catch (System.Exception e) { Debug.Log(e); Debug.Log(OutputPath.OutputPathDir + "background planes/" + b.TextureName.ToLower() + ".xnb"); Destroy(newPlane); continue; } newPlane.name = b.TextureName; index++; if (index > 5) { index = 0; if (loadOverFrames) { yield return(new WaitForEndOfFrame()); } } newPlane.transform.rotation = Quaternion.Euler(newPlane.transform.eulerAngles.x, newPlane.transform.eulerAngles.y - 180, newPlane.transform.eulerAngles.z); newPlane.transform.parent = transform.FindChild("Planes"); } } //Generate Art Objects { foreach (KeyValuePair <int, ArtObjectInstance> kvp in loaded.ArtObjects) { GameObject newTrile; if (aoObjectCache.Count > 0) { newTrile = aoObjectCache[0]; aoObjectCache.RemoveAt(0); newTrile.SetActive(true); } else { newTrile = Instantiate(aoPrefab); } MeshFilter mf = newTrile.GetComponent <MeshFilter>(); MeshRenderer mr = newTrile.GetComponent <MeshRenderer>(); MeshCollider mc = newTrile.GetComponent <MeshCollider>(); ArtObjectImported aoI = newTrile.GetComponent <ArtObjectImported>(); aoI.myInstance = kvp.Value; mr.material = FezToUnity.GeometryToMaterial(aoCache[kvp.Value.ArtObjectName].Cubemap); mf.mesh = aoMeshCache[aoCache[kvp.Value.ArtObjectName]]; mc.sharedMesh = aoMeshCache[aoCache[kvp.Value.ArtObjectName]]; newTrile.transform.position = kvp.Value.Position - (Vector3.one / 2); newTrile.transform.rotation = kvp.Value.Rotation; index++; if (index > 5) { index = 0; if (loadOverFrames) { yield return(new WaitForEndOfFrame()); } } newTrile.name = kvp.Value.ArtObjectName; newTrile.transform.parent = transform.FindChild("ArtObjects"); } } } sw.Stop(); Debug.Log("Objects created in " + sw.ElapsedMilliseconds + " ms"); }
private void TryInitialize() { this.DoorAo = (ArtObjectInstance)null; this.AttachedGroup = (TrileGroup)null; this.AssociatedVolume = (Volume)null; this.Enabled = false; this.sRumble = (SoundEffect)null; this.sLightUp = (SoundEffect)null; this.sFadeOut = (SoundEffect)null; if (this.eRumble != null && !this.eRumble.Dead) { this.eRumble.Cue.Stop(false); } this.eRumble = (SoundEmitter)null; foreach (ArtObjectInstance artObjectInstance in (IEnumerable <ArtObjectInstance>) this.LevelManager.ArtObjects.Values) { if (artObjectInstance.ArtObject.ActorType == ActorType.SecretPassage) { this.DoorAo = artObjectInstance; this.Enabled = true; break; } } if (!this.Enabled) { if (this.GlowPlane != null) { this.GlowPlane.Dispose(); } this.GlowPlane = (BackgroundPlane)null; } if (!this.Enabled) { return; } this.AttachedGroup = this.LevelManager.Groups[this.DoorAo.ActorSettings.AttachedGroup.Value]; this.AssociatedVolume = Enumerable.FirstOrDefault <Volume>((IEnumerable <Volume>) this.LevelManager.Volumes.Values, (Func <Volume, bool>)(x => { if (x.ActorSettings != null) { return(x.ActorSettings.IsSecretPassage); } else { return(false); } })); string key = (string)null; foreach (Script script in (IEnumerable <Script>) this.LevelManager.Scripts.Values) { foreach (ScriptAction scriptAction in script.Actions) { if (scriptAction.Object.Type == "Level" && scriptAction.Operation.Contains("Level")) { foreach (ScriptTrigger scriptTrigger in script.Triggers) { if (scriptTrigger.Object.Type == "Volume" && scriptTrigger.Event == "Enter" && scriptTrigger.Object.Identifier.HasValue) { key = scriptAction.Arguments[0]; } } } } } this.Accessible = this.GameState.SaveData.World.ContainsKey(key); this.sRumble = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/MiscActors/Rumble"); this.sLightUp = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Zu/DoorBitLightUp"); this.sFadeOut = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Zu/DoorBitFadeOut"); if (!this.Accessible) { this.Enabled = false; } else { this.GlowPlane = new BackgroundPlane(this.LevelMaterializer.StaticPlanesMesh, (Texture)this.CMProvider.CurrentLevel.Load <Texture2D>("Other Textures/glow/secret_passage")) { Fullbright = true, Opacity = 0.0f, Position = this.DoorAo.Position + FezMath.AsVector(Enumerable.First <FaceOrientation>((IEnumerable <FaceOrientation>) this.AssociatedVolume.Orientations)) / (65.0 / 32.0), Rotation = FezMath.QuaternionFromPhi(FezMath.ToPhi(Enumerable.First <FaceOrientation>((IEnumerable <FaceOrientation>) this.AssociatedVolume.Orientations))), AttachedGroup = new int?(this.AttachedGroup.Id) }; this.LevelManager.AddPlane(this.GlowPlane); this.ExpectedViewpoint = FezMath.AsViewpoint(Enumerable.First <FaceOrientation>((IEnumerable <FaceOrientation>) this.AssociatedVolume.Orientations)); if (!this.LevelManager.WentThroughSecretPassage) { return; } this.MoveUp = true; this.GlowPlane.Opacity = 1f; this.SinceStarted = TimeSpan.Zero; this.AoOrigin = this.DoorAo.Position; this.PlaneOrigin = this.GlowPlane.Position; } }
public void RemovePlane(BackgroundPlane plane) { this.BackgroundPlanes.Remove(plane.Id); plane.Dispose(); }
private void TryInitialize() { this.OpenSplash = this.OpeningSplash = this.OpenWaterfall = this.OpeningWaterfall = (AnimatedTexture)null; this.sWaterfallOpening = (SoundEffect)null; this.eWaterfallClosed = (SoundEmitter)null; this.eWaterfallOpen = (SoundEmitter)null; this.WaterfallPlane = Enumerable.FirstOrDefault <BackgroundPlane>((IEnumerable <BackgroundPlane>) this.LevelManager.BackgroundPlanes.Values, (Func <BackgroundPlane, bool>)(x => x.ActorType == ActorType.BigWaterfall)); this.Enabled = this.WaterfallPlane != null; if (!this.Enabled) { return; } this.MoriaPlane = Enumerable.FirstOrDefault <BackgroundPlane>((IEnumerable <BackgroundPlane>) this.LevelManager.BackgroundPlanes.Values, (Func <BackgroundPlane, bool>)(x => x.TextureName == "MORIA_GLOW")); if (this.GameState.SaveData.ThisLevel.InactiveGroups.Contains(1) || this.GameState.SaveData.ThisLevel.InactiveVolumes.Contains(19)) { this.MoriaPlane.Opacity = 0.0f; } this.MoriaPlane.Position -= Vector3.UnitX * (1.0 / 1000.0); Comparison <Group> oldGo = this.LevelMaterializer.StaticPlanesMesh.GroupOrder; this.LevelMaterializer.StaticPlanesMesh.GroupOrder = (Comparison <Group>)((x, y) => { if (x == this.MoriaPlane.Group) { return(1); } if (y != this.MoriaPlane.Group) { return(oldGo(x, y)); } else { return(-1); } }); bool flag = this.GameState.SaveData.ThisLevel.ScriptingState == "WATERFALL_OPEN"; if (flag) { this.OpenSplash = this.CMProvider.CurrentLevel.Load <AnimatedTexture>("Background Planes/water_giant_splash_open"); this.OpenWaterfall = this.CMProvider.CurrentLevel.Load <AnimatedTexture>("Background Planes/water_giant_open"); Waiters.Wait((Func <bool>)(() => !this.GameState.Loading), (Action)(() => this.LevelManager.Volumes[7].Enabled = true)); } else { this.ForkLoad(false); } this.SplashPlane = new BackgroundPlane(this.LevelMaterializer.AnimatedPlanesMesh, flag ? this.OpenSplash : this.CMProvider.CurrentLevel.Load <AnimatedTexture>("Background Planes/water_giant_splash")) { Doublesided = true }; this.LevelManager.AddPlane(this.SplashPlane); this.Top = FezMath.Dot(this.WaterfallPlane.Position + this.WaterfallPlane.Scale * this.WaterfallPlane.Size / 2f, Vector3.UnitY); this.TerminalPosition = this.WaterfallPlane.Position - this.WaterfallPlane.Scale * this.WaterfallPlane.Size / 2f * Vector3.UnitY + Vector3.Transform(Vector3.UnitZ, this.WaterfallPlane.Rotation) / 16f; this.sinceAlive = 0.0f; if (flag) { this.SwapOpened(); this.eWaterfallOpen = SoundEffectExtensions.EmitAt(this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/MiscActors/BigWaterfallOpen"), this.WaterfallPlane.Position, true, 0.0f, 0.0f); } else { this.eWaterfallClosed = SoundEffectExtensions.EmitAt(this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/MiscActors/BigWaterfallClosed"), this.WaterfallPlane.Position, true, 0.0f, 0.0f); } }
private void ExtractAllBackgroundComponents() { int totalBackgrounds = 0; GameObject backgroundObject = null; BackgroundPlaneSet backgroundComponent = null; GameObject[] backgroundPlaneObjects = null; GameObject planeObject = null; BackgroundPlane[] planesOfBackground = null; int totalPlanes = 0; if (backgroundPlaneSets != null) { totalBackgrounds = backgroundPlaneSets.Length; if (totalBackgrounds > 0) { backgroundComponents = new BackgroundPlaneSet[totalBackgrounds]; backgroundIDs = new int[totalBackgrounds]; backgroundPlanes = new BackgroundPlane[totalBackgrounds][]; for (int i = 0; i < totalBackgrounds; i++) { backgroundObject = backgroundPlaneSets[i]; if (backgroundObject != null) { backgroundComponent = backgroundObject.GetComponent <BackgroundPlaneSet>(); } if (backgroundComponent != null) { backgroundComponents[i] = backgroundComponent; backgroundIDs[i] = backgroundComponent.backgroundID; backgroundPlaneObjects = backgroundComponent.backgroundPlanes; if (backgroundPlaneObjects != null) { totalPlanes = backgroundPlaneObjects.Length; if (totalPlanes > 0) { planesOfBackground = new BackgroundPlane[totalPlanes]; for (int j = 0; j < totalPlanes; j++) { planeObject = backgroundPlaneObjects[j]; if (planeObject != null) { planesOfBackground[j] = planeObject.GetComponent <BackgroundPlane>(); } else { planesOfBackground[j] = null; } } } } backgroundPlanes[i] = planesOfBackground; } else { backgroundComponents[i] = null; backgroundIDs[i] = INVALID_BACKGROUND_ID; backgroundPlanes[i] = null; } backgroundComponent = null; planesOfBackground = null; } } } }
public LongRunningAction Open(int id) { if (id != this.WaterfallPlane.Id) { return((LongRunningAction)null); } this.GameState.SaveData.ThisLevel.ScriptingState = "WATERFALL_OPEN"; this.GameState.Save(); SoundEmitter eWaterfallOpen = SoundEffectExtensions.EmitAt(this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/MiscActors/BigWaterfallOpen"), this.WaterfallPlane.Position, true, true); eWaterfallOpen.VolumeFactor = 0.0f; eWaterfallOpen.Cue.Play(); this.opening = true; Waiters.Interpolate(6.0, (Action <float>)(s => { if (this.eWaterfallClosed == null || this.eWaterfallClosed.Dead) { return; } this.eWaterfallClosed.VolumeFactor = (1f - s) * this.sinceAlive; if (eWaterfallOpen.Dead) { return; } eWaterfallOpen.VolumeFactor = s * this.sinceAlive; })).AutoPause = true; SoundEffectExtensions.EmitAt(this.sWaterfallOpening, this.WaterfallPlane.Position); this.ScriptId = this.ScriptingManager.EvaluatedScript.Script.Id; this.LevelManager.RemovePlane(this.WaterfallPlane); this.LevelManager.RemovePlane(this.SplashPlane); Vector3 position1 = this.SplashPlane.Position; Vector3 scale1 = this.SplashPlane.Scale; Quaternion rotation1 = this.SplashPlane.Rotation; this.SplashPlane = new BackgroundPlane(this.LevelMaterializer.AnimatedPlanesMesh, this.OpeningSplash) { Doublesided = true }; this.LevelManager.AddPlane(this.SplashPlane); this.SplashPlane.Timing.Restart(); this.WaterfallPlane.Timing.Loop = false; this.SplashPlane.Position = position1; this.SplashPlane.Scale = scale1; this.SplashPlane.Rotation = rotation1; Vector3 position2 = this.WaterfallPlane.Position; Vector3 scale2 = this.WaterfallPlane.Scale; Quaternion rotation2 = this.WaterfallPlane.Rotation; this.WaterfallPlane = new BackgroundPlane(this.LevelMaterializer.AnimatedPlanesMesh, this.OpeningWaterfall) { Doublesided = true }; this.LevelManager.AddPlane(this.WaterfallPlane); this.WaterfallPlane.Timing.Restart(); this.WaterfallPlane.Timing.Loop = false; this.WaterfallPlane.YTextureRepeat = true; this.WaterfallPlane.Position = position2; this.WaterfallPlane.Scale = scale2; this.WaterfallPlane.Rotation = rotation2; return(new LongRunningAction((Func <float, float, bool>)((_, __) => { if (!this.WaterfallPlane.Timing.Ended) { return false; } this.opening = false; this.SwapOpened(); return true; }))); }
public IEnumerator FillCoroutine(Level level) { Level = level; if (string.IsNullOrEmpty(name)) { name = level.Name; //Offset the triles and everything back transform.position -= FezHelper.TrileOffset; } Triles.Clear(); ArtObjects.Clear(); if (chunksObj != null) { Destroy(chunksObj); } chunksObj = new GameObject("Chunks"); chunksObj.transform.parent = transform; chunksObj.isStatic = true; chunks.Clear(); TrileSet = FezManager.Instance.GetUnityTrileSet(level.TrileSetName); level.TrileSet = TrileSet.TrileSet; yield return(null); if (level.SkyName != null) { GameObject skyObj = new GameObject("Sky (" + level.SkyName + ")"); skyObj.transform.parent = transform; Sky = skyObj.AddComponent <FezUnitySky>(); Sky.Fill(FezManager.Instance.GetUnitySky(level.SkyName)); yield return(null); } if (SetupLightingOnFill) { SetupLighting(); } if (level.WaterType != LiquidType.None) { GameObject waterObj = new GameObject("Water"); waterObj.transform.parent = transform; waterObj.transform.localPosition = new Vector3(level.Size.x / 2f, level.WaterHeight, level.Size.z / -2f); Water = waterObj.AddComponent <FezUnityWater>(); Water.Fill(level.WaterType); } int asset = 0; GameObject trilesObj = new GameObject("Triles"); trilesObj.transform.parent = transform; trilesObj.transform.position += FezHelper.TrileOffset; foreach (KeyValuePair <TrileEmplacement, TrileInstance> pair in level.Triles) { TrileInstance trile = pair.Value; if (trile.TrileId == -1) { continue; } SetTrileInInstance(trile); GameObject trileObj = trile.GenObject(trilesObj); Triles[pair.Key] = trileObj; if (IsHidden(trile.Emplacement)) { trileObj.SetActive(false); } else { AddToChunk(trileObj); asset++; } if (asset >= AssetsPerFrame) { asset = 0; yield return(pair); } else { asset++; } } GameObject aosObj = new GameObject("Art Objects"); aosObj.transform.parent = transform; foreach (KeyValuePair <int, ArtObjectInstance> pair in level.ArtObjects) { ArtObjectInstance ao = pair.Value; ao.ArtObject = FezManager.Instance.GetArtObject(ao.ArtObjectName); ArtObjects[pair.Key] = ao.GenObject(aosObj); if (asset >= AssetsPerFrame) { asset = 0; yield return(pair); } else { asset++; } } GameObject planesObj = new GameObject("Background Planes"); planesObj.transform.parent = transform; foreach (KeyValuePair <int, BackgroundPlane> pair in level.BackgroundPlanes) { BackgroundPlane plane = pair.Value; BackgroundPlanes[pair.Key] = plane.GenObject(planesObj); if (asset >= AssetsPerFrame) { asset = 0; yield return(pair); } else { asset++; } } GameObject npcsObj = new GameObject("NPCs"); npcsObj.transform.parent = transform; foreach (KeyValuePair <int, NpcInstance> pair in level.NonPlayerCharacters) { NpcInstance npc = pair.Value; NPCs[pair.Key] = npc.GenObject(npcsObj); if (asset >= AssetsPerFrame) { asset = 0; yield return(pair); } else { asset++; } } asset = 0; IEnumerator buildc = BuildChunks(); while (buildc.MoveNext()) { if (asset >= ChunksPerFrame) { asset = 0; yield return(buildc.Current); } else { asset++; } } }
public override void Tick(TimeSpan elapsedGameTime) { base.Tick(elapsedGameTime); BackgroundPlane.Tick(); OverlaysPlane.Tick(); }
IEnumerator LoadLevelCoroutine() { System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); yield return(new WaitForEndOfFrame()); //Calculate level visibility foreach (KeyValuePair <TrileEmplacement, TrileInstance> kvp in loaded.Triles) { TrileEmplacement currP = kvp.Key; if (kvp.Value.TrileId < 0) { visibility.Add(currP, false); continue; } if (kvp.Value.ForceSeeThrough || s.Triles[kvp.Value.TrileId].SeeThrough) { visibility.Add(currP, true); continue; } List <TrileEmplacement> checkPos = new List <TrileEmplacement>(); checkPos.Add(new TrileEmplacement(currP.X, currP.Y, currP.Z + 1)); checkPos.Add(new TrileEmplacement(currP.X, currP.Y, currP.Z - 1)); checkPos.Add(new TrileEmplacement(currP.X, currP.Y + 1, currP.Z)); checkPos.Add(new TrileEmplacement(currP.X, currP.Y - 1, currP.Z)); checkPos.Add(new TrileEmplacement(currP.X + 1, currP.Y, currP.Z)); checkPos.Add(new TrileEmplacement(currP.X - 1, currP.Y, currP.Z)); bool isVisible = false; foreach (TrileEmplacement pos in checkPos) { if (!loaded.Triles.ContainsKey(pos)) { visibility.Add(currP, true); isVisible = true; break; } else if (loaded.Triles[pos].TrileId < 0) { break; } else if (loaded.Triles[pos].ForceSeeThrough || s.Triles[loaded.Triles[pos].TrileId].SeeThrough) { visibility.Add(currP, true); isVisible = true; break; } } if (!isVisible) { visibility.Add(currP, false); } } int index = 0; //Generate triles { foreach (KeyValuePair <TrileEmplacement, TrileInstance> kvp in loaded.Triles) { if (!visibility[kvp.Key]) { continue; } GameObject newTrile = Instantiate(trilePrefab); MeshFilter mf = newTrile.GetComponent <MeshFilter>(); MeshRenderer mr = newTrile.GetComponent <MeshRenderer>(); BoxCollider bc = newTrile.GetComponent <BoxCollider>(); mr.material = setMat; mf.mesh = trilesetCache[s.Triles[kvp.Value.TrileId]]; bc.size = mf.mesh.bounds.size; bc.center = mf.mesh.bounds.center; newTrile.transform.position = new Vector3(kvp.Key.X, kvp.Key.Y, kvp.Key.Z); newTrile.transform.rotation = Quaternion.Euler(0, Mathf.Rad2Deg * kvp.Value.Data.PositionPhi.w, 0); index++; if (index > 50) { index = 0; //yield return new WaitForEndOfFrame(); } newTrile.name = s.Triles[kvp.Value.TrileId].Name; newTrile.transform.parent = transform.FindChild("Triles"); trileObjects.Add(kvp.Key, newTrile); } //Generate Planes { foreach (KeyValuePair <int, BackgroundPlane> kvp in loaded.BackgroundPlanes) { BackgroundPlane b = kvp.Value; if (b.Hidden) { continue; } GameObject newPlane = Instantiate(planePrefab); newPlane.transform.rotation = b.Rotation; newPlane.transform.position = b.Position - (Vector3.one / 2); newPlane.transform.localScale = new Vector3(-b.Size.x, -b.Size.y, b.Size.z); MeshRenderer mr = newPlane.GetComponent <MeshRenderer>(); try { Texture2D tex = FmbUtil.ReadObject <Texture2D>(OutputPath.OutputPathDir + "background planes/" + b.TextureName.ToLower() + ".xnb"); if (tex != null) { tex.alphaIsTransparency = true; mr.material.mainTexture = tex; mr.material.mainTexture.filterMode = FilterMode.Point; } else { Debug.Log("Tex Null!"); } } catch (System.Exception e) { Debug.Log(e); Debug.Log(b.TextureName.ToLower()); Destroy(newPlane); continue; } newPlane.name = b.TextureName; index++; if (index > 5) { index = 0; //yield return new WaitForEndOfFrame(); } newPlane.transform.rotation = Quaternion.Euler(newPlane.transform.eulerAngles.x, newPlane.transform.eulerAngles.y - 180, newPlane.transform.eulerAngles.z); newPlane.transform.parent = transform.FindChild("ArtObjects"); } } //Generate Art Objects { foreach (KeyValuePair <int, ArtObjectInstance> kvp in loaded.ArtObjects) { GameObject newTrile = Instantiate(aoPrefab); MeshFilter mf = newTrile.GetComponent <MeshFilter>(); MeshRenderer mr = newTrile.GetComponent <MeshRenderer>(); mr.material = FezToUnity.GeometryToMaterial(aoCache[kvp.Key].Cubemap); mf.mesh = aoMeshCache[aoCache[kvp.Key]]; newTrile.transform.position = kvp.Value.Position - (Vector3.one / 2); newTrile.transform.rotation = kvp.Value.Rotation; index++; if (index > 5) { index = 0; //yield return new WaitForEndOfFrame(); } newTrile.name = kvp.Value.ArtObjectName; newTrile.transform.parent = transform.FindChild("ArtObjects"); } } } sw.Stop(); Debug.Log(sw.ElapsedMilliseconds); }