public void summon(Vector3 initialPosition, Vector3 intermediatePosition, Vector3 finalPosition, Vector3 mirrorPosition, float summonD) { summonInitialPosition = initialPosition; summonIntermediatePosition = intermediatePosition; summonFinalPosition = finalPosition; summonFinalPosition2 = finalPosition + new Vector3(0, 0, 1.6f); summonMirrorPosition = mirrorPosition + new Vector3(0, 3, 0); // ad-hoc correction: a tad higher summonDelay = summonD; this.transform.position = initialPosition; rigidBody.useGravity = true; rigidBody.isKinematic = false; autopilotOrigin = initialPosition; autopilotDestination = intermediatePosition; autopilot = true; state = ShadowState.summoned; state2 = ShadowStateSlot2.disabled; substate = 0; this.isWaitingForActionToComplete = true; waitingRef = this; linearSpeed = linearSpeed * 1.5f; }
// Update is called once per frame void Update() { if (Lights == null) { return; } //Browse the list of lights for (int i = 0; i < Lights.Count; ++i) { IsOnShadow = !IsOnLight(Lights[i]); if (!IsOnShadow) { break; } } //Call Events if (_lastValue != _isOnShadow) { OnChangeState.Invoke(IsOnShadow); if (IsOnShadow) { OnEnterShadow.Invoke(); } else { OnExitShadow.Invoke(); } } _lastValue = _isOnShadow; }
/// <summary> /// Calculate the solar panel power in depending on position /// </summary> /// <param name="shadow"></param> /// <returns></returns> protected double GetSolarPanelPower(ShadowState shadow) { switch (shadow) { case ShadowState.UMBRA: return 0; case ShadowState.PENUMBRA: return _penumbraSolarPanelPower; default: return _fullSolarPanelPower; } }
public void enterMirror() { y = this.transform.position.y; //navAgent.enabled = false; rigidBody.detectCollisions = false; rigidBody.useGravity = false; state = ShadowState.enteringMirror; lerp = 0.0f; state2 = ShadowStateSlot2.blinking; startPos.y = y; mirrorPos.y = y; }
/// <summary> /// Calculate the solar panel power in depending on position /// </summary> /// <param name="shadow"></param> /// <returns></returns> protected double GetSolarPanelPower(ShadowState shadow) { switch (shadow) { case ShadowState.UMBRA: return(0); case ShadowState.PENUMBRA: return(_penumbraSolarPanelPower); default: return(_fullSolarPanelPower); } }
public void mirrorConverge(Vector3 startPos, Vector3 stopPos, Vector3 mirrorPos) { state = ShadowState.seeking; state2 = ShadowStateSlot2.disabled; //navAgent.speed = linearSpeed * 75.0f; float distToMirror = (mirrorPos - this.transform.position).magnitude; if (distToMirror > ShadowSpawnController.offScreenRadius) { //navAgent.Warp (startPos); } //navAgent.destination = stopPos; //navAgent.updateRotation = false; this.mirrorPos = mirrorPos; this.startPos = stopPos; }
private void ToggleShadowAnimationToState(ShadowState state) { nfloat endOpacity = 0.0f; if (state == ShadowState.ShadowStateShown) { endOpacity = this.ShadowOpacity; } CABasicAnimation animation = CABasicAnimation.FromKeyPath("shadowOpacity"); animation.From = NSNumber.FromFloat((float)this.ShadowOpacity); animation.To = NSNumber.FromFloat((float)endOpacity); animation.Duration = animationDuration; this.BackgroundCircle.Layer.AddAnimation(animation, "shadowOpacity"); this.BackgroundCircle.Layer.ShadowOpacity = (float)endOpacity; }
public void initialize() { frame = 0; linearSpeed = maxLinearSpeed; elapsedTime = 0.0f; state = ShadowState.spawning1; state2 = ShadowStateSlot2.cannotShoot; timeToStateChange = floatRandomRange(minTimeToStateChange, maxTimeToStateChange); targetAngle = angle = (floatRandomRange(0.0f, 360.0f) / 360.0f) * 2.0f * 3.1416f; rigidBody = this.GetComponent <Rigidbody> (); spriteRend = SpriteQuad.GetComponent <SpriteRenderer> (); SpriteMat = spriteRend.material; /*SpriteMat.SetFloat("_Mode", 2); * SpriteMat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); * SpriteMat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); * SpriteMat.SetInt("_ZWrite", 1); * SpriteMat.EnableKeyword("_ALPHATEST_ON"); * SpriteMat.DisableKeyword("_ALPHABLEND_ON"); * SpriteMat.DisableKeyword("_ALPHAPREMULTIPLY_ON"); * //SpriteMat.renderQueue = 2450;*/ directionFromAngle(angle); spriteRend.sprite = images [0]; stateElapsedTime = 0.0f; canShootRedEyesTime = 0.0f; burstElapsedTime = 0.0f; timeToBurst = floatRandomRange(minBurstDuration, maxBurstDuration); initialized = true; blink = false; rigidBody.velocity = new Vector3(0, 0, 0); rigidBody.detectCollisions = false; rigidBody.isKinematic = true; if (freezer == null) { freezer = GameObject.Find("Freezer").GetComponent <Freezer> (); } //navAgent = this.GetComponent<NavMeshAgent> (); this.frozen = false; rigidBody.useGravity = true; moving = true; }
/// <summary> /// Calculate the solar panel power in over the time of the task /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <param name="state"></param> /// <param name="position"></param> /// <param name="universe"></param> /// <returns></returns> protected HSFProfile <double> CalcSolarPanelPowerProfile(double start, double end, SystemState state, DynamicState position, Universe universe) { // create solar panel profile for this event double freq = 5; ShadowState lastShadow = universe.Sun.castShadowOnPos(position, start); HSFProfile <double> solarPanelPowerProfile = new HSFProfile <double>(start, GetSolarPanelPower(lastShadow)); for (double time = start + freq; time <= end; time += freq) { ShadowState shadow = universe.Sun.castShadowOnPos(position, time); // if the shadow state changes during this step, save the power data if (shadow != lastShadow) { solarPanelPowerProfile[time] = GetSolarPanelPower(shadow); lastShadow = shadow; } } state.AddValue(POWIN_KEY, solarPanelPowerProfile); return(solarPanelPowerProfile); }
internal static void SetElevationInternal(this DependencyObject element, double elevation, Color shadowColor) #endif { #if __ANDROID__ if (element is Android.Views.View view) { AndroidX.Core.View.ViewCompat.SetElevation(view, (float)Uno.UI.ViewHelper.LogicalToPhysicalPixels(elevation)); if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.P) { view.SetOutlineAmbientShadowColor(shadowColor); view.SetOutlineSpotShadowColor(shadowColor); } } #elif __IOS__ || __MACOS__ #if __MACOS__ if (element is AppKit.NSView view) #else if (element is UIKit.UIView view) #endif { if (elevation > 0) { // Values for 1dp elevation according to https://material.io/guidelines/resources/shadows.html#shadows-illustrator const float x = 0.25f; const float y = 0.92f * 0.5f; // Looks more accurate than the recommended 0.92f. const float blur = 0.5f; #if __MACOS__ view.WantsLayer = true; view.Shadow ??= new AppKit.NSShadow(); #endif view.Layer.MasksToBounds = false; view.Layer.ShadowOpacity = shadowColor.A / 255f; #if __MACOS__ view.Layer.ShadowColor = AppKit.NSColor.FromRgb(shadowColor.R, shadowColor.G, shadowColor.B).CGColor; #else view.Layer.ShadowColor = UIKit.UIColor.FromRGB(shadowColor.R, shadowColor.G, shadowColor.B).CGColor; #endif view.Layer.ShadowRadius = (nfloat)(blur * elevation); view.Layer.ShadowOffset = new CoreGraphics.CGSize(x * elevation, y * elevation); view.Layer.ShadowPath = path; } else if (view.Layer != null) { view.Layer.ShadowOpacity = 0; } } #elif __WASM__ if (element is UIElement uiElement) { if (elevation > 0) { // Values for 1dp elevation according to https://material.io/guidelines/resources/shadows.html#shadows-illustrator const double x = 0.25d; const double y = 0.92f * 0.5f; // Looks more accurate than the recommended 0.92f. const double blur = 0.5f; var color = Color.FromArgb((byte)(shadowColor.A * .35), shadowColor.R, shadowColor.G, shadowColor.B); var str = $"{(x * elevation).ToStringInvariant()}px {(y * elevation).ToStringInvariant()}px {(blur * elevation).ToStringInvariant()}px {color.ToCssString()}"; uiElement.SetStyle("box-shadow", str); uiElement.SetCssClasses("noclip"); } else { uiElement.ResetStyle("box-shadow"); uiElement.UnsetCssClasses("noclip"); } } #elif __SKIA__ if (element is UIElement uiElement) { var visual = uiElement.Visual; const float SHADOW_SIGMA_X_MODIFIER = 1f / 3.5f; const float SHADOW_SIGMA_Y_MODIFIER = 1f / 3.5f; float x = 0.3f; float y = 0.92f * 0.5f; var dx = (float)elevation * x; var dy = (float)elevation * y; var sigmaX = (float)elevation * SHADOW_SIGMA_X_MODIFIER; var sigmaY = (float)elevation * SHADOW_SIGMA_Y_MODIFIER; var shadow = new ShadowState(dx, dy, sigmaX, sigmaY, shadowColor); visual.ShadowState = shadow; } #elif NETFX_CORE || NETCOREAPP if (element is UIElement uiElement) { var compositor = ElementCompositionPreview.GetElementVisual(uiElement).Compositor; var spriteVisual = compositor.CreateSpriteVisual(); var newSize = new Vector2(0, 0); if (uiElement is FrameworkElement contentFE) { newSize = new Vector2((float)contentFE.ActualWidth, (float)contentFE.ActualHeight); } if (!(host is Canvas uiHost) || newSize == default) { return; } spriteVisual.Size = newSize; if (elevation > 0) { // Values for 1dp elevation according to https://material.io/guidelines/resources/shadows.html#shadows-illustrator const float x = 0.25f; const float y = 0.92f * 0.5f; // Looks more accurate than the recommended 0.92f. const float blur = 0.5f; var shadow = compositor.CreateDropShadow(); shadow.Offset = new Vector3((float)elevation * x, (float)elevation * y, -(float)elevation); shadow.BlurRadius = (float)(blur * elevation); shadow.Mask = uiElement switch { // GetAlphaMask is only available for shapes, images, and textblocks Shape shape => shape.GetAlphaMask(), Image image => image.GetAlphaMask(), TextBlock tb => tb.GetAlphaMask(), _ => shadow.Mask }; if (!cornerRadius.Equals(default))
public void ToggleShadowAnimationToState(ShadowState state) { nfloat endOpacity = 0.0f; if (state == ShadowState.ShadowStateShown) { endOpacity = this.ShadowOpacity; } CABasicAnimation animation = CABasicAnimation.FromKeyPath("shadowOpacity"); animation.From = NSNumber.FromFloat((float)this.ShadowOpacity); animation.To = NSNumber.FromFloat((float)endOpacity); animation.Duration = animationDuration; this.BackgroundCircle.Layer.AddAnimation(animation, "shadowOpacity"); this.BackgroundCircle.Layer.ShadowOpacity = (float)endOpacity; }
new void Update() { if (freezer.frozen) { return; } if (state == ShadowState.seeking) { } if (state == ShadowState.entered) { } if (state == ShadowState.enteringMirror) { lerp += lerpSpeed * Time.deltaTime; if (lerp > 1.0f) { SpriteMat.color = new Color(1, 1, 1, 0); state = ShadowState.entered; state2 = ShadowStateSlot2.disabled; } } if (state2 == ShadowStateSlot2.disabled) { } if (state2 == ShadowStateSlot2.blinking) { blink = !blink; if (blink) { SpriteMat.color = new Color(1, 1, 1, 0); } else { SpriteMat.color = new Color(1, 1, 1, 1); } } if (state2 == ShadowStateSlot2.cannotShoot) { canShootRedEyesTime += Time.deltaTime; if (canShootRedEyesTime > doNotShootRedEyesTime) { state2 = ShadowStateSlot2.idling; } } if (state2 == ShadowStateSlot2.idling) { burstElapsedTime += Time.deltaTime; if (burstElapsedTime > timeToBurst) { burstElapsedTime = 0.0f; eyeShotElapsedTime = 0.0f; timeToEyeShot = floatRandomRange(minEyeShotInterval, maxEyeShotInterval); timeToBurst = floatRandomRange(minBurstDuration, maxBurstDuration); state2 = ShadowStateSlot2.bursting; } } if (state2 == ShadowStateSlot2.bursting) { eyeShotElapsedTime += Time.deltaTime; burstElapsedTime += Time.deltaTime; if (eyeShotElapsedTime > timeToEyeShot) { eyeShotElapsedTime = 0.0f; timeToEyeShot = floatRandomRange(minEyeShotInterval, maxEyeShotInterval); GameObject newEyes = (GameObject)Instantiate(eyesPrefab, this.transform.position + new Vector3(0, 2.0f, 0), Quaternion.Euler(0, 0, 0)); newEyes.GetComponent <Redeyes> ().thoughtTextPrefab = thoughtTextPrefab; IconCooldown coolDown = GameObject.Find("StarCooldown").GetComponent <IconCooldown> (); newEyes.GetComponent <Redeyes> ().eyeDispelController = coolDown; GameObject p = GameObject.Find("Player"); newEyes.GetComponent <Redeyes> ().player = p; Letter letter = GameObject.Find("Letter").GetComponent <Letter> (); newEyes.GetComponent <Redeyes> ().letter = letter; newEyes.GetComponent <Redeyes> ().initialize(); redEyesStringBank.rosetta = rosetta; newEyes.GetComponent <Redeyes> ().stringBank = redEyesStringBank; newEyes.GetComponent <Redeyes> ().rosetta = rosetta; } if (burstElapsedTime > timeToBurst) { burstElapsedTime = 0.0f; timeToBurst = floatRandomRange(minTimeToBurst, maxTimeToBurst); state2 = ShadowStateSlot2.idling; } } if (state == ShadowState.spawning1) { stateElapsedTime += Time.deltaTime; Vector3 newPos = this.transform.position; newPos.x += Time.deltaTime * spawnDirection * 2.0f; this.transform.position = newPos; if (stateElapsedTime > 1.0f) { state = ShadowState.spawning2; rigidBody.detectCollisions = true; rigidBody.isKinematic = false; } } if (state == ShadowState.spawning2) { stateElapsedTime += Time.deltaTime; if (stateElapsedTime > 2.0f) { state = ShadowState.spawning3; rigidBody.velocity = new Vector3(0, 0, 0); } rigidBody.velocity = new Vector3(1.0f, 0.0f, 0.0f); } if (state == ShadowState.spawning3) { stateElapsedTime += Time.deltaTime; if (stateElapsedTime > 2.0f) { state = ShadowState.idle; SpriteMat.color = new Vector4(1, 1, 1, 1); } } if (state == ShadowState.spawning1 || state == ShadowState.spawning2 || state == ShadowState.spawning3) { elapsedTime += Time.deltaTime; if (elapsedTime > (1.0f / blinkSpeed)) { elapsedTime = 0.0f; blink = !blink; if (blink) { SpriteMat.color = new Vector4(1, 1, 1, 0); } else { SpriteMat.color = new Vector4(1, 1, 1, 1); } } return; } elapsedTime += Time.deltaTime; animElapsedTime += Time.deltaTime; if (elapsedTime > timeToStateChange) { timeToStateChange = floatRandomRange(minTimeToStateChange, maxTimeToStateChange); targetAngle = (floatRandomRange(0.0f, 360.0f) / 360.0f) * 2.0f * 3.1416f; elapsedTime = 0.0f; } if (angle < targetAngle) { angle += angleSpeed * Time.deltaTime; if (angle > targetAngle) { angle = targetAngle; } } if (angle > targetAngle) { angle -= angleSpeed * Time.deltaTime; if (angle < targetAngle) { angle = targetAngle; } } if (state == ShadowState.walking) { } if (state == ShadowState.summoned) { if (substate == 0) // waiting for shadow to reach Intermediate position { if (!isWaitingForActionToComplete) { autopilotOrigin = summonIntermediatePosition; autopilotDestination = summonFinalPosition; autopilot = true; substate = 1; elapsedTime = 0.0f; this.isWaitingForActionToComplete = true; waitingRef = this; } } if (substate == 1) // waiting for shadow to reach final position 2 { if (!isWaitingForActionToComplete) { autopilotOrigin = summonFinalPosition; autopilotDestination = summonFinalPosition2; autopilot = true; substate = 2; elapsedTime = 0.0f; this.isWaitingForActionToComplete = true; waitingRef = this; } } if (substate == 2) // waiting for shadow to reach mirror { if (!isWaitingForActionToComplete) { moving = false; elapsedTime += Time.deltaTime; if (elapsedTime > (1.0f + summonDelay)) { rigidBody.isKinematic = true; rigidBody.useGravity = false; lerp = 0.0f; summonFinalPosition2 = this.transform.position; substate = 3; } } } if (substate == 3) { lerp += Time.deltaTime; if (lerp > 1.0f) { lerp = 1.0f; substate = 4; } if (blink) { spriteRend.enabled = false; } else { spriteRend.enabled = true; } blink = !blink; Vector3 pos = Vector3.Lerp(summonFinalPosition2, summonMirrorPosition, lerp); this.transform.position = pos; this.transform.localScale = new Vector3(1.0f - lerp, 1.0f - lerp, 1.0f - lerp); } } if (moving) { directionFromAngle(angle); spriteRend.sprite = images [frame % images.Length]; if (animElapsedTime > (1.0f / animationSpeed)) { animElapsedTime = 0.0f; frame = (frame + 1) % images.Length; } } else { spriteRend.sprite = images [0]; } }