/// <summary> /// Rebuild from scratch whole buttons lists /// </summary> void RebuildBricksButtons(BricksList list) { //clear existing list var buttons = list.GetComponentsInChildren <BrickButton>(); counter = buttons.Length; var separator = Path.DirectorySeparatorChar; RebuildBricksFromDirectory(list, string.Concat("Assets", separator, "Resources", separator, "AgaQ", separator)); }
void RefreshBricksNames(BricksList list) { var buttons = list.gameObject.GetComponentsInChildren <BrickButton>(); foreach (var button in buttons) { var go = Resources.Load(button.brickResourcePath) as GameObject; var brick = go.GetComponent <Brick>(); button.paramText = brick.name; button.tooltipText = "{0}"; } }
/// <summary> /// Find button at given list with prefab path. /// </summary> /// <returns>The button.</returns> /// <param name="prefabPath">Prefab path.</param> /// <param name="list">List.</param> BrickButton FindButton(string prefabPath, BricksList list) { var buttons = list.GetComponentsInChildren <BrickButton>(); string resourcesPath = ExtractResourcesPath(prefabPath); foreach (var button in buttons) { if (button.brickResourcePath == resourcesPath) { return(button); } } return(null); }
/// <summary> /// Rebuild all buttons icons. /// </summary> /// <param name="">.</param> void RebuildButtonsIcons(BricksList list) { var buttons = list.gameObject.GetComponentsInChildren <BrickButton>(); foreach (var button in buttons) { var image = button.GetComponent <Image>(); if (image != null) { //generate icon var brick = Resources.Load(button.brickResourcePath) as GameObject; string path = string.Format("Assets/Resources/Icons/{0}.png", brick.name); BrickUtils.GenerateIcon(brick.GetComponent <Brick>(), path, 256); } } }
/// <summary> /// Rebuild buttons list from directory content. /// </summary> /// <param name="list">List.</param> /// <param name="path">Path.</param> void RebuildBricksFromDirectory(BricksList list, string path) { var files = Directory.GetFiles(path); foreach (var file in files) { if (file.EndsWith(".prefab")) { //check if button exists var button = FindButton(file, list); if (button == null) { GenerateButton(file, counter++, list.transform); } } } var subPaths = Directory.GetDirectories(path); foreach (var subPath in subPaths) { RebuildBricksFromDirectory(list, subPath); } }