public void Update()
 {
     if (_isInitialized)
     {
         return;
     }
     try
     {
         if (!SimulationManager.exists || (SimulationManager.instance.m_metaData == null))
         {
             return;
         }
         if (SimulationManager.instance.m_metaData.m_updateMode != SimulationManager.UpdateMode.LoadAsset &&
             SimulationManager.instance.m_metaData.m_updateMode != SimulationManager.UpdateMode.NewAsset)
         {
             _isInitialized = true;
             Destroy(this);
         }
         var parent = GameObject.Find(SimulationManager.instance.m_metaData.m_environment + " Collections");
         foreach (var t in from Transform t in parent.transform where t.name == "Common" select t)
         {
             t.gameObject.GetComponent <PropCollection>();
         }
     }
     catch (Exception)
     {
         return;
     }
     Loading.QueueLoadingAction(() =>
     {
         InitializeImpl();
         PrefabCollection <PropInfo> .InitializePrefabs("Advanced Buildings Editor", _customPrefabs.Values.ToArray(), null);
     });
     _isInitialized = true;
 }
Ejemplo n.º 2
0
 public void Update()
 {
     if (_isInitialized)
     {
         return;
     }
     try
     {
         var parent = GameObject.Find(SimulationManager.instance.m_metaData.m_environment + " Collections");
         foreach (var t in from Transform t in parent.transform where t.name == "Public Transport" select t)
         {
             t.gameObject.GetComponent <NetCollection>();
         }
     }
     catch (Exception)
     {
         return;
     }
     Loading.QueueLoadingAction(() =>
     {
         InitializeImpl();
         PrefabCollection <NetInfo> .InitializePrefabs("Rail Extensions", _customPrefabs.Values.ToArray(), null);
     });
     _isInitialized = true;
 }
Ejemplo n.º 3
0
        internal void PropTreeTrailerImpl(string packageName, Package.Asset data)
        {
            try
            {
                string name = AssetName(data.name);
                LoadingManager.instance.m_loadingProfilerCustomAsset.BeginLoading(name);
                // CODebugBase<LogChannel>.Log(LogChannel.Modding, string.Concat("Loading custom asset ", assetMetaData.name, " from ", asset));

                GameObject go = data.Instantiate <GameObject>();
                go.name = packageName + "." + go.name;
                go.SetActive(false);
                PrefabInfo info = go.GetComponent <PrefabInfo>();
                info.m_isCustomContent = true;

                if (info.m_Atlas != null && info.m_InfoTooltipThumbnail != null && info.m_InfoTooltipThumbnail != string.Empty && info.m_Atlas[info.m_InfoTooltipThumbnail] != null)
                {
                    info.m_InfoTooltipAtlas = info.m_Atlas;
                }

                PropInfo pi = go.GetComponent <PropInfo>();

                if (pi != null)
                {
                    if (pi.m_lodObject != null)
                    {
                        pi.m_lodObject.SetActive(false);
                    }

                    PrefabCollection <PropInfo> .InitializePrefabs("Custom Assets", pi, null);

                    propsCount++;
                }

                TreeInfo ti = go.GetComponent <TreeInfo>();

                if (ti != null)
                {
                    PrefabCollection <TreeInfo> .InitializePrefabs("Custom Assets", ti, null);

                    treeCount++;
                }

                // Trailers, this way.
                VehicleInfo vi = go.GetComponent <VehicleInfo>();

                if (vi != null)
                {
                    PrefabCollection <VehicleInfo> .InitializePrefabs("Custom Assets", vi, null);

                    if (vi.m_lodObject != null)
                    {
                        vi.m_lodObject.SetActive(false);
                    }
                }
            }
            finally
            {
                LoadingManager.instance.m_loadingProfilerCustomAsset.EndLoading();
            }
        }
 public void Update()
 {
     if (OptionsWrapper <Options> .Options.ghostMode)
     {
         //return;
     }
     if (_isInitialized)
     {
         return;
     }
     try
     {
         var parent = GameObject.Find(SimulationManager.instance.m_metaData.m_environment + " Collections");
         foreach (var t in from Transform t in parent.transform where t.name == "Public Transport" select t)
         {
             t.gameObject.GetComponent <NetCollection>();
         }
     }
     catch (Exception)
     {
         return;
     }
     Loading.QueueLoadingAction(() =>
     {
         InitializeNetInfoImpl();
         PrefabCollection <NetInfo> .InitializePrefabs("Metro Extensions", _customNetInfos.Values.ToArray(), null);
         //PrefabCollection<BuildingInfo>.InitializePrefabs("Metro Building Extensions", _customBuildingInfos.Values.ToArray(), null);
         //PrefabCollection<BuildingInfo>.BindPrefabs();
     });
     _isInitialized = true;
 }
