コード例 #1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (!other.TryGetComponent <IngredientInitializer>(out IngredientInitializer collidingIngredient))
        {
            return;
        }
        if (!collidingIngredient.Detector.TryGetComponent <Mergable>(out Mergable mergableIngredient))
        {
            return;
        }

        IngredientData.IngredientType collidingType = mergableIngredient.type;
        foreach (Mergable alreadyCollidingIngredient in alreadyCollidingIngredients)
        {
            IngredientData.IngredientType alreadyCollidingType = alreadyCollidingIngredient.type;
            if (alreadyCollidingType != type &&
                collidingType != type &&
                alreadyCollidingType != collidingType)
            {
                canGeneratePlanet = true;
                Mergable[] ingredients = new Mergable[] { mergableIngredient, alreadyCollidingIngredient, this };
                foreach (Mergable ingredient in ingredients)
                {
                    switch (ingredient.type)
                    {
                    case IngredientData.IngredientType.SOLID:
                        this.ingredients.Add(IngredientData.IngredientType.SOLID, ingredient);
                        break;

                    case IngredientData.IngredientType.LIQUID:
                        this.ingredients.Add(IngredientData.IngredientType.LIQUID, ingredient);
                        break;

                    default:
                        this.ingredients.Add(IngredientData.IngredientType.GASEOUS, ingredient);
                        break;
                    }
                }
                break;
            }
        }
        if (canGeneratePlanet)
        {
            HandleGeneration();
        }
        else
        {
            alreadyCollidingIngredients.Add(mergableIngredient);
        }
    }
コード例 #2
0
 public void Init(IngredientData.IngredientType type, float detectionZoneFactor,
                  IngredientData.NameElements namingElements, Sprite surface, Texture2D pattern,
                  Color[] colors, Sprite extra, IngredientInitializer ingredient, GameObject gameManager, Canvas canvas, Camera mainCamera)
 {
     this.type = type;
     this.detectionZoneFactor = detectionZoneFactor;
     this.namingElements      = namingElements;
     this.surface             = surface;
     this.pattern             = pattern;
     this.colors      = colors;
     this.extra       = extra;
     this.ingredient  = ingredient;
     this.gameManager = gameManager;
     this.canvas      = canvas;
     this.mainCamera  = mainCamera;
 }