[add] Engine

This commit is contained in:
2022-08-26 16:48:17 +08:00
parent f67e566f2a
commit d9c19f096c
197 changed files with 10626 additions and 0 deletions

View File

@@ -0,0 +1,188 @@
import { CoroutineV2 } from "../../CatanEngine/CoroutineV2/CoroutineV2";
import { UIManager } from "./UIManager";
/**畫面自適應(換場景手動呼叫) */
export default class ScreenResize {
private static _instance: ScreenResize = null;
public static get Instance(): ScreenResize { return this._instance; }
/**直橫式的製作尺寸 */
public static readonly CanvasSize: cc.Vec2[] = [cc.v2(1422, 800), cc.v2(800, 1422)];
/**是否直式機台 */
public static IsPortrait: number = 0;
/**固定橫直判斷(null=通用.0=固定橫.1=固定直) */
public static PL: number = null;
constructor() {
cc.log("creat ScreenResize");
ScreenResize._instance = this;
ScreenResize._instance.CallManual();
}
public AddEven(): void {
ScreenResize._instance.AddResizeEvent();
}
/**手動呼叫 */
public CallManual(): void {
ScreenResize.Instance.GameResize("inGameResize");
}
public AddResizeEvent() {
this.GameResize("inGameResize");
window.onresize = () => {
this.GameResize("window.onresize");
};
cc.view.setResizeCallback(() => {
this.GameResize("cc.view.setResizeCallback");
});
}
public GameResize(resizeType: string) {
if (ScreenResize.PL == null) {
//自適應
ScreenResize.IsPortrait = this._isPortraitMode();
} else {
//固定直橫
ScreenResize.IsPortrait = ScreenResize.PL;
}
cc.log("resizeType:" + resizeType);
cc.log("ScreenResize.IsPortrait:" + ScreenResize.IsPortrait);
if (cc.sys.isBrowser) {
//網頁版的修正顯示範圍判斷
this._browserAutoScreenSetting(resizeType);
} else {
this._appAutoScreenSetting();
}
this._alignWithScreen();
CoroutineV2.Single(this._delayChangeDir()).Start();
this._alignWithGameUI();
}
private _browserAutoScreenSetting(resizeType: string) {
let frameSize = cc.view.getFrameSize();
if (ScreenResize.IsPortrait) {
cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT);
if (resizeType === "inGameResize") {
//只需要進遊戲設定一次,避免第一次進入場景時萬一跟設計分辨率不同會導致世界座標跑掉(cocos engine底層沒處理好)
if (frameSize.width > frameSize.height) {
cc.view.setFrameSize(frameSize.height, frameSize.width)
} else {
cc.view.setFrameSize(frameSize.width, frameSize.height)
}
}
} else {
cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE);
if (resizeType === "inGameResize") {
//只需要進遊戲設定一次,避免第一次進入場景時萬一跟設計分辨率不同會導致世界座標跑掉(cocos engine底層沒處理好)
if (frameSize.height > frameSize.width) {
cc.view.setFrameSize(frameSize.height, frameSize.width)
} else {
cc.view.setFrameSize(frameSize.width, frameSize.height)
}
}
}
cc.view.setDesignResolutionSize(ScreenResize.CanvasSize[ScreenResize.IsPortrait].x, ScreenResize.CanvasSize[ScreenResize.IsPortrait].y, new cc.ResolutionPolicy(cc.ContainerStrategy["PROPORTION_TO_FRAME"], cc.ContentStrategy["NO_BORDER"]));
if (document.getElementById("GameCanvas")["width"] % 2 != 0) {
document.getElementById("GameCanvas")["width"] -= 1;
}
if (document.getElementById("GameCanvas")["height"] % 2 != 0) {
document.getElementById("GameCanvas")["height"] -= 1;
}
document.body.style.width = "100%";
document.body.style.height = "100%";
}
private _appAutoScreenSetting() {
cc.view.setDesignResolutionSize(ScreenResize.CanvasSize[ScreenResize.IsPortrait].x, ScreenResize.CanvasSize[ScreenResize.IsPortrait].y, cc.ResolutionPolicy.SHOW_ALL);
}
/**舊版COCOS引擎內的座標對齊 */
private _alignWithScreen(): void {
var designSize, nodeSize;
if (CC_EDITOR) {
nodeSize = designSize = cc["engine"]["getDesignResolutionSize"]();
cc.Canvas.instance.node.setPosition(designSize.width * 0.5, designSize.height * 0.5);
}
else {
var canvasSize = nodeSize = cc.visibleRect;
designSize = cc.view.getDesignResolutionSize();
var clipTopRight = !cc.Canvas.instance.fitHeight && !cc.Canvas.instance.fitWidth;
var offsetX = 0;
var offsetY = 0;
if (clipTopRight) {
// offset the canvas to make it in the center of screen
offsetX = (designSize.width - canvasSize.width) * 0.5;
offsetY = (designSize.height - canvasSize.height) * 0.5;
}
cc.Canvas.instance.node.setPosition(canvasSize.width * 0.5 + offsetX, canvasSize.height * 0.5 + offsetY);
}
cc.Canvas.instance.node.width = nodeSize.width;
cc.Canvas.instance.node.height = nodeSize.height;
}
private *_delayChangeDir() {
yield CoroutineV2.WaitTime(0.2);
this._alignWithScreen();
this._alignWithGameUI();
}
private _alignWithGameUI() {
UIManager.DireEvent.DispatchCallback([]);
}
private _isPortraitMode(): number {
let sw = window.screen.width;
let sh = window.screen.height;
let _Width = sw < sh ? sw : sh;
let _Height = sw >= sh ? sw : sh;
if (cc.sys.isBrowser) {
//網頁版的顯示範圍判斷
let w = document.documentElement.clientWidth;
let h = document.documentElement.clientHeight;
let w2 = window.innerWidth;
let h2 = window.innerHeight;
let containerW = Number.parseInt(document.getElementById("Cocos2dGameContainer").style.width) + Number.parseInt(document.getElementById("Cocos2dGameContainer").style.paddingRight) + Number.parseInt(document.getElementById("Cocos2dGameContainer").style.paddingLeft);
let containerH = Number.parseInt(document.getElementById("Cocos2dGameContainer").style.height) + Number.parseInt(document.getElementById("Cocos2dGameContainer").style.paddingTop) + Number.parseInt(document.getElementById("Cocos2dGameContainer").style.paddingBottom);
let rotate = Number.parseInt(document.getElementById("Cocos2dGameContainer").style.transform.replace("rotate(", "").replace("deg)", ""));
/*cc.log(
"w:" + w + ",h:" + h +
"\n,w2:" + w2 + ",h2:" + h2 +
"\n,sw:" + sw + ",sh:" + sh +
"\n,_Width:" + _Width + ",_Height:" + _Height +
"\n,frameW:" + cc.view.getFrameSize().width + ",frameH:" + cc.view.getFrameSize().height +
"\n,containerW:" + containerW + ",containerH:" + containerH + ",rotate:" + rotate +
"\n,canvasW:" + cc.game.canvas.width + ",canvasrH:" + cc.game.canvas.height
);*/
if (w == _Width) {
return 1;
} else if (w == _Height) {
if (!CC_DEV) {
return 0;
} else {
if (containerW >= containerH) {
return rotate == 0 ? 0 : 1;
} else {
return rotate == 0 ? 1 : 0;
}
}
} else if (w == w2) {
if (containerW >= containerH) {
return rotate == 0 ? 0 : 1;
} else {
return rotate == 0 ? 1 : 0;
}
} else {
if (containerW >= containerH) {
return rotate == 0 ? 0 : 1;
} else {
return rotate == 0 ? 1 : 0;
}
}
} else {
if (sw == _Width) {
return 1;
} else if (sw == _Height) {
return 0;
} else {
cc.log("XXXXXXXXXXXXXXXXXX");
return 1;
}
}
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "187716a0-d35c-4b06-80fb-48b799e7fe9e",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,13 @@
{
"ver": "1.1.3",
"uuid": "f63b1b10-07ba-49bc-aa9f-a0ea4c652076",
"importer": "folder",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}

View File

@@ -0,0 +1,27 @@
import ScreenResize from "../ScreenResize";
const { ccclass, property } = cc._decorator;
@ccclass("SwitchActive")
export class SwitchActive {
@property({ type: cc.Node })
public UI: cc.Node = null;
@property({ type: cc.Boolean/*, visible: function (this: ImageGroup) { return this.Reset; } */ })
public show: boolean[] = [];
public SetObjActive(obj: cc.Node, show: boolean): void {
obj.active = show;
}
}
@ccclass
export default class SwitchActiveGroup extends cc.Component {
@property({ displayName: "縮放scale群組", type: SwitchActive })
public ScaleGroups: SwitchActive[] = [];
public Run(): void {
if (this.ScaleGroups != null && this.ScaleGroups.length) {
for (let group of this.ScaleGroups) {
group.SetObjActive(group.UI, group.show[ScreenResize.IsPortrait]);
}
}
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "a96cf057-9e35-4146-89df-5f0f4819fb6c",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,32 @@
import ScreenResize from "../ScreenResize";
import { UIManager } from "../UIManager";
const { ccclass, property } = cc._decorator;
@ccclass("SwitchActiveObj")
export class SwitchActiveObj {
@property({ type: cc.Node })
public UI: cc.Node = null;
@property({ type: cc.Boolean/*, visible: function (this: ImageGroup) { return this.Reset; } */ })
public show: boolean[] = [];
public SetObjActive(obj: cc.Node, show: boolean): void {
obj.active = show;
}
}
@ccclass
export default class SwitchActiveGroupExtra extends cc.Component {
@property({ displayName: "縮放scale群組", type: SwitchActiveObj })
public ScaleGroups: SwitchActiveObj[] = [];
public Run(): void {
if (this.ScaleGroups != null && this.ScaleGroups.length) {
for (let group of this.ScaleGroups) {
group.SetObjActive(group.UI, group.show[ScreenResize.IsPortrait]);
}
}
}
onLoad() {
UIManager.DireEvent.AddCallback(this.Run, this);
this.Run();
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "9d9e9007-973c-4926-b5cf-aacceae74665",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,30 @@
import ScreenResize from "../ScreenResize";
const { ccclass, property } = cc._decorator;
@ccclass("SwitchImgSourceGroup")
export class SwitchImgSourceGroup {
@property({ type: cc.Node })
public Sprite: cc.Sprite = null;
@property({ type: cc.SpriteFrame/*, visible: function (this: ImageGroup) { return this.Reset; } */ })
public SourceImg: cc.SpriteFrame[] = [];
public SetImg(obj: cc.Sprite, switchObj: cc.SpriteFrame): void {
if (obj == null || switchObj == null) {
return;
}
obj.getComponent(cc.Sprite).spriteFrame = switchObj;
}
}
@ccclass
export default class SwitchImgGroup extends cc.Component {
@property({ displayName: "換UI群組", type: SwitchImgSourceGroup })
public ImgGroups: SwitchImgSourceGroup[] = [];
public Run(): void {
if (this.ImgGroups != null && this.ImgGroups.length) {
for (let group of this.ImgGroups) {
group.SetImg(group.Sprite, group.SourceImg[ScreenResize.IsPortrait]);
}
}
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "56151188-edd5-4384-8a84-50a84456a6c3",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,35 @@
import ScreenResize from "../ScreenResize";
import { UIManager } from "../UIManager";
const { ccclass, property } = cc._decorator;
@ccclass("SwitchImgSource")
export class SwitchImgSource {
@property({ type: cc.Node })
public Sprite: cc.Sprite = null;
@property({ type: cc.SpriteFrame/*, visible: function (this: ImageGroup) { return this.Reset; } */ })
public SourceImg: cc.SpriteFrame[] = [];
public SetImg(obj: cc.Sprite, switchObj: cc.SpriteFrame): void {
if (obj == null || switchObj == null) {
return;
}
obj.getComponent(cc.Sprite).spriteFrame = switchObj;
}
}
@ccclass
export default class SwitchImgGroupExtra extends cc.Component {
@property({ displayName: "換UI群組", type: SwitchImgSource })
public ImgGroups: SwitchImgSource[] = [];
public Run(): void {
if (this.ImgGroups != null && this.ImgGroups.length) {
for (let group of this.ImgGroups) {
group.SetImg(group.Sprite, group.SourceImg[ScreenResize.IsPortrait]);
}
}
}
onLoad() {
UIManager.DireEvent.AddCallback(this.Run, this);
this.Run();
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "208b15b7-a199-4b86-a538-3d1d18695552",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,31 @@
import ScreenResize from "../ScreenResize";
const { ccclass, property } = cc._decorator;
@ccclass("SwitchPosition")
export class SwitchPosition {
@property({ type: cc.Node })
public UI: cc.Node = null;
@property({ type: cc.Vec2/*, visible: function (this: ImageGroup) { return this.Reset; } */ })
public Pos: cc.Vec2[] = [];
public SetPos(obj: cc.Node, posNum: cc.Vec2): void {
obj.setPosition(posNum);
}
}
@ccclass
export default class SwitchPositionGroup extends cc.Component {
@property({ displayName: "改變座標群組", type: SwitchPosition })
public PosGroups: SwitchPosition[] = [];
public Run(): void {
if (this.PosGroups != null && this.PosGroups.length) {
for (let group of this.PosGroups) {
if (!group.UI || !group.Pos[ScreenResize.IsPortrait]) {
cc.error("沒有設定節點或座標.name=" + this.node.name);
continue;
}
group.SetPos(group.UI, group.Pos[ScreenResize.IsPortrait]);
}
}
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "2083e1d2-be99-4173-b425-cdc9da21cbb3",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,33 @@
import ScreenResize from "../ScreenResize";
import { UIManager } from "../UIManager";
const { ccclass, property } = cc._decorator;
@ccclass("SwitchPositionObj")
export class SwitchPositionObj {
@property({ type: cc.Node })
public UI: cc.Node = null;
@property({ type: cc.Vec2/*, visible: function (this: ImageGroup) { return this.Reset; } */ })
public Pos: cc.Vec2[] = [];
public SetPos(obj: cc.Node, posNum: cc.Vec2): void {
obj.setPosition(posNum);
}
}
@ccclass
export default class SwitchPositionGroupExtra extends cc.Component {
@property({ displayName: "改變座標群組", type: SwitchPositionObj })
public PosGroups: SwitchPositionObj[] = [];
public Run(param: any[] = null): void {
if (this.PosGroups != null && this.PosGroups.length) {
for (let group of this.PosGroups) {
cc.log("橫直轉換:" + group.UI.name + ":" + group.Pos[ScreenResize.IsPortrait]);
group.SetPos(group.UI, group.Pos[ScreenResize.IsPortrait]);
}
}
}
onLoad() {
UIManager.DireEvent.AddCallback(this.Run, this);
this.Run();
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "512c7a23-3a86-4d84-abc6-9553be08da10",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,27 @@
import ScreenResize from "../ScreenResize";
const { ccclass, property } = cc._decorator;
@ccclass("SwitchRotation")
export class SwitchRotation {
@property({ type: cc.Node })
public UI: cc.Node = null;
@property({ type: cc.Float/*, visible: function (this: ImageGroup) { return this.Reset; } */ })
public rotaitonNum: number[] = [];
public SetObjRotation(obj: cc.Node, r: number): void {
obj.angle = -r;
}
}
@ccclass
export default class SwitchRotationGroup extends cc.Component {
@property({ displayName: "設定rotation群組", type: SwitchRotation })
public ScaleGroups: SwitchRotation[] = [];
public Run(): void {
if (this.ScaleGroups != null && this.ScaleGroups.length) {
for (let group of this.ScaleGroups) {
group.SetObjRotation(group.UI, group.rotaitonNum[ScreenResize.IsPortrait]);
}
}
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "e53fa0f6-ddad-41e1-b0d2-df151a2f3ff0",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,27 @@
import ScreenResize from "../ScreenResize";
const { ccclass, property } = cc._decorator;
@ccclass("SwitchSize")
export class SwitchScale {
@property({ type: cc.Node })
public UI: cc.Node = null;
@property({ type: cc.Float/*, visible: function (this: ImageGroup) { return this.Reset; } */ })
public ScaleNum: number[] = [];
public SetObjScale(obj: cc.Node, scaleNum: number): void {
obj.setScale(scaleNum);
}
}
@ccclass
export default class SwitchScaleGroup extends cc.Component {
@property({ displayName: "縮放scale群組", type: SwitchScale })
public ScaleGroups: SwitchScale[] = [];
public Run(): void {
if (this.ScaleGroups != null && this.ScaleGroups.length) {
for (let group of this.ScaleGroups) {
group.SetObjScale(group.UI, group.ScaleNum[ScreenResize.IsPortrait]);
}
}
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "4e2f6235-b5a6-4c44-9ea5-4779b97f1630",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,32 @@
import ScreenResize from "../ScreenResize";
import { UIManager } from "../UIManager";
const { ccclass, property } = cc._decorator;
@ccclass("SwitchSizeObj")
export class SwitchScaleObj {
@property({ type: cc.Node })
public UI: cc.Node = null;
@property({ type: cc.Float/*, visible: function (this: ImageGroup) { return this.Reset; } */ })
public ScaleNum: number[] = [];
public SetObjScale(obj: cc.Node, scaleNum: number): void {
obj.setScale(scaleNum);
}
}
@ccclass
export default class SwitchScaleGroupExtra extends cc.Component {
@property({ displayName: "縮放scale群組", type: SwitchScaleObj })
public ScaleGroups: SwitchScaleObj[] = [];
public Run(): void {
if (this.ScaleGroups != null && this.ScaleGroups.length) {
for (let group of this.ScaleGroups) {
group.SetObjScale(group.UI, group.ScaleNum[ScreenResize.IsPortrait]);
}
}
}
onLoad() {
UIManager.DireEvent.AddCallback(this.Run, this);
this.Run();
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "065d43a0-b2c1-4a41-8e84-8a0f3d3817f2",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,34 @@
import ScreenResize from "../ScreenResize";
const { ccclass, property } = cc._decorator;
@ccclass("SwitchUIGroup")
export class SwitchUIGroup {
@property({ type: cc.Node })
public UI: cc.Node = null;
@property({ type: cc.Integer/*, visible: function (this: ImageGroup) { return this.Reset; } */ })
public SourceID: number[] = [];
public Set(obj: cc.Node, switchObj: cc.Node): void {
if (obj == null || switchObj == null) {
return;
}
obj.removeAllChildren();
obj.ExAddChild(switchObj);
}
}
@ccclass
export default class SwitchSoueceGroup extends cc.Component {
@property({ displayName: "換UI群組", type: SwitchUIGroup })
public UIGroups: SwitchUIGroup[] = [];
public Run(switchObg: cc.Node): void {
if (this.UIGroups != null && this.UIGroups.length) {
for (let group of this.UIGroups) {
let child: cc.Node[] = switchObg.getChildByName(group.SourceID[ScreenResize.IsPortrait].toString()).children;
for (let i: number = 0; i < child.length; i++) {
group.Set(group.UI, child[i]);
}
}
}
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "45ea513f-8665-4d40-8b51-3a67ab35f327",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,26 @@
import ScreenResize from "../ScreenResize";
const { ccclass, property } = cc._decorator;
@ccclass("SwitchWH")
export class SwitchWH {
@property({ type: cc.Node })
public UI: cc.Node = null;
@property({ type: cc.Vec2/*, visible: function (this: ImageGroup) { return this.Reset; } */ })
public WH: cc.Vec2[] = [];
public SetWH(obj: cc.Node, WHNum: cc.Vec2): void {
obj.SetSizeDelta(WHNum);
}
}
@ccclass
export default class SwitchWHGroup extends cc.Component {
@property({ displayName: "改變寬高群組", type: SwitchWH })
public WHGroups: SwitchWH[] = [];
public Run(): void {
if (this.WHGroups != null && this.WHGroups.length) {
for (let group of this.WHGroups) {
group.SetWH(group.UI, group.WH[ScreenResize.IsPortrait]);
}
}
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "5cfb2592-7ada-4b09-81dc-0dc14dc94aa5",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,31 @@
import ScreenResize from "../ScreenResize";
import { UIManager } from "../UIManager";
const { ccclass, property } = cc._decorator;
@ccclass("SwitchWHObj")
export class SwitchWHObj {
@property({ type: cc.Node })
public UI: cc.Node = null;
@property({ type: cc.Vec2/*, visible: function (this: ImageGroup) { return this.Reset; } */ })
public WH: cc.Vec2[] = [];
public SetWH(obj: cc.Node, WHNum: cc.Vec2): void {
obj.SetSizeDelta(WHNum);
}
}
@ccclass
export default class SwitchWHGroupExtra extends cc.Component {
@property({ displayName: "改變寬高群組", type: SwitchWHObj })
public WHGroups: SwitchWHObj[] = [];
public Run(): void {
if (this.WHGroups != null && this.WHGroups.length) {
for (let group of this.WHGroups) {
group.SetWH(group.UI, group.WH[ScreenResize.IsPortrait]);
}
}
}
onLoad() {
UIManager.DireEvent.AddCallback(this.Run, this);
this.Run();
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "b9806317-d4bd-4aac-be3e-a16b0a3159f9",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,8 @@
import { Action } from "../../CatanEngine/CSharp/System/Action";
export class UIManager {
public static readonly ScreenScale = 0.58;
/**橫直切換監聽 */
public static readonly DireEvent: Action<any[]> = new Action<any[]>();
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "277e84bb-8d5d-4e7c-8dd1-06d752d7bba1",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,182 @@
import { CoroutineV2 } from "../../CatanEngine/CoroutineV2/CoroutineV2";
import ScreenResize from "./ScreenResize";
import SwitchActiveGroup from "./SwitchShowUI/SwitchActiveGroup";
import SwitchImgGroup from "./SwitchShowUI/SwitchImgGroup";
import SwitchPositionGroup from "./SwitchShowUI/SwitchPositionGroup";
import SwitchRotationGroup from "./SwitchShowUI/SwitchRotationGroup";
import SwitchScaleGroup from "./SwitchShowUI/SwitchScaleGroup";
import SwitchWHGroup from "./SwitchShowUI/SwitchWHGroup";
import { UIManager } from "./UIManager";
const { ccclass } = cc._decorator;
@ccclass
export default class UIPanel extends cc.Component {
/**[基底UIPanel]等待跳出旗標*/
private _isWaiting: boolean = false;
/**
* [基底UIPanel]初始化實做(UI每次創建時呼叫, 只會呼叫一次)
* @param initData
*/
protected ImplementInitial(...initData: any[]): void {
}
/**
* [基底UIPanel]顯示準備實做(UI顯示前呼叫)
* @param param
*/
protected *ImplementReadyShow(...param: any[]): IterableIterator<any> {
}
/**
* [基底UIPanel]顯示實做(UI顯示呼叫)
* @param param
*/
protected *ImplementShow(): IterableIterator<any> {
}
/**
* [基底UIPanel]隱藏(實做)
* @param param
*/
protected *ImplementHide(...param: any[]): IterableIterator<any> {
}
/**
* [基底UIPanel]移除實做
*/
protected ImplementDestroy() {
}
/**
* [基底UIPanel]直橫版切換
* @param param
*/
public ChangeDire(param: any[] = null): void {
if (!cc.isValid(this)) {
return;
}
cc.log("ChangeDire:" + this.name);
if (this.getComponent(SwitchScaleGroup)) {
this.getComponent(SwitchScaleGroup).Run();
}
if (this.getComponent(SwitchPositionGroup)) {
this.getComponent(SwitchPositionGroup).Run();
}
if (this.getComponent(SwitchWHGroup)) {
this.getComponent(SwitchWHGroup).Run();
}
if (this.getComponent(SwitchImgGroup)) {
this.getComponent(SwitchImgGroup).Run();
}
if (this.getComponent(SwitchActiveGroup)) {
this.getComponent(SwitchActiveGroup).Run();
}
if (this.getComponent(SwitchRotationGroup)) {
this.getComponent(SwitchRotationGroup).Run();
}
this._uiMaskHandler();
}
private _uiMaskHandler(): void {
let mask: cc.Node = this.node.getChildByName("Mask");
if (mask && this.node.parent.name == "ElementContent") {
let size: cc.Vec2 = ScreenResize.CanvasSize[ScreenResize.IsPortrait];
mask.SetSizeDelta(cc.v2(size.x / UIManager.ScreenScale, size.y / UIManager.ScreenScale));
}
}
//=======================================================================================
/**
* [禁止複寫]創UI
* @param source
* @param parent
* @param data
*/
public static CreateUI(source: cc.Prefab, parent: cc.Node, ...data: any[]): UIPanel {
let node = parent.ExAddChild(source);
let script = node.getComponent(UIPanel);
script.Initial(...data);
return script;
}
/**
* [禁止複寫]初始化
* @param initData
*/
public Initial(...initData: any[]): void {
UIManager.DireEvent.RemoveByBindTarget(this);
UIManager.DireEvent.AddCallback(this.ChangeDire, this);
this.node.active = false;
this._uiMaskHandler();
this.ImplementInitial(...initData);
}
/**
* [禁止複寫]顯示UI
* @param param
*/
public *Show(...param: any[]): IterableIterator<any> {
yield* this.ImplementReadyShow(...param);
this.node.active = true;
yield* this.ImplementShow();
}
/**
* [禁止複寫]隱藏UI
* @param param
*/
public *Hide(...param: any[]): IterableIterator<any> {
if (this._isWaiting) {
cc.warn(this.node.name, "_isWaiting = true無法關閉");
}
else {
yield* this.ImplementHide(...param);
if (this && this.node) {
this.node.active = false;
}
}
}
/**
* [禁止複寫]等待UI
* @param showData
* @param hideData
*/
public *Wait(showData: any[] = [], hideData: any[] = []): IterableIterator<any> {
yield* this.Show(...showData);
this._isWaiting = true;
while (this._isWaiting) {
yield null;
}
yield* this.Hide(...hideData);
}
/**
* [禁止複寫]關閉UI
* @param param
*/
public Close(...param: any[]): void {
if (this._isWaiting) {
this._isWaiting = false;
}
else {
CoroutineV2.Single(this.Hide(...param)).Start();
}
}
//=======================================================================================
onLoad() {
UIManager.DireEvent.RemoveByBindTarget(this);
UIManager.DireEvent.AddCallback(this.ChangeDire, this);
}
//COCOS引擎內建生命週期
//onLoad->start->update->lateUpdate->onDestroy->onEnable->onDisable
onDestroy() {
UIManager.DireEvent.RemoveByBindTarget(this);
this.ImplementDestroy();
}
//=======================================================================================
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "066bf037-e621-482f-a93f-fc1e59e90cfb",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}