Ejemplo n.º 5
0
        private static void AddNetInfo()
        {
            NetInfo info = CreateMetroTrack();

            PrefabCollection <NetInfo> .InitializePrefabs("URS", info, null);

            PrefabCollection <NetInfo> .BindPrefabs();
        }
Ejemplo n.º 6
0
            private static void InstallPropInfos(RExModule host)
            {
                var newInfos = new List <PropInfo>();

                var piBuilders = host.Parts
                                 .OfType <IPrefabBuilder <PropInfo> >()
                                 .WhereActivated()
                                 .ToArray();

                foreach (var piBuilder in piBuilders)
                {
                    var       builder = piBuilder;
                    Stopwatch sw      = new Stopwatch();
                    Loading.QueueAction(() =>
                    {
                        try
                        {
                            sw.Start();
                            newInfos.Add(builder.Build());
                            sw.Stop();
                            Debug.Log(string.Format("REx: Prop {0} installed in {1}ms", builder.Name, sw.ElapsedMilliseconds));
                        }
                        catch (Exception ex)
                        {
                            Debug.Log(string.Format("REx: Crashed-Prop builder {0}", builder.Name));
                            Debug.Log("REx: " + ex.Message);
                            Debug.Log("REx: " + ex.ToString());

                            Debug.Log(string.Format("REx: Fallbacking-Prop builder {0}", builder.Name));
                            try
                            {
                                newInfos.Add(builder.BuildEmergencyFallback());
                            }
                            catch (Exception exFallback)
                            {
                                Debug.Log(string.Format("REx: Crashed-Fallback Prop builder {0}", builder.Name));
                                Debug.Log("REx: " + exFallback.Message);
                                Debug.Log("REx: " + exFallback.ToString());
                            }
                        }
                    });
                }

                Loading.QueueAction(() =>
                {
                    var props  = host._props = host._container.AddComponent <PropCollection>();
                    props.name = REX_PROPCOLLECTION;
                    if (newInfos.Count > 0)
                    {
                        props.m_prefabs = newInfos.ToArray();
                        PrefabCollection <PropInfo> .InitializePrefabs(props.name, props.m_prefabs, new string[] { });
                        PrefabCollection <PropInfo> .BindPrefabs();
                    }
                });
            }
