Пример #1
0
    /// <summary>
    /// Gets the lane asset pool.
    /// </summary>
    /// <returns>The lane asset pool.</returns>
    /// <param name="laneResType">Lane res type.</param>
    public AssetPool <Lane> GetLaneAssetPool(LaneResourceType laneResType)
    {
        switch (laneResType)
        {
        case LaneResourceType.Grass_Dark:
            return(m_grassDarkLanes);

        case LaneResourceType.Grass_Light:
            return(m_grassLightLanes);

        case LaneResourceType.Road_Single:
            return(m_roadSingleLanes);

        case LaneResourceType.Road_Bottom:
            return(m_roadBottomLanes);

        case LaneResourceType.Road_Middle:
            return(m_roadMiddleLanes);

        case LaneResourceType.Road_Top:
            return(m_roadTopLanes);

        case LaneResourceType.River:
            return(m_riverLanes);

        case LaneResourceType.Railroad:
            return(m_railroadLanes);

        default:
            return(null);
        }
    }
Пример #2
0
    /// <summary>
    /// Creates the lane asset pool.
    /// </summary>
    /// <param name="assetPool">Asset pool.</param>
    /// <param name="laneCount">Lane count.</param>
    private void CreateLaneAssetPool(ref AssetPool <Lane> assetPool, int laneCount, LaneResourceType laneResType)
    {
        // Prepare the pool
        if (assetPool == null)
        {
            // Create a new one if it hasn't been created yet
            assetPool = new AssetPool <Lane>(laneCount);
        }
        else
        {
            // Clear the pool if it already exists
            assetPool.ClearAllAssets();
            assetPool.Resize(laneCount);
        }
        // Populate the pool
        GameObject prefab = m_mapResources.GetLanePrefab(laneResType);

        for (int i = 0; i < laneCount; ++i)
        {
            GameObject newlaneObj = Instantiate <GameObject>(prefab);
            Lane       newLane    = newlaneObj.AddComponentNoDupe <Lane>();
            newLane.Initialize(m_mapManager, m_tileSize, m_activeTileCount, m_edgeTileCount, this);
            newlaneObj.transform.parent = m_lanesRoot;
            newlaneObj.SetActive(false);
            assetPool.AddAsset(newLane);
        }
    }
Пример #3
0
 /// <summary>
 /// Gets the lane prefab.
 /// </summary>
 /// <returns>The lane prefab.</returns>
 /// <param name="laneResType">Lane res type.</param>
 public GameObject GetLanePrefab(LaneResourceType laneResType)
 {
     if (laneResType == LaneResourceType.SIZE || m_loadedMapType == MapType.SIZE)
     {
         return(null);
     }
     return(m_lanePrefabs[(int)laneResType]);
 }
Пример #4
0
 /// <summary>
 /// Gets the lane prefab path.
 /// </summary>
 /// <returns>The lane prefab path.</returns>
 private string GetLanePrefabPath(LaneResourceType laneResType,
                                  MapType mapType = MapType.Default)
 {
     if (laneResType == LaneResourceType.SIZE || mapType == MapType.SIZE)
     {
         return("");
     }
     return(m_mapSkinFilePath + mapType.ToString() + m_laneFilePath + laneResType.ToString());
 }
Пример #5
0
    /// <summary>
    /// Creates a lane.
    /// </summary>
    protected override Lane CreateLane()
    {
        // Alternate between dark and light grass assets
        LaneResourceType laneResType = LaneResourceType.Grass_Dark;

        if ((Mathf.Abs(m_startRowCoord) + m_currentCount) % 2 == 1)
        {
            laneResType = LaneResourceType.Grass_Light;
        }

        Lane newLane = m_mapAssetPool.GetLaneAssetPool(laneResType).GetAsset();

        ActivateLane(newLane);
        return(newLane);
    }
    /// <summary>
    /// Creates a lane.
    /// </summary>
    protected override Lane CreateLane()
    {
        // Choose assets so road lines are properly placed
        LaneResourceType laneResType = LaneResourceType.Road_Middle;

        if (m_targetCount == 1)
        {
            laneResType = LaneResourceType.Road_Single;
        }
        else if (m_currentCount == 0)
        {
            laneResType = LaneResourceType.Road_Bottom;
        }
        else if (m_currentCount == m_targetCount - 1)
        {
            laneResType = LaneResourceType.Road_Top;
        }

        Lane newLane = m_mapAssetPool.GetLaneAssetPool(laneResType).GetAsset();

        ActivateLane(newLane);
        return(newLane);
    }
Пример #7
0
    /// <summary>
    /// Loads the lane prefabs.
    /// </summary>
    private bool LoadLanePrefabs(MapType mapType)
    {
        if (mapType == MapType.SIZE)
        {
            return(false);
        }

        string lanePath    = m_mapSkinFilePath + mapType.ToString() + m_laneFilePath;
        int    laneResSize = (int)LaneResourceType.SIZE;

        for (int i = 0; i < laneResSize; ++i)
        {
            if (m_lanePrefabs[i] != null)
            {
                // Unload previously loaded asset
                Resources.UnloadAsset(m_lanePrefabs[i]);
            }

            LaneResourceType laneResType = (LaneResourceType)i;
            m_lanePrefabs[i] = Resources.Load <GameObject>(lanePath + laneResType.ToString());
        }

        return(true);
    }