Ejemplo n.º 1
0
 public override void OnCreated(ILoading loading)
 {
     try //So we don't f**k up loading the city
     {
         LoadSprites();
     }
     catch (Exception ex)
     {
         LoggerUtils.LogException(ex);
     }
 }
        public override void OnSaveData()
        {
            LoggerUtils.Log("Saving Screen Objects");

            BinaryFormatter binaryFormatter    = new BinaryFormatter();
            MemoryStream    propDictStream     = new MemoryStream();
            MemoryStream    buildingDictStream = new MemoryStream();

            try
            {
                ScreenObj[] propDict     = ScreenManager.instance.saveScreen(true);
                ScreenObj[] buildingDict = ScreenManager.instance.saveScreen(false);

                if (propDict != null)
                {
                    binaryFormatter.Serialize(propDictStream, propDict);
                    serializableDataManager.SaveData(propDictKey, propDictStream.ToArray());
                    LoggerUtils.Log("Prop screen objs have been saved!");
                }
                else
                {
                    LoggerUtils.LogWarning("Couldn't save props, as the array is null!");
                }


                if (buildingDict != null)
                {
                    binaryFormatter.Serialize(buildingDictStream, buildingDict);
                    serializableDataManager.SaveData(buildingDictKey, buildingDictStream.ToArray());
                    LoggerUtils.Log("building screen objs have been saved!");
                }
                else
                {
                    LoggerUtils.LogWarning("Couldn't save buildings, as the array is null!");
                }
            }
            catch (Exception ex)
            {
                LoggerUtils.LogException(ex);
            }
            finally
            {
                buildingDictStream.Close();
                propDictStream.Close();
            }
        }
Ejemplo n.º 3
0
        public override void OnLoadData()
        {
            LoggerUtils.Log("Loading data");
            BinaryFormatter binaryFormatter = new BinaryFormatter();

            lock (thisLock)
            {
                byte[] loadedPropData = serializableDataManager.LoadData(dataKey);
                LoggerUtils.Log("Props loaded, parsing data");
                if (loadedPropData != null && loadedPropData.Length > 0)
                {
                    MemoryStream memoryStream = new MemoryStream(loadedPropData);

                    try
                    {
                        PropWrapper[] props = binaryFormatter.Deserialize(memoryStream) as PropWrapper[];

                        if (props != null && props.Length > 0)
                        {
                            PropUnlimiterManager.instance.LoadWrappers(props.ToList());
                        }
                        else
                        {
                            LoggerUtils.LogWarning("Couldn't load props, as the array is null!");
                        }
                    }
                    catch (Exception ex)
                    {
                        LoggerUtils.LogException(ex);
                    }
                    finally
                    {
                        memoryStream.Close();
                    }
                }
                else
                {
                    LoggerUtils.LogWarning("Found no data to load");
                }
            }
        }
Ejemplo n.º 4
0
        public override void OnLoadData()
        {
            LoggerUtils.Log("Loading routes");

            byte[] loadedRouteData       = serializableDataManager.LoadData(routeDataKey);
            byte[] loadedSignData        = serializableDataManager.LoadData(signDataKey);
            byte[] loadedDynamicSignData = serializableDataManager.LoadData(dynamicSignDataKey);

            if (loadedRouteData != null)
            {
                MemoryStream routeMemoryStream = new MemoryStream();

                routeMemoryStream.Write(loadedRouteData, 0, loadedRouteData.Length);
                routeMemoryStream.Position = 0;

                BinaryFormatter binaryFormatter = new BinaryFormatter();

                try
                {
                    RouteContainer[] routeNames = binaryFormatter.Deserialize(routeMemoryStream) as RouteContainer[];

                    if (routeNames != null)
                    {
                        RouteManager.Instance().Load(routeNames);
                    }
                    else
                    {
                        LoggerUtils.LogWarning("Couldn't load routes, as the array is null!");
                    }
                }
                catch (Exception ex)
                {
                    LoggerUtils.LogException(ex);
                }
                finally
                {
                    routeMemoryStream.Close();
                }
            }
            else
            {
                LoggerUtils.LogWarning("Found no data to load");
            }

            if (loadedSignData != null)
            {
                MemoryStream signMemoryStream = new MemoryStream();

                signMemoryStream.Write(loadedSignData, 0, loadedSignData.Length);
                signMemoryStream.Position = 0;

                BinaryFormatter binaryFormatter = new BinaryFormatter();

                try
                {
                    SignContainer[] signNames = binaryFormatter.Deserialize(signMemoryStream) as SignContainer[];

                    if (signNames != null)
                    {
                        RouteManager.Instance().LoadSigns(signNames);
                    }
                    else
                    {
                        LoggerUtils.LogWarning("Couldn't load routes, as the array is null!");
                    }
                }
                catch (Exception ex)
                {
                    LoggerUtils.LogException(ex);
                }
                finally
                {
                    signMemoryStream.Close();
                }
            }
            else
            {
                LoggerUtils.LogWarning("Found no data to load");
            }

            if (loadedDynamicSignData != null)
            {
                MemoryStream dynamicSignMemoryStream = new MemoryStream();

                dynamicSignMemoryStream.Write(loadedDynamicSignData, 0, loadedDynamicSignData.Length);
                dynamicSignMemoryStream.Position = 0;

                BinaryFormatter binaryFormatter = new BinaryFormatter();

                try
                {
                    DynamicSignContainer[] signNames = binaryFormatter.Deserialize(dynamicSignMemoryStream) as DynamicSignContainer[];

                    if (signNames != null)
                    {
                        RouteManager.Instance().LoadDynamicSigns(signNames);
                    }
                    else
                    {
                        LoggerUtils.LogWarning("Couldn't load routes, as the array is null!");
                    }
                }
                catch (Exception ex)
                {
                    LoggerUtils.LogException(ex);
                }
                finally
                {
                    dynamicSignMemoryStream.Close();
                }
            }
            else
            {
                LoggerUtils.LogWarning("Found no data to load");
            }
        }
