/// The minimal preparation for use. If these are not set ShowChildLayer() can't work. public void Initialize(ConstellationMenuRoot root, AssetTree.Node asset, float scale) { menuRoot = root; menuRoot.MarkGraphDirty(); menuNode = asset; menuScale = scale; menuOrientation = transform.rotation; menuCenter = transform.position; startPosition = transform.position; savedCameraPosition = Camera.main.transform.position; savedCameraRotation = Camera.main.transform.rotation; state = IconState.Shown; }
/// Called to make this icon visible and interactable public void Initialize(ConstellationMenuRoot root, ConstellationMenuIcon _parentMenu, AssetTree.Node node, Vector3 _menuCenter, float scale, IconState initialState) { parentMenu = _parentMenu; startPosition = transform.position; startScale = transform.localScale; menuRoot = root; menuNode = node; menuCenter = _menuCenter; savedCameraPosition = _parentMenu.savedCameraPosition; savedCameraRotation = _parentMenu.savedCameraRotation; menuOrientation = transform.rotation; // Icons are oriented up in world space. Vector3 iconToCamera = savedCameraPosition - transform.position; Quaternion rotationToCamera = Quaternion.FromToRotation(-transform.forward, iconToCamera.normalized); transform.localRotation = rotationToCamera * transform.localRotation; menuScale = scale; background = null; state = IconState.Closed; if (node != null) { // Set foreground icon menuItem = (ConstellationMenuItem)node.value; spriteRenderer.sprite = menuItem.icon; gameObject.name = menuItem.name; // Set background icon background = new GameObject(name + " Item Background"); background.transform.parent = transform.parent; background.transform.localPosition = transform.localPosition + transform.forward * BACKGROUND_ICON_ZOFFSET; background.transform.localRotation = transform.localRotation; background.transform.localScale = transform.localScale; backgroundSpriteRenderer = background.AddComponent <SpriteRenderer>(); backgroundSpriteRenderer.sprite = menuRoot.iconBackground; if (menuNode.children.Count != 0 && decorationLabelPrefab != null && menuRoot.expandableIconDecoration) { decorationLabel = Instantiate(decorationLabelPrefab, background.transform); decorationLabelRenderer = decorationLabel.GetComponent <SpriteRenderer>(); decorationLabelRenderer.sprite = menuRoot.expandableIconDecoration; decorationLabel.SetActive(false); } menuRoot.MarkGraphDirty(); float tooltipOffset; if (menuItem.tooltipSprite) { tooltip = new GameObject(name + " Tooltip Sprite"); SpriteRenderer tooltipSpriteRenderer = tooltip.AddComponent <SpriteRenderer>(); tooltipSpriteRenderer.sprite = menuItem.tooltipSprite; tooltipRenderer = tooltipSpriteRenderer; tooltip.transform.localScale *= TOOLTIP_SPRITE_SCALE; tooltipOffset = TOOLTIP_SPRITE_OFFSET; } else { tooltip = Instantiate(tooltipPrefab); tooltip.name = name + " Tooltip Text"; tooltip.GetComponent <TextMesh>().text = menuItem.toolTip.Replace('\\', '\n'); tooltipRenderer = tooltip.GetComponent <MeshRenderer>(); tooltip.transform.localScale = Vector3.one * TOOLTIP_TEXT_SCALE; tooltipOffset = TOOLTIP_TEXT_OFFSET; } tooltip.transform.SetParent(transform, false); tooltip.transform.localPosition = Vector3.up * tooltipOffset; tooltip.transform.rotation = transform.rotation; SetRendererAlpha(tooltipRenderer, DEFAULT_TOOLTIP_ALPHA); } parentMenu.childMenus.Add(this); lineToParent = GetComponent <LineRenderer>(); lineToParent.startColor = Color.clear; lineToParent.endColor = Color.clear; UpdateLines(); SetDecorationLabelAlpha(decorationLabelAlpha.ValueAtTime(Time.time)); SetBackgroundTransparency(iconBgAlpha.ValueAtTime(Time.time)); SetRendererAlpha(spriteRenderer, iconAlpha.ValueAtTime(Time.time)); StartFade(initialState); SetColliderSize(0.0f); }