Exemple #1
0
        /// <summary>
        /// Returns true if otherStack can be stacked
        /// onto this stack
        /// </summary>
        /// <param name="otherStack">The `Stackable` that may or may not
        /// be able to be stacked</param>
        /// <returns>True if passed `Stackable` can be stacked
        /// on this `Stackable`</returns>
        public bool CanStack(Stackable otherStack)
        {
            if (otherStack.GetType() != GetType()) {
                return false;
            }

            if (Size() >= max - 1 || Size() + otherStack.Size() >= max - 1) {
                return false;
            }

            return true;
        }
Exemple #2
0
        /// <summary>
        /// Returns true if otherStack can be stacked
        /// onto this stack
        /// </summary>
        /// <param name="otherStack">The `Stackable` that may or may not
        /// be able to be stacked</param>
        /// <returns>True if passed `Stackable` can be stacked
        /// on this `Stackable`</returns>
        public bool CanStack(Stackable otherStack)
        {
            if (otherStack.GetType() != GetType())
            {
                return(false);
            }

            if (Size() >= max - 1 || Size() + otherStack.Size() >= max - 1)
            {
                return(false);
            }

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Add an item to this stack.If a `Stackable` item
        /// is added that has several children, will iterate
        /// through the children first and add them. Then,
        /// it will add the container of the stack. 
        /// If the size of both stacks is larger than the max
        /// allowed, will throw a `NotStackableException`.
        /// </summary>
        /// <param name="stackable">The `Stackable` item to stack</param>
        public void Add(Stackable stackable)
        {
            if (stackable.GetType() != GetType()) {
                throw new NotStackableException("Unable to stack, these items are not of the same type");
            }

            if (Size() >= max - 1 || Size() + stackable.Size() >= max - 1) {
                throw new NotStackableException("Unable to stack: " + this + " with " + stackable);
            }

            foreach(Stackable s in stackable.Stack) {
                Add(s);
            }

            stackable.transform.SetParent(transform);
            stackable.gameObject.SetActive(false);
            stackable.Stack.Clear();
            Stack.Add(stackable);
            UpdateCountLabel();
        }
Exemple #4
0
        /// <summary>
        /// Add an item to this stack.If a `Stackable` item
        /// is added that has several children, will iterate
        /// through the children first and add them. Then,
        /// it will add the container of the stack.
        /// If the size of both stacks is larger than the max
        /// allowed, will throw a `NotStackableException`.
        /// </summary>
        /// <param name="stackable">The `Stackable` item to stack</param>
        public void Add(Stackable stackable)
        {
            if (stackable.GetType() != GetType())
            {
                throw new NotStackableException("Unable to stack, these items are not of the same type");
            }

            if (Size() >= max - 1 || Size() + stackable.Size() >= max - 1)
            {
                throw new NotStackableException("Unable to stack: " + this + " with " + stackable);
            }

            foreach (Stackable s in stackable.Stack)
            {
                Add(s);
            }

            stackable.transform.SetParent(transform);
            stackable.gameObject.SetActive(false);
            stackable.Stack.Clear();
            Stack.Add(stackable);
            UpdateCountLabel();
        }