Ejemplo n.º 7
0
        void BuildingVehicleImpl(string packageName, Package.Asset data, bool wanted)
        {
            try
            {
                string name = AssetName(data.name);
                LoadingManager.instance.m_loadingProfilerCustomAsset.BeginLoading(name);
                // CODebugBase<LogChannel>.Log(LogChannel.Modding, string.Concat("Loading custom asset ", assetMetaData.name, " from ", asset));

                loadedAsset = data;
                GameObject go = data.Instantiate <GameObject>();
                go.name = packageName + "." + go.name;
                go.SetActive(false);
                PrefabInfo info = go.GetComponent <PrefabInfo>();
                info.m_isCustomContent = true;

                if (info.m_Atlas != null && info.m_InfoTooltipThumbnail != null && info.m_InfoTooltipThumbnail != string.Empty && info.m_Atlas[info.m_InfoTooltipThumbnail] != null)
                {
                    info.m_InfoTooltipAtlas = info.m_Atlas;
                }

                BuildingInfo bi = go.GetComponent <BuildingInfo>();

                if (bi != null)
                {
                    if (bi.m_lodObject != null)
                    {
                        bi.m_lodObject.SetActive(false);
                    }

                    PrefabCollection <BuildingInfo> .InitializePrefabs("Custom Assets", bi, null);

                    bi.m_dontSpawnNormally = !wanted;
                    buildingsCount++;
                }

                VehicleInfo vi = go.GetComponent <VehicleInfo>();

                if (vi != null)
                {
                    PrefabCollection <VehicleInfo> .InitializePrefabs("Custom Assets", vi, null);

                    if (vi.m_lodObject != null)
                    {
                        vi.m_lodObject.SetActive(false);
                    }

                    vehicleCount++;
                }
            }
            finally
            {
                loadedAsset = null;
                LoadingManager.instance.m_loadingProfilerCustomAsset.EndLoading();
            }
        }
        public static IEnumerator InitializeAndBindClones()
        {
            yield return(null);

            PrefabCollection <PropInfo> .InitializePrefabs("NTC Prop", Mod.cloneMap.Select((KeyValuePair <PropInfo, PropInfo> k) => k.Key).ToArray(), null);

            yield return(null);

            PrefabCollection <PropInfo> .BindPrefabs();

            yield return(null);
        }
        private static void InitializeNewRoads(NetCollection newRoads)
        {
            Loading.QueueAction(() =>
            {
                Debug.Log("NExt: Build NetworkExtensions");


                // Builders -----------------------------------------------------------------------
                var newInfos = new List <NetInfo>();

                foreach (var builder in Mod.NetInfoBuilders)
                {
                    try
                    {
                        newInfos.AddRange(builder.Build());
                    }
                    catch (Exception ex)
                    {
                        Debug.Log(string.Format("NExt: Crashed-Network builders {0}", builder));
                        Debug.Log("NExt: " + ex.Message);
                        Debug.Log("NExt: " + ex.ToString());
                    }
                }

                if (newInfos.Count > 0)
                {
                    newRoads.m_prefabs = newInfos.ToArray();

                    PrefabCollection <NetInfo> .InitializePrefabs(newRoads.name, newRoads.m_prefabs, new string[] { });
                    PrefabCollection <NetInfo> .BindPrefabs();
                }


                // Modifiers ----------------------------------------------------------------------
                foreach (var modifier in Mod.NetInfoModifiers)
                {
                    try
                    {
                        modifier.ModifyExistingNetInfo();
                    }
                    catch (Exception ex)
                    {
                        Debug.Log(string.Format("NExt: Crashed-Network modifiers {0}", modifier));
                        Debug.Log("NExt: " + ex.Message);
                        Debug.Log("NExt: " + ex.ToString());
                    }
                }

                Debug.Log("NExt: Finished installing components");
            });
        }
        private static void PostInitializeHook(BuildingInfo prefab)
        {
            if (!isGrowable || prefab != previousPrefab)
            {
                return;
            }
            var prefabVariations = Singleton <BuildingVariationManager> .instance.CreateVariations(prefab).Values.ToArray <BuildingInfo>();

            if (prefabVariations.Length > 0)
            {
                PrefabCollection <BuildingInfo> .InitializePrefabs("BetterUpgrade", prefabVariations, null);
            }
            //Debugger.Log("InitializePrefab done:   " + this.name);
        }
Ejemplo n.º 11
0
        void Initialize <T>(T info) where T : PrefabInfo
        {
            string fullName     = info.gameObject.name;
            string brokenAssets = LoadingManager.instance.m_brokenAssets;

            PrefabCollection <T> .InitializePrefabs("Custom Assets", info, null);

            LoadingManager.instance.m_brokenAssets = brokenAssets;

            if (CustomDeserializer.FindLoaded <T>(fullName) == null)
            {
                throw new Exception(string.Concat(typeof(T).Name, " ", fullName, " failed"));
            }
        }
Ejemplo n.º 12
0
        public void Update()
        {
            if (!_isInitialized)
            {
                RadioContentCollection collection = Resources.FindObjectsOfTypeAll <RadioContentCollection>().FirstOrDefault();

                if (collection != null && collection.isActiveAndEnabled)
                {
                    Loading.QueueLoadingAction(() =>
                    {
                        InitializeImpl();
                        PrefabCollection <RadioContentInfo> .InitializePrefabs("CSLMusicContent ", _customPrefabs.Values.ToArray(), null);
                    });
                    _isInitialized = true;
                }
            }
        }
