• Runtimes
  • [Unity]Material change the code after update not working(

  • Đã chỉnh sửa
Related Discussions
...
  • Đã chỉnh sửa
protected override void _Init()
    {
        base._Init();

    if (skeletonAnimation == null)
    {
        skeletonAnimation = cachedTransform.gameObject.AddComponent<SkeletonAnimation>();
    }

    if (spineAnimationManager == null)
    {
        spineAnimationManager = cachedTransform.gameObject.AddComponent<SpineAnimationManager>();
    }

    Material[] newMaterial = new Material[renderer.materials.Length];
    
    for ( int i = 0; i < renderer.materials.Length; i++ )
    {
        newMaterial[i] = new Material(renderer.materials[i]);
    }

    renderer.materials = newMaterial;
    m_shadowRenderer.sprite = ResourcesManager.LoadAsset<Sprite>("shadow/cha_shadow", ResourcesManager.AssetParentPath.Sprites);

    m_objType = ObjectType.Unit;
    m_fsm = new CFSM_Unit();
    m_fsm.ownerObject = this;
}

protected virtual void _UpdateDamageEffect()
    {
        if (m_isShowDamageEffect)
        {
            m_damageEffectTimer += Time.deltaTime;
            if (m_damageEffectTimer < m_damageEffectTime)
            {
                cachedRenderer.material.SetColor("_Color", new Color(1, 0.38f, 0.38f, 1));
            }
            else
            {
                EndDamageEffect();
            }
        }
    }

Material change the code after update not working(2.0 -> 2.1)

change in the source of the LateUpdate skeletonRendrer I think.
The change in value of a particular Material shaders, but How?

I Want Change Material....

I'm not sure what you code is meant to do and what doesn't work?

You can tint a whole skeleton by setting the r, g, b, a properties on the skeleton. You can tint the image for a particular slot by setting the r, g, b, a properties on the slot.

Yeah. Use Skeleton's a, r, g, and b. You can get the skeleton reference from SkeletonAnimation.

Spine doesn't do instance-specific stuff through the material.
This allows the material to be shared across several instances and even different types of skeletons. (which allows them to be batched).

I'm not English..
I Use Google Translate....

I want Change Material
Show Attachments Imgae

Spine uses renderer.sharedMaterials. If you change "_Color" on these, it will change for all skeletons. This is easier:

if (m_damageEffectTimer < m_damageEffectTime) {
    skeletonAnimation.skeleton.R = 1;
    skeletonAnimation.skeleton.G = 0.38f;
    skeletonAnimation.skeleton.B = 0.38f;
    skeletonAnimation.skeleton.A = 1;
} else {
    skeletonAnimation.skeleton.R = 1;
    skeletonAnimation.skeleton.G = 1;
    skeletonAnimation.skeleton.B = 1;
    skeletonAnimation.skeleton.A = 1;
}

Pharan, any ideas for using the material instance stuff, for when you need to change a material for a single skeleton instance?

Thank You. The problem was resolved

Nate đã viết

Pharan, any ideas for using the material instance stuff, for when you need to change a material for a single skeleton instance?

Sorry. I can't say I have any experience implementing anything in that area of Unity. I just remember the interface gets weird with sharedMaterials and materials and that some properties return copies instead of references. I know per-instance stuff is possible though, if not a little dirtier than some might like.

một tháng sau

Hey guys, I'm trying to do exactly what Pharan just said he doesn't know how to do. <_< I have multiple enemy skeletons and I'm trying to change the material for single instances without affecting the rest of the instances. I talked to Mr. 2D Toolkit (which I also use) Unikron and he says my issue is that tk2D is changing my material back, so I'd have to dig into the code manually and force some stuff. Seems simple enough, but Spine is complicating things, and I don't know if it's possible to get what I need from a SkeletonAnimation object. If it helps, here's what Unikron says:

"If you want to swap the material at runtime you will need to manage it yourself. Hook into the SpriteChanged event on the sprite, then when the sprite changes, swap the material from the original. tk2d will reassign material every time you change sprite, i..e. while you're playing an animation."

"tk2dBaseSprite.SpriteChanged. Its a c# event. The attach point script uses it if you want an example."

http://2dtoolkit.com/forum/index.php/topic,4087.0.html

Any idea if it's possible to access base tk2D components through a SkeletonAnimation object?

Look at how SkeletonRenderer casts the renderer object. You can change SpriteCollectionAttachmentLoader so it stores the TK2D object instead of the Material.