Exemplo n.º 1
0
    public static MathBlock Instantiate(MathItemType type, Color bgColor, Transform parent)
    {
        var loadedResource = ResourceLoader.LoadMathItemPrefab(type, bgColor);

        if (!loadedResource)
        {
            return(null);
        }

        var mathBlock = Instantiate(loadedResource, parent)?.GetComponent <MathBlock>();

        if (!mathBlock)
        {
            return(null);
        }

        mathBlock.GetComponent <SpriteRenderer>().color = bgColor;
        mathBlock.Type = type;

        return(mathBlock);
    }
Exemplo n.º 2
0
    public static GameObject LoadMathItemPrefab(MathItemType type, Color bgColor)
    {
        string prefabName;

        switch (type)
        {
        case MathItemType.Zero:
            prefabName = "0";
            break;

        case MathItemType.One:
            prefabName = "1";
            break;

        case MathItemType.Two:
            prefabName = "2";
            break;

        case MathItemType.Three:
            prefabName = "3";
            break;

        case MathItemType.Four:
            prefabName = "4";
            break;

        case MathItemType.Five:
            prefabName = "5";
            break;

        case MathItemType.Six:
            prefabName = "6";
            break;

        case MathItemType.Seven:
            prefabName = "7";
            break;

        case MathItemType.Eight:
            prefabName = "8";
            break;

        case MathItemType.Nine:
            prefabName = "9";
            break;

        case MathItemType.Plus:
            prefabName = "plus";
            break;

        case MathItemType.Minus:
            prefabName = "minus";
            break;

        case MathItemType.Division:
            prefabName = "division";
            break;

        case MathItemType.Multiply:
            prefabName = "multiply";
            break;

        default:
            Debug.Log("wrong type for instantiating shape");
            return(null);
        }

        var prefabFullName = string.Format("Prefabs/MathItems/{0}", prefabName);

        return(Resources.Load <GameObject>(prefabName));
    }
Exemplo n.º 3
0
 public static MathBlock InstantiateRandomMathBlock(MathItemType type, Color bgColor, Transform parent)
 {
     return(Instantiate(type, bgColor, parent));
 }