Esempio n. 1
0
        /// <summary>
        /// Initializes the Data objects.
        /// Creates unique copies of TreeInfos from saved data,
        /// then loads them into specific instances that use them.
        /// </summary>
        public void InitializeTrees()
        {
            //Create the new infos
            foreach (var uniqueTree in TreeInfos)
            {
                uniqueTree.CreateCopy();
            }

            //Bind new copies to prefab collection
            PrefabCollection <TreeInfo> .BindPrefabs();

            //Copy fields from old info to new info, then overwrite with saved custom values
            foreach (var uniqueTree in TreeInfos)
            {
                uniqueTree.CopyFields();
                uniqueTree.Load();
            }

            //Set new infos on building instances
            foreach (var treeInstance in TreeInstances)
            {
                if ((treeInstance.Flags & TreeInstance.Flags.Created) != 0)
                {
                    treeInstance.Load();
                }
            }
        }
Esempio n. 2
0
        private static void AddNetInfo()
        {
            NetInfo info = CreateMetroTrack();

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

            PrefabCollection <NetInfo> .BindPrefabs();
        }
Esempio n. 3
0
        void BindPrefabs()
        {
            PrefabCollection <VehicleInfo> .BindPrefabs();

            PrefabCollection <BuildingInfo> .BindPrefabs();

            PrefabCollection <PropInfo> .BindPrefabs();

            PrefabCollection <TreeInfo> .BindPrefabs();
        }
Esempio n. 4
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();
                    }
                });
            }
        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");
            });
        }
        public static UniqueBuilding GetImmediateCopy(this BuildingInfo oldInfo, string newName, string newDescription = "", ushort buildingID = 0)
        {
            string oldName = oldInfo.name;

            oldInfo.CopyInfo(newName);
            PrefabCollection <BuildingInfo> .BindPrefabs();

            oldInfo.CopyFields(newName);
            BuildingInfo newInfo = PrefabCollection <BuildingInfo> .FindLoaded(newName);

            if (buildingID != 0)
            {
                BuildingManager.instance.m_buildings.m_buffer[buildingID].Info = newInfo;
                BuildingManager.instance.UpdateBuildingRenderer(buildingID, true);
                BuildingManager.instance.UpdateBuildingInfo(buildingID, newInfo);
            }
            return(new UniqueBuilding(newInfo, oldName, newName, newDescription));
        }
Esempio n. 8
0
        public static UniqueTree GetImmediateCopy(this TreeInfo tree, string newName, string newDescription = "", uint treeID = 0)
        {
            string oldName = tree.name;

            tree.CopyInfo(newName);
            PrefabCollection <BuildingInfo> .BindPrefabs();

            tree.CopyFields(newName);
            TreeInfo newInfo = PrefabCollection <TreeInfo> .FindLoaded(newName);

            if (treeID != 0)
            {
                TreeManager.instance.m_trees.m_buffer[treeID].Info = newInfo;
                TreeManager.instance.m_trees.m_buffer[treeID].UpdateTree(treeID);
                TreeManager.instance.UpdateTreeRenderer(treeID, true);
                TreeManager.instance.UpdateTree(treeID);
            }
            return(new UniqueTree(newInfo, oldName, newName, newDescription));
        }
        public void Load()
        {
            GameObject newRoad = GameObject.Instantiate <GameObject>(PrefabCollection <NetInfo> .FindLoaded(baseNetwork).gameObject);

            if (newRoad == null)
            {
                Debug.Log("newRoad is null");
            }
            newRoad.name = name;
            NetInfo ni = newRoad.GetComponent <NetInfo>();

            ni.m_prefabInitialized = false;
            ni.m_netAI             = null;
            typeof(NetInfo).GetField("m_UICategory", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(ni, category);

            Locale locale = (Locale)typeof(LocaleManager).GetField("m_Locale", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(SingletonLite <LocaleManager> .instance);

            locale.AddLocalizedString(new Locale.Key()
            {
                m_Identifier = "NET_TITLE", m_Key = name
            }, title);
            locale.AddLocalizedString(new Locale.Key()
            {
                m_Identifier = "NET_DESC", m_Key = name
            }, description);

            MethodInfo initMethod = typeof(NetCollection).GetMethod("InitializePrefabs", BindingFlags.Static | BindingFlags.NonPublic);

            Singleton <LoadingManager> .instance.QueueLoadingAction((IEnumerator)initMethod.Invoke(null, new object[] {
                category,
                new[] { ni },
                new string[] { }
            }));

            Singleton <LoadingManager> .instance.QueueLoadingAction(inCoroutine(() =>
            {
                setup(ni);
                PrefabCollection <NetInfo> .BindPrefabs();
                GameObject.Find(category + "Panel").GetComponent <GeneratedScrollPanel>().RefreshPanel();
            }));
        }
Esempio n. 10
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;
                });
            }
Esempio n. 11
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());
                    }
                }
            });
        }
Esempio n. 12
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;
                });
            }