Пример #1
0
        public override void HandleInput(Scene scene)
        {
            TextParameters parameters = new TextParameters().SetColor(Color.White, Color.Black).SetConstraints(Width - 16 - 16, int.MaxValue);
            int            textHeight = FontUtil.GetStringHeight(Text(), parameters);

            if (scene.InputState.IsKeyPressed(Keys.Enter))
            {
                Close();
            }
            if (scene.InputState.IsKeyPressed(Keys.Escape))
            {
                Close();
            }
            if (scene.InputState.IsKeyPressed(Keys.W, 10, 1))
            {
                Scroll -= 3;
            }
            if (scene.InputState.IsKeyPressed(Keys.S, 10, 1))
            {
                Scroll += 3;
            }
            if (scene.InputState.IsMouseWheelUp())
            {
                Scroll -= 6;
            }
            if (scene.InputState.IsMouseWheelDown())
            {
                Scroll += 6;
            }
            Scroll = MathHelper.Clamp(Scroll, 0, textHeight - Height + 8);
            base.HandleInput(scene);
        }
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         int hashCode = 41;
         if (AnnotationLayout != null)
         {
             hashCode = hashCode * 59 + AnnotationLayout.GetHashCode();
         }
         if (TextParameters != null)
         {
             hashCode = hashCode * 59 + TextParameters.GetHashCode();
         }
         if (Title != null)
         {
             hashCode = hashCode * 59 + Title.GetHashCode();
         }
         if (Subject != null)
         {
             hashCode = hashCode * 59 + Subject.GetHashCode();
         }
         hashCode = hashCode * 59 + ShowBorder.GetHashCode();
         if (Color != null)
         {
             hashCode = hashCode * 59 + Color.GetHashCode();
         }
         return(hashCode);
     }
 }
Пример #3
0
 public ProceduralObjectContainer(ProceduralObject baseObject)
 {
     id             = baseObject.id;
     basePrefabName = baseObject.basePrefabName;
     objectType     = baseObject.baseInfoType;
     // meshStatus = baseObject.meshStatus;
     renderDistance = baseObject.renderDistance;
     position       = new SerializableVector3(baseObject.m_position);
     rotation       = new SerializableQuaternion(baseObject.m_rotation);
     scale          = 1f;
     // if (meshStatus > 0)
     vertices             = SerializableVector3.ToSerializableArray(baseObject.m_mesh.vertices);
     hasCustomTexture     = baseObject.customTexture != null;
     visibility           = baseObject.m_visibility;
     disableRecalculation = baseObject.disableRecalculation;
     layerId = (baseObject.layer == null) ? 0 : baseObject.layer.m_id;
     // flipFaces = baseObject.flipFaces;
     tilingFactor = baseObject.tilingFactor;
     if (baseObject.m_textParameters != null)
     {
         textParam = TextParameters.Clone(baseObject.m_textParameters, false);
         for (int i = 0; i < textParam.Count(); i++)
         {
             textParam[i].serializableColor = null;
         }
     }
     if (hasCustomTexture == true)
     {
         customTextureName = baseObject.customTexture.name;
     }
     else
     {
         customTextureName = string.Empty;
     }
 }
Пример #4
0
        /// <summary>
        /// Returns true if PdfInsertTextParameters instances are equal
        /// </summary>
        /// <param name="input">Instance of PdfInsertTextParameters to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(PdfInsertTextParameters input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     FileId == input.FileId ||
                     (FileId != null &&
                      FileId.Equals(input.FileId))
                     ) &&
                 (
                     PageRange == input.PageRange ||
                     (PageRange != null &&
                      PageRange.Equals(input.PageRange))
                 ) &&
                 (
                     TextParameters == input.TextParameters ||
                     (TextParameters != null &&
                      TextParameters.Equals(input.TextParameters))
                 ) &&
                 (
                     TextBoundingBoxLayout == input.TextBoundingBoxLayout ||
                     (TextBoundingBoxLayout != null &&
                      TextBoundingBoxLayout.Equals(input.TextBoundingBoxLayout))
                 ));
        }
Пример #5
0
        public override void Draw(SceneGame scene, DrawPass pass)
        {
            var    calcParams = new TextParameters().SetColor(FontColor, BorderColor).SetConstraints(128, 64);
            string fit        = FontUtil.FitString(Game.ConvertToSmallPixelText(Text), calcParams);
            var    width      = FontUtil.GetStringWidth(fit, calcParams);
            var    height     = FontUtil.GetStringHeight(fit);

            scene.DrawText(fit, Position + Offset - new Vector2(128, height) / 2, Alignment.Center, new TextParameters().SetColor(FontColor, BorderColor).SetConstraints(128, height + 64));
        }
