Example #1
0
    /// <summary>
    /// Replaces a grid square with a new one from a prefab.
    /// </summary>
    /// <param name="prefab">Prefab.</param>
    /// <param name="squareData">Square data.</param>
    /// <param name="x">The x coordinate.</param>
    /// <param name="y">The y coordinate.</param>
    /// <param name="attributes">Attributes.</param>
    public void ReplaceSquare(PlatformSquare prefab, PlatformSquareData squareData, int x, int y, Dictionary <string, string> attributes)
    {
        if (m_grid [x, y] != null)
        {
            m_grid [x, y].OnRemoveFromLevel(this, new GridCoord(x, y));
            Destroy(m_grid [x, y].gameObject);
        }

        m_grid [x, y] = Instantiate <PlatformSquare> (prefab, this.transform);
        m_grid [x, y].InitializeSquareData(squareData);
        m_grid [x, y].name         = "Grid (" + x + ", " + y + ")";
        m_grid [x, y].Grid         = this;
        m_grid [x, y].GridPosition = new GridCoord(x, y);
        m_grid [x, y].InitializeFromStringAttributes(attributes);

        m_grid [x, y].OnAddToLevel(this, new GridCoord(x, y));
    }
Example #2
0
    // Use this for initialization
    void Start()
    {
        m_grid = FindObjectOfType <LevelGrid> ();
        if (!m_grid)
        {
            Debug.LogError("Unable to start LevelBuilder properly: Couldn't find LevelGrid instance in the scene.");
        }

        m_squareTypes = new List <PlatformSquare> ();
        m_squareTypes.Add(emptyPlatformSquarePrefab);
        m_squareTypes.Add(solidPlatformSquarePrefab);
        m_squareTypes.Add(winPlatformSquarePrefab);
        m_squareTypes.Add(toggleTriggerPlatformSquare);
        m_squareTypes.Add(triggeredPlatformSquare);
        m_squareTypes.Add(disappearingSquare);
        m_squareTypes.Add(warpSquare);
        m_squareTypes.Add(lightSwitchSquare);

        PlatformSquareData emptySquareData         = Resources.Load <PlatformSquareData> ("Platform Squares/Empty Square Prototype");
        PlatformSquareData solidPlatformData       = Resources.Load <PlatformSquareData> ("Platform Squares/Solid Platform Prototype");
        PlatformSquareData winSquareData           = Resources.Load <PlatformSquareData> ("Platform Squares/Win Platform Prototype");
        PlatformSquareData toggleTriggerSquareData = Resources.Load <PlatformSquareData> ("Platform Squares/Toggle Trigger Prototype");
        PlatformSquareData triggeredSquareData     = Resources.Load <PlatformSquareData> ("Platform Squares/Triggered Platform Prototype");
        PlatformSquareData disappearingSquareData  = Resources.Load <PlatformSquareData>("Platform Squares/Disappearing Square Prototype");
        PlatformSquareData warpSquareData          = Resources.Load <PlatformSquareData>("Platform Squares/Warp Square Prototype");
        PlatformSquareData lightSwitchSquareData   = Resources.Load <PlatformSquareData> ("Platform Squares/Light Switch Prototype");

        m_squareData = new List <PlatformSquareData> ();
        m_squareData.Add(emptySquareData);
        m_squareData.Add(solidPlatformData);
        m_squareData.Add(winSquareData);
        m_squareData.Add(toggleTriggerSquareData);
        m_squareData.Add(triggeredSquareData);
        m_squareData.Add(disappearingSquareData);
        m_squareData.Add(warpSquareData);
        m_squareData.Add(lightSwitchSquareData);
    }
 public void InitializeSquareData(PlatformSquareData data)
 {
     this.GetComponent <SpriteRenderer> ().sprite = data.sprite;
 }