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

public class CameraCaptureViewFinder : MonoBehaviour
{
    private class ViewFinderOptions
    {
       public GameObject go;
       public bool enable;

        public ViewFinderOptions(GameObject _go, bool _enable)
        {
            enable = _enable;
            go = _go;
        }
    }


    private IEnumerator AttachAfterDisable(GameObject go)
    {
        yield return null;

        Attach(go);
    }

    private IEnumerator AttachWithEnable(ViewFinderOptions options)
    {
        yield return null;

        Attach(options.go);
        gameObject.SetActive(options.enable);
    }


    public void Attach(GameObject go)
    {
        if (transform.parent.gameObject != go)
        {
            transform.SetParent(go.transform, false);
        }
    }

    public void AttachViewFinder(GameObject go)
    {
        StartCoroutine("AttachAfterDisable", go);
    }

    public void AttachAndEnable(GameObject go, bool enable)
    {
        //enable so we can reparent
        gameObject.SetActive(true);
        StartCoroutine("AttachWithEnable", new ViewFinderOptions(go, enable));
    }


}
