} // retrieve after finishing to get real damage number private void Awake() { foreach (Transform child in gameObject.transform) { if (child.name == "FightUILine") { line = new LuaSpriteController(child.GetComponent <Image>()); } else if (child.name == "SliceAnim") { slice = new LuaSpriteController(child.GetComponent <Image>()); } else if (child.name == "DamageNumber") { damageText = child.GetComponent <TextManager>(); } else if (child.name == "HPBar") { lifeBar = child.GetComponent <LifeBarController>(); } } damageTextRt = damageText.GetComponent <RectTransform>(); }
public void Initialize(HealthLogicData data) { _spawnedLifeBarGO = ObjectPoolController.Instance.Spawn(_lifeBarPrefab, Vector3.zero, Quaternion.identity); _lifeBarController = _spawnedLifeBarGO.GetComponent <LifeBarController>(); _data = data; _combatHealthAngle = 0f; SetFullLife(); if (_invincibleFx != null) { _invincibleFx.SetActive(false); } }
// Start is called before the first frame update private void Start() { HealthPoints = maxHealthPoints; _damageTextSpawner = GetComponentInChildren <DamageTextSpawner>(); _lifeBarController = GetComponent <LifeBarController>(); _animator = GetComponent <Animator>(); _actionScheduler = GetComponent <ActionScheduler>(); _capsuleCollider = GetComponent <CapsuleCollider>(); _navMeshAgent = GetComponent <NavMeshAgent>(); _aiController = GetComponent <AIController>(); _combatTarget = GetComponent <CombatTarget>(); if (_lifeBarController != null) { _lifeBarController.InitLifeBar(); } }
private void Start() { lifebar = gameObject.GetComponentInChildren <LifeBarController>(); lifebarRt = lifebar.GetComponent <RectTransform>(); nameLevelTextManParent = GameObject.Find("NameLv"); nameLevelTextManParent.transform.position = new Vector3(nameLevelTextManParent.transform.position.x, nameLevelTextManParent.transform.position.y - 1, nameLevelTextManParent.transform.position.z); hpTextManParent = GameObject.Find("HPTextParent"); hpTextManParent.transform.position = new Vector3(hpTextManParent.transform.position.x, hpTextManParent.transform.position.y - 1, hpTextManParent.transform.position.z); nameLevelTextMan = nameLevelTextManParent.AddComponent <TextManager>(); hpTextMan = hpTextManParent.AddComponent <TextManager>(); hpRect = GameObject.Find("HPRect"); hpTextMan.SetFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_SMALLTEXT_NAME)); initialized = true; setMaxHP(); setPlayerInfo(PlayerCharacter.instance.Name, PlayerCharacter.instance.LV); }
private void Start() { GameObject statsObj = GameObject.Find("Stats"); lifebar = statsObj.GetComponentInChildren <LifeBarController>(); lifebarRt = lifebar.GetComponent <RectTransform>(); nameLevelTextManParent = GameObject.Find("NameLv"); hpTextManParent = GameObject.Find("HPTextParent"); nameLevelTextMan = nameLevelTextManParent.AddComponent <TextManager>(); hpTextMan = hpTextManParent.AddComponent <TextManager>(); hpTextMan.setFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_SMALLTEXT_NAME)); initialized = true; setMaxHP(); setHP(hpCurrent); setPlayerInfo(nameCurrent, lvCurrent); }
public void Start() { foreach (RectTransform child in transform) { switch (child.name) { case "SliceAnim": slice = new LuaSpriteController(child.GetComponent <Image>()); break; case "HPBar": lifeBar = child.GetComponent <LifeBarController>(); break; case "DamageNumber": damageText = child.GetComponent <TextManager>(); damageTextRt = child.GetComponent <RectTransform>(); break; } } sliceAnim = UIController.instance.fightUI.sliceAnim; sliceAnimFrequency = UIController.instance.fightUI.sliceAnimFrequency; shakeX = UIController.instance.fightUI.shakeX; damageText.SetFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_DAMAGETEXT_NAME)); damageText.SetMute(true); }
public void SwitchState(UIState state) { //Pre-state if (parentStateCall) { parentStateCall = false; encounter.script.Call("EnteringState", new DynValue[] { DynValue.NewString(state.ToString()), DynValue.NewString(this.state.ToString()) }); parentStateCall = true; if (childStateCalled) { childStateCalled = false; return; } } else { childStateCalled = true; } // TODO Quick and dirty addition to add some humor to the Run away command. // Will be removed without question. if (musicPausedFromRunning) { Camera.main.GetComponent <AudioSource>().UnPause(); musicPausedFromRunning = false; } // END DEBUG // below: actions based on ending a previous state, or actions that affect multiple states if (this.state == UIState.DEFENDING && state != UIState.DEFENDING) { encounter.endWave(); } if (state != UIState.ENEMYDIALOGUE && state != UIState.DEFENDING) { ArenaSizer.instance.Resize(ArenaSizer.UIWidth, ArenaSizer.UIHeight); PlayerController.instance.invulTimer = 0.0f; PlayerController.instance.setControlOverride(true); } if (this.state == UIState.ENEMYSELECT && action == Actions.FIGHT) { foreach (LifeBarController lbc in arenaParent.GetComponentsInChildren <LifeBarController>()) { Destroy(lbc.gameObject); } } if (state == UIState.DEFENDING || state == UIState.ENEMYDIALOGUE) { textmgr.destroyText(); PlayerController.instance.SetPosition(320, 160, false); PlayerController.instance.GetComponent <Image>().enabled = true; fightBtn.overrideSprite = null; actBtn.overrideSprite = null; itemBtn.overrideSprite = null; mercyBtn.overrideSprite = null; textmgr.setPause(true); } if (this.state == UIState.ENEMYDIALOGUE) { TextManager[] textmen = FindObjectsOfType <TextManager>(); foreach (TextManager textman in textmen) { if (textman.gameObject.name.StartsWith("DialogBubble")) // game object name is hardcoded as it won't change { Destroy(textman.gameObject); } } } this.state = state; switch (state) { case UIState.ATTACKING: textmgr.destroyText(); PlayerController.instance.GetComponent <Image>().enabled = false; fightUI.Init(encounter.enabledEnemies[selectedEnemy]); break; case UIState.ACTIONSELECT: PlayerController.instance.setControlOverride(true); PlayerController.instance.GetComponent <Image>().enabled = true; setPlayerOnAction(action); textmgr.setPause(ArenaSizer.instance.isResizeInProgress()); textmgr.setCaller(encounter.script); // probably not necessary due to ActionDialogResult changes textmgr.setText(new RegularMessage(encounter.EncounterText)); break; case UIState.ACTMENU: string[] actions = new string[encounter.enabledEnemies[selectedEnemy].ActCommands.Length]; for (int i = 0; i < actions.Length; i++) { actions[i] = encounter.enabledEnemies[selectedEnemy].ActCommands[i]; } selectedAction = 0; setPlayerOnSelection(selectedAction); textmgr.setText(new SelectMessage(actions, false)); break; case UIState.ITEMMENU: string[] items = getInventoryPage(0); selectedItem = 0; setPlayerOnSelection(0); textmgr.setText(new SelectMessage(items, false)); /*ActionDialogResult(new TextMessage[] { * new TextMessage("Can't open inventory.\nClogged with pasta residue.", true, false), * new TextMessage("Might also be a dog.\nIt's ambiguous.",true,false) * }, UIState.ENEMYDIALOG);*/ break; case UIState.MERCYMENU: selectedMercy = 0; string[] mercyopts = new string[1 + (encounter.CanRun ? 1 : 0)]; mercyopts[0] = "Spare"; foreach (EnemyController enemy in encounter.enabledEnemies) { if (enemy.CanSpare) { mercyopts[0] = "[starcolor:ffff00][color:ffff00]" + mercyopts[0] + "[color:ffffff]"; break; } } if (encounter.CanRun) { mercyopts[1] = "Flee"; } setPlayerOnSelection(0); textmgr.setText(new SelectMessage(mercyopts, true)); break; case UIState.ENEMYSELECT: string[] names = new string[encounter.enabledEnemies.Length]; string[] colorPrefixes = new string[names.Length]; for (int i = 0; i < encounter.enabledEnemies.Length; i++) { names[i] = encounter.enabledEnemies[i].Name; if (encounter.enabledEnemies[i].CanSpare) { colorPrefixes[i] = "[color:ffff00]"; } } textmgr.setText(new SelectMessage(names, true, colorPrefixes)); if (action == Actions.FIGHT) { int maxWidth = (int)initialHealthPos.x; for (int i = 0; i < encounter.enabledEnemies.Length; i++) { int mNameWidth = UnitaleUtil.fontStringWidth(textmgr.Charset, "* " + encounter.enabledEnemies[i].Name) + 50; if (mNameWidth > maxWidth) { maxWidth = mNameWidth; } } for (int i = 0; i < encounter.enabledEnemies.Length; i++) { LifeBarController lifebar = Instantiate(Resources.Load <LifeBarController>("Prefabs/HPBar")); lifebar.transform.SetParent(textmgr.transform); RectTransform lifebarRt = lifebar.GetComponent <RectTransform>(); lifebarRt.anchoredPosition = new Vector2(maxWidth, initialHealthPos.y - i * textmgr.Charset.LineSpacing); lifebarRt.sizeDelta = new Vector2(90, lifebarRt.sizeDelta.y); lifebar.setFillColor(Color.green); float hpFrac = (float)encounter.enabledEnemies[i].HP / (float)encounter.enabledEnemies[i].getMaxHP(); lifebar.setInstant(hpFrac); } } if (selectedEnemy >= encounter.enabledEnemies.Length) { selectedEnemy = 0; } setPlayerOnSelection(selectedEnemy * 2); // single list so skip right row by multiplying x2 break; case UIState.DEFENDING: ArenaSizer.instance.Resize((int)encounter.ArenaSize.x, (int)encounter.ArenaSize.y); PlayerController.instance.setControlOverride(false); encounter.nextWave(); // ActionDialogResult(new TextMessage("This is where you'd\rdefend yourself.\nBut the code was spaghetti.", true, false), UIState.ACTIONSELECT); break; case UIState.DIALOGRESULT: PlayerController.instance.GetComponent <Image>().enabled = false; break; case UIState.ENEMYDIALOGUE: PlayerController.instance.GetComponent <Image>().enabled = true; ArenaSizer.instance.Resize(155, 130); encounter.CallOnSelfOrChildren("EnemyDialogueStarting"); monDialogues = new TextManager[encounter.enabledEnemies.Length]; for (int i = 0; i < encounter.enabledEnemies.Length; i++) { string[] msgs = encounter.enabledEnemies[i].GetDefenseDialog(); if (msgs == null) { UserDebugger.warn("Entered ENEMYDIALOGUE, but no current/random dialogue was set for " + encounter.enabledEnemies[i].Name); SwitchState(UIState.DEFENDING); break; } GameObject speechBub = Instantiate(SpriteFontRegistry.BUBBLE_OBJECT); RectTransform enemyRt = encounter.enabledEnemies[i].GetComponent <RectTransform>(); TextManager sbTextMan = speechBub.GetComponent <TextManager>(); monDialogues[i] = sbTextMan; sbTextMan.setCaller(encounter.enabledEnemies[i].script); Image speechBubImg = speechBub.GetComponent <Image>(); SpriteUtil.SwapSpriteFromFile(speechBubImg, encounter.enabledEnemies[i].DialogBubble); Sprite speechBubSpr = speechBubImg.sprite; // TODO improve position setting/remove hardcoding of position setting speechBub.transform.SetParent(encounter.enabledEnemies[i].transform); speechBub.GetComponent <RectTransform>().anchoredPosition = encounter.enabledEnemies[i].DialogBubblePosition; sbTextMan.setOffset(speechBubSpr.border.x, -speechBubSpr.border.w); sbTextMan.setFont(SpriteFontRegistry.Get(SpriteFontRegistry.UI_MONSTERTEXT_NAME)); sbTextMan.setEffect(new RotatingEffect(sbTextMan)); MonsterMessage[] monMsgs = new MonsterMessage[msgs.Length]; for (int j = 0; j < monMsgs.Length; j++) { monMsgs[j] = new MonsterMessage(msgs[j]); } sbTextMan.setTextQueue(monMsgs); speechBub.GetComponent <Image>().enabled = true; } break; case UIState.DONE: StaticInits.Reset(); Application.LoadLevel("ModSelect"); break; } }
public HeartImage(LifeBarController lifeBarController, Image heartImage) { this.lifeBarController = lifeBarController; this.heartImage = heartImage; }