using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using AX.InputSystem;

[RequireComponent(typeof(BaseGameObjInfo))]
public class TestScroll : MonoBehaviour
{

	// Use this for initialization
	void Start () {
        
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    void OnEnable()
    {
        this.GetComponent<ScrollRect>().onValueChanged.AddListener(OnValueChanged);
    }

    void OnDisable()
    {
        this.GetComponent<ScrollRect>().onValueChanged.RemoveListener(OnValueChanged);
    }

    void OnDestroy()
    {
        this.GetComponent<ScrollRect>().onValueChanged.RemoveListener(OnValueChanged);
    }

    public void OnValueChanged(Vector2 vctr)
    {
        var arg = new UIScrollCmdArgs();
        arg.vctr = vctr;

        ValueChanged(arg);
    }

    public void ValueChanged(CmdArgs arg)
    {
        if (GameSettings.othersSettings.playState==PlayState.Playing)
        {
            transform.Find("Scrollbar Vertical").GetComponent<Scrollbar>().value = ((UIScrollCmdArgs)arg).vctr.y;
        }

        RegisterUIInputEvent.RegisterUIInputHistory(gameObject, this.GetType().Name, "ValueChanged", arg);

        Debug.Log("Scrolled!"); 
    }
}