Ejemplo n.º 13
0
        private static PropInfo Clone(PropInfo prop, Flag modification, bool isWall)
        {
            var gameObject = GameObject.Find("MoreFlags") ?? new GameObject("MoreFlags");
            var collection = gameObject.GetComponent <FlagsCollection>() ?? gameObject.AddComponent <FlagsCollection>();
            var instance   = Object.Instantiate(prop.gameObject);
            var clone      = instance.GetComponent <PropInfo>();
            var name       = $"{prop.name}_{modification.id}";

            clone.name                = name;
            instance.name             = name;
            instance.transform.parent = gameObject.transform;

            clone.m_lodObject = Object.Instantiate(prop.m_lodObject);
            clone.m_lodObject.transform.parent = instance.transform;
            clone.m_lodObject.name             = prop.m_lodObject.name + $"_{modification.id}";
            var renderer = clone.m_lodObject.GetComponent <MeshRenderer>();

            Object.DestroyImmediate(renderer);
            renderer          = clone.m_lodObject.AddComponent <MeshRenderer>();
            renderer.material = new Material(prop.m_lodObject.GetComponent <Renderer>().sharedMaterial)
            {
                mainTexture = modification.textureLod,
                name        = $"{prop.m_lodObject.GetComponent<Renderer>().sharedMaterial.name}_{modification.id}"
            };

            SetupMainMaterial(prop, modification, clone);
            SetupLodMaterial(prop, modification, clone);

            clone.m_placementStyle   = ItemClass.Placement.Manual;
            clone.m_createRuining    = false;
            clone.m_Atlas            = Atlas;
            clone.m_InfoTooltipAtlas = Atlas;
            var thumb = isWall ? modification.thumbWall : modification.thumb;

            if (thumb != null)
            {
                clone.m_Thumbnail            = thumb.name;
                clone.m_InfoTooltipThumbnail = thumb.name;
            }

            PrefabCollection <PropInfo> .InitializePrefabs("MoreFlags", new[] { clone }, null);

            AddLocale(modification, isWall, name);
            collection.flags.Add(clone);
            return(clone);
        }
Ejemplo n.º 14
0
        public static void CopyInfo(this BuildingInfo oldInfo, string newName)
        {
            int prefabCount = PrefabCollection <BuildingInfo> .LoadedCount();

            if (++prefabCount <= Data.MAX_UNIQUE_COUNT)
            {
                BuildingInfo newInfo = Instantiate(oldInfo);

                newInfo.gameObject.name = newName;
                newInfo.gameObject.SetActive(false);

                PrefabCollection <BuildingInfo> .InitializePrefabs("Custom Assets", newInfo, null);
            }
            else
            {
                throw new Exception("Maximum number of prefab instances reached!");
            }
        }
Ejemplo n.º 15
0
        public void Update()
        {
            if (!_isInitialized)
            {
                // Wait until the game got its radio channels.
                // Then we can inject our custom channels.
                RadioChannelCollection collection = Resources.FindObjectsOfTypeAll <RadioChannelCollection>().FirstOrDefault();

                if (collection != null && collection.isActiveAndEnabled)
                {
                    Loading.QueueLoadingAction(() =>
                    {
                        InitializeImpl();
                        PrefabCollection <RadioChannelInfo> .InitializePrefabs("CSLMusicChannel ", _customPrefabs.Values.ToArray(), null);
                    });
                    _isInitialized = true;
                }
            }
        }
 public void Update()
 {
     if (_isInitialized)
     {
         return;
     }
     try
     {
         var parent = GameObject.Find("Expansion 2");
         parent.GetComponent <NetCollection>();
     }
     catch (Exception)
     {
         return;
     }
     Loading.QueueLoadingAction(() =>
     {
         InitializeImpl();
         PrefabCollection <NetInfo> .InitializePrefabs("Rail Extensions", _customPrefabs.Values.ToArray(), null);
     });
     _isInitialized = true;
 }
Ejemplo n.º 17
0
        public static void PostInitializeHook(BuildingInfo __instance, State __state)
        {
            try
            {
                if (!__state.isGrowable || !__state.prefixSuccess)
                {
                    return;
                }

                var prefabVariations = Singleton <BuildingVariationManager> .instance.CreateVariations(__instance).Values
                                       .ToArray <BuildingInfo>();

                if (prefabVariations.Length > 0)
                {
                    PrefabCollection <BuildingInfo> .InitializePrefabs("BetterUpgrade", prefabVariations, null);
                }
                //Debugger.Log("InitializePrefab done:   " + this.name);
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogException(e);
            }
        }
