void Awake(){ instance = (AbilityManager)target; GetAbility(); EditorUtility.SetDirty(instance); }
void OnFPSMode(bool flag) { //FPSModeCrosshairObj.SetActive(flag); #if UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_BLACKBERRY UIGameMessage.DisplayMessage("FPS mode is not supported in mobile"); #endif if (flag) { UIBuildButton.Hide(); UIAbilityButton.Hide(); UIPerkMenu.Hide(); UIFPSHUD.Show(); } else { if (UseDragNDrop()) { UIBuildButton.Show(); } if (AbilityManager.IsOn()) { UIAbilityButton.Show(); } if (PerkManager.IsOn()) { UIPerkMenu.Show(); } UIFPSHUD.Hide(); } }
void Awake() { instance = this; thisT = transform; List <Ability> dbList = AbilityDB.Load(); abilityList = new List <Ability>(); for (int i = 0; i < dbList.Count; i++) { if (!unavailableIDList.Contains(dbList[i].ID)) { abilityList.Add(dbList[i].Clone()); } } for (int i = 0; i < abilityList.Count; i++) { abilityList[i].ID = i; } if (defaultIndicator) { defaultIndicator = (Transform)Instantiate(defaultIndicator); defaultIndicator.parent = thisT; defaultIndicator.gameObject.SetActive(false); } }
public void OnAbilityButton(GameObject butObj) { //if(FPSControl.IsOn()) return; //in drag and drop mode, player could be hitting the button while having an active tower selected //if that's the case, clear the selectedTower first. and we can show the tooltip properly if (UI.UseDragNDrop() && GameControl.GetSelectedTower() != null) { UI.ClearSelectedTower(); return; } UI.ClearSelectedTower(); int ID = GetButtonID(butObj); string exception = AbilityManager.SelectAbility(ID); if (exception != "") { UIGameMessage.DisplayMessage(exception); } //Hide(); }
void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { if (BuildManager.UseDragNDrop() && BuildManager.InDragNDrop()) { return; } if (!UITowerView.IsOn() && !AbilityManager.IsSelectingTarget() && !UIPerkMenu.IsOn() && !UIFPS.IsOn()) { TogglePause(); } } //keyboard for cursor based input start here if (!enableInput) { return; } if (Input.touchCount > 1) { return; } if (UI.IsCursorOnUI(0) || UI.IsCursorOnUI()) { return; } if (Input.GetMouseButtonDown(0)) { OnCursorDown(Input.mousePosition); } }
public void _Show(Ability ability, Vector3 pos, int pivotCorner = 2, Vector3 offset = default(Vector3)) { SetPivot(pivotCorner); labelName.text = ability.name; labelDesp.text = ability.desp; labelDesp.enabled = true; if (AbilityManager.UseRscManagerForCost()) { List <float> cost = ability.GetCostRsc(); for (int i = 0; i < RscManager.GetResourceCount(); i++) { rscItemList[i].imgMain.sprite = RscManager.GetRscIcon(i); rscItemList[i].lbMain.text = cost[i].ToString("f0"); rscItemList[i].SetActive(true); } } else { rscItemList[0].imgMain.sprite = AbilityDB.GetRscIcon(); rscItemList[0].lbMain.text = ability.GetCost().ToString("f0"); for (int i = 1; i < RscManager.GetResourceCount(); i++) { rscItemList[i].SetActive(false); } } minHeight = 120; rectT.position = pos + offset; canvasGroup.alpha = 1; thisObj.SetActive(true); }
private int currentButtonID = -1; //last touched button, for touch mode only public void OnAbilityButton(GameObject butObj, int pointerID = -1) { int ID = GetButtonID(butObj); if (UIMainControl.InTouchMode()) { if (currentButtonID >= 0) { buttonList[currentButtonID].imgHighlight.enabled = false; } if (currentButtonID != ID) { //OnAbilitySelectingTarget(true); //to turn on cancel button butCancelCanvasG.alpha = 1; butCancelCanvasG.interactable = true; currentButtonID = ID; buttonList[ID].imgHighlight.enabled = true; OnHoverButton(butObj); return; } ClearTouchModeButton(); } string exception = AbilityManager.SelectAbility(ID, pointerID); if (exception != "") { UIMessage.DisplayMessage(exception); } }
void Awake(){ instance=this; thisT=transform; if(startWithFullEnergy) energy=fullEnergy; List<Ability> dbList=AbilityDB.Load(); abilityList=new List<Ability>(); for(int i=0; i<dbList.Count; i++){ if(!unavailableIDList.Contains(dbList[i].ID)){ abilityList.Add(dbList[i].Clone()); } } List<Ability> newList=PerkManager.GetUnlockedAbility(); for(int i=0; i<newList.Count; i++) abilityList.Add(newList[i]); for(int i=0; i<abilityList.Count; i++) abilityList[i].ID=i; if(defaultIndicator){ defaultIndicator=(Transform)Instantiate(defaultIndicator); defaultIndicator.parent=thisT; defaultIndicator.gameObject.SetActive(false); } }
public float CreepDestroyed() { List <int> rscGain = new List <int>(); for (int i = 0; i < valueRscMin.Count; i++) { rscGain.Add(Random.Range(valueRscMin[i], valueRscMax[i])); } ResourceManager.GainResource(rscGain, PerkManager.GetRscCreepKilled()); AbilityManager.GainEnergy(valueEnergyGain + (int)PerkManager.GetEnergyWaveClearedModifier()); if (spawnUponDestroyed != null && spawnUponDestroyedCount > 0) { for (int i = 0; i < spawnUponDestroyedCount; i++) { Vector3 posOffset = new Vector3(Random.Range(-0.5f, 0.5f), 0, Random.Range(-0.5f, 0.5f)); GameObject obj = ObjectPoolManager.Spawn(spawnUponDestroyed, thisT.position + posOffset, thisT.rotation); UnitCreep unit = obj.GetComponent <UnitCreep>(); unit.waveID = waveID; int ID = SpawnManager.AddDestroyedSpawn(unit); unit.Init(path, ID, waveID, this); } } if (aniInstance != null) { return(aniInstance.PlayDead()); } return(0); }
public void Activate(Vector3 pos = default(Vector3)) { useCount += 1; currentCD = GetCooldown(); if (AbilityManager.UseRscManagerForCost()) { RscManager.SpendRsc(GetCostRsc()); } else { AbilityManager.SpendRsc(GetCost()); } effectOnActivate.Spawn(pos, Quaternion.identity); AudioManager.PlaySound(soundOnActivate); //activateCallback(); if (effectType != _EffectType.Default) { return; } AbilityManager.GetInstance().StartCoroutine(AbilityEffect(pos)); }
// Update is called once per frame void Update() { txtEnergy.text = AbilityManager.GetEnergy().ToString("f0") + "/" + AbilityManager.GetEnergyFull().ToString("f0"); float valueX = Mathf.Clamp(AbilityManager.GetEnergy() / AbilityManager.GetEnergyFull() * 200, 4, 200); float valueY = Mathf.Min(valueX, 8); energyRect.sizeDelta = new Vector2(valueX, valueY); }
public static void ClearSelectedAbility() { pendingAbilityIdx = -1; if (AbilityManager.InTargetSelectionMode()) { AbilityManager.ClearSelect(); } }
void Awake() { instance = (AbilityManager)target; GetAbility(); EditorUtility.SetDirty(instance); }
public void OnExitAbilityButton(GameObject butObj) { int idx = UI.GetItemIndex(butObj, abilityButtons); if (AbilityManager.GetPendingTargetAbilityIndex() == idx || UIControl.GetPendingAbilityIdx() == idx) { return; } UITooltip.Hide(); }
public void Init() { instance = this; thisT = transform; if (startWithFullEnergy) { energy = fullEnergy; } List <Ability> dbList = TDTK.GetAbilityDBList(); //AbilityDB.Load(); availableIDList = new List <int>(); abilityList = new List <Ability>(); for (int i = 0; i < dbList.Count; i++) { if (dbList[i].disableInAbilityManager) { continue; } if (!unavailableIDList.Contains(dbList[i].ID)) { abilityList.Add(dbList[i].Clone()); availableIDList.Add(dbList[i].ID); } } List <Ability> newList = PerkManager.GetUnlockedAbilityList(); for (int i = 0; i < newList.Count; i++) { abilityList.Add(newList[i].Clone()); } for (int i = 0; i < abilityList.Count; i++) { abilityList[i].Init(); } if (defaultIndicator != null) { defaultIndicator = (Transform)Instantiate(defaultIndicator); defaultIndicator.parent = thisT; defaultIndicator.gameObject.SetActive(false); } maskAOE = 1 << TDTK.GetLayerPlatform(); int terrainLayer = TDTK.GetLayerTerrain(); if (terrainLayer >= 0) { maskAOE |= 1 << terrainLayer; } }
void Start() { if (!AbilityManager.IsOn() || AbilityManager.GetAbilityCount() == 0) { thisObj.SetActive(false); return; } List <Ability> abList = AbilityManager.GetAbilityList(); for (int i = 0; i < abList.Count; i++) { if (i == 0) { buttonList[0].Init(); } else if (i > 0) { buttonList.Add(UIButton.Clone(buttonList[0].rootObj, "AbilityButton" + (i + 1))); } buttonList[i].imgIcon.sprite = abList[i].icon; buttonList[i].imgHighlight.enabled = false; buttonList[i].label.text = ""; if (abList[i].usedRemained > 0) { buttonList[i].label.text = abList[i].usedRemained.ToString(); } //else buttonList[i].label.text="∞"; if (UIMainControl.InTouchMode()) { buttonList[i].SetCallback(null, null, this.OnAbilityButton, null); } else { buttonList[i].SetCallback(this.OnHoverButton, this.OnExitButton, this.OnAbilityButton, null); } } tooltipRscItem.Init(); butCancelCanvasG = butCancelObj.AddComponent <CanvasGroup>(); OnAbilitySelectingTarget(false); UIItemCallback cancelCallback = butCancelObj.AddComponent <UIItemCallback>(); cancelCallback.SetDownCallback(this.OnCancelAbilityButton); //cancelCallback.SetUpCallback(up); tooltipObj.SetActive(false); }
public static void SelectAbility(int idx) { if (UseDragNDropTgtMode()) { AbilityManager.SelectAbility(idx); } else { instance.StartCoroutine(_SelectAbility(idx)); } }
public void Cleared() { cleared = true; GameControl.GainLife(PerkManager.GetLifeGainOnWaveCleared(lifeGainOnCleared)); RscManager.GainRsc(rscGainOnCleared, RscManager._GainType.WaveCleared); PerkManager.GainRsc(perkRscGainOnCleared); AbilityManager.GainRsc(PerkManager.GetAbRscGainOnWaveCleared(abilityRscGainOnCleared)); PerkManager.WaveCleared(waveIdx + 1); }
//not compatible with PointNBuild mode void OnMouseEnter() { if (UIUtilities.IsCursorOnUI()) { return; } if (AbilityManager.InTargetSelectMode()) { return; } BuildManager.ShowIndicator(this); }
// Use this for initialization void Start() { tooltipObj.SetActive(false); if (!AbilityManager.IsOn()) { Hide(); return; } List <Ability> abList = AbilityManager.GetAbilityList(); if (abList.Count == 0) { Hide(); return; } EventTrigger.Entry entryRequireTargetSelect = SetupTriggerEntry(true); EventTrigger.Entry entryDontRequireTargetSelect = SetupTriggerEntry(false); for (int i = 0; i < abList.Count; i++) { if (i == 0) { buttonList[0].Init(); } else if (i > 0) { buttonList.Add(buttonList[0].Clone("button" + (i + 1), new Vector3(i * 55, 0, 0))); } buttonList[i].imageIcon.sprite = abList[i].icon; buttonList[i].label.text = ""; EventTrigger trigger = buttonList[i].rootObj.GetComponent <EventTrigger>(); if (abList[i].requireTargetSelection) { trigger.triggers.Add(entryRequireTargetSelect); } else { trigger.triggers.Add(entryDontRequireTargetSelect); } } float offset = 0.5f * (buttonList.Count - 1) * 55; for (int i = 0; i < buttonList.Count; i++) { buttonList[i].rootT.localPosition -= new Vector3(offset, 0, 0); } }
private void OnCursorDownAbilityTargetMode(int idx = -1) { TargetingInfo tInfo = AbilityManager.OnCursorDown(Input.mousePosition, idx); //if -1 is passed, AbilityManager will use the idx given when AbilityManager.SelectAbility() is called if (tInfo.valid) { AbilityManager.ActivateAbility(idx, tInfo.pos); } else { Debug.Log("target not valid"); } }
void Update() { if (FPSControl.IsInFPSMode()) { return; } if (AbilityManager.IsSelectingTarget()) { return; } //if(!disableCursorIndicator) BuildManager.SetTileIndicator(Input.mousePosition); }
//~ void OnGUI(){ //~ GUI.Label(new Rect(10, Screen.height/2, 130, 35), "ability:"); //~ if(GUI.Button(new Rect(80, Screen.height/2, 130, 35), ""+targetMode)){ //~ if(targetMode==_TargetMode.DragNDrop) targetMode=_TargetMode.SelectNDeploy; //~ else if(targetMode==_TargetMode.SelectNDeploy) targetMode=_TargetMode.DragNDrop; //~ } //~ GUI.Label(new Rect(10, Screen.height/2+40, 130, 35), "build:"); //~ if(GUI.Button(new Rect(80, Screen.height/2+40, 130, 35), ""+buildMode)){ //~ if(buildMode==_BuildMode.DragNDrop) buildMode=_BuildMode.PointNBuild; //~ else if(buildMode==_BuildMode.PointNBuild) buildMode=_BuildMode.PointNBuild; //~ } //~ } void Update() { if (!isGameScene) { return; } if (TowerManager.InDragNDropPhase()) { //for mobile, to prevent getting stuck in DnD phase if user click but not drag the button //if(Input.touchCount==0) TowerManager.ExitDragNDropPhase(); return; } //for mobile, to prevent getting stuck in target select phase if user click but not drag the button //if(AbilityManager.InTargetSelectionMode()){ // if(Input.touchCount==0) AbilityManager.ClearSelect(); //} int pointerID = Input.touchCount == 0 ? -1 : 0; if (Input.GetMouseButtonDown(0) && !UI.IsCursorOnUI(pointerID)) { if (!InTargetSelectionMode()) { OnCursorDown(); } } if (Input.GetMouseButtonUp(0) && !wasCursorOnUI) { if (AbilityManager.InTargetSelectionMode()) { OnCursorDownAbilityTargetMode(); } else if (pendingAbilityIdx >= 0) { OnCursorDownAbilityTargetMode(pendingAbilityIdx); pendingAbilityIdx = -1; } } if (Input.GetMouseButtonDown(1)) { UIAbilityButton.ClearSelect(); //ClearSelectedAbility(); } wasCursorOnUI = UI.IsCursorOnUI(pointerID); //to be used for next frame }
public string IsAvailable() { if (GetCost() > AbilityManager.GetEnergy()) { return("Insufficient Energy"); } if (currentCD > 0) { return("Ability is on cooldown"); } if (maxUseCount > 0 && usedCount >= maxUseCount) { return("Usage limit exceed"); } return(""); }
public void OnHoverAbilityButton(GameObject butObj) { if (GameControl.GetSelectedTower() != null) { return; } int ID = GetButtonID(butObj); Ability ability = AbilityManager.GetAbilityList()[ID]; txtTooltipName.text = ability.name; txtTooltipCost.text = "" + ability.GetCostInt(); txtTooltipDesp.text = ability.GetDesp(); tooltipObj.SetActive(true); }
public void Init() { if (maxUseCount > 0) { usedRemained = maxUseCount; } else { usedRemained = -1; } if (indicator != null) { indicator = (Transform)MonoBehaviour.Instantiate(indicator); indicator.parent = AbilityManager.GetInstance().transform; } }
public void Activate(Vector3 pos) { usedCount += 1; usedRemained -= 1; AbilityManager.GetInstance().StartCoroutine(CooldownRoutine()); if (effectObj != null) { if (!destroyEffectObj) { ObjectPoolManager.Spawn(effectObj, pos, Quaternion.identity); } else { ObjectPoolManager.Spawn(effectObj, pos, Quaternion.identity, destroyEffectDuration); } } }
public override void Destroyed(float delay = 0) { if (destroyed) { return; } destroyed = true; List <int> rscGain = new List <int>(); for (int i = 0; i < valueRscMin.Count; i++) { rscGain.Add(Random.Range(valueRscMin[i], valueRscMax[i])); } ResourceManager.GainResource(rscGain, PerkManager.GetRscCreepKilled()); AbilityManager.GainEnergy(valueEnergyGain + (int)PerkManager.GetEnergyWaveClearedModifier()); if (lifeValue > 0) { GameControl.GainLife(lifeValue); } if (spawnUponDestroyed != null && spawnUponDestroyedCount > 0) { for (int i = 0; i < spawnUponDestroyedCount; i++) { Vector3 posOffset = new Vector3(Random.Range(-0.5f, 0.5f), 0, Random.Range(-0.5f, 0.5f)); GameObject obj = ObjectPoolManager.Spawn(spawnUponDestroyed.gameObject, thisT.position + posOffset, thisT.rotation); UnitCreep unit = obj.GetComponent <UnitCreep>(); unit.waveID = waveID; int ID = SpawnManager.AddDestroyedSpawn(unit); unit.Init(path, ID, waveID, this); } } SpawnManager.OnUnitDestroyed(this); TDTK.OnUnitCreepDestroyed(this); base.Destroyed(PlayAnimDestroyed()); }
IEnumerator ButtonCDRoutine(Ability ability) { int ID = AbilityManager.GetAbilityIndex(ability); if (ability.usedRemained >= 0) { buttonList[ID].label.text = ability.usedRemained.ToString(); } buttonList[ID].button.interactable = false; if (ability.usedRemained == 0) { yield break; } while (true) { string text = ""; float duration = ability.currentCD; if (duration <= 0) { break; } if (duration > 60) { text = Mathf.Floor(duration / 60).ToString("F0") + "m"; } else { text = (Mathf.Ceil(duration)).ToString("F0") + "s"; } buttonList[ID].label.text = text; yield return(new WaitForSeconds(0.05f)); } buttonList[ID].label.text = ""; buttonList[ID].button.interactable = true; }
void Awake() { instance = this; List <Ability> dbList = AbilityDB.GetList(); for (int i = 0; i < dbList.Count; i++) { if (!unavailablePrefabIDList.Contains(dbList[i].prefabID) && !dbList[i].hideInInspector) { abilityList.Add(dbList[i].Clone()); } } tgtSelectIndicator = Instantiate(tgtSelectIndicator.gameObject).transform; tgtSelectIndicator.parent = transform; tgtSelectIndicator.gameObject.SetActive(false); pendingTgtAbilityIdx = -1; }
public _Status IsReady() { if (currentCD > 0) { return(_Status.OnCooldown); } if (UseLimitReached()) { return(_Status.UseLimitReached); } if (AbilityManager.UseRscManagerForCost() && !RscManager.HasSufficientRsc(GetCostRsc())) { return(_Status.InsufficientRsc); } if (!AbilityManager.UseRscManagerForCost() && !AbilityManager.HasSufficientRsc(GetCost())) { return(_Status.InsufficientRsc); } return(_Status.Ready); }
// Use this for initialization void Start() { tooltipObj.SetActive(false); if (!AbilityManager.IsOn()) { Hide(); return; } abList = AbilityManager.GetAbilityList(); if (abList.Count == 0) { Hide(); return; } EventTrigger.Entry entryRequireTargetSelect = SetupTriggerEntry(true); EventTrigger.Entry entryDontRequireTargetSelect = SetupTriggerEntry(false); for (int i = 0; i < abList.Count; i++) { if (i == 0) { buttonList[0].Init(); } else if (i > 0) { buttonList.Add(buttonList[0].Clone("button" + (i + 1), new Vector3(i * 155, 0, 0))); } buttonList[i].InitAbility(abList[i]); EventTrigger trigger = buttonList[i].gameObject.GetComponent <EventTrigger>(); if (abList[i].requireTargetSelection) { trigger.triggers.Add(entryRequireTargetSelect); } else { trigger.triggers.Add(entryDontRequireTargetSelect); } } }
void OnDestroy(){ instance=null; }