Пример #6
0
        public CourseWork()
        {
            GlobalParameters = new GlobalParameters(false);
            GlobalParameters.AddParameter(NameForUsers.MarginTop, "2", ValueManager.ValueTypes.Sm);
            GlobalParameters.AddParameter(NameForUsers.MarginBottom, "2", ValueManager.ValueTypes.Sm);
            GlobalParameters.AddParameter(NameForUsers.MarginLeft, "3", ValueManager.ValueTypes.Sm);
            GlobalParameters.AddParameter(NameForUsers.MarginRight, "1,5", ValueManager.ValueTypes.Sm);

            TextParameters = new TextParameters(false);
            TextParameters.AddParameter(NameForUsers.FontFamily, "Times New Roman", ValueManager.ValueTypes.FontFamily);
            TextParameters.AddParameter(NameForUsers.FontSize, "14", ValueManager.ValueTypes.Pt);
        }
        public CacheProceduralObject(ProceduralObject sourceObj)
        {
            renderDistance   = sourceObj.renderDistance;
            renderDistLocked = sourceObj.renderDistLocked;
            if (sourceObj.meshStatus == 2)
            {
                allVertices = sourceObj.m_mesh.vertices;
                meshStatus  = 2;
            }
            else
            {
                meshStatus = 1;
            }
            customTexture        = sourceObj.customTexture;
            _staticPos           = sourceObj.m_position;
            m_rotation           = sourceObj.m_rotation;
            basePrefabName       = sourceObj.basePrefabName;
            baseInfoType         = sourceObj.baseInfoType;
            layer                = sourceObj.layer;
            m_color              = sourceObj.m_color;
            flipFaces            = sourceObj.flipFaces;
            disableCastShadows   = sourceObj.disableCastShadows;
            normalsRecalculation = sourceObj.normalsRecalcMode;
            tilingFactor         = sourceObj.tilingFactor;
            switch (baseInfoType)
            {
            case "PROP":
                _baseProp = sourceObj._baseProp;
                break;

            case "BUILDING":
                _baseBuilding = sourceObj._baseBuilding;
                break;
            }
            visibility           = sourceObj.m_visibility;
            textParam            = TextParameters.Clone(sourceObj.m_textParameters, false);
            disableRecalculation = sourceObj.disableRecalculation;
            if (sourceObj.m_modules != null)
            {
                modules = new List <POModule>();
                foreach (var m in sourceObj.m_modules)
                {
                    try { modules.Add(m.Clone()); }
                    catch (Exception e) { Debug.LogError("[ProceduralObjects] Error inside module Clone() method!\n" + e); }
                }
            }
        }
        /// <summary>
        /// Returns true if FreeTextAnnotationParameters instances are equal
        /// </summary>
        /// <param name="input">Instance of FreeTextAnnotationParameters to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(FreeTextAnnotationParameters input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     AnnotationLayout == input.AnnotationLayout ||
                     (AnnotationLayout != null &&
                      AnnotationLayout.Equals(input.AnnotationLayout))
                     ) &&
                 (
                     TextParameters == input.TextParameters ||
                     (TextParameters != null &&
                      TextParameters.Equals(input.TextParameters))
                 ) &&
                 (
                     Title == input.Title ||
                     (Title != null &&
                      Title.Equals(input.Title))
                 ) &&
                 (
                     Subject == input.Subject ||
                     (Subject != null &&
                      Subject.Equals(input.Subject))
                 ) &&
                 (
                     ShowBorder == input.ShowBorder ||
                     ShowBorder.Equals(input.ShowBorder)
                 ) &&
                 (
                     Color == input.Color ||
                     (Color != null &&
                      Color.Equals(input.Color))
                 ));
        }
Пример #9
0
        public override void DrawText(TextParameters parms)
        {
            if (!Style.StrokeParameters.Disabled)
            {
                using (DeviceContextHandler dch = GetDeviceContextHandler())
                {
                    Rectangle rect = new Rectangle(parms.X, parms.Y, parms.Width, parms.Height);
                    //TextFormatFlags tff = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter | TextFormatFlags.WordBreak;
                    //TextRenderer.DrawText(_graphics, parms.Text, _currentFont, rect, _currentStroke.Color, tff);

                    StringFormat sf = new StringFormat();
                    sf.LineAlignment =
                        Style.TextVerticalAlignment == VerticalAlignment.Bottom ? StringAlignment.Far :
                        Style.TextVerticalAlignment == VerticalAlignment.Top ? StringAlignment.Near :
                        StringAlignment.Center;
                    sf.Alignment =
                        Style.TextHorizontalAlignment == HorizontalAlignment.Right ? StringAlignment.Far :
                        Style.TextHorizontalAlignment == HorizontalAlignment.Left ? StringAlignment.Near :
                        StringAlignment.Center;
                    dch.DrawingSurface.DrawString(parms.Text, Style.Font, Style.StrokeParameters.ToBrush(), rect.SystemRectangleF, sf);
                }
            }
        }