Ejemplo n.º 18
0
        public new virtual void InitializePrefab()
        {
            bool growable = this.m_class.GetZone() != ItemClass.Zone.None;

            if (growable)
            {
                //Debugger.Log("InitializePrefab called: " + this.name);
            }

            RedirectionHelper.RevertRedirect(_InitializePrefab_original, _InitializePrefab_state);
            base.InitializePrefab();
            RedirectionHelper.RedirectCalls(_InitializePrefab_original, _InitializePrefab_detour);

            if (growable)
            {
                var prefabVariations = Singleton <BuildingVariationManager> .instance.CreateVariations(this).Values.ToArray <BuildingInfo>();

                if (prefabVariations.Length > 0)
                {
                    PrefabCollection <BuildingInfo> .InitializePrefabs("BetterUpgrade", prefabVariations, null);
                }
                //Debugger.Log("InitializePrefab done:   " + this.name);
            }
        }
        private void CreateBuildingInfo(string newBuildingInfoName, BuildingInfo originalBuildingInfo, Action <BuildingInfo> setupAction = null)
        {
            if (originalBuildingInfo == null)
            {
                Debug.LogErrorFormat("AbstractInitializer#CreatePrefab - Prefab '{0}' not found (required for '{1}')", originalBuildingInfo.name, newBuildingInfoName);
                return;
            }
            if (_customBuildingInfos.ContainsKey(newBuildingInfoName))
            {
                return;
            }
            var newPrefab = Util.ClonePrefab(originalBuildingInfo, newBuildingInfoName, transform);

            if (newPrefab == null)
            {
                Debug.LogErrorFormat("AbstractInitializer#CreatePrefab - Couldn't make prefab '{0}'", newBuildingInfoName);
                return;
            }

            setupAction?.Invoke(newPrefab);
            _customBuildingInfos.Add(newBuildingInfoName, newPrefab);
            Debug.Log("Prefab Made: " + newPrefab.name);
            PrefabCollection <BuildingInfo> .InitializePrefabs("Metro Building Extensions", newPrefab, null);
        }
Ejemplo n.º 20
0
        internal void LoadImpl(string fullName, Package.Asset assetRef, bool spawnNormally = true)
        {
            try
            {
                stack.Push(fullName);
                LoadingManager.instance.m_loadingProfilerCustomAsset.BeginLoading(AssetName(assetRef.name));
                GameObject go = assetRef.Instantiate <GameObject>();
                go.name = fullName;
                go.SetActive(false);
                PrefabInfo info = go.GetComponent <PrefabInfo>();
                info.m_isCustomContent = true;

                if (info.m_Atlas != null && !string.IsNullOrEmpty(info.m_InfoTooltipThumbnail) && info.m_Atlas[info.m_InfoTooltipThumbnail] != null)
                {
                    info.m_InfoTooltipAtlas = info.m_Atlas;
                }

                PropInfo pi = go.GetComponent <PropInfo>();

                if (pi != null)
                {
                    if (pi.m_lodObject != null)
                    {
                        pi.m_lodObject.SetActive(false);
                    }

                    if (loadedProps.Add(fullName))
                    {
                        PrefabCollection <PropInfo> .InitializePrefabs("Custom Assets", pi, null);

                        propCount++;
                    }
                }

                TreeInfo ti = go.GetComponent <TreeInfo>();

                if (ti != null && loadedTrees.Add(fullName))
                {
                    PrefabCollection <TreeInfo> .InitializePrefabs("Custom Assets", ti, null);

                    treeCount++;
                }

                BuildingInfo bi = go.GetComponent <BuildingInfo>();

                if (bi != null)
                {
                    if (bi.m_lodObject != null)
                    {
                        bi.m_lodObject.SetActive(false);
                    }

                    if (loadedBuildings.Add(fullName))
                    {
                        PrefabCollection <BuildingInfo> .InitializePrefabs("Custom Assets", bi, null);

                        bi.m_dontSpawnNormally = !spawnNormally;
                        buildingCount++;

                        if (bi.GetAI() is IntersectionAI)
                        {
                            loadedIntersections.Add(fullName);
                        }
                    }
                }

                VehicleInfo vi = go.GetComponent <VehicleInfo>();

                if (vi != null)
                {
                    if (vi.m_lodObject != null)
                    {
                        vi.m_lodObject.SetActive(false);
                    }

                    if (loadedVehicles.Add(fullName))
                    {
                        PrefabCollection <VehicleInfo> .InitializePrefabs("Custom Assets", vi, null);

                        vehicleCount++;
                    }
                }
            }
            finally
            {
                stack.Pop();
                LoadingManager.instance.m_loadingProfilerCustomAsset.EndLoading();
            }
        }
