/// <summary> /// Sets the intensity for the glow line renderer, the hemispherical end glows and ambient glow. /// </summary> /// <param name="intensity">An intensity of 1 is no change, 2 - twice as intense, 0, off.</param> public void SetIntensity(float intensity) { // Glow line renderer Gradient glowLineGradient = glowLineRenderer.colorGradient; GradientAlphaKey[] glowLineAlphaKeys = glowLineGradient.alphaKeys; for (int i = 0; i < glowLineAlphaKeys.Length; i++) { glowLineAlphaKeys[i].alpha *= intensity; } glowLineGradient.alphaKeys = glowLineAlphaKeys; glowLineRenderer.colorGradient = glowLineGradient; // Hemisphere end glows LightSprite startLightSprite = startTransform.GetComponent <LightSprite>(); LightSprite endLightSprite = endTransform.GetComponent <LightSprite>(); Color endColor = endLightSprite.Color; endColor.a *= intensity; startLightSprite.Color = endColor; endLightSprite.Color = endColor; // Ambient glow LightSprite ambientLightSprite = ambientTransform.GetComponent <LightSprite>(); Color ambientColor = ambientLightSprite.Color; ambientColor.a *= intensity; ambientLightSprite.Color = ambientColor; }
void Awake() { //Gets ship matrix move by getting root (top parent) of current gameobject shipMatrixMove = transform.root.gameObject.GetComponent <MatrixMove>(); particleFX = GetComponentInChildren <ParticleSystem>(); lightSprite = GetComponentInChildren <LightSprite>(); }
private void EnsureInit() { if (mLightRendererObject == null) { mLightRendererObject = LightSpriteBuilder.BuildDefault(gameObject, new Color(0, 0, 0, 0), 12); } directional.OnDirectionChange.AddListener(OnDirectionChange); if (lightSprite == null) { lightSprite = mLightRendererObject.GetComponent <LightSprite>(); } if (currentState == null) { ChangeCurrentState(InitialState); } if (traitRequired == null) { traitRequired = currentState.TraitRequired; } if (!isWithoutSwitch) { switchState = InitialState == LightMountState.On; } }
private void Awake() { lightSprite = GetComponent <LightSprite>(); baseColour = lightSprite.Color; //Used to make mirror cache network identity so it wont do get component checks in atmos thread var netIdSet = netId; }
public void SetIntensity(float newIntensity) { intensity = newIntensity; LightSprite light = GetComponent <LightSprite>(); light.Color = new Color(light.Color.r, light.Color.g, light.Color.b, intensity); transform.localScale = new Vector2(radius * 2f, radius * 2f); }
private void EnsureInit() { if (isInit) { return; } if (mLightRendererObject == null) { mLightRendererObject = LightSpriteBuilder.BuildDefault(gameObject, new Color(0, 0, 0, 0), 12); } if (spriteRenderer == null) { spriteRenderer = GetComponentInChildren <SpriteRenderer>(); } if (spriteRendererLightOn == null) { spriteRendererLightOn = GetComponentsInChildren <SpriteRenderer>().Length > 1 ? GetComponentsInChildren <SpriteRenderer>()[1] : GetComponentsInChildren <SpriteRenderer>()[0]; } if (lightSprite == null) { lightSprite = mLightRendererObject.GetComponent <LightSprite>(); } if (emergencyLightAnimator == null) { emergencyLightAnimator = GetComponent <EmergencyLightAnimator>(); } if (integrity == null) { integrity = GetComponent <Integrity>(); } if (directional == null) { directional = GetComponent <Directional>(); } if (currentState == null) { ChangeCurrentState(InitialState); } if (traitRequired == null) { traitRequired = currentState.TraitRequired; } if (!isWithoutSwitch) { switchState = InitialState == LightMountState.On; } }
private IEnumerator ChangeColor() { LightSprite light = GetComponent <LightSprite>(); while (IsWinking()) { light.Color = new Color(Random.Range(0, 255), Random.Range(0, 255), Random.Range(0, 255), light.Color.a); yield return(new WaitForSeconds(4)); } }
private void Start() { LightSprite rend = GetComponent <LightSprite>(); rend.transform.localScale = Vector3.one * Random.Range(minRadius, maxRadius); Vector4 c = new Vector4(Random.value, Random.value, Random.value, Random.Range(minLightAlpha, maxLightAlpha)); float maxc = Mathf.Max(c.x, c.y, c.z); rend.color = new Color(c.x / maxc, c.y / maxc, c.z / maxc, c.w); }
internal virtual void GoBoom() { if (spriteRend.isVisible) { Camera2DFollow.followControl.Shake(0.2f, 0.2f); } // Instantiate a clone of the source so that multiple explosions can play at the same time. spriteRend.enabled = false; try { registerTile.Unregister(); PushPull oA = gameObject.GetComponent <PushPull>(); if (oA != null) { if (oA.pusher == PlayerManager.LocalPlayer) { PlayerManager.LocalPlayerScript.playerMove.IsPushing = false; } oA.isPushable = false; } } catch { Logger.LogWarning("Object may of already been removed", Category.Health); } foreach (Collider2D collider2d in gameObject.GetComponents <Collider2D>()) { collider2d.enabled = false; } string name = explosions[Random.Range(0, explosions.Length)]; AudioSource source = SoundManager.Instance[name]; if (source != null) { Instantiate(source, transform.position, Quaternion.identity).Play(); } GameObject fireRing = Resources.Load <GameObject>("effects/FireRing"); Instantiate(fireRing, transform.position, Quaternion.identity); GameObject lightFx = Resources.Load <GameObject>("lighting/BoomLight"); lightFxInstance = Instantiate(lightFx, transform.position, Quaternion.identity); lightSprite = lightFxInstance.GetComponentInChildren <LightSprite>(); //lightSprite.fadeFX(1f); // TODO Removed animation (Should be in a separate component) SetFire(); }
private void Awake() { //yeah dam Unity initial Conditions is not updating color = new Color(93f / 255f, 202 / 255f, 49 / 255f, 0); objectBehaviour = this.GetComponent <ObjectBehaviour>(); ObjectID = this.GetInstanceID(); mLightRendererObject = LightSpriteBuilder.BuildDefault(gameObject, color, 7); mLightRendererObject.SetActive(true); lightSprite = mLightRendererObject.GetComponent <LightSprite>(); lightSprite.Sprite = DotSprite; registerObject = this.GetComponent <RegisterObject>(); }
public static void CreateLightSource() { GameObject obj = new GameObject("Light"); if (LightingSystem.Instance != null) { obj.layer = LightingSystem.Instance.LightSourcesLayer; } LightSprite light = obj.AddComponent <LightSprite>(); light.Material = AssetDatabase.LoadAssetAtPath <Material>("Assets/Light2D/Materials/Light60Points.mat"); light.Sprite = Resources.Load <Sprite>("DefaultLight"); light.Color = new Color(1, 1, 1, 0.5f); Selection.activeObject = obj; }
private void Start() { mLightSprite = gameObject.GetComponent <LightSprite>(); if (mLightSprite == null) { mLightSprite = gameObject.GetComponentInChildren <LightSprite>(true); } mOriginalColor = mLightSprite.Color; mOriginalPosition = mLightSprite.transform.localPosition; GlitchTime = UnityEngine.Random.Range(0.5f, 3f); GlitchDuration = UnityEngine.Random.Range(0.2f, 1f); }
private void Awake() { registerTile = GetComponent <RegisterTile>(); construction = GetComponent <LightFixtureConstruction>(); if (mLightRendererObject == null) { mLightRendererObject = LightSpriteBuilder.BuildDefault(gameObject, new Color(0, 0, 0, 0), 12); } lightSprite = mLightRendererObject.GetComponent <LightSprite>(); if (!isWithoutSwitch) { switchState = InitialState == LightMountState.On; } ChangeCurrentState(InitialState); traitRequired = currentState.TraitRequired; }
// ----- Misc ----- public static Sprite Light(LightSprite size) { if (size == LightSprite.Light200x200) { return(GetSprite(@"Light200x200x2.png")); } if (size == LightSprite.Light300x300) { return(GetSprite(@"Light300x300x2.png")); } if (size == LightSprite.Light400x400) { return(GetSprite(@"Light400x400x2.png")); } throw new NotSupportedException(); }
private void EnsureLightsInit() { if (mLightRendererObject == null) { mLightRendererObject = LightSpriteBuilder.BuildDefault(gameObject, new Color(0, 0, 0, 0), 12); } lightSprite = mLightRendererObject.GetComponent <LightSprite>(); if (lightStateColorOn == new Color(0, 0, 0, 0)) { lightStateColorOn = new Color(0.7264151f, 0.7264151f, 0.7264151f, 0.8f); } if (lightStateColorEmergency == new Color(0, 0, 0, 0)) { lightStateColorEmergency = new Color(0.7264151f, 0, 0, 0.8f); } }
internal virtual void GoBoom() { if (spriteRend.isVisible) { Camera2DFollow.followControl.Shake(0.2f, 0.2f); } // Instantiate a clone of the source so that multiple explosions can play at the same time. spriteRend.enabled = false; try{ Matrix.Matrix.At(transform.position).TryRemoveTile(gameObject); ObjectActions oA = gameObject.GetComponent <ObjectActions>(); if (oA != null) { if (oA.pusher == PlayerManager.LocalPlayer) { PlayerManager.LocalPlayerScript.playerMove.isPushing = false; } oA.isPushable = false; } } catch { Debug.LogWarning("Object may of already been removed"); } Collider2D[] getColls = gameObject.GetComponents <Collider2D>(); for (int i = 0; i < getColls.Length; i++) { getColls[i].enabled = false; } var name = explosions[Random.Range(0, explosions.Length)]; var source = SoundManager.Instance[name]; if (source != null) { Instantiate <AudioSource>(source, transform.position, Quaternion.identity).Play(); } var fireRing = Resources.Load <GameObject>("effects/FireRing"); Instantiate(fireRing, transform.position, Quaternion.identity); var lightFx = Resources.Load <GameObject>("lighting/BoomLight"); lightFxInstance = Instantiate(lightFx, transform.position, Quaternion.identity); lightSprite = lightFxInstance.GetComponentInChildren <LightSprite>(); lightSprite.fadeFX(1f); SetFire(); }
private void Awake() { objectBehaviour = GetComponent <ObjectBehaviour>(); construction = GetComponent <LightFixtureConstruction>(); if (mLightRendererObject == null) { mLightRendererObject = LightSpriteBuilder.BuildDefault(gameObject, new Color(0, 0, 0, 0), 12); } lightSprite = mLightRendererObject.GetComponent <LightSprite>(); if (isWithoutSwitch == false) { switchState = InitialState == LightMountState.On; } ChangeCurrentState(InitialState); traitRequired = currentState.TraitRequired; RefreshBoxCollider(); }
/// <summary> /// Draws the optional "light sprite", just a simple sprite with no shadows /// </summary> /// <param name="spriteBatch"></param> public void DrawSprite(SpriteBatch spriteBatch, Camera cam) { if (DeformableLightSprite != null) { Vector2 origin = DeformableLightSprite.Origin; Vector2 drawPos = position; if (ParentSub != null) { drawPos += ParentSub.DrawPosition; } DeformableLightSprite.Draw( cam, new Vector3(drawPos, 0.0f), origin, -Rotation, SpriteScale, new Color(Color, lightSourceParams.OverrideLightSpriteAlpha ?? Color.A / 255.0f), LightSpriteEffect == SpriteEffects.FlipHorizontally); } if (LightSprite != null) { Vector2 origin = LightSprite.Origin; if (LightSpriteEffect == SpriteEffects.FlipHorizontally) { origin.X = LightSprite.SourceRect.Width - origin.X; } if (LightSpriteEffect == SpriteEffects.FlipVertically) { origin.Y = LightSprite.SourceRect.Height - origin.Y; } Vector2 drawPos = position; if (ParentSub != null) { drawPos += ParentSub.DrawPosition; } drawPos.Y = -drawPos.Y; LightSprite.Draw( spriteBatch, drawPos, new Color(Color, lightSourceParams.OverrideLightSpriteAlpha ?? Color.A / 255.0f), origin, -Rotation, SpriteScale, LightSpriteEffect); } }
public void Remove() { if (!lightSourceParams.Persistent) { LightSprite?.Remove(); OverrideLightTexture?.Remove(); } DeformableLightSprite?.Remove(); DeformableLightSprite = null; lightVolumeBuffer?.Dispose(); lightVolumeBuffer = null; lightVolumeIndexBuffer?.Dispose(); lightVolumeIndexBuffer = null; GameMain.LightManager.RemoveLight(this); }
// ******************************** // Awake // ******************************** protected override void Awake() { base.Awake(); // On button sprite OnButton = new GameObject("On Button Sprite"); OnButton.transform.SetParent(this.transform); OnButton.transform.localPosition = OnButtonPosition; OnButton.transform.localScale = ButtonScale; OnButtonSprite = OnButton.AddComponent <SpriteRenderer>(); OnButtonSprite.sprite = GlowSprite; OnButtonSprite.sharedMaterial = ModAPI.FindMaterial("VeryBright"); OnButtonSprite.color = OnButtonColour; OnButtonSprite.enabled = false; // On button light OnButtonLight = ModAPI.CreateLight(transform, Color.red); OnButtonLight.Color = OnButtonColour; OnButtonLight.Brightness = 10.0f; OnButtonLight.Radius = 0.01f; OnButtonLight.transform.localPosition = OnButtonPosition; OnButtonLight.SpriteRenderer.enabled = false; }
/* * Recursively traverse all lights under `parent`. */ private float TraverseLights(Transform parent) { float lightsum = 0.0f; LightSprite lightSprite = parent.gameObject.GetComponent <LightSprite>(); // if parent is not active, ignore if (!parent.gameObject.activeSelf) { return(lightsum); } // if parent is not a light, traverse its children and return immediately if (lightSprite == null) { foreach (Transform child in parent) { lightsum += TraverseLights(child); } return(lightsum); } // parent is a light. // calculate illumination from light Vector4 color = lightSprite.Color; float luminance = 0.3f * color.x + 0.59f * color.y + 0.11f * color.z; // red, green, blue components luminance *= color.w; // alpha component float dx = parent.position.x - transform.position.x; float dy = parent.position.y - transform.position.y; float distance = Mathf.Sqrt(dx * dx + dy * dy); float falloff_denom = Mathf.Pow(distance, visibility_illumination_falloff); // raycast to see if player is occluded CircleCollider2D player_collider = GetComponent <CircleCollider2D>(); Vector2 dir = transform.position - parent.position; float player_radius = player_collider.radius; float radius_offset = player_radius + 0.01f; // offset player radius //RaycastHit2D hit = Physics2D.Raycast(parent.position, dir, distance - (radius_offset)); RaycastHit2D[] hits = Physics2D.RaycastAll(parent.position, dir, distance - (radius_offset)); if (hits.Length == 0) { lightsum += luminance / falloff_denom; // inverse square fall-off } else { bool hit_visibility_occluder = false; foreach (RaycastHit2D hit in hits) { VisibilityOccluder visibility_occluder = hit.collider.gameObject.GetComponent <VisibilityOccluder>(); hit_visibility_occluder = visibility_occluder != null; if (hit_visibility_occluder) { float occlusion_multiplier = 1.0f - visibility_occluder.obstacle_multiplicative_alpha; lightsum += (luminance / falloff_denom) * occlusion_multiplier; break; } } if (!hit_visibility_occluder) { lightsum += luminance / falloff_denom; } } // TODO illumination from guard flashlights. Take flashlight cone shape into account. return(lightsum); }
private void Awake() { lightSprite = GetComponent <LightSprite>(); }
public override void PostInitialize() { bool oldShapeManagerSuppressAdd = FlatRedBall.Math.Geometry.ShapeManager.SuppressAddingOnVisibilityTrue; FlatRedBall.Math.Geometry.ShapeManager.SuppressAddingOnVisibilityTrue = true; base.PostInitialize(); if (mSpriteInstance.Parent == null) { mSpriteInstance.CopyAbsoluteToRelative(); mSpriteInstance.AttachTo(this, false); } base.SpriteInstance.Texture = Stage2; base.SpriteInstance.LeftTexturePixel = 3f; base.SpriteInstance.RightTexturePixel = 142f; base.SpriteInstance.TopTexturePixel = 373f; base.SpriteInstance.BottomTexturePixel = 760f; base.SpriteInstance.TextureScale = 0.5f; base.SpriteInstance.UseAnimationRelativePosition = true; base.SpriteInstance.AnimationChains = Rabbit2Animations; base.SpriteInstance.CurrentChainName = "Running"; base.SpriteInstance.IgnoreAnimationChainTextureFlip = true; if (mCircleInstance.Parent == null) { mCircleInstance.CopyAbsoluteToRelative(); mCircleInstance.AttachTo(this, false); } base.CircleInstance.Radius = 16f; if (LightSprite.Parent == null) { LightSprite.CopyAbsoluteToRelative(); LightSprite.AttachTo(this, false); } base.LightSprite.Texture = AllAssetsSheet; base.LightSprite.LeftTexturePixel = 1792f; base.LightSprite.RightTexturePixel = 2048f; base.LightSprite.TopTexturePixel = 1792f; base.LightSprite.BottomTexturePixel = 2048f; base.LightSprite.TextureScale = 0.5f; if (ShadowSprite.Parent == null) { ShadowSprite.CopyAbsoluteToRelative(); ShadowSprite.AttachTo(this, false); } if (ShadowSprite.Parent == null) { base.ShadowSprite.Y = -32f; } else { base.ShadowSprite.RelativeY = -32f; } if (ShadowSprite.Parent == null) { base.ShadowSprite.Z = -1f; } else { base.ShadowSprite.RelativeZ = -1f; } base.ShadowSprite.Texture = AllParticles; base.ShadowSprite.LeftTexturePixel = 1019f; base.ShadowSprite.RightTexturePixel = 1072f; base.ShadowSprite.TopTexturePixel = 1895f; base.ShadowSprite.BottomTexturePixel = 1948f; base.ShadowSprite.TextureScale = 1f; base.ShadowSprite.Width = 48f; base.ShadowSprite.Height = 16f; #if FRB_MDX ShadowSprite.ColorOperation = Microsoft.DirectX.Direct3D.TextureOperation.Modulate; #else base.ShadowSprite.ColorOperation = FlatRedBall.Graphics.ColorOperation.Modulate; #endif base.ShadowSprite.Alpha = 0.3f; if (PoisonedParticles.Parent == null) { PoisonedParticles.CopyAbsoluteToRelative(); PoisonedParticles.AttachTo(this, false); } if (FrozenParticles.Parent == null) { FrozenParticles.CopyAbsoluteToRelative(); FrozenParticles.AttachTo(this, false); } if (SmokeParticles.Parent == null) { SmokeParticles.CopyAbsoluteToRelative(); SmokeParticles.AttachTo(this, false); } if (StunParticles.Parent == null) { StunParticles.CopyAbsoluteToRelative(); StunParticles.AttachTo(this, false); } mGeneratedCollision = new FlatRedBall.Math.Geometry.ShapeCollection(); mGeneratedCollision.Circles.AddOneWay(mCircleInstance); FlatRedBall.Math.Geometry.ShapeManager.SuppressAddingOnVisibilityTrue = oldShapeManagerSuppressAdd; }
// Start is called before the first frame update void Start() { lightComponent = light.GetComponent <LightSprite>(); baseAlpha = lightComponent.Color.a; StartCoroutine("Flicker"); }
private void Awake() { spriteHandler = GetComponentInChildren <SpriteHandler>(); lightSprite = GetComponentInChildren <LightSprite>(); }
/// <summary> /// Draws the optional "light sprite", just a simple sprite with no shadows /// </summary> /// <param name="spriteBatch"></param> public void DrawSprite(SpriteBatch spriteBatch, Camera cam) { if (DeformableLightSprite != null) { Vector2 origin = DeformableLightSprite.Origin; Vector2 drawPos = position; if (ParentSub != null) { drawPos += ParentSub.DrawPosition; } DeformableLightSprite.Draw( cam, new Vector3(drawPos, 0.0f), origin, -Rotation, SpriteScale, new Color(Color, lightSourceParams.OverrideLightSpriteAlpha ?? Color.A / 255.0f), LightSpriteEffect == SpriteEffects.FlipHorizontally); } if (LightSprite != null) { Vector2 origin = LightSprite.Origin; if (LightSpriteEffect == SpriteEffects.FlipHorizontally) { origin.X = LightSprite.SourceRect.Width - origin.X; } if (LightSpriteEffect == SpriteEffects.FlipVertically) { origin.Y = LightSprite.SourceRect.Height - origin.Y; } Vector2 drawPos = position; if (ParentSub != null) { drawPos += ParentSub.DrawPosition; } drawPos.Y = -drawPos.Y; LightSprite.Draw( spriteBatch, drawPos, new Color(Color, lightSourceParams.OverrideLightSpriteAlpha ?? Color.A / 255.0f), origin, -Rotation, SpriteScale, LightSpriteEffect); } if (GameMain.DebugDraw) { //visualize light recalculations float timeSinceRecalculation = (float)Timing.TotalTime - lastRecalculationTime; if (timeSinceRecalculation < 0.1f) { Vector2 drawPos = position; if (ParentSub != null) { drawPos += ParentSub.DrawPosition; } drawPos.Y = -drawPos.Y; GUI.DrawRectangle(spriteBatch, drawPos - Vector2.One * 10, Vector2.One * 20, Color.Red * (1.0f - timeSinceRecalculation * 10.0f), isFilled: true); GUI.DrawLine(spriteBatch, drawPos - Vector2.One * Range, drawPos + Vector2.One * Range, Color); GUI.DrawLine(spriteBatch, drawPos - new Vector2(1.0f, -1.0f) * Range, drawPos + new Vector2(1.0f, -1.0f) * Range, Color); } } }