public void Init(GameRule _activeGameRules) { ruleBarItemByRule = new Dictionary <GameRule, RuleBarItem>(); foreach (RuleBarItemWithGameRule ruleBarItemWithGameRuleItem in ruleBarItemWithGameRuleArray) { ruleBarItemByRule[ruleBarItemWithGameRuleItem.Rule] = ruleBarItemWithGameRuleItem.RuleBarItemPrefab; } if (_activeGameRules != GameRule.None) { gameObject.SetActive(true); // foreach (Transform childItem in transform) { // Destroy(childItem.gameObject); // } Type gameRuleType = typeof(GameRule); Array gameRulesArray = Enum.GetValues(gameRuleType); foreach (Enum gameRuleItem in gameRulesArray) { if (_activeGameRules.HasFlag(gameRuleItem)) { GameRule currentRule = (GameRule)Enum.ToObject(gameRuleType, gameRuleItem); RuleBarItem currentRuleBarItemPrefab; if (ruleBarItemByRule.TryGetValue(currentRule, out currentRuleBarItemPrefab)) { RuleBarItem ruleBarItemInstance = Instantiate(currentRuleBarItemPrefab, transform, false); ruleBarItemInstance.RuleDescriptionPanel = ruleDescriptionPanel; } } } } }
public void Show(RuleBarItem _targetRuleBarItem, string _titleText) { backgroundPanel.gameObject.SetActive(true); titleText.text = _titleText; transform.position = _targetRuleBarItem.transform.position; // StartCoroutine(UpdatePosition(_targetRuleBarItem)); }
private IEnumerator UpdatePosition(RuleBarItem _targetRuleBarItem) { yield return(new WaitForEndOfFrame()); Rect transformRect = GetComponent <RectTransform>().rect; Vector2 newPosition = _targetRuleBarItem.transform.position; newPosition.x -= transformRect.width; transform.position = newPosition; backgroundPanel.gameObject.SetActive(true); }