Ejemplo n.º 21
0
        bool RegisterPrefab(String fullName, Package.Asset asset, CustomAssetMetaData metaData, PrefabInfo info, GameObject go)
        {
            PropInfo pi = go.GetComponent <PropInfo>();

            if (pi != null)
            {
                if (pi.m_lodObject != null)
                {
                    pi.m_lodObject.SetActive(false);
                }

                if (StorePropName(fullName))
                {
                    PrefabCollection <PropInfo> .InitializePrefabs("Custom Assets", pi, null);

                    return(true);
                }
            }

            TreeInfo ti = go.GetComponent <TreeInfo>();

            if (ti != null && StoreTreeName(fullName))
            {
                PrefabCollection <TreeInfo> .InitializePrefabs("Custom Assets", ti, null);

                return(true);
            }

            BuildingInfo bi = go.GetComponent <BuildingInfo>();

            if (bi != null)
            {
                if (bi.m_lodObject != null)
                {
                    bi.m_lodObject.SetActive(false);
                }

                if (StoreBuildingName(fullName))
                {
                    PrefabCollection <BuildingInfo> .InitializePrefabs("Custom Assets", bi, null);

                    bi.m_dontSpawnNormally = !IsCommonBuilding(fullName, asset, metaData);

                    if (bi.GetAI() is IntersectionAI)
                    {
                        loadedIntersections.Add(fullName);
                    }

                    return(true);
                }
            }

            VehicleInfo vi = go.GetComponent <VehicleInfo>();

            if (vi != null)
            {
                if (vi.m_lodObject != null)
                {
                    vi.m_lodObject.SetActive(false);
                }

                if (StoreVehicleName(fullName))
                {
                    PrefabCollection <VehicleInfo> .InitializePrefabs("Custom Assets", vi, null);

                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 22
0
            private void InstallNetInfos(RExModule host)
            {
                var newInfos = new List <NetInfo>();

                var niBuilders = host.Parts
                                 .OfType <INetInfoBuilder>()
                                 .WhereActivated()
                                 .ToArray();

                var lateOperations = new List <Action>();

                foreach (var niBuilder in niBuilders)
                {
                    var builder = niBuilder;

                    Loading.QueueAction(() =>
                    {
                        Stopwatch sw = new Stopwatch();
                        try
                        {
                            sw.Start();
                            var isMultiMenu  = builder is IMenuItemBuildersProvider;
                            var isSingleMenu = builder is IMenuItemBuilder;
                            m_Infos.Clear();
                            foreach (NetInfoVersion version in Enum.GetValues(typeof(NetInfoVersion)))
                            {
                                NetInfo info = null;
                                if (version != NetInfoVersion.All && version != NetInfoVersion.AllWithDecoration && builder.SupportedVersions.HasFlag(version))
                                {
                                    var basedPrefabName = builder.GetBasedPrefabName(version);
                                    var newPrefabName   = builder.GetBuiltPrefabName(version);
                                    if (m_BasedPrefabs.ContainsKey(basedPrefabName) == false)
                                    {
                                        m_BasedPrefabs.Add(basedPrefabName, Resources.FindObjectsOfTypeAll <NetInfo>().FirstOrDefault(netInfo => netInfo.name == basedPrefabName));
                                    }
                                    info = m_BasedPrefabs[basedPrefabName].Clone(newPrefabName, transform);

                                    builder.BuildUp(info, version);

                                    var lateBuilder = builder as INetInfoLateBuilder;
                                    if (lateBuilder != null)
                                    {
                                        lateOperations.Add(() => lateBuilder.LateBuildUp(info, version));
                                    }
                                    m_Infos.Add(version, info);
                                }
                            }
                            List <NetInfo> groundInfos = new List <NetInfo>();
                            foreach (var kvp in m_Infos)
                            {
                                if (kvp.Value != null)
                                {
                                    if (kvp.Key == NetInfoVersion.Ground || kvp.Key == NetInfoVersion.GroundGrass || kvp.Key == NetInfoVersion.GroundTrees)
                                    {
                                        groundInfos.Add(kvp.Value);
                                    }
                                }
                            }
                            if (isSingleMenu)
                            {
                                if (m_Infos.ContainsKey(NetInfoVersion.GroundGrass) || m_Infos.ContainsKey(NetInfoVersion.GroundTrees))
                                {
                                    throw new Exception("Multiple netinfo menuitem cannot be build with the IMenuItemBuilder, use the IMenuItemBuildersProvider");
                                }
                                else
                                {
                                    var mib = builder as IMenuItemBuilder;
                                    m_Infos[NetInfoVersion.Ground].SetMenuItemConfig(mib);
                                }
                            }
                            else if (builder is IMenuItemBuildersProvider)
                            {
                                var mibp = builder as IMenuItemBuildersProvider;
                                var mibs = mibp.MenuItemBuilders.ToDictionary(x => x.Name, StringComparer.InvariantCultureIgnoreCase);
                                foreach (var info in groundInfos)
                                {
                                    if (mibs.ContainsKey(info.name))
                                    {
                                        var mib = mibs[info.name];
                                        info.SetMenuItemConfig(mib);
                                    }
                                }
                            }
                            else
                            {
                                throw new Exception("Cannot set the menuitem on netinfo, either implement IMenuItemBuilder or IMenuItemBuildersProvider");
                            }
                            foreach (var info in groundInfos)
                            {
                                var ai = info.GetComponent <RoadAI>();

                                ai.m_elevatedInfo = m_Infos.ContainsKey(NetInfoVersion.Elevated) ? m_Infos[NetInfoVersion.Elevated] : null;
                                ai.m_bridgeInfo   = m_Infos.ContainsKey(NetInfoVersion.Bridge) ? m_Infos[NetInfoVersion.Bridge] : null;
                                ai.m_tunnelInfo   = m_Infos.ContainsKey(NetInfoVersion.Tunnel) ? m_Infos[NetInfoVersion.Tunnel] : null;
                                ai.m_slopeInfo    = m_Infos.ContainsKey(NetInfoVersion.Slope) ? m_Infos[NetInfoVersion.Slope] : null;
                            }

                            newInfos.AddRange(m_Infos.Values);
                            sw.Stop();

                            Debug.Log(string.Format("REx: {0} installed in {1}ms", builder.Name, sw.ElapsedMilliseconds));
                        }
                        catch (Exception ex)
                        {
                            Debug.Log(string.Format("REx: Crashed-Network builder {0}", builder.Name));
                            Debug.Log("REx: " + ex.Message);
                            Debug.Log("REx: " + ex.ToString());

                            Debug.Log(string.Format("REx: Fallbacking-Network builder {0}", builder.Name));
                            try
                            {
                                newInfos.AddRange(builder.BuildEmergencyFallback());
                            }
                            catch (Exception exFallback)
                            {
                                Debug.Log(string.Format("REx: Crashed-Fallback Network builder {0}", builder.Name));
                                Debug.Log("REx: " + exFallback.Message);
                                Debug.Log("REx: " + exFallback.ToString());
                            }
                        }
                    });
                }

                Loading.QueueAction(() =>
                {
                    var roads  = host._roads = host._container.AddComponent <NetCollection>();
                    roads.name = REX_NETCOLLECTION;
                    if (newInfos.Count > 0)
                    {
                        roads.m_prefabs = newInfos.ToArray();
                        PrefabCollection <NetInfo> .InitializePrefabs(roads.name, roads.m_prefabs, new string[] { });
                        PrefabCollection <NetInfo> .BindPrefabs();
                    }
                });

                Loading.QueueAction(() =>
                {
                    host._lateOperations = lateOperations;
                });
            }
Ejemplo n.º 23
0
        protected override void Install()
        {
            var localNewRoads = NewRoads;

            Loading.QueueAction(() =>
            {
                //Debug.Log("REx: Setting up new Roads and Logic");


                // Builders -----------------------------------------------------------------------
                var newInfos = new List <NetInfo>();

                foreach (var builder in Mod.NetInfoBuilders)
                {
                    try
                    {
                        newInfos.AddRange(builder.Build());

                        Debug.Log(string.Format("REx: {0} installed", builder.DisplayName));
                    }
                    catch (Exception ex)
                    {
                        Debug.Log(string.Format("REx: Crashed-Network builders {0}", builder));
                        Debug.Log("REx: " + ex.Message);
                        Debug.Log("REx: " + ex.ToString());
                    }
                }

                if (newInfos.Count > 0)
                {
                    localNewRoads.m_prefabs = newInfos.ToArray();
                    PrefabCollection <NetInfo> .InitializePrefabs(localNewRoads.name, localNewRoads.m_prefabs, new string[] { });
                    PrefabCollection <NetInfo> .BindPrefabs();
                }


                // Modifiers ----------------------------------------------------------------------
                foreach (var modifier in Mod.NetInfoModifiers)
                {
                    try
                    {
                        modifier.ModifyExistingNetInfo();

                        Debug.Log(string.Format("REx: {0} modifications applied", modifier.DisplayName));
                    }
                    catch (Exception ex)
                    {
                        Debug.Log(string.Format("REx: Crashed-Network modifiers {0}", modifier));
                        Debug.Log("REx: " + ex.Message);
                        Debug.Log("REx: " + ex.ToString());
                    }
                }


                // Cross mods support -------------------------------------------------------------
                foreach (var compatibilityPart in Mod.CompatibilityParts)
                {
                    try
                    {
                        if (compatibilityPart.IsPluginActive)
                        {
                            compatibilityPart.Setup(newInfos);

                            Debug.Log(string.Format("REx: {0} compatibility activated", compatibilityPart.Name));
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.Log(string.Format("REx: Crashed-CompatibilitySupport {0}", compatibilityPart.Name));
                        Debug.Log("REx: " + ex.Message);
                        Debug.Log("REx: " + ex.ToString());
                    }
                }
            });
        }
Ejemplo n.º 24
0
        public static IEnumerator InitializeAndBindClones()
        {
            HashSet <string> customPropNames = new HashSet <string>();
            int count = PrefabCollection <PropInfo> .LoadedCount();

            for (uint i = 0; i < count; i++)
            {
                PropInfo prop = PrefabCollection <PropInfo> .GetLoaded(i);

                if (!prop.m_isCustomContent)
                {
                    continue;
                }
                customPropNames.Add(prop.name);
            }

            HashSet <PropInfo> DuplicateTreeProps = new HashSet <PropInfo>();

            foreach (var i in CS_TreeProps.Mod.propToTreeCloneMap)
            {
                if (customPropNames.Contains(i.Key.name))
                {
                    DuplicateTreeProps.Add(i.Key);
                }
            }
            foreach (var i in DuplicateTreeProps)
            {
                if (CS_TreeProps.Mod.propToTreeCloneMap.ContainsKey(i))
                {
                    CS_TreeProps.Mod.propToTreeCloneMap.Remove(i);
                }
            }

            HashSet <PropInfo> DuplicateVehicleProps = new HashSet <PropInfo>();

            foreach (var i in CS_TreeProps.Mod.propToVehicleCloneMap)
            {
                if (customPropNames.Contains(i.Key.name))
                {
                    DuplicateVehicleProps.Add(i.Key);
                }
            }
            foreach (var i in DuplicateVehicleProps)
            {
                if (CS_TreeProps.Mod.propToVehicleCloneMap.ContainsKey(i))
                {
                    CS_TreeProps.Mod.propToVehicleCloneMap.Remove(i);
                }
            }
            yield return(null);

            PrefabCollection <PropInfo> .InitializePrefabs("Tree to Prop", CS_TreeProps.Mod.propToTreeCloneMap.Select((KeyValuePair <PropInfo, TreeInfo> k) => k.Key).ToArray(), null);

            yield return(null);

            PrefabCollection <PropInfo> .InitializePrefabs("Vehicle to Prop", CS_TreeProps.Mod.propToVehicleCloneMap.Select((KeyValuePair <PropInfo, VehicleInfo> k) => k.Key).ToArray(), null);

            yield return(null);

            PrefabCollection <PropInfo> .BindPrefabs();

            Debug.Log((object)"[Tree and Vehicle Props] Bound tree and vehicle prefabs.");
            yield return(null);

            Singleton <LoadingManager> .instance.QueueLoadingAction(FixIlluminationMaps());
        }
            private static void InstallNetInfos(RExModule host)
            {
                var newInfos = new List <NetInfo>();

                var niBuilders = host.Parts
                                 .OfType <INetInfoBuilder>()
                                 .WhereActivated()
                                 .ToArray();

                var lateOperations = new List <Action>();

                foreach (var niBuilder in niBuilders)
                {
                    var builder = niBuilder;

                    Loading.QueueAction(() =>
                    {
                        try
                        {
                            newInfos.AddRange(builder.Build(lateOperations));

                            Debug.Log(string.Format("REx: {0} installed", builder.Name));
                        }
                        catch (Exception ex)
                        {
                            Debug.Log(string.Format("REx: Crashed-Network builder {0}", builder.Name));
                            Debug.Log("REx: " + ex.Message);
                            Debug.Log("REx: " + ex.ToString());

                            Debug.Log(string.Format("REx: Fallbacking-Network builder {0}", builder.Name));
                            try
                            {
                                newInfos.AddRange(builder.BuildEmergencyFallback());
                            }
                            catch (Exception exFallback)
                            {
                                Debug.Log(string.Format("REx: Crashed-Fallback Network builder {0}", builder.Name));
                                Debug.Log("REx: " + exFallback.Message);
                                Debug.Log("REx: " + exFallback.ToString());
                            }
                        }
                    });
                }

                Loading.QueueAction(() =>
                {
                    var roads  = host._roads = host._container.AddComponent <NetCollection>();
                    roads.name = REX_NETCOLLECTION;
                    if (newInfos.Count > 0)
                    {
                        roads.m_prefabs = newInfos.ToArray();
                        PrefabCollection <NetInfo> .InitializePrefabs(roads.name, roads.m_prefabs, new string[] {});
                        PrefabCollection <NetInfo> .BindPrefabs();
                    }
                });

                Loading.QueueAction(() =>
                {
                    host._lateOperations = lateOperations;
                });
            }