public static IEnumerable <NetInfo> Build(this INetInfoBuilder builder)
        {
            var newNetInfos = new List <NetInfo>();


            // Ground version--------------------------------------------------
            var mainInfo = builder.BuildVersion(NetInfoVersion.Ground, newNetInfos);

            mainInfo.m_UIPriority = builder.Priority;

            if (!builder.CodeName.IsNullOrWhiteSpace() && !builder.ThumbnailsPath.IsNullOrWhiteSpace())
            {
                var thumbnails = AssetManager.instance.GetThumbnails(builder.CodeName, builder.ThumbnailsPath);
                mainInfo.m_Atlas     = thumbnails;
                mainInfo.m_Thumbnail = thumbnails.name;
            }

            if (!builder.CodeName.IsNullOrWhiteSpace() && !builder.InfoTooltipPath.IsNullOrWhiteSpace())
            {
                var infoTips = AssetManager.instance.GetInfoTooltip(builder.CodeName, builder.InfoTooltipPath);
                mainInfo.m_InfoTooltipAtlas     = infoTips;
                mainInfo.m_InfoTooltipThumbnail = infoTips.name;
            }


            // Other versions -------------------------------------------------
            var mainInfoAI = mainInfo.GetComponent <RoadAI>();

            mainInfoAI.m_elevatedInfo = builder.BuildVersion(NetInfoVersion.Elevated, newNetInfos);
            mainInfoAI.m_bridgeInfo   = builder.BuildVersion(NetInfoVersion.Bridge, newNetInfos);
            mainInfoAI.m_tunnelInfo   = builder.BuildVersion(NetInfoVersion.Tunnel, newNetInfos);
            mainInfoAI.m_slopeInfo    = builder.BuildVersion(NetInfoVersion.Slope, newNetInfos);

            return(newNetInfos);
        }
Beispiel #2
0
        public static IEnumerable <NetInfo> Build(this INetInfoBuilder builder)
        {
            var newNetInfos = new List <NetInfo>();


            // Ground version--------------------------------------------------
            var mainInfo = builder.BuildVersion(NetInfoVersion.Ground, null, newNetInfos);

            mainInfo.m_UIPriority = builder.Priority;

            if (!builder.CodeName.IsNullOrWhiteSpace() && !builder.ThumbnailsPath.IsNullOrWhiteSpace())
            {
                var thumbnails = ToolsUnity.LoadThumbnails(builder.CodeName, builder.ThumbnailsPath);
                mainInfo.m_Atlas     = thumbnails;
                mainInfo.m_Thumbnail = thumbnails.name;
            }

            if (!builder.CodeName.IsNullOrWhiteSpace() && !builder.InfoTooltipPath.IsNullOrWhiteSpace())
            {
                var infoTips = ToolsUnity.LoadInfoTooltip(builder.CodeName, builder.InfoTooltipPath);
                mainInfo.m_InfoTooltipAtlas     = infoTips;
                mainInfo.m_InfoTooltipThumbnail = infoTips.name;
            }


            // Other versions -------------------------------------------------
            var mainInfoAI = mainInfo.GetComponent <RoadAI>();

            builder.BuildVersion(NetInfoVersion.Elevated, info => mainInfoAI.m_elevatedInfo = info, newNetInfos);
            builder.BuildVersion(NetInfoVersion.Bridge, info => mainInfoAI.m_bridgeInfo     = info, newNetInfos);
            builder.BuildVersion(NetInfoVersion.Tunnel, info => mainInfoAI.m_tunnelInfo     = info, newNetInfos);
            builder.BuildVersion(NetInfoVersion.Slope, info => mainInfoAI.m_slopeInfo       = info, newNetInfos);

            Debug.Log(string.Format("NExt: Initialized {0}", builder.Name));

            return(newNetInfos);
        }
        public static IEnumerable <NetInfo> Build(this INetInfoBuilder builder, ICollection <Action> lateOperations)
        {
            // Ground versions
            var groundInfo      = builder.BuildVersion(NetInfoVersion.Ground, lateOperations);
            var groundGrassInfo = builder.BuildVersion(NetInfoVersion.GroundGrass, lateOperations);
            var groundTreesInfo = builder.BuildVersion(NetInfoVersion.GroundTrees, lateOperations);

            var groundInfos = new[] { groundInfo, groundGrassInfo, groundTreesInfo };

            groundInfos = groundInfos.Where(gi => gi != null).ToArray();

            if (!groundInfos.Any())
            {
                yield break;
            }

            // Other versions
            var elevatedInfo = builder.BuildVersion(NetInfoVersion.Elevated, lateOperations);
            var bridgeInfo   = builder.BuildVersion(NetInfoVersion.Bridge, lateOperations);
            var tunnelInfo   = builder.BuildVersion(NetInfoVersion.Tunnel, lateOperations);
            var slopeInfo    = builder.BuildVersion(NetInfoVersion.Slope, lateOperations);

            // Setup MenuItems
            if (builder is IMenuItemBuilder)
            {
                if (groundInfos.Count() > 1)
                {
                    throw new Exception("Multiple netinfo menuitem cannot be build with the IMenuItemBuilder, use the IMenuItemBuildersProvider");
                }

                var mib = builder as IMenuItemBuilder;
                groundInfos[0].SetMenuItemConfig(mib);
            }
            else if (builder is IMenuItemBuildersProvider)
            {
                var mibp = builder as IMenuItemBuildersProvider;
                var mibs = mibp.MenuItemBuilders.ToDictionary(x => x.Name, StringComparer.InvariantCultureIgnoreCase);

                foreach (var mainInfo in groundInfos)
                {
                    if (mibs.ContainsKey(mainInfo.name))
                    {
                        var mib = mibs[mainInfo.name];
                        mainInfo.SetMenuItemConfig(mib);
                    }
                }
            }
            else
            {
                throw new Exception("Cannot set the menuitem on netinfo, either implement IMenuItemBuilder or IMenuItemBuildersProvider");
            }

            // Setup AI
            foreach (var mainInfo in groundInfos)
            {
                var ai = mainInfo.GetComponent <RoadAI>();

                ai.m_elevatedInfo = elevatedInfo;
                ai.m_bridgeInfo   = bridgeInfo;
                ai.m_tunnelInfo   = tunnelInfo;
                ai.m_slopeInfo    = slopeInfo;
            }

            // Returning
            foreach (var mainInfo in groundInfos)
            {
                yield return(mainInfo);
            }
            if (elevatedInfo != null)
            {
                yield return(elevatedInfo);
            }
            if (bridgeInfo != null)
            {
                yield return(bridgeInfo);
            }
            if (tunnelInfo != null)
            {
                yield return(tunnelInfo);
            }
            if (slopeInfo != null)
            {
                yield return(slopeInfo);
            }
        }