<repo_name>ukun1708/UserInterface<file_sep>/Assets/Scripts/Scrolling.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Scrolling : MonoBehaviour
{

    public GameObject scrollContent;

    private Coroutine coroutine;

    public void scrollVerticalPlus()
    {
        if (coroutine != null)
        {
            StopCoroutine(coroutine);
        }

        coroutine = StartCoroutine(ScrollingVerticalCor(1000f));
    }

    public void scrollVerticalMinus()
    {
        if (coroutine != null)
        {
            StopCoroutine(coroutine);
        }

        coroutine = StartCoroutine(ScrollingVerticalCor(-1000f));
    }

    IEnumerator ScrollingVerticalCor(float delta)
    {
        RectTransform rectTransform = scrollContent.GetComponent<RectTransform>();

        float time = 0f;

        float timer = 1f;

        float targetHeight = rectTransform.anchoredPosition.y + delta;

        if (targetHeight < 0f)
        {
            targetHeight = 0f;
        }

        if (targetHeight > rectTransform.sizeDelta.y)
        {
            targetHeight = rectTransform.sizeDelta.y;
        }

        while (time < timer)
        {
            time += Time.deltaTime;

            rectTransform.anchoredPosition = new Vector2(0f, Mathf.Lerp(rectTransform.anchoredPosition.y, targetHeight, time));

            yield return null;
        }
    }
}
<file_sep>/Assets/Scripts/Demo.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class Demo : MonoBehaviour
{
    public ItemView button;

    void Start()
    {
        ItemModel model =  GameConfig.StartSer();

        for (int i = 0; i < 100; i++)
        {
            ItemView view = Instantiate(button, transform);

            view.model = model;

            view.UpdateView();
        }
    }
}
<file_sep>/Assets/Scripts/ItemModel.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ItemModel
{
	public string avatar;

	public string countSubject;

	public string playerName;

	public string price;

	public string productImage;

	public string productName;
}
<file_sep>/Assets/Scripts/PopUp.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PopUp : MonoBehaviour
{

    public GameObject popPage;

    public void Pop()
    {
        popPage.SetActive(true);
    }

    public void ClosePop()
    {
        popPage.SetActive(false);
    }

    public void AppQuit()
    {
        Application.Quit();        
    }
}
<file_sep>/README.md
UserInterface
=============
Практика создания пользовотельского интерфейса под любые соотношения сторон экрана

<img src="Recorder/interface.gif" />
 
<file_sep>/Assets/Scripts/Clock.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Clock : MonoBehaviour
{
    TextMeshProUGUI textMesh;

    float hours = 00f, minut = 00f, second = 00f;

    void Start()
    {
        textMesh = GetComponent<TextMeshProUGUI>();
    }

    
    void Update()
    {
        textMesh.text = hours.ToString("F0") + ":" + minut.ToString("F0") + ":" + second.ToString("F0");

        second += Time.deltaTime;

        if (second > 59f)
        {
            minut += 1f;

            second = 0f;
        }
        if (minut > 59f)
        {
            hours += 1f;

            minut = 0f;

            second = 0f;
        }
        if (hours > 23f)
        {
            hours = 0f;

            minut = 0f;

            second = 0f;
        }
    }
}
<file_sep>/Assets/Scripts/ItemView.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;

public class ItemView : MonoBehaviour
{
    public Image avatarImg;

    public TextMeshProUGUI countSub;

    public TextMeshProUGUI player_Name;

    public TextMeshProUGUI price;

    public Image productImg;

    public TextMeshProUGUI productName;

    public ItemModel model;
    public void UpdateView()
    {
        productName.text = model.productName;

        player_Name.text = model.playerName;

        price.text = model.price;

        countSub.text = model.countSubject;

        StartCoroutine(LoadSpriteFromUrl(avatarImg, model.avatar));

        var sp = Resources.Load<Sprite>(model.productImage);

        productImg.sprite = sp;
    }

    
    IEnumerator LoadSpriteFromUrl(Image image, string url)
    {
        WWW www = new WWW(url);
        yield return www;
        image.sprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0, 0));
    }
}
<file_sep>/Assets/Scripts/GameConfig.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameConfig : MonoBehaviour
{
    public static ItemModel StartSer()
	{
		ItemModel model;

		string path = Application.streamingAssetsPath + "/item_00.json";

		UnityEngine.Networking.UnityWebRequest www = UnityEngine.Networking.UnityWebRequest.Get(path);

		www.SendWebRequest();

		while (!www.isDone)
		{

		}

		string text = www.downloadHandler.text;

		model = JsonUtility.FromJson<ItemModel>(text);

		return model;
	}
}
