private void BlueprintClicked(BlueprintButton sender) { //craftTimer = new Timer_Bar(new Size(200,15), new TimeSpan(0,0,0,10)); if (_playerManager != null) { if (_playerManager.ControlledEntity != null) { if (_playerManager.ControlledEntity.HasComponent(ComponentFamily.Inventory)) { var invComp = (InventoryComponent)_playerManager.ControlledEntity.GetComponent(ComponentFamily.Inventory); if (!invComp.ContainsEntity(sender.Compo1) || !invComp.ContainsEntity(sender.Compo2)) { _craftStatus.Text = "Status: You do not have the required items."; _craftStatus.Color = Color.DarkRed; } else { _craftSlot1.SetEntity(invComp.GetEntity(sender.Compo1)); _craftSlot2.SetEntity(invComp.GetEntity(sender.Compo2)); CraftButtonClicked(null); //This is pretty dumb but i hate duplicate code. } } } } }
void Start() { self_AS = GetComponent <AudioSource>(); all_ACs = new Dictionary <string, AudioClip>(); all_ACs.Add("Error", Resources.Load <AudioClip>("AudioClip/Error")); unit_blueprint = GameObject.Find("DesignPlatform/Unit").GetComponent <UnitBlueprint>(); BB = GameObject.Find("UICanvasTop/BlueprintButton").GetComponent <BlueprintButton>(); creat_part_audio = GameObject.Find("AudioClickButton01").GetComponent <AudioSource>(); UI_canvas_base = GameObject.Find("UICanvasBase").transform as RectTransform; part_interface_top = GameObject.Find("UICanvasTop/PartInterface").transform as RectTransform; part_interface_ground = GameObject.Find("UICanvasBase/PartInterfaceGround").transform as RectTransform; part_interface = GameObject.Find("UICanvasBase/PartInterfaceGround/PartInterfaceBackGround/PartInterface").transform as RectTransform; part_interface_middle = GameObject.Find("UICanvasMiddle/PartInterfaceMiddle").transform as RectTransform; all_part_buttons = new List <PartButton>(); all_layer_button = new List <LayerButton>(); power_part_buttons = new List <PartButton>(); leg_part_buttons = new List <PartButton>(); control_part_buttons = new List <PartButton>(); equip_part_buttons = new List <PartButton>(); module_part_buttons = new List <PartButton>(); Transform LB_temp = GameObject.Find("UICanvasTop/PartInterfaceBottomBar/PartsLayerToogleGroup").transform; foreach (var lb in LB_temp.GetComponentsInChildren <LayerButton>()) { all_layer_button.Add(lb); } foreach (var temp in part_interface.GetComponentsInChildren <PartButton>()) { all_part_buttons.Add(temp); temp.Init();//手动初始化 switch ((int)temp.part_type) { case 0: power_part_buttons.Add(temp); break; case 1: leg_part_buttons.Add(temp); break; case 2: control_part_buttons.Add(temp); break; case 3: equip_part_buttons.Add(temp); break; } } ToolClosePartInterface(); }
private async Task LoadBlueprints(string blueprintDirectory) { if (string.IsNullOrWhiteSpace(blueprintDirectory)) { throw new ArgumentException($"'{nameof(blueprintDirectory)}' cannot be null or whitespace", nameof(blueprintDirectory)); } var knownWriteDateTime = DateTime.MinValue; int exceptions = 0; while (true) { try { var lastWriteDateTime = Directory.GetLastWriteTime(blueprintDirectory); if (knownWriteDateTime < lastWriteDateTime) { knownWriteDateTime = lastWriteDateTime; foreach (string bpDir in Directory.GetDirectories(blueprintDirectory)) { if (!LoadedBlueprints.ContainsKey(bpDir) && Directory.Exists(bpDir) && File.Exists($"{bpDir}/blueprint.json")) { BlueprintContext bp = BlueprintContext.FromFolderPath(bpDir); LoadedBlueprints.Add(bpDir, bp); GameObject newButton = buttonObjectPool.GetObject(); newButton.transform.SetParent(contentPanel); BlueprintButton blueprintButton = newButton.GetComponent <BlueprintButton>(); blueprintButton.Setup(bp); } } } } catch (Exception e) { if (exceptions++ < 10) { Debug.LogException(e); } } finally { await Task.Delay(2000); } } }
private void AddBlueprint(NetIncomingMessage message) { string compo1Temp = message.ReadString(); string compo1Name = message.ReadString(); string compo2Temp = message.ReadString(); string compo2Name = message.ReadString(); string resultTemp = message.ReadString(); string resultName = message.ReadString(); _craftStatus.Text = "Status: You successfully create '" + resultName + "'"; _craftStatus.Color = Color.Green; foreach (BlueprintButton bpbutt in _blueprints.components) { var req = new List <string> { compo1Temp, compo2Temp }; if (req.Exists(x => x.ToLowerInvariant() == bpbutt.Compo1.ToLowerInvariant())) { req.Remove(req.First(x => x.ToLowerInvariant() == bpbutt.Compo1.ToLowerInvariant())); } if (req.Exists(x => x.ToLowerInvariant() == bpbutt.Compo2.ToLowerInvariant())) { req.Remove(req.First(x => x.ToLowerInvariant() == bpbutt.Compo2.ToLowerInvariant())); } if (!req.Any()) { return; } } var newBpb = new BlueprintButton(compo1Temp, compo1Name, compo2Temp, compo2Name, resultTemp, resultName, _resourceManager); newBpb.Update(0); newBpb.Clicked += BlueprintClicked; newBpb.Position = new Point(0, _blueprintsOffset); _blueprintsOffset += newBpb.ClientArea.Height; _blueprints.components.Add(newBpb); }
public void SelectBlueprintButton(BlueprintButton blueprintButton) { Color color; if (SelectedBlueprintButton != null) { color = SelectedBlueprintButton.button.image.color; color.a = 40f / 255f; SelectedBlueprintButton.button.image.color = color; } SelectedBlueprintButton = blueprintButton; color = blueprintButton.button.image.color; color.a = 100f / 255f; blueprintButton.button.image.color = color; DescriptionData descriptionData = blueprintButton.BlueprintContextReference.Description; titleField.SetTextWithoutNotify(descriptionData.Name); descriptionField.SetTextWithoutNotify(descriptionData.Description); applyButton.gameObject.SetActive(false); }
RectTransform unit_interface_middle; //单位菜单遮挡用外框 #endregion void Start() { self = this; sp = Resources.LoadAll <Sprite>("Image/LayerButtonImage"); self_image = GetComponent <Image>(); unit_blueprint = GameObject.Find("DesignPlatform/Unit").GetComponent <UnitBlueprint>(); UIunit_group = GameObject.Find("UnitPart").transform; BC = GameObject.Find("ButtonController").GetComponent <ButtonController>(); content = GameObject.Find("UICanvasBase/UnitInterfaceGround/UnitInterfaceBackGround/UnitInterface/Viewport/UnitInterfaceContent").transform as RectTransform; UI_canvas_base = GameObject.Find("UICanvasBase").transform as RectTransform; unit_interface_top = GameObject.Find("UICanvasTop/UnitInterface").transform as RectTransform; unit_interface_ground = GameObject.Find("UICanvasBase/UnitInterfaceGround").transform as RectTransform; unit_interface = GameObject.Find("UICanvasBase/UnitInterfaceGround/UnitInterfaceBackGround/UnitInterface").transform as RectTransform; unit_interface_middle = GameObject.Find("UICanvasMiddle/UnitInterfaceMiddle").transform as RectTransform; //调用协程加载所有用户数据: LoadUserDataAtStart(); self_image.sprite = sp[0]; }
private void OnChanged(object sender, FileSystemEventArgs e)// different thread { try { string path = e.FullPath; bool exists = Directory.Exists(path) || File.Exists(path); if (exists) { FileAttributes fileAttributes = File.GetAttributes(path); if ((fileAttributes & FileAttributes.Directory) != FileAttributes.Directory) { path = Directory.GetParent(path)?.FullName; } if (LoadedBlueprints.TryGetValue(path, out var blueprintCtx)) { _ = RunMain(() => { blueprintCtx.LoadDescription(); blueprintCtx.LoadIcon(); blueprintCtx.btn.Initialize(); if (SelectedBlueprintButton == blueprintCtx.btn) { SelectBlueprintButton(SelectedBlueprintButton); } }).LogErrors(); } else if (File.Exists($"{path}/blueprint.json")) { _ = RunMain(() => { BlueprintContext bp = BlueprintContext.FromFolderPath(path); LoadedBlueprints.Add(path, bp); GameObject newButton = buttonObjectPool.GetObject(); newButton.transform.SetParent(contentPanel); BlueprintButton blueprintButton = newButton.GetComponent <BlueprintButton>(); blueprintButton.Setup(bp); }).LogErrors(); } } else { if (path.Contains('.')) // assume it's a file { path = path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar)); } if (LoadedBlueprints.TryGetValue(path, out var blueprintCtx)) { _ = RunMain(() => { if (SelectedBlueprintButton == blueprintCtx.btn) { titleField.text = string.Empty; descriptionField.text = string.Empty; applyButton.gameObject.SetActive(false); } Destroy(blueprintCtx.btn.gameObject); LoadedBlueprints.Remove(path); }).LogErrors(); } } } catch (Exception ex) { Debug.LogException(ex); } }