Пример #10
0
        public CacheProceduralObject(ProceduralObject sourceObj)
        {
            renderDistance = sourceObj.renderDistance;
            allVertices    = sourceObj.m_mesh.vertices;
            customTexture  = sourceObj.customTexture;
            m_rotation     = sourceObj.m_rotation;
            basePrefabName = sourceObj.basePrefabName;
            baseInfoType   = sourceObj.baseInfoType;
            //  flipFaces = sourceObj.flipFaces;
            tilingFactor = sourceObj.tilingFactor;
            switch (baseInfoType)
            {
            case "PROP":
                _baseProp = sourceObj._baseProp;
                break;

            case "BUILDING":
                _baseBuilding = sourceObj._baseBuilding;
                break;
            }
            visibility           = sourceObj.m_visibility;
            textParam            = TextParameters.Clone(sourceObj.m_textParameters, false);
            disableRecalculation = sourceObj.disableRecalculation;
        }
Пример #11
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         int hashCode = 41;
         if (FileId != null)
         {
             hashCode = hashCode * 59 + FileId.GetHashCode();
         }
         if (PageRange != null)
         {
             hashCode = hashCode * 59 + PageRange.GetHashCode();
         }
         if (TextParameters != null)
         {
             hashCode = hashCode * 59 + TextParameters.GetHashCode();
         }
         if (TextBoundingBoxLayout != null)
         {
             hashCode = hashCode * 59 + TextBoundingBoxLayout.GetHashCode();
         }
         return(hashCode);
     }
 }
