rolopogo / ValheimMods

MIT License
20 stars 25 forks source link

CustomSails restore default texture #31

Open douglas-srs opened 3 years ago

douglas-srs commented 3 years ago

@rolopogo Can you please add an option to restore the default texture of the sail?

I already implemented it for myself, maybe this can help:

In order to get back the default texture, just remove the URL from the Sail and press enter.

//SailUrlSetter class
...
private Texture defaultTexture;
...
private void Awake()
{
    ...
    sailRenderer = ...
    defaultTexture = sailRenderer.material.GetTexture("_MainTex");
}

public void SetText(string text)
{
    if (!PrivateArea.CheckAccess(transform.position, 0f, true))
    {
        return;
    }

    if (text == String.Empty)
    {
        ApplyDefaultTexture();
    } else
    {
        StartCoroutine(DownloadTexture(text, ApplyTexture));
    }            
}

private void ApplyDefaultTexture()
{
    m_nview.ClaimOwnership();
    m_nview.GetZDO().Set("SailUrl", String.Empty);
    sailRenderer.material.SetTexture("_MainTex", defaultTexture);
}
douglas-srs commented 3 years ago

Also, I'm working on a CustomBanners mod totally inspired on your CustomSails mod and I want no credits for it, it's already working with only one "bug", as you already know the Banner textures are kind of "duplicated and mirrored on both sides", that's cool but that would not work for custom urls since get messed up. I'm new to Unity and C# so I have no idea how to fix this behaviour.

Would you be kind enough to take ownership of it? It has the same style as your own mods, all you gotta do is rename the BepInPlugin namespace :)

douglas-srs commented 3 years ago

Here is an example of how it is in-game: image And here is the image I used: gato fw