예제 #1
0
    public static void CreateCoverFlow(MenuCommand menuCommand)
    {
        //从asset中获取coverflow参数
        CoverFlowParameters.Instance = AssetDatabase.LoadAssetAtPath <CoverFlowParameters>("Assets/Settings/CoverFlowParameters.asset");
        CoverFlowParameters coverFlowParameters = CoverFlowParameters.Instance;

        //CoverFlow根对象
        GameObject    coverflow     = new GameObject("CoverFlow");
        RectTransform coverflowRTrs = coverflow.AddComponent <RectTransform>();
        Transform     parent        = (menuCommand.context as GameObject).transform;

        coverflow.transform.SetParent(parent, false);

        CoverFlowBehavior coverFlowBehavior = coverflow.AddComponent <CoverFlowBehavior>();

        coverFlowBehavior.imageHeight = coverFlowParameters.imageSizeDelta.y;

        //CoverFlow图片子对象
        for (int i = 0; i < coverFlowParameters.imageCount; i++)
        {
            GameObject    image     = new GameObject("Image" + i);
            RectTransform imageRTrs = image.AddComponent <RectTransform>();
            image.transform.SetParent(coverflowRTrs, false);
            imageRTrs.sizeDelta = coverFlowParameters.imageSizeDelta;

            image.AddComponent <RawImage>();
            AspectRatioFitter aspectRatioFitter = image.AddComponent <AspectRatioFitter>();
            aspectRatioFitter.aspectMode = AspectRatioFitter.AspectMode.HeightControlsWidth;

            CoverFlowImageBehavior coverFlowImageBehavior = image.AddComponent <CoverFlowImageBehavior>();
            coverFlowImageBehavior.coverFlowIndex = i - coverFlowParameters.imageCount / 2;
        }
    }
예제 #2
0
    private void Awake()
    {
        rTrs              = GetComponent <RectTransform>();
        rawImage          = GetComponent <RawImage>();
        aspectRatioFitter = GetComponent <AspectRatioFitter>();

        coverFlowBehavior = transform.parent.GetComponent <CoverFlowBehavior>();
        coverFlowBehavior.setImageIndex   += SetIndex;        //订阅刷新图片索引事件
        coverFlowBehavior.setImageDisPlay += SetImageDisplay; //订阅刷新图片显示效果事件
    }