android 2.3 webview transform,UGUI UniWebView适配

using System.Collections;

using System.Collections.Generic;

using NxFish;

using UnityEngine;

using UnityEngine.UI;

public class UniTest : MonoBehaviour {

private UniWebView webView;

public NxFish.Data.AccountData account;

public RectTransform trans;

public Button btn_back;

private float viewWidth= 1920f;

private float viewHeght= 1080f;

float scaleWidth ;

float scaleHeight;

private void Awake() {

//this.webView = Singleton.Instance;

if (webView == null) {

webView = this.gameObject.AddComponent();

}

scaleWidth = (Screen.width * 1f / viewWidth);

scaleHeight = (Screen.height * 1f / viewHeght);

}

// Use this for initialization

void Start () {

btn_back.onClick.AddListener(()=> {

});

//动态修改panel大小

UnityEngine.Debug.Log(trans.rect.top + ":" +trans.rect.bottom + ":" + trans.rect.left + ":" + trans.rect.right);

//this.webView.Show(this.account.platformLink, trans.rect, () => { UnityEngine.Debug.Log("游戏加载完成"); });

float neweWidth = scaleWidth * trans.sizeDelta.x;

float neweHeight = scaleHeight * trans.sizeDelta.y;

//this.SetRectTransformSize(trans, new Vector2(neweWidth, neweHeight));

this.WebViewInsets();

this.webView.Load(this.account.platformLink);

this.webView.Show(true, UniWebViewTransitionEdge.None, 0.3f);

}

public void SetRectTransformSize(RectTransform trans, Vector2 newSize) {

Vector2 oldSize = trans.rect.size;

Vector2 deltaSize = newSize - oldSize;

trans.offsetMin = trans.offsetMin - new Vector2(deltaSize.x * trans.pivot.x, deltaSize.y * trans.pivot.y);

trans.offsetMax = trans.offsetMax + new Vector2(deltaSize.x * (1f - trans.pivot.x), deltaSize.y * (1f - trans.pivot.y));

}

void WebViewInsets() {

Vector3[] VectorArray=new Vector3[4];

trans.GetWorldCorners(VectorArray);

//Vector3 bottomLeft = Camera.main.WorldToScreenPoint(VectorArray[0]);

//Vector3 topRight = Camera.main.WorldToScreenPoint(VectorArray[2]);

float Left = VectorArray[0].x;

float Top = Screen.height - VectorArray[2].y;

float Bottom = VectorArray[0].y;

float Right = Screen.width - VectorArray[2].x;

//UnityEngine.Debug.Log(Left + ":" + Top + ":" + Bottom + ":" + Right);

//this.webView.insets = new UniWebViewEdgeInsets(UniWebViewHelper.ConvertPixelToPoint(Top, false), UniWebViewHelper.ConvertPixelToPoint(Left, true), UniWebViewHelper.ConvertPixelToPoint(Bottom, false), UniWebViewHelper.ConvertPixelToPoint(Right, true));

this.webView.insets = new UniWebViewEdgeInsets(70 * (int)scaleHeight, 0, 0, 0);

}

}

41aecd6c8e332624f296b4df03792f22.png

Image是容器

a3a15fe79800dd8411476e1ffbadc96d.png

附:

Android刘海屏手机适配正在测试中。。

iPhoneX可以单独处理

标签:适配,float,VectorArray,new,UniWebView,UGUI,trans,webView,rect

来源: https://blog.csdn.net/u012909508/article/details/97803964

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值