UILogin

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

public class UILogin : UIBase 
{
	public UIInput mInputAccount, mInputPwd;
	public GameObject mObjLogin;

	void OnClickEvent(GameObject objChild)
	{
		switch ( objChild.name )
		{
		case "btnLogin":
			this.StartLogin();
			break;
		}
	}
	
	public override void InitUI(UIFont font, Camera uiCamera, UIData uidata )
    {
        base.InitUI(font, uiCamera, uidata);
		this.OpenLoginUI();

		mInputAccount.defaultText = StringsMgr.cstr_userDefaultText;
		mInputAccount.text =PlayerPrefs.GetString ("playerAccount");// GameClient.Instance.MyGameLogin.MyAccount;
		mInputPwd.defaultText =StringsMgr.cstr_pwdDefaultText;
		mInputPwd.text =PlayerPrefs.GetString ("playerPwd"); //GameClient.Instance.MyGameLogin.MyPassword;
    }
	
	private void OpenLoginUI ()
	{
		#if (UNITY_ANDROID || UNITY_IPHONE || UNITY_WP8) && !UNITY_EDITOR && !USE_ACCOUNTTYPE
		mObjLogin.SetActive(false);
		this.StartLogin();
		#else
		mObjLogin.SetActive(true);
		#endif
	}

	public override void OpenWindow()
    {
        base.OpenWindow();
		SetCameraData ();
    }
	private void SetCameraData()
	{
		Camera cam = Camera.main;
		cam.fieldOfView = 72f;
		if(cam.GetComponent<CameraScript>() == null){
			cam.gameObject.AddComponent<CameraScript>();
		}
//		GameObject go = new GameObject ("targetParent");
//		go.transform.position = new Vector3 (116.8f,154.6f,70.6f);
//		CameraScript.instance.targetParent = go.transform;
//		GameObject go = new GameObject ("camPrivot");
//		CameraScript.instance.cameraPivot = go.transform;
		CameraScript.instance.transform.position = new Vector3(115.99f,150.62f,77.06f);
		CameraScript.instance.transform.rotation = Quaternion.Euler (new Vector3(9.453053f,248.9984f,0.0f));
	}
    public override void CloseWindow()
    {
        base.CloseWindow();
    }
    
	private void StartLogin()
	{
		if (mInputAccount.text.Length == 0)
			return;
		if (HasInvalidChar (mInputAccount.text))
			return;
		if (mInputPwd.text.Length == 0)
			return;
		if (HasInvalidChar (mInputPwd.text))
			return;
		mObjLogin.SetActive(false);
  
		GameClient.Instance.MyGameLogin.MyAccount = mInputAccount.text;
		GameClient.Instance.MyGameLogin.MyPassword = mInputPwd.text;
		PlayerPrefs.SetString ("playerAccount",mInputAccount.text);
		PlayerPrefs.SetString ("playerPwd",mInputPwd.text);

		GameClient.Instance.MyGameLogin.StartLogin();
	}

	private bool HasInvalidChar(string str)
	{
		return(str.IndexOf (' ') >= 0) || str != str.Trim () || str.IndexOf ('\r') >= 0 || str.IndexOf ('\n') >= 0;
	}

	private void Enter()
	{
		this.StartLogin();
	}
	
	void FixedUpdate()
	{
		if ( !mObjLogin.activeSelf && GameClient.Instance.MyGameLogin.mLoginState == eLoginState.l_faild)
		{
			GameClient.Instance.MyGameLogin.mLoginState = eLoginState.l_none;
			mObjLogin.SetActive(true);
		}
	}
}