Ejemplo n.º 5
0
        protected override void BeginOverlayImpl(RenderManager.CameraInfo cameraInfo)
        {
            NetManager      netManager      = NetManager.instance;
            DistrictManager districtManager = DistrictManager.instance;

            cameraInfo.m_height = 100;
            if (m_lastCount != RouteManager.Instance().m_routeDict.Count)
            {
                m_lastCount = RouteManager.Instance().m_routeDict.Count;

                try
                {
                    RenderText();
                }
                catch (Exception ex)
                {
                    LoggerUtils.LogException(ex);
                }
            }

            if (!textHidden && cameraInfo.m_height > m_renderHeight)
            {
                foreach (RouteContainer route in RouteManager.Instance().m_routeDict.Values)
                {
                    route.m_shieldMesh.GetComponent <Renderer>().enabled = false;
                    route.m_numMesh.GetComponent <Renderer>().enabled    = false;
                }

                foreach (SignContainer sign in RouteManager.Instance().m_signList)
                {
                    /*sign.m_destinationMesh.GetComponent<Renderer>().enabled = false;
                     * sign.m_shieldMesh.GetComponent<Renderer>().enabled = false;
                     * sign.m_numMesh.GetComponent<Renderer>().enabled = false;*/
                    sign.m_sign.GetComponent <Renderer>().enabled = false;
                }
                textHidden = true;
            }
            else if (textHidden && cameraInfo.m_height <= m_renderHeight)  //This is a mess, and I'll sort it soon :)
            {
                if (m_routeEnabled)
                {
                    foreach (RouteContainer route in RouteManager.Instance().m_routeDict.Values)
                    {
                        route.m_shieldMesh.GetComponent <Renderer>().enabled = true;
                        route.m_numMesh.GetComponent <Renderer>().enabled    = true;
                    }

                    foreach (SignContainer sign in RouteManager.Instance().m_signList)
                    {
                        /*sign.m_destinationMesh.GetComponent<Renderer>().enabled = true;
                         * sign.m_shieldMesh.GetComponent<Renderer>().enabled = true;
                         * sign.m_numMesh.GetComponent<Renderer>().enabled = true;*/
                        sign.m_sign.GetComponent <Renderer>().enabled = true;
                    }
                }
                textHidden = false;
            }

            if (m_updateDynamicSignFlag)
            {
                m_updateDynamicSignFlag = false;
                float  avg;
                float  lowTrafficMsgChance;
                String msgText;
                foreach (DynamicSignContainer sign in RouteManager.Instance().m_dynamicSignList)
                {
                    avg  = (float)sign.m_trafficDensity;
                    avg -= sign.m_trafficDensity / 3;
                    avg += netManager.m_segments.m_buffer[sign.m_segment].m_trafficDensity / 3;
                    sign.m_trafficDensity = avg;
                    msgText = (sign.m_route == null ? "Traffic" : (sign.m_routePrefix + '-' + sign.m_route)) +
                              String.Format(" moving {0}", sign.m_trafficDensity > 65 ? "slowly" : "well");

                    if (sign.m_trafficDensity < 35)
                    {
                        lowTrafficMsgChance = 0.8f;
                    }
                    else
                    {
                        lowTrafficMsgChance = 0.1f;
                    }

                    sign.m_messageTextMesh.text = (messageRandom.NextDouble() > lowTrafficMsgChance) ? msgText :
                                                  DynamicSignConfig.Instance().msgStrings[messageRandom.Next(DynamicSignConfig.Instance().msgStrings.Count)];
                }
            }
        }
