Exemplo n.º 1
0
        public void SpawnObject(GameObject prefab)
        {
            prefab.SetActive(false);
            GameObject instance = Instantiate <GameObject>(prefab, Vector3.zero, Quaternion.identity, transform);

            if (instance.transform is RectTransform)
            {
                RectTransform rect       = instance.transform as RectTransform;
                RectTransform parentRect = GetComponentInParent <RectTransform>();
                if (parentRect != null)
                {
                    rect.transform.localPosition = Vector3.zero;
                    rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, parentRect.rect.width);
                    rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, parentRect.rect.height);
                }
            }
            prefab.SetActive(true);

            GameObjectStackElement element = instance.GetComponent <GameObjectStackElement>();

            if (element == null)
            {
                element = instance.AddComponent <GameObjectStackElement>();
            }

            stack.Add(element);

            instance.SetActive(true);
        }
Exemplo n.º 2
0
        public void PopTopElement()
        {
            if (stack.Count == 0)
            {
                return;
            }
            GameObjectStackElement instance = stack[stack.Count - 1];

            stack.RemoveAt(stack.Count - 1);
            Destroy(instance.gameObject);
        }
Exemplo n.º 3
0
        public void HandleCloseButtonClicked()
        {
            GameObjectStackElement element = GetComponentInParent <GameObjectStackElement>();

            GameObjectStack stack = element.GetComponentInParent <GameObjectStack>();

            if (stack.stack.Count > 0 && stack.stack[stack.stack.Count - 1] == element)
            {
                stack.PopTopElement();
                if (onCloseClicked != null)
                {
                    onCloseClicked.Invoke();
                }
            }
        }
        void FindStack()
        {
            Transform elementSearchObj = transform;
            Transform stackSearchObj   = elementSearchObj.parent;

            while (stack == null && stackSearchObj != null)
            {
                GameObjectStack foundStack = stackSearchObj.GetComponent <GameObjectStack>();
                if (foundStack != null && (string.IsNullOrEmpty(stackId) || stackId == foundStack.id))
                {
                    stack   = foundStack;
                    element = elementSearchObj.GetComponent <GameObjectStackElement>();
                    return;
                }

                elementSearchObj = stackSearchObj;
                stackSearchObj   = elementSearchObj.parent;
            }
        }
Exemplo n.º 5
0
        public void RemoveElement(GameObject element)
        {
            if (element == null)
            {
                return;
            }
            GameObjectStackElement instance = element.GetComponent <GameObjectStackElement>();

            if (instance == null)
            {
                return;
            }
            int index = stack.FindIndex(se => se == instance);

            if (index != -1)
            {
                stack.RemoveAt(index);
                Destroy(instance.gameObject);
            }
        }