Пример #12
0
 public ProceduralObjectContainer(ProceduralObject baseObject)
 {
     id               = baseObject.id;
     basePrefabName   = baseObject.basePrefabName;
     objectType       = baseObject.baseInfoType;
     renderDistance   = baseObject.renderDistance;
     renderDistLocked = baseObject.renderDistLocked;
     position         = new SerializableVector3(baseObject.m_position);
     rotation         = new SerializableQuaternion(baseObject.m_rotation);
     scale            = 1f;
     if (baseObject.group != null)
     {
         belongsToGroup = true;
         if (baseObject.isRootOfGroup)
         {
             groupRootId = -1; // = we are a group root
         }
         else
         {
             groupRootId = baseObject.group.root.id;
         }
     }
     else
     {
         belongsToGroup = false; // we don't have a group
     }
     color = baseObject.m_color;
     // if (meshStatus > 0)
     meshStatus = baseObject.meshStatus;
     if (meshStatus != 1)
     {
         /*
          * try
          * {
          *  serializedMeshData = new POSerializableMeshData(baseObject);
          *  vertices = null;
          * }
          * catch (Exception e)
          * {
          *  Debug.LogWarning("[ProceduralObjects] Warning : error while compressing Mesh data for object #" + baseObject.id + " (" + baseObject.baseInfoType + ", " + baseObject.basePrefabName + "). Saving uncompressed raw data instead\n" + e);
          *
          *
          * */
         vertices           = SerializableVector3.ToSerializableArray(baseObject.m_mesh.vertices);
         serializedMeshData = null;
         //   }
     }
     else
     {
         serializedMeshData = null;
         vertices           = null;
     }
     hasCustomTexture     = baseObject.customTexture != null;
     visibility           = baseObject.m_visibility;
     disableRecalculation = baseObject.disableRecalculation;
     normalsRecalculation = baseObject.normalsRecalcMode;
     layerId            = (baseObject.layer == null) ? 0 : baseObject.layer.m_id;
     flipFaces          = baseObject.flipFaces;
     disableCastShadows = baseObject.disableCastShadows;
     // recalculateNormals = baseObject.recalculateNormals;
     tilingFactor = baseObject.tilingFactor;
     if (baseObject.m_textParameters != null)
     {
         textParam = TextParameters.Clone(baseObject.m_textParameters, false);
         for (int i = 0; i < textParam.Count(); i++)
         {
             textParam[i].serializableColor = null;
         }
     }
     if (hasCustomTexture == true)
     {
         customTextureName = baseObject.customTexture.name;
     }
     else
     {
         customTextureName = string.Empty;
     }
     modulesData = new List <Dictionary <string, string> >();
     if (baseObject.m_modules != null)
     {
         foreach (POModule m in baseObject.m_modules)
         {
             modulesData.Add(m._get_data(true));
         }
     }
 }
 public ProceduralObject(CacheProceduralObject sourceCacheObj, int id, Vector3 position, LayerManager layerManager)
 {
     if (sourceCacheObj.baseInfoType == "PROP")
     {
         PropInfo sourceProp = sourceCacheObj._baseProp;
         if (sourceCacheObj._baseProp == null)
         {
             sourceProp = Resources.FindObjectsOfTypeAll <PropInfo>().FirstOrDefault(info => info.name == sourceCacheObj.basePrefabName);
         }
         this._baseProp          = sourceProp;
         this.id                 = id;
         this.basePrefabName     = sourceCacheObj.basePrefabName;
         this.baseInfoType       = "PROP";
         this.isPloppableAsphalt = sourceProp.IsPloppableAsphalt();
         m_material              = GameObject.Instantiate(sourceProp.m_material);
         if (sourceCacheObj.meshStatus == 2)
         {
             m_mesh = sourceProp.m_mesh.InstantiateMesh();
             m_mesh.SetVertices(new List <Vector3>(sourceCacheObj.allVertices));
             vertices   = Vertex.CreateVertexList(this);
             meshStatus = 2;
         }
         else
         {
             meshStatus = 1;
             m_mesh     = sourceProp.m_mesh;
             vertices   = Vertex.CreateVertexList(sourceProp);
         }
         if (sourceProp.m_mesh.name == "ploppableasphalt-prop" || sourceProp.m_mesh.name == "ploppableasphalt-decal")
         {
             m_color = m_material.ApplyPloppableColor();
         }
     }
     else if (sourceCacheObj.baseInfoType == "BUILDING")// building
     {
         BuildingInfo sourceBuilding = sourceCacheObj._baseBuilding;
         if (sourceCacheObj._baseBuilding == null)
         {
             sourceBuilding = Resources.FindObjectsOfTypeAll <BuildingInfo>().FirstOrDefault(info => info.name == sourceCacheObj.basePrefabName);
         }
         this._baseBuilding      = sourceBuilding;
         this.id                 = id;
         this.basePrefabName     = sourceCacheObj.basePrefabName;
         this.baseInfoType       = "BUILDING";
         this.isPloppableAsphalt = false;
         m_material              = GameObject.Instantiate(sourceBuilding.m_material);
         m_mesh     = sourceBuilding.m_mesh.InstantiateMesh();
         meshStatus = 2;
         m_mesh.SetVertices(new List <Vector3>(sourceCacheObj.allVertices));
         vertices        = Vertex.CreateVertexList(this);
         m_mesh.colors   = new Color[] { };
         m_mesh.colors32 = new Color32[] { };
     }
     if (sourceCacheObj.customTexture != null)
     {
         m_material.mainTexture = sourceCacheObj.customTexture as Texture;
         customTexture          = sourceCacheObj.customTexture;
     }
     m_visibility         = sourceCacheObj.visibility;
     historyEditionBuffer = new HistoryBuffer(this);
     if (sourceCacheObj.textParam != null)
     {
         m_textParameters = TextParameters.Clone(sourceCacheObj.textParam, false);
         // m_textParameters.SetFonts();
         var originalTex = new Texture2D(m_material.mainTexture.width, m_material.mainTexture.height, TextureFormat.RGBA32, false);
         originalTex.SetPixels(((Texture2D)m_material.mainTexture).GetPixels());
         originalTex.Apply();
         m_material.mainTexture = m_textParameters.ApplyParameters(originalTex);
     }
     else
     {
         m_textParameters = null;
     }
     if (sourceCacheObj.layer != null)
     {
         if (layerManager.m_layers.Contains(sourceCacheObj.layer))
         {
             layer = sourceCacheObj.layer;
         }
     }
     m_color                 = sourceCacheObj.m_color;
     m_material.color        = m_color;
     this.flipFaces          = sourceCacheObj.flipFaces;
     this.disableCastShadows = sourceCacheObj.disableCastShadows;
     if (this.flipFaces)
     {
         VertexUtils.flipFaces(this);
     }
     renderDistance   = sourceCacheObj.renderDistance;
     renderDistLocked = sourceCacheObj.renderDistLocked;
     MaterialOptions.FixDecalRenderDist(this);
     m_position           = position;
     m_rotation           = sourceCacheObj.m_rotation;
     disableRecalculation = sourceCacheObj.disableRecalculation;
     normalsRecalcMode    = sourceCacheObj.normalsRecalculation;
     this.tilingFactor    = sourceCacheObj.tilingFactor;
     if (sourceCacheObj.modules != null)
     {
         m_modules = new List <POModule>();
         foreach (var m in sourceCacheObj.modules)
         {
             POModule clone;
             try { clone = m.Clone(); }
             catch (Exception e)
             {
                 Debug.LogError("[ProceduralObjects] Error inside module Clone() method!\n" + e);
                 continue;
             }
             ModuleManager.instance.modules.Add(clone);
             if (clone.enabled)
             {
                 ModuleManager.instance.enabledModules.Add(clone);
             }
             clone.parentObject = this;
             try { clone.OnModuleCreated(ProceduralObjectsLogic.instance); }
             catch (Exception e) { Debug.LogError("[ProceduralObjects] Error inside module OnModuleCreated() method!\n" + e); }
             m_modules.Add(clone);
         }
     }
 }
        public ProceduralObject(ProceduralObjectContainer container, LayerManager layerManager, PropInfo[] props, BuildingInfo[] buildings)
        {
            if (container.objectType == "PROP")
            {
                PropInfo sourceProp = props.FirstOrDefault(info => info.name == container.basePrefabName);
                this._baseProp          = sourceProp;
                this.id                 = container.id;
                this.basePrefabName     = container.basePrefabName;
                this.baseInfoType       = "PROP";
                this.isPloppableAsphalt = sourceProp.IsPloppableAsphalt();
                m_position              = container.position.ToVector3();
                m_rotation              = container.rotation.ToQuaternion();
                m_material              = GameObject.Instantiate(sourceProp.m_material); // overkil ??
                if (container.meshStatus == 0 && container.vertices != null)
                {
                    // CHECK FOR MESH REPETITION
                    if (ProceduralUtils.CheckMeshEquivalence(container.vertices, sourceProp.m_mesh.vertices))
                    {
                        meshStatus = 1;
                        m_mesh     = sourceProp.m_mesh;
                        vertices   = Vertex.CreateVertexList(sourceProp);
                    }
                    else
                    {
                        meshStatus = 2;
                        m_mesh     = sourceProp.m_mesh.InstantiateMesh();
                        var vert = SerializableVector3.ToStandardVector3Array(container.vertices);
                        if (container.scale != 0)
                        {
                            for (int i = 0; i < vert.Count(); i++)
                            {
                                vert[i] = new Vector3(vert[i].x * container.scale, vert[i].y * container.scale, vert[i].z * container.scale);
                            }
                        }
                        m_mesh.SetVertices(new List <Vector3>(vert));
                        vertices = Vertex.CreateVertexList(this);
                    }
                }
                else if (container.meshStatus == 1)
                {
                    meshStatus = 1;
                    m_mesh     = sourceProp.m_mesh;
                    vertices   = Vertex.CreateVertexList(sourceProp);
                }
                else // meshstatus2
                {
                    meshStatus = 2;
                    m_mesh     = sourceProp.m_mesh.InstantiateMesh();
                    if (container.serializedMeshData != null)
                    {
                        container.serializedMeshData.ApplyDataToObject(this);
                    }
                    else if (container.vertices != null)
                    {
                        var vert = SerializableVector3.ToStandardVector3Array(container.vertices);
                        if (container.scale != 0)
                        {
                            for (int i = 0; i < vert.Count(); i++)
                            {
                                vert[i] = new Vector3(vert[i].x * container.scale, vert[i].y * container.scale, vert[i].z * container.scale);
                            }
                        }
                        m_mesh.SetVertices(new List <Vector3>(vert));
                    }
                    else
                    {
                        throw new Exception("[ProceduralObjects] Loading failure : Missing mesh data !");
                    }
                    vertices = Vertex.CreateVertexList(this);
                }
                if (sourceProp.m_mesh.name == "ploppableasphalt-prop" || sourceProp.m_mesh.name == "ploppableasphalt-decal")
                {
                    m_color = m_material.ApplyPloppableColor();
                }
                if (container.hasCustomTexture && TextureManager.instance != null)
                {
                    var customTex = TextureManager.instance.FindTexture(container.customTextureName);
                    m_material.mainTexture = customTex as Texture;
                    customTexture          = customTex;
                }
            }
            else if (container.objectType == "BUILDING")// building
            {
                BuildingInfo sourceProp = buildings.FirstOrDefault(info => info.name == container.basePrefabName);
                this._baseBuilding      = sourceProp;
                this.id                 = container.id;
                this.basePrefabName     = container.basePrefabName;
                this.baseInfoType       = "BUILDING";
                this.isPloppableAsphalt = false;
                m_position              = container.position.ToVector3();
                m_rotation              = container.rotation.ToQuaternion();
                meshStatus              = 2;
                m_material              = GameObject.Instantiate(sourceProp.m_material); // overkill ??
                m_mesh = sourceProp.m_mesh.InstantiateMesh();
                if (container.serializedMeshData != null)
                {
                    container.serializedMeshData.ApplyDataToObject(this);
                }
                else if (container.vertices != null)
                {
                    var vert = SerializableVector3.ToStandardVector3Array(container.vertices);
                    if (container.scale != 0)
                    {
                        for (int i = 0; i < vert.Count(); i++)
                        {
                            vert[i] = new Vector3(vert[i].x * container.scale, vert[i].y * container.scale, vert[i].z * container.scale);
                        }
                    }
                    m_mesh.SetVertices(new List <Vector3>(vert));
                }
                else
                {
                    throw new Exception("[ProceduralObjects] Loading failure : Missing mesh data !");
                }
                vertices        = Vertex.CreateVertexList(this);
                m_mesh.colors   = new Color[] { };
                m_mesh.colors32 = new Color32[] { };

                if (container.hasCustomTexture && TextureManager.instance != null)
                {
                    var customTex = TextureManager.instance.FindTexture(container.customTextureName);
                    m_material.mainTexture = customTex as Texture;
                    customTexture          = customTex;
                }
            }
            m_visibility   = container.visibility;
            renderDistance = container.renderDistance;
            MaterialOptions.FixDecalRenderDist(this);
            renderDistLocked = container.renderDistLocked;
            if (container.textParam != null)
            {
                m_textParameters = TextParameters.Clone(container.textParam, true);
                for (int i = 0; i < m_textParameters.Count(); i++)
                {
                    if (m_textParameters[i].m_fontColor == null)
                    {
                        if (m_textParameters[i].serializableColor != null)
                        {
                            m_textParameters[i].m_fontColor = m_textParameters[i].serializableColor.ToColor();
                        }
                        else
                        {
                            m_textParameters[i].m_fontColor = Color.white;
                        }
                    }
                }
                //  m_textParameters.SetFonts();
                var originalTex = new Texture2D(m_material.mainTexture.width, m_material.mainTexture.height, TextureFormat.RGBA32, false);
                originalTex.SetPixels(((Texture2D)m_material.mainTexture).GetPixels());
                originalTex.Apply();
                m_material.mainTexture = m_textParameters.ApplyParameters(originalTex) as Texture;
            }
            else
            {
                m_textParameters = null;
            }
            if (container.belongsToGroup)
            {
                if (container.groupRootId == -1)
                {
                    isRootOfGroup    = true;
                    _groupRootIdData = -1;
                }
                else
                {
                    _groupRootIdData = container.groupRootId;
                    isRootOfGroup    = false;
                }
            }
            else
            {
                _groupRootIdData = -2;
                group            = null;
                isRootOfGroup    = false;
            }

            disableRecalculation    = container.disableRecalculation;
            this.normalsRecalcMode  = container.normalsRecalculation;
            this.flipFaces          = container.flipFaces;
            this.disableCastShadows = container.disableCastShadows;
            if (this.flipFaces)
            {
                VertexUtils.flipFaces(this);
            }
            historyEditionBuffer = new HistoryBuffer(this);

            if (container.color == null)
            {
                if (!(m_mesh.name == "ploppableasphalt-prop" || m_mesh.name == "ploppableasphalt-decal"))
                {
                    m_color = Color.white;
                }
            }
            else
            {
                m_color          = container.color;
                m_material.color = m_color;
            }

            if (container.layerId != 0)
            {
                if (layerManager.m_layers.Any(l => l.m_id == container.layerId))
                {
                    layer = layerManager.m_layers.Single(l => l.m_id == container.layerId);
                }
                else
                {
                    Debug.LogError("[ProceduralObjects] Layer of an object not found !");
                }
            }
            else
            {
                layer = null;
            }
            if (container.tilingFactor == 0)
            {
                this.tilingFactor = 8;
            }
            else
            {
                this.tilingFactor = container.tilingFactor;
            }

            m_modules = ModuleManager.LoadModulesFromData(container.modulesData, true, this);
        }