Ejemplo n.º 6
0
        protected override void BeginOverlayImpl(RenderManager.CameraInfo cameraInfo)
        {
            if (refreshFlag)
            {
                refreshFlag = false;
                try
                {
                    renderGameObjects();
                }
                catch (Exception ex)
                {
                    LoggerUtils.LogException(ex);
                }
            }

            if (!objHidden && cameraInfo.m_height > renderHeight)
            {
                foreach (ScreenObj screen in ScreenManager.instance.propDict.Values)
                {
                    if (screen.signObject != null)
                    {
                        screen.signObject.SetActive(false);
                    }
                }
                foreach (ScreenObj screen in ScreenManager.instance.buildingDict.Values)
                {
                    if (screen.signObject != null)
                    {
                        screen.signObject.SetActive(false);
                    }
                }
                objHidden = true;
            }
            else if (objHidden && cameraInfo.m_height <= renderHeight) //This is a mess, and I'll sort it soon :)
            {
                foreach (ScreenObj screen in ScreenManager.instance.propDict.Values)
                {
                    if (screen.signObject != null)
                    {
                        screen.signObject.SetActive(true);
                    }
                }
                foreach (ScreenObj screen in ScreenManager.instance.buildingDict.Values)
                {
                    if (screen.signObject != null)
                    {
                        screen.signObject.SetActive(true);
                    }
                }
                objHidden = false;
            }

            if (screenRefreshFlag)
            {
                screenRefreshFlag = false;
                List <Material> materials = TextureUtils.m_screenTextureStore.Values.ToList();

                foreach (ScreenObj obj in ScreenManager.instance.buildingDict.Values)
                {
                    if (obj.signObject)
                    {
                        PropPositioningInfo positioningInfo = PropConfig.Instance().propPositioningDict[obj.propName];

                        for (byte i = 0; i < positioningInfo.numSigns; i++)
                        {
                            Transform child = obj.signObject.transform.Find(i.ToString());
                            if (child != null && !obj.isStatic[i])
                            {
                                Material mat = materials[messageRandom.Next(materials.Count)];
                                child.gameObject.GetComponent <MeshRenderer>().material = mat;
                            }
                        }
                    }
                }
                foreach (ScreenObj obj in ScreenManager.instance.propDict.Values)
                {
                    if (obj.signObject)
                    {
                        PropPositioningInfo positioningInfo = PropConfig.Instance().propPositioningDict[obj.propName];

                        for (byte i = 0; i < positioningInfo.numSigns; i++)
                        {
                            Transform child = obj.signObject.transform.Find(i.ToString());
                            if (child != null && !obj.isStatic[i])
                            {
                                Material mat = materials[messageRandom.Next(materials.Count)];
                                child.gameObject.GetComponent <MeshRenderer>().material = mat;
                            }
                        }
                    }
                }
            }
        }
        public override void OnLoadData()
        {
            LoggerUtils.Log("Loading routes");

            byte[] loadPropDict     = serializableDataManager.LoadData(propDictKey);
            byte[] loadBuildingDict = serializableDataManager.LoadData(buildingDictKey);

            if (loadPropDict != null)
            {
                MemoryStream propDictStream = new MemoryStream();

                propDictStream.Write(loadPropDict, 0, loadPropDict.Length);
                propDictStream.Position = 0;

                BinaryFormatter binaryFormatter = new BinaryFormatter();

                try
                {
                    ScreenObj[] propArray = binaryFormatter.Deserialize(propDictStream) as ScreenObj[];

                    if (propArray != null)
                    {
                        ScreenManager.instance.loadScreen(true, propArray);
                    }
                    else
                    {
                        LoggerUtils.LogWarning("Couldn't load props, as the array is null!");
                    }
                }
                catch (Exception ex)
                {
                    LoggerUtils.LogException(ex);
                }
                finally
                {
                    propDictStream.Close();
                }
            }
            else
            {
                LoggerUtils.LogWarning("Found no data to load");
            }

            if (loadBuildingDict != null)
            {
                MemoryStream buildingPropDict = new MemoryStream();

                buildingPropDict.Write(loadBuildingDict, 0, loadBuildingDict.Length);
                buildingPropDict.Position = 0;

                BinaryFormatter binaryFormatter = new BinaryFormatter();

                try
                {
                    ScreenObj[] buildingArray = binaryFormatter.Deserialize(buildingPropDict) as ScreenObj[];

                    if (buildingArray != null)
                    {
                        ScreenManager.instance.loadScreen(false, buildingArray);
                    }
                    else
                    {
                        LoggerUtils.LogWarning("Couldn't load building, as the array is null!");
                    }
                }
                catch (Exception ex)
                {
                    LoggerUtils.LogException(ex);
                }
                finally
                {
                    buildingPropDict.Close();
                }
            }
            else
            {
                LoggerUtils.LogWarning("Found no data to load");
            }
        }