/// <summary> /// Creates a `StackableSplitter` directly on /// top of this stack and sets its parent to /// the canvas. /// </summary> /// <param name="stack">The `Stackable` to create a `StacakbleSplitter` for</param> public static void Create(Stackable stack) { GameObject stackableSplitterResource = Resources.Load(stackableSplitterPath) as GameObject; GameObject stackableSplitterObject = GameObject.Instantiate(stackableSplitterResource, stack.transform.position, Quaternion.identity) as GameObject; stackableSplitterObject.transform.SetParent(CanvasHelper.GetCanvas().transform); StackableSplitter stackableSplitter = stackableSplitterObject.GetComponent <StackableSplitter>(); stackableSplitter.Stack = stack; }
public void Start() { if (ContainerPrefab == null) { throw new MissingReferenceException("Container Parent must have a Container Prefab set."); } GameObject containerObject = GameObject.Instantiate(ContainerPrefab); containerObject.transform.SetParent(CanvasHelper.GetCanvas().transform); container = containerObject.GetComponent <Container>(); if (container == null) { throw new MissingComponentException("Container Prefab must have `Container` component attached."); } // don't show by default container.Close(); }
/// <summary> /// Create a new tooltip from passed prefab, with text as /// content, and the trigger as the bounds to appear near. /// </summary> /// <param name="prefab">The `Tooltip` prefab</param> /// <param name="text">The text to display in the tooltip</param> /// <param name="trigger">The RectTransform that triggered /// this tooltip. Will dictate where the tooltip will display /// on the canvas</param> /// <returns>The `Tooltip` that is created</returns> public static Tooltip Create(GameObject prefab, string text, RectTransform trigger) { Canvas canvas = CanvasHelper.GetCanvas(); GameObject tooltipObject = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject; tooltipObject.transform.SetParent(canvas.transform); // TODO: if the tooltip is off the screen, reposition // should this be moved elsewhere? In the tooltip itself? Vector3 newPosition = trigger.position; newPosition.x += (trigger.rect.width * canvas.scaleFactor) / 2; newPosition.y += (trigger.rect.height * canvas.scaleFactor) / 2; tooltipObject.transform.position = newPosition; Tooltip t = tooltipObject.GetComponent <Tooltip>(); t.Display(text); return(t); }