Пример #15
0
 public ProceduralObject(CacheProceduralObject sourceCacheObj, int id, Vector3 position)
 {
     if (sourceCacheObj.baseInfoType == "PROP")
     {
         PropInfo sourceProp = sourceCacheObj._baseProp;
         if (sourceCacheObj._baseProp == null)
         {
             sourceProp = Resources.FindObjectsOfTypeAll <PropInfo>().FirstOrDefault(info => info.name == sourceCacheObj.basePrefabName);
         }
         this._baseProp          = sourceProp;
         this.id                 = id;
         this.basePrefabName     = sourceCacheObj.basePrefabName;
         this.baseInfoType       = "PROP";
         this.isPloppableAsphalt = sourceProp.IsPloppableAsphalt();
         renderDistance          = sourceCacheObj.renderDistance;
         m_position              = position;
         m_rotation              = sourceCacheObj.m_rotation;
         m_mesh      = sourceProp.m_mesh.InstantiateMesh();
         allVertices = sourceCacheObj.allVertices;
         m_mesh.SetVertices(new List <Vector3>(allVertices));
         m_material = GameObject.Instantiate(sourceProp.m_material);
         if (sourceProp.m_mesh.name == "ploppableasphalt-prop" || sourceProp.m_mesh.name == "ploppableasphalt-decal")
         {
             m_material.ApplyPloppableColor();
         }
     }
     else if (sourceCacheObj.baseInfoType == "BUILDING")// building
     {
         BuildingInfo sourceBuilding = sourceCacheObj._baseBuilding;
         if (sourceCacheObj._baseBuilding == null)
         {
             sourceBuilding = Resources.FindObjectsOfTypeAll <BuildingInfo>().FirstOrDefault(info => info.name == sourceCacheObj.basePrefabName);
         }
         this._baseBuilding      = sourceBuilding;
         this.id                 = id;
         this.basePrefabName     = sourceCacheObj.basePrefabName;
         this.baseInfoType       = "BUILDING";
         this.isPloppableAsphalt = false;
         renderDistance          = sourceCacheObj.renderDistance;
         m_position              = position;
         m_rotation              = sourceCacheObj.m_rotation;
         m_mesh      = sourceBuilding.m_mesh.InstantiateMesh();
         allVertices = sourceCacheObj.allVertices;
         m_mesh.SetVertices(new List <Vector3>(allVertices));
         m_mesh.colors   = new Color[] { };
         m_mesh.colors32 = new Color32[] { };
         m_material      = GameObject.Instantiate(sourceBuilding.m_material);
     }
     if (sourceCacheObj.customTexture != null)
     {
         m_material.mainTexture = sourceCacheObj.customTexture as Texture;
         customTexture          = sourceCacheObj.customTexture;
     }
     m_visibility         = sourceCacheObj.visibility;
     historyEditionBuffer = new HistoryBuffer(this);
     if (sourceCacheObj.textParam != null)
     {
         m_textParameters = TextParameters.Clone(sourceCacheObj.textParam, false);
         // m_textParameters.SetFonts();
         var originalTex = new Texture2D(m_material.mainTexture.width, m_material.mainTexture.height, TextureFormat.RGBA32, false);
         originalTex.SetPixels(((Texture2D)m_material.mainTexture).GetPixels());
         originalTex.Apply();
         m_material.mainTexture = m_textParameters.ApplyParameters(originalTex);
     }
     else
     {
         m_textParameters = null;
     }
     // this.flipFaces = sourceCacheObj.flipFaces;
     // if (this.flipFaces)
     //      VertexUtils.flipFaces(this);
     disableRecalculation = sourceCacheObj.disableRecalculation;
     this.tilingFactor    = sourceCacheObj.tilingFactor;
 }
