private void Start() { StationaryMissScript _smc = Resources.Load <StationaryMissScript>("Prefabs/StationaryMiss"); if (_smc != null && _smc.ToString().ToLower() != "null") { smc = _smc; } GameObject go = Resources.Load <GameObject>("Prefabs/FightInstance"); if (go != null && go.ToString().ToLower() != "null") { FightInstance = go; } line.Set("UI/Battle/spr_targetchoice_0"); instance = this; }
private void Start() { line.Set("UI/Battle/spr_targetchoice_0"); instance = this; }
private void Start() { damageText.setFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_DAMAGETEXT_NAME)); damageText.setMute(true); line.Set("UI/Battle/spr_targetchoice_0"); }
// Update is called once per frame private void Update() { // do not update the attack UI if the ATTACKING state is frozen if (UIController.instance.frozenState != UIController.UIState.PAUSE) { return; } if (shakeInProgress) { int shakeidx = (int)Mathf.Floor(shakeTimer * shakeX.Length / totalShakeTime); if (Damage > 0 && shakeIndex != shakeidx) { if (shakeIndex != shakeidx && shakeIndex >= shakeX.Length) { shakeIndex = shakeX.Length - 1; } shakeIndex = shakeidx; Vector2 localEnePos = enemy.GetComponent <RectTransform>().anchoredPosition; // get local position to do the shake enemy.GetComponent <RectTransform>().anchoredPosition = new Vector2(localEnePos.x + shakeX[shakeIndex], localEnePos.y); /*#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN * if (StaticInits.ENCOUNTER == "01 - Two monsters" && StaticInits.MODFOLDER == "Examples") * Misc.MoveWindow(shakeX[shakeIndex] * 2, 0); #endif*/ } if (shakeTimer < 1.5f) { damageTextRt.localPosition = new Vector2(damageTextRt.localPosition.x, enemy.offsets[2].y + 40 * (2 + Mathf.Sin(shakeTimer * Mathf.PI * 0.75f))); } shakeTimer += Time.deltaTime; if (shakeTimer >= totalShakeTime) { shakeInProgress = false; } } else if ((slice.animcomplete && !slice.img.GetComponent <KeyframeCollection>().enabled&& stopped && !showedup) || needAgain) { needAgain = true; if (!wait1frame) { wait1frame = true; slice.StopAnimation(); slice.Set("empty"); enemy.TryCall("BeforeDamageValues", new[] { DynValue.NewNumber(Damage) }); if (Damage > 0) { AudioSource aSrc = GetComponent <AudioSource>(); aSrc.clip = AudioClipRegistry.GetSound("hitsound"); aSrc.Play(); } // set damage numbers and positioning string damageTextStr; if (Damage == 0) { if (enemy.DefenseMissText == null) { damageTextStr = "[color:c0c0c0]MISS"; } else { damageTextStr = "[color:c0c0c0]" + enemy.DefenseMissText; } } else if (Damage > 0) { damageTextStr = "[color:ff0000]" + Damage; } else { damageTextStr = "[color:00ff00]" + Damage; } damageTextRt.localPosition = new Vector3(0, 0, 0); damageText.SetText(new TextMessage(damageTextStr, false, true)); damageTextRt.localPosition = new Vector3(-UnitaleUtil.CalcTextWidth(damageText) / 2 + enemy.offsets[2].x, 40 + enemy.offsets[2].y); // initiate lifebar and set lerp to its new health value if (Damage != 0) { int newHP = enemy.HP - Damage; try { lifeBar.GetComponent <RectTransform>().localPosition = new Vector2(enemy.offsets[2].x, 20 + enemy.offsets[2].y); lifeBar.GetComponent <RectTransform>().sizeDelta = new Vector2(enemy.GetComponent <RectTransform>().rect.width, 13); lifeBar.whenDamageValue = enemy.GetComponent <RectTransform>().rect.width; lifeBar.setInstant(enemy.HP < 0 ? 0 : enemy.HP / (float)enemy.MaxHP); lifeBar.setLerp(enemy.HP / (float)enemy.MaxHP, newHP / (float)enemy.MaxHP); lifeBar.setVisible(true); enemy.doDamage(Damage); } catch { return; } } enemy.HandleAttack(Damage); } else { // finally, damage enemy and call its attack handler in case you wanna stop music on death or something shakeInProgress = true; waitingToFade = true; needAgain = false; totalShakeTime = shakeX.Length * (1.5f / 8.0f); showedup = true; } } else if (!slice.animcomplete) { slice.img.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(slice.img.GetComponent <Image>().sprite.rect.width, slice.img.GetComponent <Image>().sprite.rect.height); } }
// Update is called once per frame void Update() { if (shakeInProgress) { int shakeidx = (int)Mathf.Floor(shakeTimer * shakeX.Length / totalShakeTime); bool wentIn = false; if (Damage > 0 && shakeIndex != shakeidx || wentIn) { if (shakeIndex != shakeidx && shakeIndex >= shakeX.Length) { shakeIndex = shakeX.Length - 1; } shakeIndex = shakeidx; wentIn = true; Vector2 localEnePos = enemy.GetComponent <RectTransform>().anchoredPosition; // get local position to do the shake enemy.GetComponent <RectTransform>().anchoredPosition = new Vector2(localEnePos.x + shakeX[shakeIndex], localEnePos.y); /*#if UNITY_STANDALONE_WIN || UNITY_EDITOR * if (StaticInits.ENCOUNTER == "01 - Two monsters" && StaticInits.MODFOLDER == "Examples") * Misc.MoveWindow(shakeX[shakeIndex] * 2, 0); #endif*/ } if (shakeTimer < 1.5f) { damageTextRt.localPosition = new Vector2(damageTextRt.localPosition.x, enemy.offsets[2].y + 40 * (2 + Mathf.Sin(shakeTimer * Mathf.PI * 0.75f))); } shakeTimer += Time.deltaTime; if (shakeTimer >= totalShakeTime) { shakeInProgress = false; } } else if ((slice.animcomplete && !slice.img.GetComponent <KeyframeCollection>().enabled&& stopped && !showedup) || needAgain) { needAgain = true; if (!wait1frame) { wait1frame = true; slice.StopAnimation(); slice.Set("empty"); enemy.TryCall("BeforeDamageValues"); if (Damage > 0) { AudioSource aSrc = GetComponent <AudioSource>(); aSrc.clip = AudioClipRegistry.GetSound("hitsound"); aSrc.Play(); } // set damage numbers and positioning string damageTextStr = ""; if (Damage == 0) { damageTextStr = "[color:c0c0c0]MISS"; } else if (Damage > 0) { damageTextStr = "[color:ff0000]" + Damage; } else { damageTextStr = "[color:00ff00]" + Damage; } // the -14 is to compensate for the 14 characters that [color:rrggbb] is worth until commands no longer count for text length. soon int damageTextWidth = (damageTextStr.Length - 14) * 29 + (damageTextStr.Length - 1 - 14) * 3; // lol hardcoded offsets foreach (char c in damageTextStr) { if (c == '1') { damageTextWidth -= 12; // lol hardcoded offsets } } damageTextRt.localPosition = new Vector2(-0.5f * damageTextWidth + enemy.offsets[2].x, 40 + enemy.offsets[2].y); damageText.SetText(new TextMessage(damageTextStr, false, true)); // initiate lifebar and set lerp to its new health value if (Damage != 0) { int newHP = enemy.HP - Damage; try { lifeBar.GetComponent <RectTransform>().localPosition = new Vector2(enemy.offsets[2].x, 20 + enemy.offsets[2].y); lifeBar.GetComponent <RectTransform>().sizeDelta = new Vector2(enemy.GetComponent <RectTransform>().rect.width, 13); lifeBar.whenDamageValue = enemy.GetComponent <RectTransform>().rect.width; lifeBar.setInstant(enemy.HP < 0 ? 0 : (float)enemy.HP / (float)enemy.MaxHP); lifeBar.setLerp((float)enemy.HP / (float)enemy.MaxHP, (float)newHP / (float)enemy.MaxHP); lifeBar.setVisible(true); enemy.doDamage(Damage); } catch { return; } } enemy.HandleAttack(Damage); } else { // finally, damage enemy and call its attack handler in case you wanna stop music on death or something shakeInProgress = true; waitingToFade = true; needAgain = false; totalShakeTime = shakeX.Length * (1.5f / 8.0f); showedup = true; } } else if (!slice.animcomplete) { slice.img.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(slice.img.GetComponent <Image>().sprite.rect.width, slice.img.GetComponent <Image>().sprite.rect.height); } }