This commit is contained in:
2024-07-17 16:14:14 +08:00
commit 2ef3bcf322
1817 changed files with 63826 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
/*
* @Author: dgflash
* @Date: 2021-11-18 17:47:56
* @LastEditors: dgflash
* @LastEditTime: 2022-08-04 15:43:04
*/
import { instantiate, Node, Prefab, Vec3 } from "cc";
import { UICallbacks } from "../../../../extensions/oops-plugin-framework/assets/core/gui/layer/Defines";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { UIID } from "../common/config/GameUIConfig";
import { smc } from "../common/SingletonModuleComp";
import Charactor from "../map/view/map/charactor/Charactor";
import { RoleModelComp } from "./model/RoleModelComp";
import { RoleSpine } from "./view/RoleSpine";
import { RoleViewComp } from "./view/RoleViewComp";
import { RoleViewUIControllerComp } from "./view/RoleViewUIControllerComp";
/** 角色实体 */
@ecs.register(`Role`)
export class Role extends ecs.Entity {
// 数据层
RoleModel!: RoleModelComp;
// 视图层
RoleView!: RoleViewComp;
RoleViewUIController!: RoleViewUIControllerComp;
protected init() {
this.addComponents<ecs.Comp>(
RoleModelComp);
}
destroy(): void {
this.remove(RoleViewComp);
super.destroy();
}
/** 加载角色 */
load(pos: Vec3 = Vec3.ZERO, isOwn: boolean = false) {
var path = isOwn ? "game/player/own" : "game/player/player";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
var scene = smc.map.MapView.scene;
node.parent = scene.entityLayer!.node!;
node.setPosition(pos)
var mv = node.getComponent(RoleViewComp)!;
this.add(mv);
var as = node.getComponent(RoleSpine);
// as.setPlayer(pos);
if (isOwn) {
smc.map.MapView.scene.setPlayer(node.getComponent(Charactor));
}
}
/** 摇撼控制 */
loadJoystick() {
var uic: UICallbacks = {
onAdded: (node: Node, params: any) => {
var comp = node.getComponent(RoleViewUIControllerComp) as ecs.Comp;
this.add(comp);
}
};
oops.gui.open(UIID.Role_Controller, null, uic);
}
removeJoystick() {
oops.gui.remove(UIID.Role_Controller);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "deb5a90b-5729-4a03-9f73-28ed96202f8a",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,4 @@
/** 角色模块全局事件 */
export enum RoleEvent {
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "a2e7abd7-21aa-4dfc-ab5c-6dd0dfba2a7c",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "8164d96e-0467-4bd2-9123-8a490de8c68f",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "5130ca90-66bd-4c87-8db9-f9f847396454",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "52966ec2-355b-4c89-a608-5d5f34ba8ae9",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "7bde0e45-7d4e-4cf5-b0ce-f8b6a5ca4d12",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "20fb6abb-3b0e-4361-8200-941b98891456",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "3fba28ee-42f7-4be0-a42d-776301b37fbc",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "2fc06e2a-6834-4ce6-9a7b-96eae66f0abe",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "d299c6b5-6424-4c27-ab35-013e8ad0c433",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "1ca33287-9c39-44a8-b8dd-c6e0c21dd8a7",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,18 @@
/*
* @Author: dgflash
* @Date: 2022-01-26 14:14:34
* @LastEditors: dgflash
* @LastEditTime: 2022-01-27 15:49:36
*/
/** 角色动作名 */
export enum RoleAnimatorType {
/** 待机 */
Idle = "Idle",
/** 攻击 */
Attack = "Attack",
/** 受击 */
Hurt = "Hurt",
/** 死亡 */
Dead = "Dead"
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "a8fd6149-fa4b-4b2c-83c0-c08b3813b9f7",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "5c21f8a7-8fd1-4845-a777-a2e03256526b",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "b53c6b75-188b-46ae-93a9-4c1ecd6009c8",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,27 @@
/*
* @Author: dgflash
* @Date: 2021-11-18 15:56:01
* @LastEditors: dgflash
* @LastEditTime: 2022-08-17 13:43:25
*/
import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
/**
* 角色属性数据
*/
@ecs.register('RoleModel')
export class RoleModelComp extends ecs.Comp {
/** 角色编号 */
id: number = -1;
/** 角色名 */
name: string = "oops-framework";
/** 动画名资源 */
anim: string = "model1";
reset() {
this.id = -1;
this.name = "";
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "0b31330a-261d-4b13-a0d5-15d2727b1dbd",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "58956230-0127-4793-ad43-621ceedb7d25",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "25e1a634-f8fe-44ca-9650-0d287532b566",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "b6c9dfb2-45d4-485c-8d0e-55a7f98e324e",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "71fe316b-1691-4a24-b0b8-8c6e88938401",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,95 @@
/*
* @Author: dgflash
* @Date: 2022-08-04 15:08:35
* @LastEditors: dgflash
* @LastEditTime: 2022-08-04 15:26:26
*/
import { Color, Component, EventTouch, sp, Vec3, _decorator } from "cc";
import { LayerUtil } from "../../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
import { smc } from "../../common/SingletonModuleComp";
import Charactor, { CharactorDirection, CharactorState } from "../../map/view/map/charactor/Charactor";
import { ICharactorClip } from "../../map/view/map/charactor/ICharactorClip";
import RoleSpineAnimator from "./RoleSpineAnimator";
const { ccclass, property } = _decorator;
/**
* SPINE角色模型
*/
@ccclass('RoleSpine')
export class RoleSpine extends Component implements ICharactorClip {
@property({ type: RoleSpineAnimator, tooltip: '动画控制器' })
animator: RoleSpineAnimator = null!;
private spine!: sp.Skeleton;
private charactor!: Charactor;
onLoad() {
// 角色控制组件
this.charactor = this.addComponent(Charactor)!;
this.initAnimator();
LayerUtil.setNodeLayer(LayerUtil.MAP, this.node);
}
/** 初始化动画 */
protected initAnimator() {
this.spine = this.animator.getComponent(sp.Skeleton)!;
}
setPlayer(pos: Vec3) {
// var scene = smc.map.MapView.scene;
// this.node.parent = scene.entityLayer!.node!;
// this.charactor.clip = this;
// this.charactor.sceneMap = scene;
this.charactor.pos = pos;
this.charactor.updateZIndex();
}
setDirection(value: CharactorDirection): void {
if (value > 4) {
this.animator!.node.setScale(-1, 1, 1);
}
else {
this.animator!.node.setScale(1, 1, 1);
}
}
setState(value: CharactorState): void {
switch (value) {
case CharactorState.Idle:
this.idle();
break;
case CharactorState.Run:
this.walk();
break;
}
}
setAlpha(value: number): void {
var color: Color = this.spine.color;
color.a = 255 * (value / 1);
this.spine.color = color;
}
setPos(value: Vec3): void {
this.node.position = value;
}
checkTouch(event: EventTouch): boolean {
return false;
}
onDestroy() {
this.node.destroy();
}
walk() {
this.animator!.setNumber("Speed", 1);
}
idle() {
this.animator!.setNumber("Speed", 0);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "9b5610bf-dad3-4695-bb64-92006701ea56",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,72 @@
/*
* @Author: dgflash
* @Date: 2022-08-04 15:08:35
* @LastEditors: dgflash
* @LastEditTime: 2022-08-04 15:26:38
*/
import { sp, _decorator } from "cc";
import AnimatorSpine from "../../../../../extensions/oops-plugin-framework/assets/libs/animator/AnimatorSpine";
import Charactor, { CharactorDirection } from "../../map/view/map/charactor/Charactor";
const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
/**
* Spine状态机组件主状态机trackIndex为0
*/
@ccclass
@disallowMultiple
@requireComponent(sp.Skeleton)
export default class RoleSpineAnimator extends AnimatorSpine {
private charactor!: Charactor;
private dir: CharactorDirection = CharactorDirection.bottom;
private animName: string = "Stand";
private loop: boolean = true;
start() {
this.charactor = this.node.parent!.getComponent(Charactor)!;
super.start();
}
lateUpdate(dt: number) {
if (this.dir != this.charactor.direction) {
this.dir = this.charactor.direction;
this.playAnimation(this.animName, this.loop);
}
}
/**
* 播放动画
* @override
* @param animName 动画名
* @param loop 是否循环播放
*/
protected playAnimation(animName: string, loop: boolean) {
if (animName) {
this.animName = animName;
this.loop = loop;
animName = `huaxian/${this.getDirection(this.charactor.direction)}${animName}`;
this._spine.setAnimation(0, animName, loop);
}
else {
this._spine.clearTrack(0);
}
}
private getDirection(dir: CharactorDirection): string {
let dirName = "";
if (dir == CharactorDirection.up) {
dirName = "back";
}
else if (dir == CharactorDirection.bottom) {
dirName = "positive";
}
else if (dir == CharactorDirection.left || dir == CharactorDirection.left_up || dir == CharactorDirection.left_bottom) {
dirName = "side";
}
else if (dir == CharactorDirection.right || dir == CharactorDirection.right_up || dir == CharactorDirection.right_bottom) {
dirName = "side";
}
return dirName;
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "eb846c27-0bd3-4d9c-8261-e6ed8ac379a3",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "6842e219-fc64-4f36-94ad-5874aa08735f",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "95fb600c-f0c6-4720-94da-b222ff2a3574",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "495b1f8f-d6a5-48bb-9a8c-4ed84361f127",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,42 @@
/*
* @Author: dgflash
* @Date: 2021-11-18 17:42:59
* @LastEditors: dgflash
* @LastEditTime: 2022-08-17 12:36:18
*/
import { Vec3, _decorator } from "cc";
import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import Charactor from "../../map/view/map/charactor/Charactor";
import { RoleSpine } from "./RoleSpine";
const { ccclass, property } = _decorator;
/** 角色显示组件 */
@ccclass('RoleViewComp') // 定义为 Cocos Creator 组件
@ecs.register('RoleView', false) // 定义为 ECS 组件
export class RoleViewComp extends CCComp {
/** 角色动画 */
as: RoleSpine = null!;
/** 角色控制器 */
charactor: Charactor = null!;
/** 视图层逻辑代码分离演示 */
onLoad() {
this.as = this.getComponent(RoleSpine);
this.charactor = this.getComponent(Charactor);
}
/**
* 摇杆移动
* @param dir 移动方向
*/
runJoystick(dir: Vec3) {
this.charactor.joystick(dir);
}
reset() {
this.node.destroy();
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "60726b1a-adbb-480c-97cb-2c4fbbe7228b",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,42 @@
/*
* @Author: dgflash
* @Date: 2022-08-04 15:08:35
* @LastEditors: dgflash
* @LastEditTime: 2022-08-04 15:28:02
*/
import { Component, v3, _decorator } from "cc";
import { smc } from "../../common/SingletonModuleComp";
import Charactor from "../../map/view/map/charactor/Charactor";
import MapRoadUtils from "../../map/view/map/road/MapRoadUtils";
import RoadNode from "../../map/view/map/road/RoadNode";
const { ccclass, property } = _decorator;
@ccclass('RoleViewOwn')
export class RoleViewOwn extends Component {
private charactor!: Charactor;
onLoad() {
this.charactor = this.getComponent(Charactor)!;
this.node.on(Charactor.NextRoadNode, this.onNextRoadNode, this);
}
private onNextRoadNode(rn: RoadNode) {
var key: string = rn.dx + "," + rn.dy;
var mv = smc.map.MapView;
var delivery = mv.deliverys.get(key);
if (delivery && mv.isTransfer == false) {
this.charactor.stop();
mv.transfer(delivery.toMapId, this.aStarToVec3(delivery.start));
}
}
private aStarToVec3(str: string) {
let array = str.split(",");
let x = parseInt(array[0]);
let y = parseInt(array[1]);
let p = MapRoadUtils.instance.getPixelByDerect(x, y);
return v3(p.x, p.y);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "dce416c5-4d4c-4ccd-b79f-ebdcf9bd0ddc",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,48 @@
/*
* @Author: dgflash
* @Date: 2022-02-12 13:38:13
* @LastEditors: dgflash
* @LastEditTime: 2022-08-17 12:36:31
*/
import { EventTouch, Vec3, _decorator } from 'cc';
import { ecs } from '../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS';
import { CCComp } from '../../../../../extensions/oops-plugin-framework/assets/module/common/CCComp';
import { smc } from '../../common/SingletonModuleComp';
import { Role } from '../Role';
import { JoystickDataType, RoleViewUIJoystick, SpeedType } from './RoleViewUIJoystick';
const { ccclass, property } = _decorator;
@ccclass("RoleViewUIControllerComp")
@ecs.register('RoleViewUIController', false)
export class RoleViewUIControllerComp extends CCComp {
@property({ type: RoleViewUIJoystick })
joystick: RoleViewUIJoystick = null!;
private target: Role = null!;
start() {
this.target = smc.own;
this.joystick.onController = (event: EventTouch, data: JoystickDataType) => {
switch (data.type) {
case SpeedType.NORMAL:
case SpeedType.FAST:
this.target.RoleView.runJoystick(data.vector);
break;
case SpeedType.STOP:
this.target.RoleView.runJoystick(Vec3.ZERO);
break;
}
}
}
onDestroy() {
this.ent.remove(RoleViewUIControllerComp);
super.onDestroy();
}
reset(): void {
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "adad65c3-b462-4ea5-8d65-060a5f2de25d",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,250 @@
import { CCFloat, Component, Enum, error, EventTouch, macro, Node, UIOpacity, UITransform, Vec2, Vec3, _decorator } from "cc";
import { Vec3Util } from "../../../../../extensions/oops-plugin-framework/assets/core/utils/Vec3Util";
const { ccclass, property } = _decorator;
/**
* 方向类型
*/
export enum DirectionType {
FOUR,
EIGHT,
ALL,
}
/**
* 速度类型
*/
export enum SpeedType {
Start,
STOP,
NORMAL,
FAST,
}
/**
* 摇杆类型
*/
export enum JoystickType {
FIXED,
FOLLOW,
}
export interface JoystickDataType {
/** 速度类型 */
type: SpeedType;
/** 移动向量 */
vector: Vec3;
/** 角度 */
angle: number;
}
export type ControllerFunc = (event: EventTouch, data: JoystickDataType) => void;
/** 摇杆 */
@ccclass("RoleViewUIJoystick")
export class RoleViewUIJoystick extends Component {
@property({
type: Node,
tooltip: "摇杆操纵点",
})
dot: Node | null = null;
@property({
type: Node,
tooltip: "摇杆背景节点",
})
ring: Node | null = null;
@property({
type: Enum(JoystickType),
tooltip: "触摸类型",
})
joystickType = JoystickType.FIXED;
@property({
type: Enum(DirectionType),
tooltip: "方向类型",
})
directionType = DirectionType.ALL;
@property({
tooltip: "摇杆所在位置"
})
_stickPos = new Vec3();
@property({
tooltip: "触摸位置"
})
_touchLocation = new Vec2();
@property({
type: CCFloat,
tooltip: "摇杆背景半径"
})
radius = -1;
onController: ControllerFunc | null = null;
onLoad() {
if (!this.dot) {
error("Joystick Dot is null!");
return;
}
if (!this.ring) {
error("Joystick Ring is null!");
return;
}
// 摇杆背景半径
if (this.radius == -1)
this.radius = this.ring.getComponent(UITransform)!.width / 2;
// 摇杆跟随跟随时默认隐藏界面
const uiOpacity = this.node.getComponent(UIOpacity);
if (this.joystickType === JoystickType.FOLLOW && uiOpacity) {
uiOpacity.opacity = 0;
}
this._initTouchEvent();
}
/**
* 改变摇杆类型
* @param type
*/
setJoystickType(type: JoystickType) {
this.joystickType = type;
const uiOpacity = this.node.getComponent(UIOpacity);
if (uiOpacity) {
uiOpacity.opacity = type === JoystickType.FIXED ? 255 : 0;
}
}
/**
* 初始化触摸事件
*/
private _initTouchEvent() {
this.node.on(Node.EventType.TOUCH_START, this._touchStartEvent, this);
this.node.on(Node.EventType.TOUCH_MOVE, this._touchMoveEvent, this);
this.node.on(Node.EventType.TOUCH_END, this._touchEndEvent, this);
this.node.on(Node.EventType.TOUCH_CANCEL, this._touchEndEvent, this);
}
/**
* 触摸开始回调函数
* @param event
*/
private _touchStartEvent(event: EventTouch) {
if (!this.ring || !this.dot) return;
if (this.onController) {
this.onController(event, {
type: SpeedType.Start,
vector: Vec3Util.zero,
angle: 0
});
}
const location = event.getUILocation();
const touchPos = new Vec3(location.x, location.y);
if (this.joystickType === JoystickType.FIXED) {
this._stickPos = this.ring.getWorldPosition();
// 相对中心的向量
const moveVec = touchPos.subtract(this.ring.getWorldPosition());
// 触摸点与圆圈中心的距离
const distance = moveVec.length();
// 手指在圆圈内触摸,控杆跟随触摸点
if (this.radius > distance) {
this.dot.setPosition(moveVec);
}
}
else if (this.joystickType === JoystickType.FOLLOW) {
// 记录摇杆位置,给 touch move 使用
this.node.getComponent(UIOpacity)!.opacity = 255;
this._stickPos = touchPos;
this._touchLocation = event.getUILocation();
// 更改摇杆的位置
this.ring.setWorldPosition(touchPos);
this.dot.setPosition(Vec3.ZERO);
}
}
/**
* 触摸移动回调函数
* @param event
*/
private _touchMoveEvent(event: EventTouch) {
if (!this.dot || !this.ring) return;
// 如果 touch start 位置和 touch move 相同,禁止移动
if (this.joystickType === JoystickType.FOLLOW && this._touchLocation === event.getUILocation()) {
return false;
}
// 以圆圈为锚点获取触摸坐标
const location = event.getUILocation();
const touchPos = new Vec3(location.x, location.y);
// 移动向量
const moveVec = touchPos.subtract(this.ring.getWorldPosition());
const distance = moveVec.length();
let speedType = SpeedType.NORMAL;
if (this.radius > distance) {
this.dot.setPosition(moveVec);
speedType = SpeedType.NORMAL;
}
else {
// 控杆永远保持在圈内,并在圈内跟随触摸更新角度
this.dot.setPosition(moveVec.normalize().multiplyScalar(this.radius));
speedType = SpeedType.FAST;
}
// 算出与(1,0)的夹角
let angle = this.covertToAngle(moveVec);
if (this.onController) {
this.onController(event, {
type: speedType,
vector: moveVec.normalize(),
angle
});
}
}
/** 根据位置转化角度 */
private covertToAngle(pos: Vec3) {
let angle = Math.atan2(pos.y, pos.x);
return angle * macro.DEG;
}
/**
* 触摸结束回调函数
* @param event
*/
private _touchEndEvent(event: EventTouch) {
if (!this.dot || !this.ring) return;
this.dot.setPosition(new Vec3());
if (this.joystickType === JoystickType.FOLLOW) {
this.node.getComponent(UIOpacity)!.opacity = 0;
}
if (this.onController) {
this.onController(event, {
type: SpeedType.STOP,
vector: Vec3Util.zero,
angle: 0
});
}
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "472d9967-6ca2-4293-b18d-b056a5a82fec",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "b3bb384b-5a96-4e00-a5f8-29bd621bdf99",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}