import { Application, Assets, Sprite } from "pixi.js"; import { UIManager } from "./Frame/UIManager.js"; import { UILogin } from "./UIView/uiLogin.js"; import i18n from "./Frame/localize/localizeMgr.js"; import util from "./Frame/util.js"; import { dataPersistenceMgr } from "./Frame/dataPersistenceMgr.js"; import networkMgr from "./Frame/networkMgr.js"; import gameData from "./Frame/gameDataMgr.js"; // 目标宽高比 (优先20:9,最低16:9) const IDEAL_ASPECT = 20 / 9; const MIN_ASPECT = 16 / 9; // 基础设计尺寸(建议使用20:9比例) const DESIGN_WIDTH = 1280; const DESIGN_HEIGHT = 576; // 1280 / (20/9) ≈ 576 let isLandscape = false; let app; // 首次调整 resizeApp(); window.addEventListener("resize", resizeApp); // 检测横竖屏 screen.orientation?.addEventListener("change", handleOrientation); window .matchMedia("(orientation: portrait)") .addEventListener("change", handleOrientation); function resizeApp() { if (!app) return; const availableWidth = window.innerWidth; const availableHeight = window.innerHeight; // 1. 计算当前屏幕宽高比 const currentAspect = availableWidth / availableHeight; // 2. 确定目标宽高比(在约束范围内) const targetAspect = Math.max( MIN_ASPECT, Math.min(IDEAL_ASPECT, currentAspect), ); // 3. 计算画布尺寸 let canvasWidth, canvasHeight; if (currentAspect > targetAspect) { // 屏幕过宽 → 高度撑满,宽度按比例 canvasHeight = availableHeight; canvasWidth = canvasHeight * targetAspect; } else { // 屏幕过高 → 宽度撑满,高度按比例 canvasWidth = availableWidth; canvasHeight = canvasWidth / targetAspect; } // 4. 更新Pixi视口 app.renderer.resize(canvasWidth, canvasHeight); // 5. 居中定位画布 app.view.style.width = `${canvasWidth}px`; app.view.style.height = `${canvasHeight}px`; app.view.style.position = "absolute"; app.view.style.left = `${(availableWidth - canvasWidth) / 2}px`; app.view.style.top = `${(availableHeight - canvasHeight) / 2}px`; // 6. 缩放舞台内容(可选) scaleStage(canvasWidth, canvasHeight); } function scaleStage(width, height) { // 按设计尺寸缩放内容 const scaleX = width / DESIGN_WIDTH; const scaleY = height / DESIGN_HEIGHT; const scale = Math.min(scaleX, scaleY); app.stage.scale.set(scale); app.stage.position.set( (width - DESIGN_WIDTH * scale) / 2, (height - DESIGN_HEIGHT * scale) / 2, ); } function handleOrientation() { isLandscape = window.matchMedia("(orientation: landscape)").matches; if (!isLandscape) { showRotateTip(); } else { hideRotateTip(); resizeApp(); } } function showRotateTip() { // 显示旋转提示层(CSS实现) document.getElementById("rotate-tip").style.display = "flex"; } function hideRotateTip() { document.getElementById("rotate-tip").style.display = "none"; } // 尝试锁定横屏方向 function tryLockLandscape() { if (screen.orientation && screen.orientation.lock) { screen.orientation.lock("landscape").catch((error) => { console.log("屏幕方向锁定失败:", error); }); } } // 页面加载完成后尝试锁定横屏 window.addEventListener("load", tryLockLandscape); (async () => { // Create a new application const app = new Application(); // Initialize the application await app.init({ background: "#1099bb", resizeTo: window, }); // Append the application canvas to the document body document.getElementById("pixi-container").appendChild(app.canvas); // Load the bunny texture const texture = await Assets.load("/assets/GameBg.png"); // Create a bunny Sprite const gameBg = new Sprite(texture); // Center the sprite's anchor point gameBg.anchor.set(0.5); // Move the sprite to the center of the screen gameBg.position.set(app.screen.width / 2, app.screen.height / 2); let rat = app.screen.height / gameBg.height; gameBg.height = app.screen.height; gameBg.width *= rat; // Add the bunny to the stage app.stage.addChild(gameBg); // Listen for animate update app.ticker.add((time) => { // Just for fun, let's rotate mr rabbit a little. // * Delta is 1 if running at 100% performance * // * Creates frame-independent transformation * //bunny.rotation += 0.1 * time.deltaTime; }); if (dataPersistenceMgr.uniqueCode == "") { let uuid = await util.getOrCreateUUID(); dataPersistenceMgr.uniqueCode = uuid; } let lang = navigator.language || navigator.userLanguage; let langStr = "id"; console.log("lang:" + lang); //zh-CN,zh-HK,zh-TW,zh if ( lang.toLowerCase().includes("zh") || lang.toLowerCase().includes("hans") ) { if ( lang.toLowerCase().includes("hk") || lang.toLowerCase().includes("tw") ) { langStr = "cht"; } else { langStr = "chs"; } } else if (lang.toLowerCase().includes("hant")) { langStr = "cht"; } else if (lang.toLowerCase().includes("en")) { langStr = "en"; } else if (lang.toLowerCase().includes("ar")) { lang = "ar"; } else if (lang.toLowerCase().includes("pt")) { lang = "pt"; } await i18n.load(langStr); networkMgr.resetUrl(); networkMgr.setData({ appType: `${gameData.appType}` }); UIManager.app = app; UIManager.show(UILogin); })(); 解释一下这个所有代码
09-11
同上 这个代码报错,帮改一下我这原文,错误提示的是: uiDemo.js:15 Uncaught (in promise) TypeError: Sprite.from is not a constructor at uiDemo.init (uiDemo.js:15:22) at uiDemo.show (uiDemo.js:76:18) at uiManager.show (uiManager.js:17:29) at uiLogin.js:117:16 // uiDemo.js import uiBase from "./uiBase.js"; import { Container,Sprite, Assets,Graphics, Text, Point } from "pixi.js"; //import { UIManager } from "../Frame/UIManager.js"; class uiDemo extends uiBase { constructor() { super(); } async init() { super.init(); // 创建一个背景遮罩 const mask = new Sprite.from("https://pixijs.io/examples/examples/assets/bg_button.png"); mask.width = this.app.screen.width; mask.height = this.app.screen.height; mask.alpha = 0.6; mask.interactive = true; // 创建弹出窗口容器 const popup = new Container(); popup.position.set(this.app.screen.width / 2, this.app.screen.height / 2); // 创建一个精灵(图案) const texture = await Assets.load("https://pixijs.io/examples/examples/assets/bunny.png"); const bunny = new Sprite(texture); bunny.anchor.set(0.5); bunny.interactive = true; bunny.buttonMode = true; // 添加拖拽功能 let dragging = false; let offset = new PIXI.Point(); bunny.on("pointerdown", (event) => { dragging = true; offset = event.data.global.clone(); }); bunny.on("pointerup", () => { dragging = false; }); bunny.on("pointerupoutside", () => { dragging = false; }); bunny.on("pointermove", (event) => { if (dragging) { const newPosition = event.data.global; bunny.position.x += newPosition.x - offset.x; bunny.position.y += newPosition.y - offset.y; offset = newPosition; } }); // 创建关闭按钮 const closeBtn = new Button("https://pixijs.io/examples/examples/assets/btn-close.png"); closeBtn.view.position.set(100, -100); closeBtn.onPress.connect(() => { this.hide(); }); // 添加到容器 popup.addChild(bunny, closeBtn); // 添加到UI this.container.addChild(mask, popup); this.app.stage.addChild(this.container); this.isInist = true; } show() { if (!this.isInist) { this.init(); } this.container.visible = true; } hide() { this.container.visible = false; } } // 导出单例 export const UIDemo = new uiDemo();
09-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值