using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Allegiance;

public class OnPossessChangeMaterial : MonoBehaviour, Event.ILocalAction<PossessEvent>, Event.ILocalAction<DepossessEvent>
{
    [System.Serializable]
    public struct SkinChange
    {
        public Renderer renderer;
        public Material matA;
        public Material matB;
    }

    public List<SkinChange> changes;
    Ownership owner;

    void Start() {
        Ownership owner = GetComponent<BasicWeapon>().owner;
    }

    public void OnEvent(PossessEvent arg)
    {
        changes.ForEach(s => s.renderer.material = s.matB);
    }
    public void OnEvent(DepossessEvent arg)
    {
        changes.ForEach(s => s.renderer.material = s.matA);
    }

    void Update() {
        if(this.gameObject == PlayerManager.I.unit.gameObject) {
            PossessionManager.I.possessed = this.gameObject;
        }
    }
}
