public static IEnumerable <NetInfo> BuildEmergencyFallback(this INetInfoBuilder builder)
 {
     return(builder
            .SupportedVersions
            .ToCollection()
            .Select(niv => builder.BuildEmergencyFallbackVersion(niv)));
 }
        public static NetInfo BuildVersion(this INetInfoBuilder builder, NetInfoVersion version, ICollection <Action> lateOperations)
        {
            if (builder.SupportedVersions.HasFlag(version))
            {
                var basedPrefabName = builder.GetBasedPrefabName(version);
                var builtPrefabName = builder.GetBuiltPrefabName(version);

                var info = Prefabs
                           .Find <NetInfo>(basedPrefabName)
                           .Clone(builtPrefabName);

                builder.BuildUp(info, version);

                var lateBuilder = builder as INetInfoLateBuilder;
                if (lateBuilder != null)
                {
                    lateOperations.Add(() => lateBuilder.LateBuildUp(info, version));
                }

                return(info);
            }
            else
            {
                return(null);
            }
        }
        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);
        }
        //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
        //    var swMb = new Stopwatch();
        //    swMb.Start();
        //    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");
        //    }
        //    swMb.Stop();
        //    Debug.Log($"{builder.Name} menu item built in {swMb.ElapsedMilliseconds}");
        //    // 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;
        //}

        public static NetInfo BuildVersion(this INetInfoBuilder builder, NetInfoVersion version, ICollection <Action> lateOperations)
        {
            if (builder.SupportedVersions.HasFlag(version))
            {
                var sw = new Stopwatch();
                var basedPrefabName = builder.GetBasedPrefabName(version);
                var builtPrefabName = builder.GetBuiltPrefabName(version);

                sw.Start();
                var info = Prefabs
                           .Find <NetInfo>(basedPrefabName)
                           .Clone(builtPrefabName);
                sw.Stop();
                Debug.Log($"cloned {builder.BasedPrefabName} as {builder.Name} in {sw.ElapsedMilliseconds}");
                builder.BuildUp(info, version);

                var lateBuilder = builder as INetInfoLateBuilder;
                if (lateBuilder != null)
                {
                    var swl = new Stopwatch();
                    swl.Start();
                    lateOperations.Add(() => lateBuilder.LateBuildUp(info, version));
                    swl.Stop();
                    Debug.Log($"cloned {builder.BasedPrefabName} in {swl.ElapsedMilliseconds}");
                }

                return(info);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 5
0
        private static NetInfo BuildVersion(this INetInfoBuilder builder, NetInfoVersion version, Action <NetInfo> assign, ICollection <NetInfo> holdingCollection)
        {
            if (builder.SupportedVersions.HasFlag(version))
            {
                var completePrefabName = builder.GetPrefabName(version);
                var completeName       = builder.GetNewName(version);

                var info = ToolsCSL
                           .FindPrefab <NetInfo>(completePrefabName)
                           .Clone(completeName);

                info.SetUICategory(builder.UICategory);
                builder.BuildUp(info, version);

                if (assign != null)
                {
                    assign(info);
                }

                holdingCollection.Add(info);

                return(info);
            }
            else
            {
                if (assign != null)
                {
                    assign(null);
                }
            }

            return(null);
        }
        private static NetInfo BuildEmergencyFallbackVersion(this INetInfoBuilder builder, NetInfoVersion version)
        {
            var basedPrefabName = builder.GetBasedPrefabName(version);
            var builtPrefabName = builder.GetBuiltPrefabName(version);

            return(Prefabs
                   .Find <NetInfo>(basedPrefabName)
                   .Clone(builtPrefabName));
        }
 public static string GetBasedPrefabName(this INetInfoBuilder builder, NetInfoVersion version)
 {
     if (builder is INetInfoSpecificBaseBuilder)
     {
         return(((INetInfoSpecificBaseBuilder)builder).GetSpecificBasedPrefabName(version));
     }
     else
     {
         return(NetInfos.Vanilla.GetPrefabName(builder.BasedPrefabName, version));
     }
 }
 public static string GetBuiltPrefabName(this INetInfoBuilder builder, NetInfoVersion version)
 {
     if (builder is INetInfoSpecificNameBuilder)
     {
         return(((INetInfoSpecificNameBuilder)builder).GetSpecificBuiltPrefabName(version));
     }
     else
     {
         return(NetInfos.New.GetPrefabName(builder.Name, version));
     }
 }
        private static string GetNewName(this INetInfoBuilder builder, NetInfoVersion version)
        {
            switch (version)
            {
            case NetInfoVersion.Ground:
                return(builder.Name);

            default:
                return(builder.Name + " " + version);
            }
        }
Esempio n. 10
0
        public static void DefineLocalization(this INetInfoBuilder builder, Locale locale)
        {
            locale.AddLocalizedString(new Locale.Key
            {
                m_Identifier = "NET_TITLE",
                m_Key        = builder.Name
            }, builder.Name);

            locale.AddLocalizedString(new Locale.Key()
            {
                m_Identifier = "NET_DESC",
                m_Key        = builder.Name
            }, builder.Description);
        }
        private static NetInfo BuildVersion(this INetInfoBuilder builder, NetInfoVersion version, ICollection <NetInfo> holdingCollection)
        {
            if (builder.SupportedVersions.HasFlag(version))
            {
                var completePrefabName = NetInfos.Vanilla.GetPrefabName(builder.TemplatePrefabName, version);
                var completeName       = builder.GetNewName(version);

                var info = Prefabs
                           .Find <NetInfo>(completePrefabName)
                           .Clone(completeName);

                info.SetUICategory(builder.UICategory);
                builder.BuildUp(info, version);

                holdingCollection.Add(info);

                return(info);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 12
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);
            }
        }