private IEnumerator _StartTraining() { ItemsCollection.ItemData itemData = Items.GetItem(_currentTrainingTroop); float buildTime = itemData.configuration.buildTime; trainingStartTime = Time.realtimeSinceStartup; yield return(new WaitForSeconds(buildTime)); Vector3 randomFrontCell = _baseItem.GetRandomFrontCellPosition(); BaseItemScript newUnit = SceneManager.instance.AddItem(_currentTrainingTroop, -1, (int)randomFrontCell.x, (int)randomFrontCell.y, true, true); BaseItemScript nearestArmyCamp = SceneManager.instance.GetNearestArmyCamp(newUnit.GetPosition()); if (nearestArmyCamp != null) { newUnit.WalkRandom(nearestArmyCamp); } _currentTrainingTroop = -1; trainingQueue.RemoveAt(0); if (trainingQueue.Count > 0) { _Train(trainingQueue[0]); } if (TrainTroopsWindowScript.instance != null) { TrainTroopsWindowScript.instance.RenderTrainingQueue(); } }
public void InitSpriteAnimations() { if (selectedItemIndex == -1) { return; } ItemsCollection.ItemData itemData = itemsCollection.list[selectedItemIndex]; this.spriteAnimationList = new List <SpriteAnimationItem>(); foreach (int spriteId in itemData.GetSprites((Common.State)state)) { SpriteCollection.SpriteData sprite = spriteCollection.GetSprite(spriteId); SpriteAnimationItem spriteAnimationData = new SpriteAnimationItem(); spriteAnimationData.sprite = sprite; spriteAnimationData.lastUpdatedTime = Time.realtimeSinceStartup; SpriteCollection.TextureData textureData = GetTextureDataDirection(sprite); spriteAnimationData.numberOfColumns = textureData.numberOfColumns; spriteAnimationData.numberOfRows = textureData.numberOfRows; this.spriteAnimationList.Add(spriteAnimationData); } this.spriteAnimationList.Sort(SortByDepth); }
public void AddToTrainingQueue(int troopId) { ItemsCollection.ItemData data = Items.GetItem(troopId); if (SceneManager.instance.ConsumeResource("elixir", 10)) { _selectedBarrack.Training.AddToTrainingQueue(troopId); this.RenderTrainingQueue(); } }
public void SetItemData(int itemId, int posX, int posY) { this.gameObject.GetComponent <BoxCollider>().enabled = true; if (itemId == 3823) { this.gameObject.GetComponent <BoxCollider>().center = new Vector3(0.5f, 1f, 0.5f); this.gameObject.GetComponent <BoxCollider>().size = new Vector3(1.96f, 3.25f, 0.2f); } else if (itemId == 8833) { this.gameObject.GetComponent <BoxCollider>().center = new Vector3(0.5f, 1.5f, 0.5f); this.gameObject.GetComponent <BoxCollider>().size = new Vector3(3.26f, 2.31f, 0.2f); } else { this.gameObject.GetComponent <BoxCollider>().center = new Vector3(0.5f, 1.26f, 0.5f); this.gameObject.GetComponent <BoxCollider>().size = new Vector3(3.26f, 2.31f, 0.2f); } this.itemData = Items.GetItem(itemId); this.gameObject.name = itemData.name + " [INSTANCE]"; this.SetSize(Vector3.one * itemData.gridSize); this.healthPoints = this.itemData.configuration.healthPoints; this.Renderer.Init(); this.Walker.SetData(this); this.Attacker.SetData(this); this.Training.SetData(this); this.UI.SetData(this); this.Particles.SetData(this); if (this.itemData.configuration.productionRate > 0) { this.Production.SetData(this); } this.connectedItems = new List <BaseItemScript>(); if (this.itemData.configuration.defenceRange > 0) { this.Defender.SetData(this); } //disable box collider for characters, otherwise characters can select by tap //this.BoxCollider.enabled = !this.itemData.configuration.isCharacter; this.SetPosition(new Vector3(posX, posY, 0)); this.UpdateConnectedItems(); HonjinManager.instance.dicSDModel[itemId].SetTargetPos(new Vector3(posX, posY, 0)); //if(this.itemData.configuration.productionRate > 0) //{ // this.ShowCollectNotificationUI(true, this.itemData.configuration.product); //} }
public BaseItemScript AddItem(int itemId, bool immediate, bool ownedItem) { int posX = 0; int posY = 0; if (!immediate) { ItemsCollection.ItemData itemData = Items.GetItem(itemId); Vector3 freePosition = GroundManager.instance.GetRandomFreePositionForItem(itemData.gridSize, itemData.gridSize); posX = (int)freePosition.x; posY = (int)freePosition.y; } return(this.AddItem(itemId, -1, posX, posY, immediate, ownedItem)); }
private void UpdateDataValues() { if (selectedItemIndex == -1) { return; } ItemsCollection.ItemData itemData = itemsCollection.list[selectedItemIndex]; itemData.name = this.name; itemData.gridSize = this.gridSize; itemData.thumb = thumb; EditorUtility.SetDirty(itemsCollection); }
public void SetId(int troopId) { this._troopId = troopId; ItemsCollection.ItemData itemData = Items.GetItem(troopId); if (itemData.name == "SwordMan") { this.TroopImage.sprite = SwordManThumb; } else if (itemData.name == "Archer") { this.TroopImage.sprite = ArcherThumb; } this.ProgressPanel.SetActive(false); }
private void LoadDataValues() { if (selectedItemIndex == -1) { return; } ItemsCollection.ItemData itemData = itemsCollection.list[selectedItemIndex]; id = itemData.id.ToString(); name = itemData.name; thumb = itemData.thumb; gridSize = itemData.gridSize; if (gridSize == 0) { gridTexture = null; } else if (gridSize == 1) { gridTexture = Resources.Load("grid_1x1", typeof(Texture2D)) as Texture2D; } else if (gridSize == 2) { gridTexture = Resources.Load("grid_2x2", typeof(Texture2D)) as Texture2D; } else if (gridSize == 3) { gridTexture = Resources.Load("grid_3x3", typeof(Texture2D)) as Texture2D; } else if (gridSize == 4) { gridTexture = Resources.Load("grid_4x4", typeof(Texture2D)) as Texture2D; } else if (gridSize == 5) { gridTexture = Resources.Load("grid_5x5", typeof(Texture2D)) as Texture2D; } else if (gridSize == 6) { gridTexture = Resources.Load("grid_6x6", typeof(Texture2D)) as Texture2D; } }
public static void LoadItems() { items = new Dictionary <int, ItemsCollection.ItemData> (); ItemsCollection itemsCollection = Resources.Load("ItemsCollection", typeof(ItemsCollection)) as ItemsCollection; if (itemsCollection != null) { for (int index = 0; index < itemsCollection.list.Count; index++) { ItemsCollection.ItemData itemData = itemsCollection.list [index]; items.Add(itemData.id, itemData); } } else { Debug.LogError("ItemsCollection is missing! please go to 'Windows/Item Editor'"); } }
void RenderSpritesList() { ItemsCollection.ItemData itemData = itemsCollection.list[selectedItemIndex]; foreach (int spriteId in itemData.GetSprites((Common.State)state)) { SpriteCollection.SpriteData sprite = spriteCollection.GetSprite(spriteId); GUILayout.BeginHorizontal(); GUILayout.Space(20); //BOX Rect pos = GUILayoutUtility.GetLastRect(); pos.height = 25; pos.x += 20; pos.width = WidthOfRightPanel - 25; GUI.Box(pos, "", "box"); GUILayout.Label(sprite.name); GUILayout.FlexibleSpace(); if (GUILayout.Button("-")) { removedSprites.Add(sprite); } GUILayout.EndHorizontal(); GUILayout.Space(5); } foreach (SpriteCollection.SpriteData sprite in removedSprites) { itemData.RemoveSprite(sprite, (Common.State)state); this.InitSpriteAnimations(); } if (removedSprites.Count != null) { removedSprites = new List <SpriteCollection.SpriteData>(); } }
void AddSpriteButtonMenu() { Rect position = new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y - 10, 0, 0); GenericMenu toolsMenu = new GenericMenu(); if (spriteCollection != null) { foreach (SpriteCollection.SpriteData sprite in spriteCollection.list) { toolsMenu.AddItem(new GUIContent(sprite.name), false, data => { ItemsCollection.ItemData itemData = itemsCollection.list[selectedItemIndex]; itemData.AddSprite((SpriteCollection.SpriteData)data, (Common.State)state); this.InitSpriteAnimations(); }, sprite); } } toolsMenu.DropDown(position); EditorGUIUtility.ExitGUI(); }
public void SetItemData(int itemId, int posX, int posZ) { this.itemData = Items.GetItem(itemId); this.gameObject.name = itemData.name + " [INSTANCE]"; this.SetSize(Vector3.one * itemData.gridSize); this.healthPoints = this.itemData.configuration.healthPoints; this.Renderer.Init(); this.Walker.SetData(this); this.Attacker.SetData(this); this.Training.SetData(this); this.UI.SetData(this); this.Particles.SetData(this); if (this.itemData.configuration.productionRate > 0) { this.Production.SetData(this); } this.connectedItems = new List <BaseItemScript>(); if (this.itemData.configuration.defenceRange > 0) { this.Defender.SetData(this); } //disable box collider for characters, otherwise characters can select by tap this.BoxCollider.enabled = !this.itemData.configuration.isCharacter; this.SetPosition(new Vector3(posX, 0, posZ)); this.UpdateConnectedItems(); //if(this.itemData.configuration.productionRate > 0) //{ // this.ShowCollectNotificationUI(true, this.itemData.configuration.product); //} }
void RenderRightPanel() { GUILayout.BeginArea(new Rect(position.width - WidthOfRightPanel, 0, WidthOfRightPanel, position.height)); GUI.Box(new Rect(0, 0, WidthOfRightPanel, position.height), "", EditorStyles.helpBox); if (selectedItemIndex != -1) { rightPanelScrollPos = EditorGUILayout.BeginScrollView(rightPanelScrollPos, GUILayout.Width(WidthOfRightPanel), GUILayout.Height(position.height)); GUILayout.BeginHorizontal(); GUILayout.Label("ID"); // id = GUILayout.TextField (id); EditorGUILayout.SelectableLabel(id, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight)); if (id != _oldId) { _oldId = id; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Name"); name = GUILayout.TextField(name); if (name != _oldName) { _oldName = name; this._simpleTreeView.Reload(); } GUILayout.EndHorizontal(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Space(5); spritesFoldout = EditorGUILayout.Foldout(spritesFoldout, "SPRITE", true); if (spritesFoldout) { state = EditorGUILayout.Popup("State", state, stateOptions); if (state != _oldState) { _oldState = state; this.LoadDataValues(); this.InitSpriteAnimations(); } direction = EditorGUILayout.Popup("Direction", direction, directionsOptions); if (direction != _oldDirection) { _oldDirection = direction; this.LoadDataValues(); } GUILayout.Space(5); this.RenderSpritesList(); GUILayout.BeginHorizontal(); GUILayout.Space(20); if (GUILayout.Button("Add Sprite")) { AddSpriteButtonMenu(); } GUILayout.EndHorizontal(); thumb = (GameObject)EditorGUILayout.ObjectField("Thumb", thumb, typeof(GameObject)); } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUILayout.Space(5); configFoldout = EditorGUILayout.Foldout(configFoldout, "CONFIG", true); if (configFoldout) { GUILayout.BeginHorizontal(); GUILayout.Space(20); gridSize = EditorGUILayout.Popup("Grid Size", gridSize, gridSizeOptions); if (gridSize != _oldGridSize) { _oldGridSize = gridSize; this.UpdateDataValues(); this.LoadDataValues(); } GUILayout.EndHorizontal(); ItemsCollection.ItemData itemData = itemsCollection.list[selectedItemIndex]; foreach (var property in itemData.configuration.GetType().GetFields()) { GUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.Label(property.Name); var val = property.GetValue(itemData.configuration); if (val.GetType() == typeof(System.Int32)) { string temp = GUILayout.TextField(property.GetValue(itemData.configuration).ToString()); int parsedValue = 0; int.TryParse(Utilities.CleanStringForInt(temp), out parsedValue); property.SetValue(itemData.configuration, parsedValue); } else if (val.GetType() == typeof(System.Single)) { string temp = GUILayout.TextField(property.GetValue(itemData.configuration).ToString()); float parsedValue = 0; float.TryParse(Utilities.CleanStringForFloat(temp), out parsedValue); property.SetValue(itemData.configuration, parsedValue); } else if (val.GetType() == typeof(System.Boolean)) { bool temp = GUILayout.Toggle((bool)property.GetValue(itemData.configuration), ""); property.SetValue(itemData.configuration, temp); } else if (val.GetType() == typeof(System.String)) { string temp = GUILayout.TextField((string)property.GetValue(itemData.configuration)); property.SetValue(itemData.configuration, temp); } GUILayout.EndHorizontal(); //Debug.Log(property.GetValue(itemData.confTest).GetType()); //Debug.Log("Name: " + property.Name + " Value: " + property.GetValue(this)); //property.SetValue(this, 65); } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); //GUILayout.Space(5); //aiConfigFoldout = EditorGUILayout.Foldout(aiConfigFoldout, "AI CONFIG", true); //if (aiConfigFoldout) //{ // GUILayout.BeginHorizontal(); // GUILayout.Space(20); // isCharacter = GUILayout.Toggle(isCharacter, "Is character"); // GUILayout.EndHorizontal(); // if (isCharacter) // { // GUILayout.BeginHorizontal(); // GUILayout.Space(20); // GUILayout.Label("Walk speed"); // walkSpeed = GUILayout.TextField(walkSpeed); // walkSpeed = Utilities.CleanStringForFloat(walkSpeed); // GUILayout.EndHorizontal(); // } // GUILayout.Space(10); // GUILayout.BeginHorizontal(); // GUILayout.Space(20); // GUILayout.Label("Attack range"); // attackRange = GUILayout.TextField(attackRange); // attackRange = Utilities.CleanStringForFloat(attackRange); // GUILayout.EndHorizontal(); // GUILayout.BeginHorizontal(); // GUILayout.Space(20); // GUILayout.Label("Defence range"); // defenceRange = GUILayout.TextField(defenceRange); // defenceRange = Utilities.CleanStringForFloat(defenceRange); // GUILayout.EndHorizontal(); // GUILayout.BeginHorizontal(); // GUILayout.Space(20); // GUILayout.Label("Health points"); // healthPoints = GUILayout.TextField(healthPoints); // healthPoints = Utilities.CleanStringForFloat(healthPoints); // GUILayout.EndHorizontal(); // GUILayout.BeginHorizontal(); // GUILayout.Space(20); // GUILayout.Label("Hit points"); // hitPoints = GUILayout.TextField(hitPoints); // hitPoints = Utilities.CleanStringForFloat(hitPoints); // GUILayout.EndHorizontal(); //} //GUILayout.Space(5); //newConfigFoldout = EditorGUILayout.Foldout(newConfigFoldout, "CONFIGURATIONS", true); //if (newConfigFoldout) //{ // ItemsCollection.ItemData itemData = itemsCollection.list[selectedItemIndex]; // foreach (var property in itemData.configuration.GetType().GetFields()) // { // GUILayout.BeginHorizontal(); // GUILayout.Space(20); // GUILayout.Label(property.Name); // var val = property.GetValue(itemData.configuration); // if (val.GetType() == typeof(System.Int32)) // { // string temp = GUILayout.TextField(property.GetValue(itemData.configuration).ToString()); // int parsedValue = 0; // int.TryParse(Utilities.CleanStringForInt(temp), out parsedValue); // property.SetValue(itemData.configuration, parsedValue); // } // else if (val.GetType() == typeof(System.Single)) // { // string temp = GUILayout.TextField(property.GetValue(itemData.configuration).ToString()); // float parsedValue = 0; // float.TryParse(Utilities.CleanStringForFloat(temp), out parsedValue); // property.SetValue(itemData.configuration, parsedValue); // } // else if (val.GetType() == typeof(System.Boolean)) // { // bool temp = GUILayout.Toggle((bool)property.GetValue(itemData.configuration), ""); // property.SetValue(itemData.configuration, temp); // } // else if (val.GetType() == typeof(System.String)) // { // string temp = GUILayout.TextField((string)property.GetValue(itemData.configuration)); // property.SetValue(itemData.configuration, temp); // } // GUILayout.EndHorizontal(); // //Debug.Log(property.GetValue(itemData.confTest).GetType()); // //Debug.Log("Name: " + property.Name + " Value: " + property.GetValue(this)); // //property.SetValue(this, 65); // } //} EditorGUILayout.EndScrollView(); if (GUI.changed) { UpdateDataValues(); } } GUILayout.EndArea(); }
public void addItem() { int itemId = 0; switch (this._subCategory.subCategoryName) { case "BARRACK": itemId = 8833; break; case "BOAT": itemId = 6871; break; case "BUILDER_HUT": itemId = 3635; break; case "CAMP": itemId = 2728; break; case "CANNON": itemId = 1712; break; case "ELIXIR_COLLECTOR": itemId = 4856; break; case "ELIXIR_STORAGE": itemId = 2090; break; case "GEMS": itemId = 3336; break; case "GOLD_MINE": itemId = 3265; break; case "GOLD_STORAGE": itemId = 9074; break; case "TOWER": itemId = 4764; break; case "TOWN_CENTER": itemId = 2496; break; case "TREE1": itemId = 2949; break; case "TREE2": itemId = 1251; break; case "WINDMILL": itemId = 6677; break; case "WALL": itemId = 7666; break; case "TREE3": itemId = 5341; break; case "CoconutTree": itemId = 7802; break; case "Tent": itemId = 1604; break; } ItemsCollection.ItemData itemData = Items.GetItem(itemId); Vector3 freePosition = GroundManager.instance.GetRandomFreePositionForItem(itemData.gridSize, itemData.gridSize); BaseItemScript item = SceneManager.instance.AddItem(itemId, false, true); if (item != null) { item.SetPosition(freePosition); DataBaseManager.instance.UpdateItemData(item); if (this._subCategory.reqMap[DataBaseManager.GOLD_RESOURCE_NAME] > 0) { DataBaseManager.instance.UpdateResourceData(DataBaseManager.GOLD_RESOURCE_NAME, this._subCategory.reqMap[DataBaseManager.GOLD_RESOURCE_NAME], false); SceneManager.instance.ConsumeResource("gold", this._subCategory.reqMap[DataBaseManager.GOLD_RESOURCE_NAME]); } if (this._subCategory.reqMap[DataBaseManager.WOOD_RESOURCE_NAME] > 0) { DataBaseManager.instance.UpdateResourceData(DataBaseManager.GOLD_RESOURCE_NAME, this._subCategory.reqMap[DataBaseManager.WOOD_RESOURCE_NAME], false); } if (this._subCategory.reqMap[DataBaseManager.LEAVES_RESOURCE_NAME] > 0) { DataBaseManager.instance.UpdateResourceData(DataBaseManager.LEAVES_RESOURCE_NAME, this._subCategory.reqMap[DataBaseManager.LEAVES_RESOURCE_NAME], false); } } SceneManager.instance.UpdateResourcesValues(); this.GetComponentInParent <ShopWindowScript>().Close(); }
public void StartProgress(float startTime) { ItemsCollection.ItemData itemData = Items.GetItem(this._troopId); this.StartCoroutine(_StartProgress(startTime, startTime + itemData.configuration.buildTime)); this.ProgressPanel.SetActive(true); }
public static ItemsCollection.ItemData GetItem(int itemId) { ItemsCollection.ItemData item = null; items.TryGetValue(itemId, out item); return(item); }