コード例 #1
0
    public void OnUpdate()
    {
        if (Renderer == null)
        {
            return;
        }

        if (LogicProjectile.GetVisibility() < 2)
        {
            oldVisibility          = false;
            Renderer.enabled       = false;
            ShadowRenderer.enabled = false;
            return;
        }
        else if (!oldVisibility)
        {
            Renderer.enabled       = true;
            ShadowRenderer.enabled = HasShadow;
            oldVisibility          = true;
            return;
        }

        if (LogicProjectile.DoUpdateView)
        {
            Renderer.enabled       = true;
            ShadowRenderer.enabled = HasShadow;

            /*if (_ProjectileSprite == null)
             *  _ProjectileSprite = Images.Load256("graphics/backpack/sprites.256");*/
            LogicProjectile.Class.UpdateSprite();

            Images.AllodsSprite sprites = LogicProjectile.Class.File;

            if (sprites == null || !spriteSet)
            {
                if (LogicProjectile.Class.ID == 7) // bat_sonic attack, apparently hardcoded
                {
                    Renderer.material = new Material(MainCamera.BatShader);
                }
                else
                {
                    Renderer.material = new Material(MainCamera.MainShaderPaletted);
                    if (LogicProjectile.Class.HasPalette)
                    {
                        Renderer.material.SetTexture("_Palette", sprites.OwnPalette); // no palette swap for this one
                    }
                    else
                    {
                        if (_BasePalette == null)
                        {
                            _BasePalette = Images.LoadPalette("graphics/projectiles/projectiles.pal");
                        }
                        Renderer.material.SetTexture("_Palette", _BasePalette);
                    }
                    ShadowRenderer.material       = Renderer.material;
                    ShadowRenderer.material.color = new Color(0, 0, 0, 0.5f);
                }
                spriteSet = true;
            }

            int actualFrame = 0;
            // now, projectile frame is RotationPhases * angle + CurrentFrame
            // thus, max count of frames is Count / RotationPhases
            int actualRotationPhases;
            if (LogicProjectile.Class.RotationPhases > 0)
            {
                actualRotationPhases = LogicProjectile.Class.RotationPhases;
            }
            else
            {
                actualRotationPhases = 16;
            }
            int actualAngle = 0;


            int lPA = (int)(Mathf.Round((float)LogicProjectile.Angle / 45) * 45) % 360;
            // calculate nearest angle

            bool doFlip = false;
            if (actualRotationPhases < 1)
            {
                actualAngle = 0;
            }
            else if (LogicProjectile.Class.Flip)
            {
                actualRotationPhases = actualRotationPhases / 2;
                if (LogicProjectile.Angle < 180)
                {
                    actualAngle = lPA * actualRotationPhases / 180;
                }
                else
                {
                    actualAngle = (180 - (lPA - 180)) * actualRotationPhases / 180;
                    doFlip      = true;
                }
            }
            else
            {
                actualAngle = lPA * actualRotationPhases / 360;
            }

            actualAngle %= 16;

            actualFrame = LogicProjectile.Class.Phases * actualAngle + LogicProjectile.CurrentFrame;
            //Debug.LogFormat("actualFrame = {0}, actualAngle = {1}", actualFrame, actualAngle);

            // always centered
            Vector2 xP = MapView.Instance.MapToScreenCoords(LogicProjectile.ProjectileX, LogicProjectile.ProjectileY - LogicProjectile.ProjectileZ, 1, 1);
            if (LogicProjectile.Class.ID == 7)
            {
                transform.localPosition = new Vector3(xP.x - 16,
                                                      xP.y - 16,
                                                      MakeZFromY(xP.y) - 128); // order sprites by y coordinate basically
            }
            else
            {
                transform.localPosition = new Vector3(xP.x - sprites.Sprites[actualFrame].rect.width * 0.5f,
                                                      xP.y - sprites.Sprites[actualFrame].rect.height * 0.5f,
                                                      MakeZFromY(xP.y) - 128); // order sprites by y coordinate basically
            }

            //Debug.Log(string.Format("{0} {1} {2}", xP.x, sprites.Sprites[0].rect.width, LogicObstacle.Class.CenterX));
            //Renderer.sprite = sprites.Sprites[actualFrame];
            ProjectileMesh = UpdateMesh(sprites, actualFrame, Filter.mesh, 0, (ProjectileMesh == null), doFlip);
            ShadowMesh     = UpdateMesh(sprites, actualFrame, ShadowFilter.mesh, 0.3f, (ShadowMesh == null), doFlip); // 0.3 of sprite height

            LogicProjectile.DoUpdateView = false;
        }
    }