Пример #16
0
        public ProceduralObject(ProceduralObjectContainer container, List <Texture2D> textures, LayerManager layerManager)
        {
            if (container.objectType == "PROP")
            {
                PropInfo sourceProp = Resources.FindObjectsOfTypeAll <PropInfo>().FirstOrDefault(info => info.name == container.basePrefabName);
                this._baseProp          = sourceProp;
                this.id                 = container.id;
                this.basePrefabName     = container.basePrefabName;
                this.baseInfoType       = "PROP";
                this.isPloppableAsphalt = sourceProp.IsPloppableAsphalt();
                renderDistance          = container.renderDistance;
                m_position              = container.position.ToVector3();
                m_rotation              = container.rotation.ToQuaternion();

                /*
                 * if (container.meshStatus == 0)
                 * {
                 * // CHECK FOR MESH REPETITION
                 * if (ProceduralUtils.CheckMeshEquivalence(container.vertices, sourceProp.m_mesh.vertices))
                 * {
                 *  meshStatus = 1;
                 *  m_mesh = sourceProp.m_mesh;
                 *  allVertices = sourceProp.m_mesh.vertices;
                 * }
                 * else
                 * {
                 *  meshStatus = 2;
                 * m_mesh = sourceProp.m_mesh.InstantiateMesh();
                 * allVertices = SerializableVector3.ToStandardVector3Array(container.vertices);
                 * if (container.scale != 0)
                 * {
                 *  for (int i = 0; i < allVertices.Count(); i++)
                 *  {
                 *      allVertices[i] = new Vector3(allVertices[i].x * container.scale, allVertices[i].y * container.scale, allVertices[i].z * container.scale);
                 *  }
                 * }
                 * m_mesh.SetVertices(new List<Vector3>(allVertices));
                 * // }
                 * }
                 * else if (container.meshStatus == 1)
                 * {
                 * m_mesh = sourceProp.m_mesh;
                 * allVertices = sourceProp.m_mesh.vertices;
                 * }
                 * else if (container.meshStatus == 2)
                 * { */
                m_mesh      = sourceProp.m_mesh.InstantiateMesh();
                allVertices = SerializableVector3.ToStandardVector3Array(container.vertices);
                if (container.scale != 0)
                {
                    for (int i = 0; i < allVertices.Count(); i++)
                    {
                        allVertices[i] = new Vector3(allVertices[i].x * container.scale, allVertices[i].y * container.scale, allVertices[i].z * container.scale);
                    }
                }
                m_mesh.SetVertices(new List <Vector3>(allVertices));
                // }
                m_material = GameObject.Instantiate(sourceProp.m_material); // overkil ??
                if (sourceProp.m_mesh.name == "ploppableasphalt-prop" || sourceProp.m_mesh.name == "ploppableasphalt-decal")
                {
                    m_material.ApplyPloppableColor();
                }
                if (container.hasCustomTexture && textures != null)
                {
                    if (!textures.Any(tex => tex.name == container.customTextureName))
                    {
                        Debug.LogError("[ProceduralObjects] An object was found with a texture that doesn't exist anymore with the name " + container.customTextureName + ", therefore loading the default object texture");
                    }
                    else
                    {
                        var customTex = textures.FirstOrDefault(tex => tex.name == container.customTextureName);
                        m_material.mainTexture = customTex as Texture;
                        customTexture          = customTex;
                    }
                }
            }
            else if (container.objectType == "BUILDING")// building
            {
                BuildingInfo sourceProp = Resources.FindObjectsOfTypeAll <BuildingInfo>().FirstOrDefault(info => info.name == container.basePrefabName);
                this._baseBuilding      = sourceProp;
                this.id                 = container.id;
                this.basePrefabName     = container.basePrefabName;
                this.baseInfoType       = "BUILDING";
                this.isPloppableAsphalt = false;
                renderDistance          = container.renderDistance;
                m_position              = container.position.ToVector3();
                m_rotation              = container.rotation.ToQuaternion();

                /*
                 * if (container.meshStatus == 0)
                 * {
                 * // CHECK FOR MESH REPETITION
                 * if (ProceduralUtils.CheckMeshEquivalence(container.vertices, sourceProp.m_mesh.vertices))
                 * {
                 *  meshStatus = 1;
                 *  m_mesh = sourceProp.m_mesh;
                 *  allVertices = sourceProp.m_mesh.vertices;
                 * }
                 * else
                 * {
                 *  meshStatus = 2;
                 * m_mesh = sourceProp.m_mesh.InstantiateMesh();
                 * allVertices = SerializableVector3.ToStandardVector3Array(container.vertices);
                 * if (container.scale != 0)
                 * {
                 *  for (int i = 0; i < allVertices.Count(); i++)
                 *  {
                 *      allVertices[i] = new Vector3(allVertices[i].x * container.scale, allVertices[i].y * container.scale, allVertices[i].z * container.scale);
                 *  }
                 * }
                 * m_mesh.SetVertices(new List<Vector3>(allVertices));
                 * //  m_mesh.colors = new Color[] { };
                 * //  m_mesh.colors32 = new Color32[] { };}
                 * // }
                 * }
                 * else if (container.meshStatus == 1)
                 * {
                 * m_mesh = sourceProp.m_mesh;
                 * allVertices = sourceProp.m_mesh.vertices;
                 * }
                 * else if (container.meshStatus == 2)
                 * {*/
                m_mesh      = sourceProp.m_mesh.InstantiateMesh();
                allVertices = SerializableVector3.ToStandardVector3Array(container.vertices);
                if (container.scale != 0)
                {
                    for (int i = 0; i < allVertices.Count(); i++)
                    {
                        allVertices[i] = new Vector3(allVertices[i].x * container.scale, allVertices[i].y * container.scale, allVertices[i].z * container.scale);
                    }
                }
                m_mesh.SetVertices(new List <Vector3>(allVertices));
                m_mesh.colors   = new Color[] { };
                m_mesh.colors32 = new Color32[] { };
                // }

                m_material = GameObject.Instantiate(sourceProp.m_material); // overkill ??
                if (container.hasCustomTexture && textures != null)
                {
                    if (!textures.Any(tex => tex.name == container.customTextureName))
                    {
                        Debug.LogError("[ProceduralObjects] An object was found with a texture that doesn't exist anymore at the specified path " + container.hasCustomTexture + ", therefore loading the default object texture");
                    }
                    else
                    {
                        var customTex = textures.FirstOrDefault(tex => tex.name == container.customTextureName);
                        m_material.mainTexture = customTex as Texture;
                        customTexture          = customTex;
                    }
                }
            }
            m_visibility = container.visibility;
            if (container.textParam != null)
            {
                m_textParameters = TextParameters.Clone(container.textParam, true);
                for (int i = 0; i < m_textParameters.Count(); i++)
                {
                    if (m_textParameters[i].m_fontColor == null)
                    {
                        if (m_textParameters[i].serializableColor != null)
                        {
                            m_textParameters[i].m_fontColor = m_textParameters[i].serializableColor.ToColor();
                        }
                        else
                        {
                            m_textParameters[i].m_fontColor = Color.white;
                        }
                    }
                }
                //  m_textParameters.SetFonts();
                var originalTex = new Texture2D(m_material.mainTexture.width, m_material.mainTexture.height, TextureFormat.RGBA32, false);
                originalTex.SetPixels(((Texture2D)m_material.mainTexture).GetPixels());
                originalTex.Apply();
                m_material.mainTexture = m_textParameters.ApplyParameters(originalTex) as Texture;
            }
            else
            {
                m_textParameters = null;
            }
            disableRecalculation = container.disableRecalculation;
            //  this.flipFaces = container.flipFaces;
            //  if (this.flipFaces)
            //      VertexUtils.flipFaces(this);
            historyEditionBuffer = new HistoryBuffer(this);
            if (container.layerId != 0)
            {
                if (layerManager.m_layers.Any(l => l.m_id == container.layerId))
                {
                    layer = layerManager.m_layers.Single(l => l.m_id == container.layerId);
                }
                else
                {
                    Debug.LogError("[ProceduralObjects] Layer of an object not found !");
                }
            }
            else
            {
                layer = null;
            }
            if (container.tilingFactor == 0)
            {
                this.tilingFactor = 8;
            }
            else
            {
                this.tilingFactor = container.tilingFactor;
            }
        }