void Start() { if (this.container == null) { this.container = this.GetComponent <UIWidget>(); } if (this.table == null) { this.table = this.GetComponent <UITableExtended>(); } }
public void OnSizeChange() { if (this.widget != null && this.widget.height < this.minimumHeight) { this.widget.height = this.minimumHeight; } // We need to update the parent container anchors before updating the table if (this.widget != null) { this.widget.UpdateAnchors(); } // As we know where the table is, we could try to get it right here if (this.table == null) { this.table = this.transform.parent.GetComponent <UITableExtended>(); } // Update the table layout if (this.table != null) { this.table.Reposition(); } // After the table update we need to update the scroll view UIPanel panel = NGUITools.FindInParents <UIPanel>(this.transform); if (panel != null) { UIScrollView sv = panel.GetComponent <UIScrollView>(); if (sv != null) { // Not sure why but it seems immidiate update doesnt work, // so we'll do one with a 100 ms delay // and cancel any coroutines that within the 100 ms timeframe if (svUpdateCoroutine != null) { svUpdateCoroutine.Stop(); } svUpdateCoroutine = new UIWindow.UICoroutine(sv as MonoBehaviour, UpdateScrollView(sv)); } } }
private void _Show() { // Cleanup any attributes left, if any at all this.Cleanup(); // Bring the tooltip forward NGUITools.BringForward(this.gameObject); // Save the position where the tooltip should appear this.targetPosition = uiCamera.ScreenToWorldPoint(Input.mousePosition); // Prepare the attributes if (this.mAttributes.Count > 0 && this.attributesRowPrefab != null) { bool isLeft = true; RnMUI_Tooltip_AttributeRow lastAttrRow = null; int lastDepth = this.title.depth; // Loop the attributes foreach (AttributeInfo info in this.mAttributes) { // Force left column in case it's a signle column row if (info.singleColumnRow) { isLeft = true; } if (isLeft) { // Instantiate a prefab GameObject obj = (GameObject)Instantiate(this.attributesRowPrefab); // Apply parent obj.transform.parent = this.container.transform; // Fix position and scale obj.transform.localScale = Vector3.one; obj.transform.localPosition = Vector3.zero; obj.transform.localRotation = Quaternion.identity; // Increase the depth lastDepth = lastDepth + 1; // Apply the new depth UIWidget wgt = obj.GetComponent <UIWidget>(); if (wgt != null) { wgt.depth = lastDepth; } // Get the attribute row script referrence lastAttrRow = obj.GetComponent <RnMUI_Tooltip_AttributeRow>(); // Make some changes if it's a single column row if (info.singleColumnRow) { // Destroy the right column NGUITools.Destroy(lastAttrRow.rightLabel.gameObject); // Double the size of the label lastAttrRow.leftLabel.width *= 2; } // Check if we can set margin to the row UITable_ItemMargin margins = obj.GetComponent <UITable_ItemMargin>(); // If the row does not have the component add it if (margins == null) { margins = obj.AddComponent <UITable_ItemMargin>(); } if (margins != null) { margins.left = info.margin.left; margins.right = info.margin.right; margins.top = info.margin.top; margins.bottom = info.margin.bottom; // If this is the first or last row, apply the global attr margins if (this.mInstancedAttributesRows.Count == 0) { margins.top += this.attributesMarginTop; } else if (this.mInstancedAttributesRows.Count == (Mathf.RoundToInt((float)this.mAttributes.Count / 2f) - 1)) { margins.bottom += this.attributesMarginBottom; } } // Add it to the instanced objects list this.mInstancedAttributesRows.Add(obj); } // Check if we have a row object to work with if (lastAttrRow != null) { UILabel label = (isLeft) ? lastAttrRow.leftLabel : lastAttrRow.rightLabel; // Check if we have the label if (label != null) { // Set the label alpha label.alpha = 0f; // Set the label text label.text = info.value + info.text; // Flip is left if (!info.singleColumnRow) { isLeft = !isLeft; } } // Update the row size and depth lastAttrRow.UpdateSizeAndDepth(); } } // Clear the attributes list, we no longer need it this.mAttributes.Clear(); // Apply greater depth to the description if (this.description != null) { this.description.depth = (lastDepth + 1); } } // Update the tooltip table if (this.container != null) { UITableExtended contTable = this.container.GetComponent <UITableExtended>(); if (contTable != null) { contTable.Reposition(); } } // Fade In this.StopCoroutine("FadeOut"); this.StartCoroutine("FadeIn"); }