/// <summary> /// Adds a shadow to the specified parent. /// </summary> /// <param name="parent">The parent of the shadow.</param> /// <param name="shadowLayer">If set to <c>true</c>, shadow will be on specified shadow layer. Otherwise, shadow will be on the parent's layer. Overrides default settings. </param> public void AddShadow(Transform parent, bool shadowLayer) { GameObject obj = (GameObject)Instantiate(shadowPrefab, parent.position, parent.rotation); Shadow2DDN shadow = obj.GetComponent <Shadow2DDN> (); shadow.shadowLayer = shadowLayer; shadow.shadowMoveMod = 1; shadow.transform.parent = parent; shadow.transform.localScale = Vector3.one; }
/// <summary> /// Adds a shadow to the specified parent. /// </summary> /// <param name="parent">The parent of the shadow.</param> /// <param name="parentSprite">The sprite this shadow immitates. Incase you want it to copy a sprite other than its parent's. The parent doesnt necessarily need a SpriteRenderer in this case.</param> public void AddShadow(Transform parent, SpriteRenderer parentSprite) { GameObject obj = (GameObject)Instantiate(shadowPrefab, parent.position, parent.rotation); Shadow2DDN shadow = obj.GetComponent <Shadow2DDN> (); if (allShadowsOnLayer) { shadow.shadowLayer = true; } shadow.shadowMoveMod = 1; shadow.transform.parent = parent; shadow.parentSprite = parentSprite; shadow.transform.localScale = Vector3.one; }
/// <summary> /// Updates the shadows' positions to match the time of day. /// </summary> void UpdateShadows() { for (int i = 0; i < DarkSide.Count; i++) { Shadow2DDN shadow = DarkSide [i]; // Unnecessary to apply the position to shadows off screen. if (shadow.sprite.isVisible) { Vector2 parentLoc = shadow.transform.parent.transform.position; shadow.transform.position = new Vector2(parentLoc.x + shadowLoc.x * shadow.shadowMoveMod, parentLoc.y + shadowLoc.y * shadow.shadowMoveMod); shadow.sprite.color = shadowCol; } } }
/// <summary> /// Deletes a shadow from the registry. /// </summary> /// <param name="sprite">The sprite to delte from the registry.</param> public void DelShadow(Shadow2DDN shadow) { DarkSide.Remove(shadow); }
/// <summary> /// Registers a shadow to the registry. /// </summary> /// <param name="sprite">The sprite to register. </param> public void RegShadow(Shadow2DDN shadow) { DarkSide.Add(shadow); }