123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- //================================================================================
- //
- //================================================================================
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- //================================================================================
- //
- //================================================================================
- namespace ReaderRabbit
- {
- //================================================================================
- //
- //================================================================================
- public class SandwichIngredientsColumn : MonoBehaviour
- {
- //================================================================================
- //
- //================================================================================
- [SerializeField]
- private int m_Offset = 5;
- [SerializeField] private int m_MaxNumberOfIngredients = 10;
- private int m_NumberOfIngredients;
- private BoxCollider2D m_BoxCollider;
- private SandwichManager m_Owner;
- private List<SpriteRenderer> m_Ingredients;
- //================================================================================
- //
- //================================================================================
- void Start()
- {
- this.m_Owner = this.transform.parent.GetComponent<SandwichManager>();
- this.m_BoxCollider = (BoxCollider2D)this.GetComponent<Collider2D>();
- this.m_Ingredients = new List<SpriteRenderer>();
- }
- //================================================================================
- //
- //================================================================================
- public bool AddIngredient(GameObject ingredient)
- {
- if (m_NumberOfIngredients < m_MaxNumberOfIngredients)
- {
- ingredient.transform.position = GetNextItemPosition(ingredient);
- m_Ingredients.Add(ingredient.GetComponent<SpriteRenderer>());
- m_NumberOfIngredients++;
- return true;
- }
- else
- {
- // TODO: Play feedback
- }
- return false;
- }
- //================================================================================
- //
- //================================================================================
- private Vector2 GetNextItemPosition(GameObject ingredient)
- {
- Vector2 position = new Vector2(
- this.m_BoxCollider.offset.x - this.m_BoxCollider.size.x / 2 - ingredient.GetComponent<SpriteRenderer>().bounds.size.x / 2,
- this.m_BoxCollider.offset.y - this.m_BoxCollider.size.y / 2 + ingredient.GetComponent<SpriteRenderer>().bounds.size.y);
-
- position.y += m_NumberOfIngredients * m_Offset;
-
- return position;
- }
- //================================================================================
- //
- //================================================================================
- public void ClearIngredients()
- {
- m_Ingredients.Clear();
- }
- //================================================================================
- //
- //================================================================================
- public float GetIngredientsHeight()
- {
- float height = 0;
-
- foreach (SpriteRenderer sprite in m_Ingredients)
- {
- //height += sprite.bounds.extents.y;
- height = sprite.bounds.extents.y;
- }
-
- return height;
- }
- //================================================================================
- //
- //================================================================================
- public void Reset()
- {
- m_NumberOfIngredients = 0;
- foreach (SpriteRenderer sprite in m_Ingredients)
- {
- GameObject.Destroy(sprite.gameObject);
- }
- m_Ingredients.Clear();
- }
- } // public class SandwichIngredientsColumn : MonoBehaviour
- } // namespace ReaderRabbit
|