/// <summary> /// Animates the portal. Intended to be called from PortalSpawnMessages. /// </summary> public static void AnimatePortal(GameObject portal, PortalSpawnInfo settings) { // Portal expands LeanTween.scale(portal, Vector3.one, settings.PortalOpenTime).setFrom(Vector3.zero); // Portal shrinks LeanTween.scale(portal, Vector3.zero, settings.PortalCloseTime).setDelay(settings.PortalOpenTime + settings.PortalSuspenseTime); }
private IEnumerator ServerRunPortalSequence(GameObject portal, PortalSpawnInfo settings) { yield return(WaitFor.Seconds(settings.PortalOpenTime + (settings.PortalSuspenseTime / 2))); OnPortalReady?.Invoke(portal); yield return(WaitFor.Seconds(settings.PortalCloseTime + (settings.PortalSuspenseTime / 2))); Despawn.ServerSingle(portal); }
/// <summary> /// Animates the object. Intended to be called from PortalSpawnMessages. /// </summary> public static void AnimateObject(GameObject entity, PortalSpawnInfo settings) { Transform spriteObject = entity.transform.Find("Sprite"); float fallingTime = GetFallingTime(settings.PortalHeight); // Animate entity falling. LeanTween.moveLocalY(spriteObject.gameObject, 0, fallingTime).setFrom(settings.PortalHeight).setEaseInQuad(); // Animate entity rotating during fall. if (settings.EntityRotate) { spriteObject.LeanRotateZ(UnityEngine.Random.Range(0, 720), fallingTime).setFrom(RandomUtils.RandomRotation2D().eulerAngles); } }
public override bool CastSpellServer(ConnectedPlayer caster, Vector3 clickPosition) { PortalSpawnInfo settings = PortalSpawnInfo.DefaultSettings(); settings.EntityRotate = false; // A rotated large rock doesn't look great on landing. var rockPortalSpawn = new SpawnByPortal(mainRockPrefab, portalPrefab, clickPosition, settings); rockPortalSpawn.OnObjectSpawned += (GameObject mainRock) => { mainRock.GetComponent <RegisterObject>().SetPassable(false, true); // Passable until it lands. }; rockPortalSpawn.OnObjectLanded += (GameObject mainRock) => { OnRockLanded(mainRock, 120); mainRock.GetComponent <RegisterObject>().SetPassable(false, false); }; StartCoroutine(SpawnSmallRocks(clickPosition)); return(true); }
/// <summary> /// Animates the object. Intended to be called from PortalSpawnMessages. /// </summary> public static void AnimateObject(GameObject entity, PortalSpawnInfo settings) { Transform spriteObject = entity.transform.Find("Sprite"); if (spriteObject == null) { spriteObject = entity.transform.Find("sprite"); } if (spriteObject == null) { Logger.LogError($"No Sprite object found on {entity}! Cannot animate with {nameof(SpawnByPortal)}.", Category.Spells); } float fallingTime = GetFallingTime(settings.PortalHeight); // Animate entity falling. LeanTween.moveLocalY(spriteObject.gameObject, 0, fallingTime).setFrom(settings.PortalHeight).setEaseInQuad(); // Animate entity rotating during fall. if (settings.EntityRotate) { spriteObject.LeanRotateZ(UnityEngine.Random.Range(0, 720), fallingTime).setFrom(RandomUtils.RandomRotation2D().eulerAngles); } }
private GameObject ServerSpawnObject(GameObject entityPrefab, Vector3 worldPosition, PortalSpawnInfo settings) { // Spawn object at landing zone, (sprite will move back up to worldPosition for animation). GameObject entity = Spawn.ServerPrefab(entityPrefab, worldPosition).GameObject; OnObjectSpawned?.Invoke(entity); UpdateManager.Instance.StartCoroutine(ServerRunObjectSequence(entity, settings)); return(entity); }
private GameObject ServerSpawnPortal(GameObject portalPrefab, Vector3 worldPosition, PortalSpawnInfo settings) { // Spawn portal at some "height" above the landing zone. worldPosition.y += settings.PortalHeight; GameObject portal = Spawn.ServerPrefab(portalPrefab, worldPosition).GameObject; UpdateManager.Instance.StartCoroutine(ServerRunPortalSequence(portal, settings)); return(portal); }
private void ServerSpawnPortalAndObject(GameObject entityPrefab, GameObject portalPrefab, Vector3 worldPosition, PortalSpawnInfo settings) { GameObject portal = ServerSpawnPortal(portalPrefab, worldPosition, settings); PortalSpawnAnimateMessage.SendToVisible(portal, settings, PortalSpawnAnimateMessage.AnimateType.Portal); OnPortalReady += (_) => { GameObject entity = ServerSpawnObject(entityPrefab, worldPosition, settings); PortalSpawnAnimateMessage.SendToVisible(entity, settings, PortalSpawnAnimateMessage.AnimateType.Entity); }; }
/// <summary> /// <inheritdoc cref="SpawnByPortal"/> /// </summary> /// <param name="entityPrefab">the entity which should be dropped from the portal</param> /// <param name="portalPrefab">the portal the entity drops out of</param> /// <param name="worldPosition">the position the entity will land at</param> /// <param name="settings">settings such as portal height, durations</param> public SpawnByPortal(GameObject entityPrefab, GameObject portalPrefab, Vector3 worldPosition, PortalSpawnInfo settings) { ServerSpawnPortalAndObject(entityPrefab, portalPrefab, worldPosition, settings); }
private IEnumerator ServerRunObjectSequence(GameObject entity, PortalSpawnInfo settings) { yield return(WaitFor.Seconds(GetFallingTime(settings.PortalHeight))); OnObjectLanded?.Invoke(entity); }