public void Addunit(UnitConfig unitConfig) { if (units.Count < maximumUnits) { Unit unit = Instantiate(unitConfig.GetUnitPrefab(), transform).GetComponent <Unit>(); units.Add(unit); } else { throw (new InvalidOperationException()); } //attackValue += unitConfig.GetAttackStrength(); //defenceValue += unitConfig.GetDefenceStrength(); }
// Use this for initialization void Start() { terrainRenderer = new GridRenderer(); terrainRenderer.Init(Battle.MAX_BATTLE_FILED_X, Battle.MAX_BATTLE_FILED_Y, 10, 0, "grid/mat_terrain", "Terrain"); gridRenderer = new GridRenderer(); gridRenderer.Init(Battle.MAX_BATTLE_FILED_X, Battle.MAX_BATTLE_FILED_Y, 2, 0.1f, "grid/mat_grid", "Grid"); SkillAttackFlyAttributeConfig.Initialize(); UnitConfig.Initialize(); battleplayer = new Battleplayer(); battleplayer.Init(); }
public bool TrainUnit(UnitConfig unitConfig) { if (!army) { return(false); } if (!IsBuilding() && army.GetEmpire().UseGold(unitConfig.GetCost())) { unitToBuild = unitConfig; daysLeftOnBuild = unitToBuild.GetBuildTime(); army.SetArmyStatus(Army.ArmyStatus.Training); return(true); } return(false); }
public static DataComponent CreateDataComponent( GameObject parent, UnitConfig config, MobilityData mobilityData) { UnitDataConfig unitConfig = config.Data; MobilityConfig mobilityConfig = config.Mobility; ArmorConfig armorConfig = config.Armor; parent.AddComponent <DataComponent>(); DataComponent c = parent.GetComponent <DataComponent>(); c.MovementSpeed = unitConfig.MovementSpeed * Constants.MAP_SCALE; c.ReverseSpeed = unitConfig.ReverseSpeed * Constants.MAP_SCALE; c.AccelRate = unitConfig.AccelRate * Constants.MAP_SCALE; c.MaxRotationSpeed = unitConfig.MaxRotationSpeed; c.MinTurnRadius = unitConfig.MinTurnRadius * Constants.MAP_SCALE; c.MaxLateralAccel = unitConfig.MaxLateralAccel * Constants.MAP_SCALE; c.Suspension = unitConfig.Suspension / Constants.MAP_SCALE; c.MaxHealth = unitConfig.MaxHealth; c.Length = unitConfig.Length * Constants.MAP_SCALE; c.Width = unitConfig.Width * Constants.MAP_SCALE; c.MobilityData = mobilityData; c.Radius = Mathf.Sqrt(c.Length * c.Width) / 2; c.OptimumTurnSpeed = Mathf.Sqrt(c.MaxLateralAccel * c.MinTurnRadius); c.SuspensionForward = c.Suspension * c.Radius / c.Length; c.SuspensionSide = c.Suspension * c.Radius / c.Width; c.AccelDampTime = 0.15f * c.MovementSpeed / c.AccelRate; c.ApImmunity = armorConfig.ApImmunity; c.FrontArmor = armorConfig.FrontArmor; c.SideArmor = armorConfig.SideArmor; c.RearArmor = armorConfig.RearArmor; c.TopArmor = armorConfig.TopArmor; ReconConfig reconConfig = config.Recon; c.MaxSpottingRange = reconConfig.MaxSpottingRange; c.Stealth = reconConfig.Stealth; c.StealthPenetration = reconConfig.StealthPenetration; return(c); }
public void Initialize() { _unitConfigs = new UnitConfig { FirstName = "Thomas", Address = new Address(), Emails = new List <FriendEmail> { new FriendEmail { Email = "*****@*****.**" }, new FriendEmail { Email = "*****@*****.**" } } }; }
private async void Start() { try { SynchronizationContext.SetSynchronizationContext(this.contex); DontDestroyOnLoad(gameObject); Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); Game.Scene.AddComponent <GlobalConfigComponent>(); Game.Scene.AddComponent <NetOuterComponent>(); Game.Scene.AddComponent <ResourcesComponent>(); Game.Scene.AddComponent <PlayerComponent>(); Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <ClientFrameComponent>(); Game.Scene.AddComponent <UIComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); // 加载配置 Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d"); Game.Scene.AddComponent <ConfigComponent>(); Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d"); Game.Scene.AddComponent <OpcodeTypeComponent>(); Game.Scene.AddComponent <MessageDispatherComponent>(); uiLogin = GameObject.Find("UILogin"); uiLobby = GameObject.Find("UILobby"); uiLobby.SetActive(false); login.GetComponent <Button>().onClick.Add(OnLogin); enterMap.GetComponent <Button>().onClick.Add(EnterMap); UnitConfig unitConfig = (UnitConfig)Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), 1001); Log.Debug($"config {JsonHelper.ToJson(unitConfig)}"); Game.EventSystem.Run(EventIdType.InitSceneStart); } catch (Exception e) { Log.Error(e.ToString()); } }
public void SetValue(UnitConfig unitClass, float extraValue, bool moreIsBetter = true) { classIcon.sprite = unitClass.icon; className.text = unitClass.Type.ToString(); damageValue = extraValue; extraDamageValue.text = string.Format("{0}{1}", damageValue > 0 ? "+" : damageValue < 0 ? "-" : "", damageValue ); extraDamageValue.color = damageValue == 0 ? Color.white : moreIsBetter && extraValue > 0 || !moreIsBetter && extraValue < 0 ? Color.green : Color.red; }
public void ChangeGridColor(int movement, int actions, UnitConfig position) { if (!mapConfig.turnSystem.playerTurn) { return; } playerGridColorChange = position; for (int x = 0; x < mapSizeX; x++) { for (int y = 0; y < mapSizeY; y++) { currentGrid[x, y] = 99; } } ResetColorGrid(); GetPlayerNeighbours(movement, actions); }
public ActionResult GetData(ChooseUnitViewModel model) { var lstUnits = new List <Unit>(); foreach (var unit in model.UnitsList) { var currentUnit = new Unit { Id = unit.Id, CourseName = unit.CourseName, UnitType = unit.UnitType, TeacherName = unit.TeacherName, UnitNumber = unit.UnitNumber, }; foreach (var classDateTime in unit.ClassDateTimes) { currentUnit.ClassDateTimes.Add(new UnitDateTime { DayOfWeek = classDateTime.Day, StartTime = $"{classDateTime.StartTimeHour}:{classDateTime.StartTimeMinute}", EndTime = $"{classDateTime.EndTimeHour}:{classDateTime.EndTimeMinute}" }); } lstUnits.Add(currentUnit); } var unitConfig = new UnitConfig { MinUnitNumber = model.UnitsConfig.MinUnitNumber, MaxUnitNumber = model.UnitsConfig.MaxUnitNumber, MinEspUnitNumber = model.UnitsConfig.MinEspUnitNumber, MaxEspUnitNumber = model.UnitsConfig.MaxEspUnitNumber, MinGeneralUnitNumber = model.UnitsConfig.MinGeneralUnitNumber, MaxGeneralUnitNumber = model.UnitsConfig.MaxGeneralUnitNumber, MinLabUnitNumber = model.UnitsConfig.MinLabUnitNumber, MaxLabUnitNumber = model.UnitsConfig.MaxLabUnitNumber }; return(new JsonCamelCaseResult(Program.Main(lstUnits, unitConfig), JsonRequestBehavior.DenyGet)); }
public void destroyUnit(UnitConfig unit) { if (unit.isFriendly) { unit.Die();//Animate death playerUnits.Remove(unit); } else { unit.Die();//Animate death enemyUnits.Remove(unit); } if (playerUnits.Count <= 0) { gameObject.SetActive(false);//deactivates the map gameOver.SetActive(true); gameOverText.text = "DEFEAT"; gameOverText.color = defeatColor; } }
// Use this for initialization void Start() { instance = this; int i = 0; foreach (Transform actionBox in transform.Find("ConfigBox").Find("Actions")) { actions.Add(unitClass.Actions()[i]); i++; } i = 0; foreach (Transform actionBox in transform.Find("ConfigBox").Find("Stances")) { stances.Add(unitClass.Stances()[i]); i++; } unitConfigs.Add(this); Refresh(); }
private async ETVoid StartAsync() { try { SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); ClientConfigHelper.SetConfigHelper(); Game.EventSystem.Add(DLLType.Core, typeof(Core).Assembly); Game.EventSystem.Add(DLLType.Model, typeof(Model).Assembly); Game.Scene.AddComponent <TimerComponent>(); Game.Scene.AddComponent <GlobalConfigComponent>(); Game.Scene.AddComponent <NetOuterComponent>(); Game.Scene.AddComponent <ResourcesComponent>(); // 实体管理组件 Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <UIComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); // 加载配置 Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d"); Game.Scene.AddComponent <ConfigComponent>(); Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d"); Game.Scene.AddComponent <OpcodeTypeComponent>(); Game.Scene.AddComponent <MessageDispatcherComponent>(); UnitConfig unitConfig = (UnitConfig)Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), 1001); Log.Debug($"config {JsonHelper.ToJson(unitConfig)}"); } catch (Exception e) { Log.Error(e); } }
public void SelectUnit(UnitConfig selected) { if (selected == null) { return; } if (!selected.CheckUnitState(UnitConfig.UnitState.Idle)) { return; } if (selected.isFriendly) { selectedUnit = selected; //selected = selectedUnit; selectedUnit.isSelected = true; //Move the marker to selected unit MoveMarker(unitMarker, selectedUnit.transform.position); //Update grid colors mapConfig.tileMap.ChangeGridColor(selected.movePoints, selected.actionPoints.ReturnAvailableActions(), selected); //Update Displayed Name unitName.text = selectedUnit.unitName; className.text = selectedUnit.unitClassStats.unitClassName; UpdateHUD(); //Clear old abilities generateAbilityButtons.ClearCurrentButtons(); //Generate new abilities buttons if its a player unit generateAbilityButtons.GenerateCurrentButtons(selectedUnit.unitAbilities); //Move the camera to selected Unit/target cameraControl.MoveToTarget(selectedUnit.transform.position); } if (!selected.isFriendly) { //HACK: If you're targeting an enemy, what do? selectedTarget = selected; //Move the camera to selected Unit/target cameraControl.MoveToTarget(selectedTarget.transform.position); } }
public void SpawnEnemy(TurnSystem.SpawnSetup spawnSetup, int numberOfUnits) { foreach (var unitType in spawnSetup.enemyPrefab) { for (int i = 0; i < numberOfUnits; i++) { if (unitType == null) { continue; } UnitConfig enemy = Instantiate(unitType, RandomPosition(), Quaternion.identity); mapConfig.turnSystem.enemyUnits.Add(enemy); enemy.InitializeEnemy(); enemy.actionPoints.ReplenishAllActions(); //set zombie name enemy.unitName = "Zombie Håkan"; int maxNames = (int)mapConfig.zombieNameGenerator.zombieNames.Count - 1; enemy.unitName = "Zombie " + mapConfig.zombieNameGenerator.zombieNames[Random.Range(0, maxNames)].ToString(); } } mapConfig.turnSystem.enemyUnits[0].enemyAi.isMyTurn = true; }
private void UpdateSkills() { Unit unit = currentPlayer.CurrentUnit; UnitConfig unitClass = unit.unitClass; if (unitClass.baseAttack.isActive) { baseAttackPanel.SetActions(unitClass.baseAttack); baseAttackPanel.gameObject.SetActive(true); } if (unitClass.mainAbility.isActive) { mainAbilityPanel.SetActions(unitClass.mainAbility); mainAbilityPanel.gameObject.SetActive(true); } if (unitClass.secondaryAbility.isActive) { secondaryAbilityPanel.SetActions(unitClass.secondaryAbility); secondaryAbilityPanel.gameObject.SetActive(true); } }
// Use this for initialization void Start() { Unit = GetComponent <Stats>()._unitType; uc = new UnitConfig(); List <UnitConfig> l = GameObject.Find("GameManager").GetComponent <ConfigLoader>().configuration; foreach (UnitConfig u in l) { if (u.unit == Unit) { uc = u; } } if (GetComponent <MovableCharacter>()) { GetComponent <MovableCharacter>().speed = getStat("Speed"); } if (GetComponent <Sight>()) { GetComponent <Sight>()._angle = getStat("ViewAngle"); GetComponent <Sight>()._distance = getStat("ViewDistance"); } if (GetComponent <Stats>()) { GetComponent <Stats>().SetMaxHealth((int)getStat("MaxHealth")); GetComponent <Stats>().SetHealth((int)getStat("MaxHealth")); GetComponent <Stats>().SetReloadTime((int)getStat("Reload")); } if (GetComponent <Inventory>()) { GetComponent <Inventory>()._maxSize = (int)getStat("InventorySize"); } }
public void GeneratePathTo(int tileX, int tileY, UnitConfig selected, bool isBullet = false)//(move to X pos, move to Y pos, gameobject that will be moved) { UnitConfig selectedUnit = selected; selectedUnit.currentPath = null; selectedUnit.currentBulletPath = null; if (UnitCanEnterTile(tileX, tileY) == false) { //clicked on unwalkable terrain return; } if (tileX < 0 || tileX >= mapSizeX) { return; } if (tileY < 0 || tileY >= mapSizeY) { return; } //Dijkstra function //https://sv.wikipedia.org/wiki/Dijkstras_algoritm for more information of the Dijkstra function Dictionary <Node, float> dist = new Dictionary <Node, float>(); Dictionary <Node, Node> prev = new Dictionary <Node, Node>(); List <Node> unvisited = new List <Node>(); Node source = graph[ selectedUnit.tileX, selectedUnit.tileY ]; Node target = graph[ tileX, tileY ]; if (isBullet) { source = graphAir[ selectedUnit.tileX, selectedUnit.tileY ]; target = graphAir[ tileX, tileY ]; } dist[source] = 0; prev[source] = null; //initialize everything to have infinity distance, since //we do not know how far a unit can move right now. if (!isBullet) { foreach (Node v in graph) { if (v != source) { dist[v] = Mathf.Infinity; prev[v] = null; } unvisited.Add(v); } } else { foreach (Node v in graphAir) { if (v != source) { dist[v] = Mathf.Infinity; prev[v] = null; } unvisited.Add(v); } } while (unvisited.Count > 0) { //may need inpovments later on! //"u" is going to be the unvisited node with the smallest distance Node u = null; foreach (Node possibleU in unvisited) { if (u == null || dist[possibleU] < dist[u]) { u = possibleU; } } if (u == target) { break;//exit while loop } unvisited.Remove(u); foreach (Node v in u.neighbours) { float alt = dist[u] + CostToEnterTile(u.x, u.y, v.x, v.y, isBullet); if (alt < dist[v]) { dist[v] = alt; prev[v] = u; } } } if (prev[target] == null) { //no route between our target and our source return; } List <Node> currentPath = new List <Node>(); Node curr = target; while (curr != null) { currentPath.Add(curr); curr = prev[curr]; } //current path is from goal to unit here we reverse it. to make it normal currentPath.Reverse(); if (!isBullet) { selectedUnit.currentPath = currentPath; } if (isBullet) { selectedUnit.currentBulletPath = currentPath; } }
void Update() { if (animator != null) { if (unitConfig.CheckUnitState(UnitConfig.UnitState.Idle)) { animator.SetInteger("state", 0); } if (unitConfig.CheckUnitState(UnitConfig.UnitState.Walking)) { animator.SetInteger("state", 1); } if (unitConfig.CheckUnitState(UnitConfig.UnitState.Sprinting)) { animator.SetInteger("state", 2); } if (unitConfig.CheckUnitState(UnitConfig.UnitState.Shooting)) { animator.SetInteger("state", 3); if (target == null) { if (TurnSystem.selectedUnit == TurnSystem.selectedTarget) { target = TurnSystem.selectedUnit; } else { target = TurnSystem.selectedTarget; } } if (target != null) { transform.parent.LookAt(target.transform.position); Vector3 eulerAngles = transform.parent.rotation.eulerAngles; eulerAngles.x = 0; eulerAngles.z = 0; // Set the altered rotation back transform.parent.rotation = Quaternion.Euler(eulerAngles); } } //Death animation if ((unitConfig.CheckUnitState(UnitConfig.UnitState.Dead))) { animator.SetInteger("state", 4); } //walking rotation if (animator.GetInteger("state") > 0 && animator.GetInteger("state") != 3) // HACK: What!? { direction = transform.root.position - lastPosition; lastPosition = transform.root.position; lookRotation = Quaternion.LookRotation((direction == Vector3.zero) ? Vector3.forward : direction); transform.parent.rotation = Quaternion.Lerp(transform.parent.rotation, lookRotation, Time.deltaTime * 10); } else if (animator.GetInteger("state") != 3) { Quaternion a = transform.parent.rotation; Quaternion b = Quaternion.LookRotation((direction == Vector3.zero) ? Vector3.forward : direction); transform.parent.rotation = Quaternion.Lerp(a, b, Time.deltaTime * 10); } } }
//Update the tile that need to be unwalkable for a specific unit public void UpdateUnitPosition(UnitConfig unit) { mapConfig.tileMap.UnitMapData(unit.tileX, unit.tileY); }
public static Object InstantiateSkeletonUnit(SkeletonDataAsset skeletonDataAsset, Skin skin = null) { if (!File.Exists("Assets/ExternalRes/Unit/Unit.json")) { return(null); } JSONNode jsonConfig = null; using (FileStream fs = new FileStream("Assets/ExternalRes/Unit/Unit.json", FileMode.Open)) { string sr = new StreamReader(fs).ReadToEnd(); JSONParser parser = new JSONParser(); jsonConfig = parser.Parse(new FlashCompatibleTextReader(sr)); } //读取配置文件 Dictionary <string, UnitConfig> UnitConfigs = new Dictionary <string, UnitConfig>(); TextAsset textAsset = AssetDatabase.LoadAssetAtPath("Assets/ExternalRes/Config/UnitConfig.xml", typeof(TextAsset)) as TextAsset; XMLInStream stream = new XMLInStream(textAsset.text); stream.List("item", delegate(XMLInStream itemStream) { UnitConfig ufg = new UnitConfig(itemStream); if (!UnitConfigs.ContainsKey(ufg.ResourceIcon)) { UnitConfigs.Add(ufg.ResourceIcon, ufg); } }); string path = AssetDatabase.GetAssetPath(skeletonDataAsset); string fpath = path.Replace("_SkeletonData", "_Controller").Replace(".asset", ".controller"); string mpath = path.Replace("_SkeletonData", "_Controller").Replace(".asset", ".controller.meta"); if (File.Exists(fpath)) { File.Delete(fpath); File.Delete(mpath); Debug.Log("删除旧的Controller:" + fpath); } fpath = path.Replace("_SkeletonData", "").Replace(".asset", ".prefab"); mpath = path.Replace("_SkeletonData", "").Replace(".asset", ".prefab.meta"); if (File.Exists(fpath)) { File.Delete(fpath); File.Delete(mpath); Debug.Log("删除旧的Prefab:" + fpath); } skeletonDataAsset.controller = null; // 创建状态机 SkeletonBaker.GenerateMecanimAnimationClips(skeletonDataAsset, jsonConfig); // 创建Animator Object GameObject go = GenerateAnimatorObject(skeletonDataAsset, skin); // 伙伴RectTransform go.AddComponent <RectTransform>(); RectTransform rt = go.GetComponent <RectTransform>(); rt.pivot = new Vector2(0.5f, 0); // 伙伴UnitSoundBehaviour UnitSoundBehaviour usb = go.AddComponent <UnitSoundBehaviour>(); //伙伴UnitIdleChangeBehaviour go.AddComponent <UnitIdleChangeBehaviour>(); // 创建Audio Object string name = path.Replace("Assets/ExternalRes/Unit/", "").Replace("_SkeletonData.asset", ""); name = name.Substring(name.IndexOf("/") + 1); if (UnitConfigs.ContainsKey(name)) { usb.SetSoundSource(AutoPrefab.GenerateAudioObject(go, UnitConfigs[name])); } // 创建Prefab string dataPath = AssetDatabase.GetAssetPath(skeletonDataAsset); string prefabPath = dataPath.Replace("_SkeletonData", "").Replace(".asset", ".prefab"); Object prefab = AutoPrefab.GenerateUnitPrefab(go, prefabPath); // 销毁Animator Object Object.DestroyImmediate(go); // 设置asset bundle name AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(prefab)).assetBundleName = "units/" + name; return(prefab); }
//Cycle through list of targets public void KeyboardSelect(bool ChooseNext, List <UnitConfig> unitList, UnitConfig selected) { //Check if unit is idle if (selected != null && !selected.CheckUnitState(UnitConfig.UnitState.Idle)) { return; } //if list is empty, exit function if (unitList == null) { return; } //If selected is null, pick the first unit in the list if (selected == null) { selected = unitList[0]; } int chosenUnitIndex = unitList.FindIndex(a => a == selected); DeselectUnit(selected); if (selected.isFriendly) { //Check if any friendly units have actions left //Makes sure you can't target anything at the end of your turn bool UnitHasActionsLeft = false; foreach (UnitConfig unit in unitList) { if (unit.actionPoints.CheckAvailableActions(1)) { UnitHasActionsLeft = true; break; } } if (UnitHasActionsLeft == false) { return; } } //After all the checks are done, we can start choosing a target for (int i = 0; i < unitList.Count; i++) { //loops around the list //Go up the list if (ChooseNext) { chosenUnitIndex++; } //Go down the list else if (!ChooseNext) { chosenUnitIndex--; } //If its too high, loop around if (chosenUnitIndex >= unitList.Count) { chosenUnitIndex = 0; } //If its too low, loop around else if (chosenUnitIndex < 0) { chosenUnitIndex = unitList.Count - 1; } //Check if enemy unit is targetable if (!unitList[chosenUnitIndex].isFriendly && !selected.CheckUnitState(UnitConfig.UnitState.Dead)) { selected = unitList[chosenUnitIndex]; selectedTarget = selected; selectedUnit.GetAccuracy(selectedTarget.tileX, selectedTarget.tileY); if (!selected.isFriendly && playerTurn) { //HACK: Hard coded, fix for multiple abilities generateAbilityButtons.abilityName.text = selectedUnit.unitAbilities.abilities[0].abilityName; generateAbilityButtons.abilityChanceToHit.text = "Chance to hit: " + UnitConfig.accuracy + "%"; generateAbilityButtons.abilityTooltip.text = selectedUnit.unitAbilities.abilities[0].tooltip; //HACK: quick calculations int minDamage = selectedUnit.unitWeapon.baseDamage + selectedUnit.unitWeapon.numberOfDiceDamage; int maxDamage = selectedUnit.unitWeapon.baseDamage + selectedUnit.unitWeapon.numberOfDiceDamage * selectedUnit.unitWeapon.numberOfSidesDamage; generateAbilityButtons.abilityEffect.text = minDamage + " - " + maxDamage + " Damage"; } break; } if (unitList[chosenUnitIndex].isFriendly && unitList[chosenUnitIndex].actionPoints.CheckAvailableActions(1)) { selected = unitList[chosenUnitIndex]; selectedUnit = selected; break; } } //Select the next/previous unit SelectUnit(selected); }
public void AddToProductionQueue(UnitConfig unit) { _currentlyBuilding = new CurrentlyBuilding(-1, unit.Id, -1, _currentlyBuilding.ProductionAccrued); }
private void UpdateHUD() { unitInfoHolder.SetActive(playerTurn); if (selectedUnit != null && selectedUnit != lastSelectedUnit) { lastSelectedUnit = selectedUnit; classInformationAnimator.Play("UnitInfoTransition", -1, 0f); className.text = selectedUnit.unitClassStats.unitClassName.ToUpper(); unitName.text = selectedUnit.unitName; classIcon.sprite = selectedUnit.unitClassStats.classIcon; } /*if(selectedTarget != null && selectedTarget.markerAnimator != null) * { * selectedTarget.markerAnimator.SetBool("display", true); * } * else * { * * }*/ foreach (UnitConfig unit in playerUnits)//Updates friendly units { if (unit.isSelected || unit.isHighlighted) { unit.animatorHealthbar.SetBool("display", true); } else { unit.animatorHealthbar.SetBool("display", false); } } foreach (UnitConfig unit in enemyUnits) //Update enemy units { if (!playerTurn && unit.enemyAi.isMyTurn || unit.isHighlighted || selectedUnit != null && selectedUnit.animator.target != null && selectedUnit.animator.target == unit || selectedTarget == unit && unit.markerAnimator != null)/*|| unit.enemyAi.isHighlighted CODE FOR IF THE UNIT IS HIGHLIGHTED */ { unit.animatorHealthbar.SetBool("display", true); if (selectedTarget == unit && unit.markerAnimator != null) { unit.markerAnimator.SetBool("display", true); } } else if (unit.animatorHealthbar != null) { unit.animatorHealthbar.SetBool("display", false); if (unit.markerAnimator != null) { unit.markerAnimator.SetBool("display", false); } } } }
public void SetUnit(UnitConfig unitConfig, int index, ConfigTypes configType) { transform.Find("InfoPanel").Find("UnitName").GetComponent <Text>().text = unitConfig.unitName; transform.Find("InfoPanel").Find("UnitClass").GetComponent <Text>().text = unitConfig.unitClass.Name(); int i = 0; List <string> actions = unitConfig.unitClass.Actions(); List <string> unitActions = unitConfig.actions; if (configType == ConfigTypes.Stance) { actions = unitConfig.unitClass.Stances(); unitActions = unitConfig.stances; } foreach (Transform entry in transform.Find("Grid")) { bool enableClick = true; int c = i; entry.GetComponent <Button>().onClick.RemoveAllListeners(); if (i < actions.Count) { entry.gameObject.active = true; string label = ""; string description = ""; string mpCost = ""; if (configType == ConfigTypes.Stance) { label = unitConfig.stanceMap[actions[c]].Name(); description = unitConfig.stanceMap[actions[c]].Description(); mpCost = "0"; } else { UnitAction action = unitConfig.actionMap[actions[c]]; label = unitConfig.actionMap[actions[c]].Name(); description = action.actionType().ToString() + " -- " + action.Description(); if (action.VariableMp()) { mpCost = "Variable"; } else { mpCost = unitConfig.actionMap[actions[c]].MpCost().ToString(); } } entry.Find("Text").GetComponent <Text>().text = label; entry.Find("Text").GetComponent <Text>().color = Color.white; if (actions[c] == unitActions[index]) { entry.Find("Text").GetComponent <Text>().color = Color.green; } else if (unitActions.Contains(actions[c])) { enableClick = false; entry.Find("Text").GetComponent <Text>().color = new Color(1, 1, 1, .5f); } ActionConfigButton configButton = entry.GetComponent <ActionConfigButton>(); configButton.actionName = label; configButton.description = description; configButton.mpCost = mpCost; if (enableClick) { entry.GetComponent <Button>().onClick.AddListener( () => { ActionInformation.Hide(); this.SetAction(unitConfig, index, actions[c], configType); }); } } else { entry.gameObject.active = false; } i++; } }
public void ShowActionScreen(int i, UnitConfig unitConfig, ActionConfig.ConfigTypes configType) { LobbySetupController.ShowActionConfig(unitConfig, i, configType); LobbySetupController.HideUnitConfig(); }
static private List <AssetBundleBuild> BuildUnitAssetBundles(BuildAssetBundleOptions opt, BuildTarget biuldTarget, Dictionary <string, AssetBundleInfo> assetInfoDict, string outputPath) { Debug.Log("處理資源: Unit"); //讀取UnitConfig配置文件,只有這個文件配置的Unit才會記錄在reslist.json裡 string text = File.ReadAllText(string.Format("{0}/Config/UnitConfig.xml", ASSET_BUNDLE_SRC_DIR)); XMLInStream stream = new XMLInStream(text); Dictionary <string, UnitConfig> UnitConfigs = new Dictionary <string, UnitConfig>(); stream.List("item", delegate(XMLInStream itemStream) { UnitConfig ufg = new UnitConfig(itemStream); //注意這裡用的是ResourceIcon字段 if (!UnitConfigs.ContainsKey(ufg.ResourceIcon)) { UnitConfigs.Add(ufg.ResourceIcon, ufg); } }); List <AssetBundleBuild> ret = new List <AssetBundleBuild>(); //生成prefab的AssetBundle foreach (var pair in UnitConfigs) { DirectoryInfo dInfo = new DirectoryInfo(string.Format("{0}/Unit/{1}", ASSET_BUNDLE_SRC_DIR, pair.Key)); //這裡注意轉成小寫 string assetbundlename = "unit/" + pair.Key.ToLower(); if (!dInfo.Exists) { // 如果UnitConfig配置裡沒有的字段,需要從reslist.json裡清理掉 if (assetInfoDict.ContainsKey(assetbundlename)) { assetInfoDict.Remove(assetbundlename); } continue; } AssetBundleBuild abb = new AssetBundleBuild(); abb.assetBundleName = assetbundlename; string[] assetNames = { string.Format("{0}/Unit/{1}/{2}.prefab", ASSET_BUNDLE_SRC_DIR, pair.Key, pair.Key) }; abb.assetNames = assetNames; ret.Add(abb); } //生成UnitImg的AssetBundle foreach (var pair in UnitConfigs) { //夥伴圖1 string p1 = string.Format("{0}/UnitImg1/{1}.png", ASSET_BUNDLE_SRC_DIR, pair.Key); //夥伴圖2 string p2 = string.Format("{0}/UnitImg2/{1}.png", ASSET_BUNDLE_SRC_DIR, pair.Key); FileInfo img1Info = new FileInfo(p1); FileInfo img2Info = new FileInfo(p2); string assetbundlename = string.Format("unitimg/{0}img", pair.Key.ToLower()); if (!img1Info.Exists && !img2Info.Exists) { continue; } AssetBundleBuild abb = new AssetBundleBuild(); abb.assetBundleName = assetbundlename; string[] assetNames = { p1, p2 }; abb.assetNames = assetNames; ret.Add(abb); } return(ret); }
private void OnResetExecute(object obj) { UnitConfig.RejectChanges(); }
static void BuildAllUnits() { DirectoryInfo dInfo = new DirectoryInfo("Assets/ExternalRes/Unit"); if (!dInfo.Exists) { Debug.Log("不存在目录"); return; } DirectoryInfo assetDire = new DirectoryInfo("."); //读取配置文件 Dictionary <string, UnitConfig> UnitConfigs = new Dictionary <string, UnitConfig>(); TextAsset textAsset = AssetDatabase.LoadAssetAtPath("Assets/ExternalRes/Config/UnitConfig.xml", typeof(TextAsset)) as TextAsset; XMLInStream stream = new XMLInStream(textAsset.text); stream.List("item", delegate(XMLInStream itemStream) { UnitConfig ufg = new UnitConfig(itemStream); if (!UnitConfigs.ContainsKey(ufg.ResourceIcon)) { UnitConfigs.Add(ufg.ResourceIcon, ufg); } }); DirectoryInfo[] unitsDires = dInfo.GetDirectories(); for (int i = 0, n = unitsDires.Length; i < n; i++) { dInfo = unitsDires[i]; FileInfo[] fileInfoArr = dInfo.GetFiles("*_SkeletonData.asset"); for (int j = 0, m = fileInfoArr.Length; j < m; j++) { FileInfo fInfo = fileInfoArr[j]; //Debug.Log(fInfo.FullName); //Debug.Log(fInfo.Name); string relativePath = fInfo.FullName.Replace(assetDire.FullName, ""); relativePath = relativePath.Remove(0, 1); //Debug.Log("relativePath=" + relativePath); Object o = AssetDatabase.LoadAssetAtPath(relativePath, typeof(Object)); if (o == null) { Debug.LogWarning("null"); } string guid = AssetDatabase.AssetPathToGUID(relativePath); string skinName = EditorPrefs.GetString(guid + "_lastSkin", ""); if (!UnitConfigs.ContainsKey(dInfo.Name)) { Debug.LogFormat("{0},没有相关配置,忽略", dInfo.Name); continue; } Debug.LogFormat("正在处理 name={0}", dInfo.Name); UnitConfig ufg = UnitConfigs[dInfo.Name]; try { if (ufg.isEnemy) { InstantiateSkeletonEnemy((SkeletonDataAsset)o, skinName); } else { InstantiateSkeletonUnit((SkeletonDataAsset)o, skinName); } } catch (System.Exception e) { Debug.LogFormat("{0} 处理失败,重新处理。msg={1}", dInfo.Name, e.Message); j--; } SceneView.RepaintAll(); } } }
// private void _initTroopUnit() { int[] attackerUnitTypeID = new int[5] { 1, 1, 1, 2, 2 }; int[] defenderUnitTypeID = new int[5] { 1, 1, 2, 2, 2 }; // attacker for (int troop = 0; troop < 5; ++troop) { int unitcount = 1; //Random.Rand(1, 10); int unitAttributeID = attackerUnitTypeID[troop]; UnitConfig.UnitAttribute unitConfigData = UnitConfig.GetUnitAttribute(unitAttributeID); for (int unitIndex = 0; unitIndex < unitcount; ++unitIndex) { Unit unit = new Unit(this); unit.ID = _getUnitID(troop, unitIndex); unit.IsAttacker = true; int offset = 0; //Random.Rand(-2, 2); unit.Position = ATTACKER_INIT_POSITION[troop] + new Vector2(offset, offset); unit.HP = unitConfigData.HP; unit.AttackRange = unitConfigData.AttackRange; unit.Attack = unitConfigData.Attack; unit.AttackSpeed = unitConfigData.AttackSpeed; unit.MoveSpeed = unitConfigData.MoveSpeed / Battleplayer.FRAME_RATE; unit.AttackSkillAttackID = unitConfigData.AttackSkillAttackID; attakerList.Add(unit); } } // defender for (int troop = 0; troop < 5; ++troop) { int unitcount = 1; //Random.Rand(1, 10); int unitAttributeID = defenderUnitTypeID[troop]; UnitConfig.UnitAttribute unitConfigData = UnitConfig.GetUnitAttribute(unitAttributeID); for (int unitIndex = 0; unitIndex < unitcount; ++unitIndex) { Unit unit = new Unit(this); unit.ID = _getUnitID(troop + 5, unitIndex); unit.IsAttacker = false; int offset = 0; //Random.Rand(-2, 2); unit.Position = DEFENDER_INIT_POSITION[troop] + new Vector2(offset, offset); unit.HP = unitConfigData.HP; unit.AttackRange = unitConfigData.AttackRange; unit.Attack = unitConfigData.Attack; unit.AttackSpeed = unitConfigData.AttackSpeed; unit.MoveSpeed = unitConfigData.MoveSpeed / Battleplayer.FRAME_RATE; unit.AttackSkillAttackID = unitConfigData.AttackSkillAttackID; defenderList.Add(unit); } } }
private void Start() { unitConfig = gameObject.GetComponent <UnitConfig>(); mapConfig = FindObjectOfType <MapConfig>(); }