コード例 #2
0
    public void OnUpdate()
    {
        if (Renderer == null)
        {
            return;
        }

        if (LogicProjectile.Class == null)
        {
            oldVisibility          = false;
            Renderer.enabled       = false;
            ShadowRenderer.enabled = false;
            return;
        }

        if (LogicProjectile.GetVisibility() < 2)
        {
            oldVisibility          = false;
            Renderer.enabled       = false;
            ShadowRenderer.enabled = false;
            return;
        }
        else if (!oldVisibility)
        {
            Renderer.enabled       = true;
            ShadowRenderer.enabled = HasShadow;
            oldVisibility          = true;
            return;
        }

        if (LogicProjectile.DoUpdateView)
        {
            Renderer.enabled       = true;
            ShadowRenderer.enabled = HasShadow;

            /*if (_ProjectileSprite == null)
             *  _ProjectileSprite = Images.Load256("graphics/backpack/sprites.256");*/
            LogicProjectile.Class.UpdateSprite();

            Images.AllodsSprite sprites = LogicProjectile.Class.File;

            if (sprites == null || !spriteSet)
            {
                if (LogicProjectile.Class.ID == 7) // bat_sonic attack, apparently hardcoded
                {
                    Renderer.material = new Material(MainCamera.BatShader);
                }
                else
                {
                    Renderer.material = new Material(MainCamera.MainShaderPaletted);
                    if (LogicProjectile.Class.HasPalette)
                    {
                        Renderer.material.SetTexture("_Palette", sprites.OwnPalette); // no palette swap for this one
                    }
                    else
                    {
                        if (_BasePalette == null)
                        {
                            _BasePalette = Images.LoadPalette("graphics/projectiles/projectiles.pal");
                        }
                        Renderer.material.SetTexture("_Palette", _BasePalette);
                    }
                    ShadowRenderer.material       = Renderer.material;
                    ShadowRenderer.material.color = new Color(0, 0, 0, 0.5f);
                }
                spriteSet = true;
            }

            // This is a hack for prismatic spray support. Maybe something else in the future
            Renderer.material.color = new Color(LogicProjectile.Color.r,
                                                LogicProjectile.Color.g,
                                                LogicProjectile.Color.b,
                                                LogicProjectile.Color.a * LogicProjectile.Alpha);

            int actualFrame = 0;
            // now, projectile frame is RotationPhases * angle + CurrentFrame
            // thus, max count of frames is Count / RotationPhases
            int actualRotationPhases;
            if (LogicProjectile.Class.RotationPhases > 0)
            {
                actualRotationPhases = LogicProjectile.Class.RotationPhases;
            }
            else
            {
                actualRotationPhases = 16;
            }
            int actualAngle = 0;


            int lPA = (int)(Mathf.Round((float)LogicProjectile.Angle / 45) * 45) % 360;
            // calculate nearest angle

            bool doFlip = false;
            if (actualRotationPhases < 1)
            {
                actualAngle = 0;
            }
            else if (LogicProjectile.Class.Flip)
            {
                actualRotationPhases = actualRotationPhases / 2;
                if (LogicProjectile.Angle < 180)
                {
                    actualAngle = lPA * actualRotationPhases / 180;
                }
                else
                {
                    actualAngle = (180 - (lPA - 180)) * actualRotationPhases / 180;
                    doFlip      = true;
                }
            }
            else
            {
                actualAngle = lPA * actualRotationPhases / 360;
            }

            actualAngle %= 16;

            actualFrame = LogicProjectile.Class.Phases * actualAngle + LogicProjectile.CurrentFrame;
            //Debug.LogFormat("actualFrame = {0}, actualAngle = {1}", actualFrame, actualAngle);

            Vector2 xP;
            if (LogicProjectile.ZAbsolute)
            {
                xP    = new Vector2(LogicProjectile.ProjectileX * 32, LogicProjectile.ProjectileY * 32);
                xP.y -= LogicProjectile.ProjectileZ * 32;
            }
            else if (LogicProjectile.Class.ID != (int)AllodsProjectile.Lightning)
            {
                xP    = MapView.Instance.MapToScreenCoords(LogicProjectile.ProjectileX, LogicProjectile.ProjectileY, 1, 1);
                xP.y -= LogicProjectile.ProjectileZ * 32;
            }
            else
            {
                xP = MapView.Instance.MapToScreenCoords(LogicProjectile.ProjectileX, LogicProjectile.ProjectileY - LogicProjectile.ProjectileZ, 1, 1);
            }

            // always centered
            transform.localPosition = new Vector3(xP.x - LogicProjectile.Class.Width * 0.5f * LogicProjectile.Scale,
                                                  xP.y - LogicProjectile.Class.Height * 0.5f * LogicProjectile.Scale,
                                                  MakeZFromY(xP.y) - LogicProjectile.ZOffset - LogicProjectile.ProjectileZ * 32);   // order sprites by y coordinate basically

            transform.localScale = new Vector3(LogicProjectile.Scale, LogicProjectile.Scale, LogicProjectile.Scale);
            ShadowObject.transform.localScale = new Vector3(LogicProjectile.Scale, LogicProjectile.Scale, LogicProjectile.Scale);

            ProjectileMesh = UpdateMesh(sprites, actualFrame, Filter.mesh, 0, (ProjectileMesh == null), doFlip);
            ShadowMesh     = UpdateMesh(sprites, actualFrame, ShadowFilter.mesh, 0.3f, (ShadowMesh == null), doFlip); // 0.3 of sprite height

            LogicProjectile.DoUpdateView = false;
        }
    }