[add] first
This commit is contained in:
24
assets/scripts/test/delay-play.ts
Normal file
24
assets/scripts/test/delay-play.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { _decorator, Component, Node, Animation, CCFloat, CCString } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('DelayPlay')
|
||||
export class DelayPlay extends Component {
|
||||
|
||||
|
||||
@property([Animation])
|
||||
animations = [];
|
||||
|
||||
@property([CCFloat])
|
||||
delay = [];
|
||||
|
||||
@property([CCString])
|
||||
animation_names = [];
|
||||
|
||||
start () {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
9
assets/scripts/test/delay-play.ts.meta
Normal file
9
assets/scripts/test/delay-play.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "9d854cb9-0f1c-4a91-8582-cc5590fee60e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
29
assets/scripts/test/delay_play_animation.ts
Normal file
29
assets/scripts/test/delay_play_animation.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { _decorator, Component, Node, Animation, input, Input, EventKeyboard, KeyCode } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('DelayPlayAnimation')
|
||||
export class DelayPlayAnimation extends Component {
|
||||
|
||||
|
||||
@property
|
||||
delay = 2;
|
||||
|
||||
@property
|
||||
anim_name:string = 'minmax.com';
|
||||
|
||||
start() {
|
||||
|
||||
input.on(Input.EventType.KEY_UP, (event:EventKeyboard)=>{
|
||||
if (event.keyCode === KeyCode.SPACE) this.delayPlay();
|
||||
}, this)
|
||||
|
||||
}
|
||||
|
||||
delayPlay() {
|
||||
setTimeout(()=>{
|
||||
this.node.getComponent(Animation)?.play(this.anim_name);
|
||||
var anim = this.node.getComponent(Animation);
|
||||
}, this.delay * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/test/delay_play_animation.ts.meta
Normal file
9
assets/scripts/test/delay_play_animation.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6543d85d-e8a1-4185-8dda-700125bb8130",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
12
assets/scripts/test/steeringbehaviors.meta
Normal file
12
assets/scripts/test/steeringbehaviors.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "50d508e1-bae9-4f42-811f-0003ea4a7154",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {
|
||||
"compressionType": {},
|
||||
"isRemoteBundle": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"blockX":15,"blockY":3,"blockZ":15,"count":33,"nodeMap":{"-1,0,0":[0,3],"0,0,-1":[1,11,12,32],"0,0,0":[2,4,8,26,30],"-2,0,0":[5],"-2,0,1":[6],"-1,0,1":[7,24],"1,0,0":[9],"1,0,-1":[10,27,29],"0,0,-2":[13,20,28],"-1,0,-2":[14,23],"-2,0,-2":[15],"-2,0,-1":[16,17],"1,0,-2":[18,19],"-1,0,-1":[21,22,31],"0,0,1":[25]},"nodes":[{"x":-13.223,"y":1,"z":2.287,"id":0,"radius":4.999},{"x":7.025,"y":1,"z":-2.569,"id":1,"radius":2.821},{"x":4.626,"y":1,"z":4.272,"id":2,"radius":5.664},{"x":-4.413,"y":1,"z":0,"id":3,"radius":5.999},{"x":8.424,"y":1,"z":6.26,"id":4,"radius":7.476},{"x":-17.067,"y":1,"z":10.928,"id":5,"radius":4.63},{"x":-16.491,"y":1,"z":18.869,"id":6,"radius":2.97},{"x":-3.514,"y":1,"z":19.321,"id":7,"radius":2.538},{"x":10.707,"y":1,"z":14.549,"id":8,"radius":7.286},{"x":17.577,"y":1,"z":2.187,"id":9,"radius":5.629},{"x":21.287,"y":1,"z":-8.328,"id":10,"radius":1.868},{"x":10.751,"y":1,"z":-7.847,"id":11,"radius":2.082},{"x":3.931,"y":1,"z":-7.847,"id":12,"radius":2.445},{"x":2.962,"y":1,"z":-17.849,"id":13,"radius":3.748},{"x":-4.659,"y":1,"z":-20.379,"id":14,"radius":2.845},{"x":-17.813,"y":1,"z":-17.523,"id":15,"radius":3.911},{"x":-19.594,"y":1,"z":-11.793,"id":16,"radius":2.118},{"x":-18.873,"y":1,"z":-3.171,"id":17,"radius":2.842},{"x":21.338,"y":1,"z":-16.002,"id":18,"radius":1.817},{"x":18.827,"y":1,"z":-21.375,"id":19,"radius":1.853},{"x":6.102,"y":1,"z":-21.759,"id":20,"radius":1.457},{"x":-4.446,"y":1,"z":-12.155,"id":21,"radius":3.013},{"x":-0.292,"y":1,"z":-6.216,"id":22,"radius":0.979},{"x":-11.41,"y":1,"z":-19.027,"id":23,"radius":4.197},{"x":-9.551,"y":1,"z":19.185,"id":24,"radius":2.67},{"x":3.502,"y":1,"z":18.202,"id":25,"radius":3.664},{"x":13.619,"y":1,"z":5.404,"id":26,"radius":6.147},{"x":20.314,"y":1,"z":-3.664,"id":27,"radius":2.865},{"x":12.447,"y":1,"z":-21.693,"id":28,"radius":1.528},{"x":16.231,"y":1,"z":-7.253,"id":29,"radius":2.676},{"x":2.027,"y":1,"z":12.352,"id":30,"radius":2.634},{"x":-4.696,"y":1,"z":-8.24,"id":31,"radius":2.76},{"x":3.846,"y":1,"z":-13.33,"id":32,"radius":2.827}],"links":[[3,5,17],[2,4,11,12,22],[1,3,4,26,30],[0,2,22,31],[1,2,8,26,30],[0,6],[5,24],[24,25],[4,25,26,30],[26,27,29],[18,27,29],[1,12,29],[1,11,22,32],[14,20,21,32],[13,21,23],[16,23],[15,17],[0,16],[10,19],[18,28],[13,28,32],[13,14,23,31,32],[1,3,12,31],[14,15,21],[6,7],[7,8,30],[2,4,8,9],[9,10,29],[19,20],[9,10,11,27],[2,4,8,25],[3,21,22],[12,13,20,21]],"weights":[[9.102,9.457,7.856],[7.249,8.939,6.461,6.118,8.176],[7.249,9.998,4.287,9.064,8.488],[9.102,9.998,7.458,8.245],[8.939,4.287,8.598,5.265,8.834],[9.457,7.962],[7.962,6.947],[6.039,7.105],[8.598,8.078,9.597,8.954],[5.1,6.46,9.535],[7.674,4.764,5.169],[6.461,6.82,5.512],[6.118,6.82,4.527,5.484],[8.03,5.015,9.343,4.605],[8.03,8.227,6.885],[6,6.577],[6,8.652],[7.856,8.652],[7.674,5.931],[5.931,6.388],[5.015,6.345,8.726],[9.343,8.227,9.784,3.923,8.375],[8.176,7.458,4.527,4.847],[6.885,6.577,9.784],[6.947,6.039],[7.105,8.078,6.033],[9.064,5.265,9.597,5.1],[6.46,4.764,5.436],[6.388,6.345],[9.535,5.169,5.512,5.436],[8.488,8.834,8.954,6.033],[8.245,3.923,4.847],[5.484,4.605,8.726,8.375]]}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"importer": "json",
|
||||
"imported": true,
|
||||
"uuid": "1ad6f9d1-fd08-4e76-b3bb-cd0134d9bb45",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
11905
assets/scripts/test/steeringbehaviors/scene-steering-behavior.scene
Normal file
11905
assets/scripts/test/steeringbehaviors/scene-steering-behavior.scene
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "1.1.43",
|
||||
"importer": "scene",
|
||||
"imported": true,
|
||||
"uuid": "efd44484-6795-482a-8172-052399bfeade",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
21
assets/scripts/test/steeringbehaviors/test-move-target.ts
Normal file
21
assets/scripts/test/steeringbehaviors/test-move-target.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
import { ActorBrain } from '../../logic/actor/actor-brain';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('test_move_target')
|
||||
export class test_move_target extends Component {
|
||||
|
||||
@property( { type:ActorBrain } )
|
||||
brain:ActorBrain | undefined;
|
||||
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
lateUpdate(deltaTime: number) {
|
||||
|
||||
this.node.setWorldPosition(this.brain!.targetPosition);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "48d704f3-91a1-4fbc-b52b-2ac74d1c9cc7",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
93
assets/scripts/test/steeringbehaviors/test-steering-init.ts
Normal file
93
assets/scripts/test/steeringbehaviors/test-steering-init.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { _decorator, Component, JsonAsset, Node } from 'cc';
|
||||
import { NavSystem } from '../../logic/navigation/navigation-system';
|
||||
import { ResCache } from '../../core/res/res-cache';
|
||||
|
||||
import * as dataCore from "../../logic/data/data-core";
|
||||
import { Level } from '../../logic/level/level';
|
||||
import { Actor } from '../../logic/actor/actor';
|
||||
import { Sound } from '../../core/audio/sound';
|
||||
import { Save } from '../../logic/data/save';
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('TestSteeringInit')
|
||||
export class TestSteeringInit extends Component {
|
||||
|
||||
@property(JsonAsset)
|
||||
jsonAsset:JsonAsset | undefined;
|
||||
|
||||
@property(Node)
|
||||
enemiesNode:Node | undefined;
|
||||
|
||||
//@property( { type:[Actor] } )
|
||||
//actors:Actor[] = [];
|
||||
|
||||
@property( {type : Actor } )
|
||||
player:Actor | undefined;
|
||||
|
||||
start() {
|
||||
|
||||
NavSystem.Init(this.jsonAsset?.json);
|
||||
|
||||
ResCache.Instance.load(()=>{
|
||||
|
||||
const playerNode = this.node.getChildByName('player-tps');
|
||||
|
||||
this.player = playerNode?.getComponent(Actor)!;
|
||||
|
||||
dataCore.Init();
|
||||
|
||||
Save.Instance.init();
|
||||
|
||||
|
||||
|
||||
// Init player
|
||||
this.player?.init('data-player');
|
||||
|
||||
// Set level player.
|
||||
Level.Instance._player = this.player;
|
||||
|
||||
// Init sound.
|
||||
Sound.init();
|
||||
|
||||
// Init enemy actors.
|
||||
const enemies = this.enemiesNode?.getComponentsInChildren(Actor)!;
|
||||
for(let i = 0; i < enemies.length; i++) {
|
||||
enemies[i].init('data-enemy_0');
|
||||
enemies[i].isReady = true;
|
||||
}
|
||||
|
||||
Level.Instance.stop = false;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "28f03b84-667b-4ce3-a6c3-4ccea2eeaafc",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
25
assets/scripts/test/tap-play.ts
Normal file
25
assets/scripts/test/tap-play.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { _decorator, Component, Node, input, Input, EventKeyboard, KeyCode, game, director, Scene } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('TapPlay')
|
||||
export class TapPlay extends Component {
|
||||
|
||||
start() {
|
||||
|
||||
game.pause();
|
||||
|
||||
input.on(Input.EventType.KEY_UP, (event:EventKeyboard)=>{
|
||||
|
||||
if (event.keyCode === KeyCode.SPACE) {
|
||||
game.resume();
|
||||
}
|
||||
|
||||
if (event.keyCode === KeyCode.KEY_R) {
|
||||
|
||||
}
|
||||
|
||||
}, this)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/test/tap-play.ts.meta
Normal file
9
assets/scripts/test/tap-play.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "28ec1247-56b5-407e-83d3-ad6389af43b3",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
62
assets/scripts/test/test-actor-move.ts
Normal file
62
assets/scripts/test/test-actor-move.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { _decorator, clamp, Component, EventKeyboard, EventMouse, Input, input, KeyCode, Node, v3, Vec3 } from 'cc';
|
||||
import { ActorMove } from '../logic/actor/actor-move';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('TestActorMove')
|
||||
export class TestActorMove extends Component {
|
||||
|
||||
@property( {type:ActorMove, tooltip:' Reference Actor Move Slope.'} )
|
||||
actorMove:ActorMove | undefined;
|
||||
|
||||
_dir:Vec3 = v3(0, 0, 0);
|
||||
|
||||
direction_up = 0;
|
||||
direction_down = 0;
|
||||
direction_left = 0;
|
||||
direction_right = 0;
|
||||
|
||||
start() {
|
||||
input.on(Input.EventType.KEY_DOWN, this.onKeyDown, this);
|
||||
input.on(Input.EventType.KEY_UP, this.onKeyUp, this);
|
||||
|
||||
input.on(Input.EventType.MOUSE_DOWN, this.onMouseDown, this);
|
||||
input.on(Input.EventType.MOUSE_MOVE, this.onMouseMove, this);
|
||||
}
|
||||
|
||||
|
||||
onKeyDown(event: EventKeyboard) {
|
||||
if (event.keyCode === KeyCode.KEY_W || event.keyCode === KeyCode.ARROW_UP) this.direction_up = -1;
|
||||
if (event.keyCode === KeyCode.KEY_S || event.keyCode === KeyCode.ARROW_DOWN) this.direction_down = 1;
|
||||
if (event.keyCode === KeyCode.KEY_A || event.keyCode === KeyCode.ARROW_LEFT) this.direction_left = -1;
|
||||
if (event.keyCode === KeyCode.KEY_D || event.keyCode === KeyCode.ARROW_RIGHT) this.direction_right = 1;
|
||||
if (event.keyCode == KeyCode.SPACE) this.actorMove?.jump();
|
||||
this.onMove();
|
||||
}
|
||||
|
||||
onKeyUp(event: EventKeyboard) {
|
||||
if (event.keyCode === KeyCode.KEY_W || event.keyCode === KeyCode.ARROW_UP) this.direction_up = 0;
|
||||
if (event.keyCode === KeyCode.KEY_S || event.keyCode === KeyCode.ARROW_DOWN) this.direction_down = 0;
|
||||
if (event.keyCode === KeyCode.KEY_A || event.keyCode === KeyCode.ARROW_LEFT) this.direction_left = 0;
|
||||
if (event.keyCode === KeyCode.KEY_D || event.keyCode === KeyCode.ARROW_RIGHT) this.direction_right = 0;
|
||||
this.onMove();
|
||||
}
|
||||
|
||||
onMouseDown(event: EventMouse) {
|
||||
|
||||
}
|
||||
|
||||
onMouseMove(event: EventMouse) {
|
||||
this.actorMove?.onRotation(event.movementX / 5, event.movementY / 10);
|
||||
}
|
||||
|
||||
|
||||
onMove() {
|
||||
this._dir.x = this.direction_left + this.direction_right;
|
||||
this._dir.z = this.direction_up + this.direction_down;
|
||||
this._dir.y = 0;
|
||||
//console.log('dir:', this._dir);
|
||||
this.actorMove?.moveDirection(this._dir.normalize());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
9
assets/scripts/test/test-actor-move.ts.meta
Normal file
9
assets/scripts/test/test-actor-move.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f1cc2610-a5db-423e-8294-c09a3ea4e1b9",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
148
assets/scripts/test/test-amoy-animation.ts
Normal file
148
assets/scripts/test/test-amoy-animation.ts
Normal file
@@ -0,0 +1,148 @@
|
||||
import { _decorator, Component, EventKeyboard, EventMouse, Input, input, KeyCode, math, Node, RigidBody, v3, Vec3 } from 'cc';
|
||||
import { ActorAnimationGraph } from '../logic/actor/actor-animation-graph';
|
||||
import { Msg } from '../core/msg/msg';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('TestAmoyAnimation')
|
||||
export class TestAmoyAnimation extends Component {
|
||||
|
||||
_animationGraph:ActorAnimationGraph | undefined;
|
||||
|
||||
bool_crouch = false;
|
||||
|
||||
bool_iron_sights = false;
|
||||
|
||||
direction_up = 0;
|
||||
direction_down = 0;
|
||||
direction_left = 0;
|
||||
direction_right = 0;
|
||||
|
||||
cameraTargetIndex = 0;
|
||||
|
||||
@property
|
||||
moveSpeedRate = 0.7;
|
||||
|
||||
@property
|
||||
angleSpeedRate = 0.3;
|
||||
|
||||
angleVelocity = v3(0, 0, 0);
|
||||
|
||||
linearVelocity = v3(0, 0, 0);
|
||||
moveSpeed = 1;
|
||||
|
||||
@property(Node)
|
||||
view:Node | undefined;
|
||||
|
||||
@property(RigidBody)
|
||||
targetRigid:RigidBody | undefined;
|
||||
|
||||
start() {
|
||||
this._animationGraph = this.view?.getComponent(ActorAnimationGraph)!;
|
||||
input.on(Input.EventType.KEY_DOWN, this.keyDown, this);
|
||||
input.on(Input.EventType.KEY_UP, this.keyUp, this);
|
||||
|
||||
input.on(Input.EventType.MOUSE_DOWN, this.onMouseDown, this);
|
||||
}
|
||||
|
||||
lateUpdate(deltaTime: number) {
|
||||
this.updateMove();
|
||||
}
|
||||
|
||||
keyDown(event: EventKeyboard) {
|
||||
|
||||
if (event.keyCode === KeyCode.KEY_W || event.keyCode === KeyCode.ARROW_UP) this.direction_up = -1;
|
||||
if (event.keyCode === KeyCode.KEY_S || event.keyCode === KeyCode.ARROW_DOWN) this.direction_down = 1;
|
||||
if (event.keyCode === KeyCode.KEY_A || event.keyCode === KeyCode.ARROW_LEFT) this.direction_left = -1;
|
||||
if (event.keyCode === KeyCode.KEY_D || event.keyCode === KeyCode.ARROW_RIGHT) this.direction_right = 1;
|
||||
|
||||
if(event.keyCode == KeyCode.KEY_I) {
|
||||
this.bool_iron_sights = this.bool_iron_sights ? false : true;
|
||||
console.log(this.bool_iron_sights);
|
||||
this._animationGraph?.play('bool_iron_sights', this.bool_iron_sights);
|
||||
this.cameraTargetIndex = this.bool_iron_sights? 1 : 0;
|
||||
Msg.emit('msg_change_tps_camera_target', this.cameraTargetIndex);
|
||||
}
|
||||
|
||||
if(event.keyCode == KeyCode.KEY_C) {
|
||||
this.bool_crouch = this.bool_crouch ? false : true;
|
||||
this._animationGraph?.play('bool_crouch', this.bool_crouch);
|
||||
Msg.emit('msg_change_tps_camera_height', this.bool_crouch ? 1 : 1.377);
|
||||
}
|
||||
|
||||
if(event.keyCode == KeyCode.SPACE) {
|
||||
this._animationGraph?.play('trigger_jump', true);
|
||||
this._animationGraph?.setValue('num_jump_speed', 0.8);
|
||||
}
|
||||
|
||||
if(event.keyCode === KeyCode.KEY_D) {
|
||||
this._animationGraph?.play('trigger_draw', true);
|
||||
}
|
||||
|
||||
if (event.keyCode === KeyCode.KEY_R) {
|
||||
this._animationGraph?.play('trigger_reload', true);
|
||||
}
|
||||
|
||||
if (event.keyCode === KeyCode.KEY_E) {
|
||||
this._animationGraph?.play('trigger_reload_empty', true);
|
||||
}
|
||||
|
||||
if (event.keyCode === KeyCode.KEY_H) {
|
||||
this._animationGraph?.play('trigger_hit', true);
|
||||
}
|
||||
|
||||
if (event.keyCode == KeyCode.KEY_Z) {
|
||||
|
||||
if(this.cameraTargetIndex === 1) return;
|
||||
|
||||
this.cameraTargetIndex = this.cameraTargetIndex === 0 ? 2 : 0;
|
||||
|
||||
Msg.emit('msg_change_tps_camera_target', this.cameraTargetIndex);
|
||||
}
|
||||
|
||||
//this.updateMove();
|
||||
|
||||
}
|
||||
|
||||
onMouseDown(event: EventMouse) {
|
||||
this._animationGraph?.play('trigger_fire', true);
|
||||
}
|
||||
|
||||
keyUp(event: EventKeyboard) {
|
||||
if (event.keyCode === KeyCode.KEY_W || event.keyCode === KeyCode.ARROW_UP) this.direction_up = 0;
|
||||
if (event.keyCode === KeyCode.KEY_S || event.keyCode === KeyCode.ARROW_DOWN) this.direction_down = 0;
|
||||
if (event.keyCode === KeyCode.KEY_A || event.keyCode === KeyCode.ARROW_LEFT) this.direction_left = 0;
|
||||
if (event.keyCode === KeyCode.KEY_D || event.keyCode === KeyCode.ARROW_RIGHT) this.direction_right = 0;
|
||||
//this.updateMove();
|
||||
}
|
||||
|
||||
updateMove() {
|
||||
|
||||
this.targetRigid!.getLinearVelocity(this.linearVelocity);
|
||||
this.targetRigid!.getAngularVelocity(this.angleVelocity);
|
||||
|
||||
this.linearVelocity.y = 0;
|
||||
const linearVelocityLength = this.linearVelocity.length();
|
||||
|
||||
const eulerAnglesY = this.targetRigid!.node.eulerAngles.y;
|
||||
|
||||
//rotate y.
|
||||
Vec3.rotateY(this.linearVelocity, this.linearVelocity, Vec3.ZERO, math.toRadian(-eulerAnglesY));
|
||||
|
||||
let num_velocity_x = this.linearVelocity.x;
|
||||
let num_velocity_y = this.linearVelocity.z;
|
||||
|
||||
this.moveSpeed = linearVelocityLength * this.moveSpeedRate;
|
||||
|
||||
// Check rotation.
|
||||
if((this.direction_up + this.direction_left + this.direction_right + this.direction_down) == 0 && Math.abs(this.angleVelocity.y) > 1) {
|
||||
this.moveSpeed = this.angleVelocity.y * this.angleSpeedRate;
|
||||
num_velocity_x = this.angleVelocity.y / 10;
|
||||
}
|
||||
|
||||
this._animationGraph?.setValue('num_velocity_x', num_velocity_x);
|
||||
this._animationGraph?.setValue('num_velocity_y', -num_velocity_y);
|
||||
this._animationGraph?.setValue('num_move_speed', this.moveSpeed);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
9
assets/scripts/test/test-amoy-animation.ts.meta
Normal file
9
assets/scripts/test/test-amoy-animation.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "a7be8d35-2990-4083-bd4d-fb0f3de04818",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
46
assets/scripts/test/test-anig.ts
Normal file
46
assets/scripts/test/test-anig.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { _decorator, Component, Node, input, Input, EventKeyboard, KeyCode } from 'cc';
|
||||
import { ActorAnimationGraphGroup } from '../logic/actor/actor-animation-graph-group';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('TestAnimationGraph')
|
||||
export class TestAnimationGraph extends Component {
|
||||
|
||||
_animationGraph:ActorAnimationGraphGroup | undefined;
|
||||
|
||||
start() {
|
||||
|
||||
const view = this.node.getChildByName('view');
|
||||
this._animationGraph = view.addComponent(ActorAnimationGraphGroup);
|
||||
input.on(Input.EventType.KEY_DOWN, this.keyDown, this);
|
||||
|
||||
}
|
||||
|
||||
keyDown(event: EventKeyboard) {
|
||||
|
||||
if(event.keyCode === KeyCode.KEY_D) {
|
||||
this._animationGraph?.play('trigger_draw', true);
|
||||
}
|
||||
|
||||
if (event.keyCode === KeyCode.KEY_F) {
|
||||
this._animationGraph?.play('trigger_fire', true);
|
||||
}
|
||||
|
||||
if (event.keyCode === KeyCode.KEY_R) {
|
||||
this._animationGraph?.play('trigger_reload', true);
|
||||
}
|
||||
|
||||
if (event.keyCode === KeyCode.KEY_E) {
|
||||
this._animationGraph?.play('trigger_reload_empty', true);
|
||||
}
|
||||
|
||||
if (event.keyCode === KeyCode.KEY_H) {
|
||||
this._animationGraph?.play('trigger_holster', true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/test/test-anig.ts.meta
Normal file
9
assets/scripts/test/test-anig.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "454cb20c-4860-4c37-9053-e675b917d8e2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
14
assets/scripts/test/test-camera-debug.ts
Normal file
14
assets/scripts/test/test-camera-debug.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('test_camera_debug')
|
||||
export class test_camera_debug extends Component {
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
console.log(this.node.worldPosition);
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/test/test-camera-debug.ts.meta
Normal file
9
assets/scripts/test/test-camera-debug.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "4175b2da-cf24-4bc6-8e62-6b55066fff58",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
19
assets/scripts/test/test-collider-mesh-switch.ts
Normal file
19
assets/scripts/test/test-collider-mesh-switch.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { _decorator, Component, MeshRenderer } from 'cc';
|
||||
import { DataGameInst } from '../logic/data/data-core';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('TestColliderMeshSwitch')
|
||||
export class TestColliderMeshSwitch extends Component {
|
||||
|
||||
@property
|
||||
meshRenderState:boolean = false;
|
||||
|
||||
start() {
|
||||
this.meshRenderState = DataGameInst._data.show_collider;
|
||||
console.log("meshRenderState:", this.meshRenderState);
|
||||
const meshRenders = this.getComponentsInChildren(MeshRenderer);
|
||||
for (let i = 0; i < meshRenders.length; i++) {
|
||||
meshRenders[i].enabled = this.meshRenderState;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
assets/scripts/test/test-collider-mesh-switch.ts.meta
Normal file
9
assets/scripts/test/test-collider-mesh-switch.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "cd636576-4877-4980-8d18-bbb9aa4f4413",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
25
assets/scripts/test/test-forward.ts
Normal file
25
assets/scripts/test/test-forward.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { _decorator, Component, geometry, Node, v3 } from 'cc';
|
||||
import { Gizmo, UtilVec3 } from '../core/util/util';
|
||||
import { EDITOR } from 'cc/env';
|
||||
const { ccclass, property, executeInEditMode } = _decorator;
|
||||
|
||||
@ccclass('test_forward')
|
||||
@executeInEditMode
|
||||
export class test_forward extends Component {
|
||||
|
||||
onEnable() {
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
if(EDITOR) {
|
||||
let endPosition = v3(0, 0, 0);
|
||||
UtilVec3.copy(endPosition, this.node.worldPosition);
|
||||
endPosition.add(this.node.forward);
|
||||
Gizmo.drawLine(this.node.worldPosition, endPosition);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/test/test-forward.ts.meta
Normal file
9
assets/scripts/test/test-forward.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "eb929e62-d0f8-4638-b112-a8221d0d24a7",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
22
assets/scripts/test/test-gun-fire.ts
Normal file
22
assets/scripts/test/test-gun-fire.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
import { ActorEquipBase } from '../logic/actor/actor-equip-base';
|
||||
import { TestAnimationGraph } from './test-anig';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('test_gun_fire')
|
||||
export class test_gun_fire extends Component {
|
||||
start() {
|
||||
|
||||
for(let i = 0 ;i < this.node.children.length; i++) {
|
||||
const child = this.node.children[i];
|
||||
//child.getComponent(ActorEquipBase)!.enabled = false;
|
||||
child.addComponent(TestAnimationGraph);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/test/test-gun-fire.ts.meta
Normal file
9
assets/scripts/test/test-gun-fire.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "887bcceb-c6b3-4996-96d0-c64fccd730f2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
25
assets/scripts/test/test-gun-tracer.ts
Normal file
25
assets/scripts/test/test-gun-tracer.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { _decorator, Component, EventKeyboard, input, Input, KeyCode, randomRange, v3, Vec3 } from 'cc';
|
||||
import { Msg } from '../core/msg/msg';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('TestGunTracer')
|
||||
export class TestGunTracer extends Component {
|
||||
|
||||
start() {
|
||||
input.on(Input.EventType.KEY_DOWN, this.keyDown, this);
|
||||
}
|
||||
|
||||
|
||||
keyDown(event: EventKeyboard) {
|
||||
if (event.keyCode === KeyCode.KEY_R) {
|
||||
const start = Vec3.ZERO;
|
||||
const end = v3(randomRange(0, 30), 1, randomRange(0, 30));
|
||||
Msg.emit('msg_set_tracer', {start, end});
|
||||
}
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/test/test-gun-tracer.ts.meta
Normal file
9
assets/scripts/test/test-gun-tracer.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "9ae65da2-d847-46dc-bbae-8471bd0fa1aa",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
84
assets/scripts/test/test-ik.ts
Normal file
84
assets/scripts/test/test-ik.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import { _decorator, Component, EventKeyboard, Input, input, KeyCode, Node } from 'cc';
|
||||
import { ActorAnimationGraphGroup } from '../logic/actor/actor-animation-graph-group';
|
||||
import { ActorAnimationGraph } from '../logic/actor/actor-animation-graph';
|
||||
import AimControl from '../core/ik/aim-control';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('TestIk')
|
||||
export class TestIk extends Component {
|
||||
|
||||
@property(Node)
|
||||
anim:Node | undefined;
|
||||
|
||||
@property(Node)
|
||||
targetRoot:Node | undefined;
|
||||
|
||||
@property(Node)
|
||||
ikNode:Node | undefined;
|
||||
|
||||
@property(Node)
|
||||
target:Node | undefined;
|
||||
|
||||
aimControl:AimControl | undefined;
|
||||
|
||||
animationGraph:ActorAnimationGraph | undefined | null;
|
||||
|
||||
targetIndex = 0;
|
||||
|
||||
bool_iron_sights = false;
|
||||
|
||||
|
||||
start() {
|
||||
|
||||
this.aimControl = this.ikNode?.getComponent(AimControl)!;
|
||||
|
||||
this.animationGraph = this.anim?.getComponent(ActorAnimationGraph);
|
||||
|
||||
input.on(Input.EventType.KEY_DOWN, this.keyDown, this);
|
||||
}
|
||||
|
||||
keyDown(event: EventKeyboard) {
|
||||
|
||||
if(event.keyCode === KeyCode.KEY_I) {
|
||||
this.bool_iron_sights = this.bool_iron_sights ? false : true;
|
||||
this.animationGraph?.play('bool_iron_sights', this.bool_iron_sights);
|
||||
console.log('bool_iron_sights:', this.bool_iron_sights);
|
||||
}
|
||||
|
||||
if (event.keyCode === KeyCode.KEY_F) {
|
||||
this.animationGraph?.play('trigger_fire', true);
|
||||
}
|
||||
|
||||
if (event.keyCode === KeyCode.KEY_N) {
|
||||
this.nextTarget();
|
||||
}
|
||||
|
||||
if (event.keyCode === KeyCode.KEY_R) {
|
||||
this.animationGraph!.play('trigger_reload', true);
|
||||
}
|
||||
|
||||
if (event.keyCode === KeyCode.KEY_E) {
|
||||
this.animationGraph!.play('trigger_reload_empty', true);
|
||||
}
|
||||
|
||||
if (event.keyCode === KeyCode.KEY_H) {
|
||||
this.animationGraph!.play('trigger_holster', true);
|
||||
}
|
||||
|
||||
if (event.keyCode === KeyCode.SPACE) {
|
||||
this.animationGraph!.play('trigger_jump', true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
nextTarget() {
|
||||
const worldPosition = this.targetRoot!.children[this.targetIndex].getWorldPosition();
|
||||
this.aimControl!.target?.setWorldPosition(worldPosition);
|
||||
this.target?.setWorldPosition(worldPosition);
|
||||
console.log('current target index:', this.targetIndex);
|
||||
this.targetIndex++;
|
||||
if(this.targetIndex >= this.targetRoot!.children.length) this.targetIndex = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
9
assets/scripts/test/test-ik.ts.meta
Normal file
9
assets/scripts/test/test-ik.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "df315aca-0bbb-44e5-a969-90e90fa9338f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
177
assets/scripts/test/test-normal.ts
Normal file
177
assets/scripts/test/test-normal.ts
Normal file
@@ -0,0 +1,177 @@
|
||||
import { _decorator, Component, geometry, PhysicsSystem, Node, v3, Color, Vec3, color } from 'cc';
|
||||
import { EDITOR } from 'cc/env';
|
||||
import { Gizmo, UtilVec3 } from '../core/util/util';
|
||||
const { ccclass, property, executeInEditMode } = _decorator;
|
||||
|
||||
@ccclass('TestNormal')
|
||||
@executeInEditMode
|
||||
export class TestNormal extends Component {
|
||||
|
||||
direction = v3(0, 0, 0);
|
||||
normal = v3(0, 0, 0);
|
||||
startPos = v3(0, 0, 0);
|
||||
|
||||
@property
|
||||
moveDirection = v3(0, 0, 0);
|
||||
|
||||
ray = new geometry.Ray();
|
||||
|
||||
p0 = v3(0, 0, 0);
|
||||
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
if(EDITOR) {
|
||||
this.calculateSlopDirection();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
calculateSlopeDirection() {
|
||||
const ray = this.ray;
|
||||
const mask = 0;
|
||||
const distance = 0.4
|
||||
|
||||
const p0 = v3(0, 0, 0);
|
||||
const p1 = v3(0, 0, 0);
|
||||
|
||||
let dir = v3(0, -1, 0);
|
||||
|
||||
const position = this.node.position.clone();
|
||||
|
||||
position.add(dir);
|
||||
|
||||
UtilVec3.copy(ray.o, this.node.position);
|
||||
ray.d = v3(0, -1, 0);
|
||||
|
||||
Gizmo.drawLine(ray.o, position);
|
||||
|
||||
if (PhysicsSystem.instance.raycastClosest(ray, undefined, distance)) {
|
||||
const hit1 = PhysicsSystem.instance.raycastClosestResult;
|
||||
const pos = hit1.hitPoint.clone();
|
||||
const p0 = hit1.hitPoint.clone();
|
||||
console.log(hit1.hitNormal);
|
||||
Gizmo.drawLine(hit1.hitPoint, pos.add(hit1.hitNormal).multiplyScalar(2), Color.RED);
|
||||
|
||||
Gizmo.drawLine(this.node.worldPosition, p0, Color.GREEN);
|
||||
ray.o.z = 0.03;
|
||||
ray.o.x = 0.03
|
||||
const o1 = ray.o.clone();
|
||||
Gizmo.drawLine(ray.o, o1.add(dir));
|
||||
if(PhysicsSystem.instance.raycastClosest(ray, undefined, distance)) {
|
||||
const hit2 = PhysicsSystem.instance.raycastClosestResult;
|
||||
const pos2 = hit2.hitPoint.clone();
|
||||
const p1 = hit2.hitPoint.clone();
|
||||
Gizmo.drawLine(this.node.worldPosition, p1, Color.YELLOW);
|
||||
UtilVec3.copy(this.direction, p1);
|
||||
this.direction.subtract(p0).normalize();
|
||||
|
||||
Vec3.cross(this.normal, p0.subtract(this.node.worldPosition), p1.subtract(this.node.worldPosition))
|
||||
|
||||
const n = v3(0, 0, 0);
|
||||
UtilVec3.copy(n, this.node.worldPosition);
|
||||
n.add(this.normal);
|
||||
Gizmo.drawLine(this.node.worldPosition, n, Color.CYAN);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
calculateSlopNormal() {
|
||||
const ray = this.ray
|
||||
const mask = 0;
|
||||
const distance = 0.4
|
||||
|
||||
const p0 = v3(0, 0, 0);
|
||||
const p1 = v3(0, 0, 0);
|
||||
const p2 = v3(0, 0, 0);
|
||||
|
||||
let dir = v3(0, -1, 0);
|
||||
|
||||
const position = this.node.position.clone();
|
||||
|
||||
position.add(dir);
|
||||
|
||||
UtilVec3.copy(ray.o, this.node.position);
|
||||
ray.d = v3(0, -1, 0);
|
||||
|
||||
Gizmo.drawLine(ray.o, position);
|
||||
|
||||
if (PhysicsSystem.instance.raycastClosest(ray, undefined, distance)) {
|
||||
const hit1 = PhysicsSystem.instance.raycastClosestResult;
|
||||
const p0 = hit1.hitPoint.clone();
|
||||
Gizmo.drawLine(this.node.worldPosition, p0, Color.GREEN);
|
||||
ray.o.z = 0.03;
|
||||
ray.o.x = 0.03
|
||||
const o1 = ray.o.clone();
|
||||
|
||||
if(PhysicsSystem.instance.raycastClosest(ray, undefined, distance)) {
|
||||
const hit2 = PhysicsSystem.instance.raycastClosestResult;
|
||||
Gizmo.drawLine(ray.o, hit2.hitPoint);
|
||||
UtilVec3.copy(p1, hit2.hitPoint);
|
||||
Gizmo.drawLine(this.node.worldPosition, ray.o, Color.YELLOW);
|
||||
//UtilVec3.copy(this.direction, p1);
|
||||
//this.direction.subtract(p0).normalize();
|
||||
}
|
||||
|
||||
|
||||
ray.o.z = -0.03;
|
||||
ray.o.x = -0.03
|
||||
if(PhysicsSystem.instance.raycastClosest(ray, undefined, distance)) {
|
||||
const hit3 = PhysicsSystem.instance.raycastClosestResult;
|
||||
UtilVec3.copy(p2, hit3.hitPoint);
|
||||
Gizmo.drawLine(ray.o, hit3.hitPoint);
|
||||
Gizmo.drawLine(this.node.worldPosition, ray.o, Color.YELLOW);
|
||||
|
||||
Gizmo.drawLine(p0, p1, Color.RED);
|
||||
Gizmo.drawLine(p0, p2, Color.RED);
|
||||
|
||||
|
||||
Vec3.cross(this.normal, p1.subtract(p0), p2.subtract(p0));
|
||||
|
||||
const n = v3(0, 0, 0);
|
||||
UtilVec3.copy(n, p0);
|
||||
n.add(this.normal);
|
||||
Gizmo.drawLine(p0, n, Color.RED);
|
||||
|
||||
UtilVec3.copy(this.startPos, p0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
calculateSlopDirection() {
|
||||
|
||||
const moveLength = this.moveDirection.length();
|
||||
|
||||
console.log(moveLength);
|
||||
|
||||
if(this.ray === undefined) this.ray = new geometry.Ray();
|
||||
|
||||
UtilVec3.copy(this.ray.o, this.node.worldPosition);
|
||||
UtilVec3.copy(this.direction, this.moveDirection);
|
||||
|
||||
this.ray.d = v3(0, -1, 0);
|
||||
|
||||
if (PhysicsSystem.instance.raycastClosest(this.ray, undefined, 1)) {
|
||||
const hit1 = PhysicsSystem.instance.raycastClosestResult;
|
||||
UtilVec3.copy(this.p0, hit1.hitPoint);
|
||||
Gizmo.drawLine(this.ray.o, this.p0, Color.YELLOW);
|
||||
this.ray.o.add(this.moveDirection);
|
||||
Gizmo.drawLine(this.p0, this.p0.clone().add(this.moveDirection), Color.YELLOW);
|
||||
if (PhysicsSystem.instance.raycastClosest(this.ray, undefined, 1)) {
|
||||
const hit2 = PhysicsSystem.instance.raycastClosestResult;
|
||||
Gizmo.drawLine(this.ray.o, hit2.hitPoint, Color.GREEN);
|
||||
UtilVec3.copy(this.direction, hit2.hitPoint);
|
||||
this.direction.subtract(this.p0).normalize().multiplyScalar(moveLength);
|
||||
Gizmo.drawLine(this.p0, this.p0.clone().add(this.direction), Color.GREEN);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
9
assets/scripts/test/test-normal.ts.meta
Normal file
9
assets/scripts/test/test-normal.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "53f33708-7aae-43fc-bc5c-817b1913f0f1",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
27
assets/scripts/test/test-rigidbody-vector.ts
Normal file
27
assets/scripts/test/test-rigidbody-vector.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { _decorator, Component, Node, RigidBody, v3, Vec3 } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('TestRigidBodyVector')
|
||||
export class TestRigidBodyVector extends Component {
|
||||
|
||||
@property(RigidBody)
|
||||
rigid:RigidBody | undefined;
|
||||
|
||||
@property(Vec3)
|
||||
velocity:Vec3 = v3(0, 0, 0);
|
||||
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
lateUpdate(deltaTime: number) {
|
||||
|
||||
this.node.setWorldPosition(this.rigid!.node.worldPosition);
|
||||
this.rigid!.getLinearVelocity(this.velocity);
|
||||
if(this.velocity.length() > 0.5) {
|
||||
this.velocity.add(this.node.worldPosition);
|
||||
this.node.lookAt(this.velocity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/test/test-rigidbody-vector.ts.meta
Normal file
9
assets/scripts/test/test-rigidbody-vector.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "1ed651f1-9bfe-4f33-aa4a-9999ce25ed40",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
50
assets/scripts/test/test-slope-direction.ts
Normal file
50
assets/scripts/test/test-slope-direction.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { _decorator, Color, Component, Node, Quat, v3, Vec3 } from 'cc';
|
||||
import { EDITOR } from 'cc/env';
|
||||
import { Gizmo, UtilVec3 } from '../core/util/util';
|
||||
import { TestNormal } from './test-normal';
|
||||
import { TestSlopeVector } from './test-slope-vector';
|
||||
const { ccclass, property, executeInEditMode } = _decorator;
|
||||
|
||||
@ccclass('TestSlopeDirection')
|
||||
@executeInEditMode
|
||||
export class TestSlopeDirection extends Component {
|
||||
|
||||
@property(TestNormal)
|
||||
playerNode:TestNormal | undefined | null;
|
||||
|
||||
@property(Vec3)
|
||||
moveDirection:Vec3 = v3(0, 0, 0);
|
||||
|
||||
@property(TestSlopeVector)
|
||||
slopeDirection:TestSlopeVector | undefined | null;
|
||||
|
||||
endPosition = v3(0, 0, 0);
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
if(EDITOR) {
|
||||
|
||||
UtilVec3.copy(this.endPosition, this.node.worldPosition);
|
||||
|
||||
this.endPosition.add(this.moveDirection);
|
||||
|
||||
Gizmo.drawLine(this.node.worldPosition, this.endPosition, Color.MAGENTA);
|
||||
|
||||
UtilVec3.copy(this.slopeDirection!.direction, this.moveDirection);
|
||||
|
||||
//const direction = this.playerNode!.direction;
|
||||
//const planeNormal = this.playerNode!.normal;
|
||||
//let project = v3(0, 0, 0);
|
||||
//Vec3.projectOnPlane(project, project, planeNormal);
|
||||
|
||||
UtilVec3.copy(this.endPosition, this.node.worldPosition);
|
||||
|
||||
this.endPosition.add(this.slopeDirection!.vectorSlop);
|
||||
|
||||
Gizmo.drawLine(this.node.worldPosition, this.endPosition, Color.YELLOW);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/test/test-slope-direction.ts.meta
Normal file
9
assets/scripts/test/test-slope-direction.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e5fb364a-1a51-4d50-bf2e-70739f03f6e4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
14
assets/scripts/test/test-slope-move.ts
Normal file
14
assets/scripts/test/test-slope-move.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('TestSlopeMove')
|
||||
export class TestSlopeMove extends Component {
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/test/test-slope-move.ts.meta
Normal file
9
assets/scripts/test/test-slope-move.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ddfff1f3-5f36-4467-ab29-71773144892d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
63
assets/scripts/test/test-slope-vector.ts
Normal file
63
assets/scripts/test/test-slope-vector.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { _decorator, Color, Component, geometry, Node, PhysicsSystem, v3, Vec3, CCFloat } from 'cc';
|
||||
import { Gizmo, UtilVec3 } from '../core/util/util';
|
||||
import { EDITOR } from 'cc/env';
|
||||
const { ccclass, property, executeInEditMode } = _decorator;
|
||||
|
||||
@ccclass('TestSlopeVector')
|
||||
@executeInEditMode
|
||||
export class TestSlopeVector extends Component {
|
||||
|
||||
@property([CCFloat])
|
||||
masks = [];
|
||||
|
||||
@property(CCFloat)
|
||||
distance = 0.5;
|
||||
|
||||
@property(Vec3)
|
||||
direction = v3(0, 0, 1);
|
||||
|
||||
_mask: number = 0;
|
||||
_ray: geometry.Ray = new geometry.Ray();
|
||||
hitPoint = v3(0.5, 0, 0.5);
|
||||
|
||||
@property(Vec3)
|
||||
vectorSlop = v3(0, 0, 0);
|
||||
|
||||
|
||||
start () {
|
||||
for (let i = 0; i < this.masks.length; i++)
|
||||
this._mask = this._mask | 1 << this.masks[i];
|
||||
}
|
||||
|
||||
update (deltaTime: number) {
|
||||
|
||||
if (EDITOR) {
|
||||
|
||||
UtilVec3.copy(this._ray.o, this.direction);
|
||||
this._ray.o.multiplyScalar(0.1);
|
||||
this._ray.o.add(this.node.worldPosition);
|
||||
this._ray.o.y += 0.1;
|
||||
this._ray.d.y = -1;
|
||||
this._ray.d.x = 0;
|
||||
this._ray.d.z = 0;
|
||||
this._mask = 1 << 0;
|
||||
|
||||
if (PhysicsSystem.instance.raycastClosest(this._ray, undefined, this.distance)) {
|
||||
UtilVec3.copy(this.hitPoint, PhysicsSystem.instance.raycastClosestResult.hitPoint);
|
||||
UtilVec3.copy(this.vectorSlop, this.hitPoint);
|
||||
this.vectorSlop.subtract(this.node.worldPosition);
|
||||
} else {
|
||||
UtilVec3.copy(this.hitPoint, Vec3.ZERO);
|
||||
UtilVec3.copy(this.vectorSlop, Vec3.ZERO);
|
||||
console.log('no hit ');
|
||||
}
|
||||
|
||||
Gizmo.drawBox(this._ray.o, v3(0.1, 0.1, 0.1), Color.YELLOW);
|
||||
|
||||
Gizmo.drawLine(this._ray.o, this._ray.d.add(this._ray.o), Color.BLUE);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/test/test-slope-vector.ts.meta
Normal file
9
assets/scripts/test/test-slope-vector.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "79d734dd-7a71-402f-b2e5-61ded4e1ef67",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
46
assets/scripts/test/test-stairs.ts
Normal file
46
assets/scripts/test/test-stairs.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { _decorator, Component, Node, v3, Vec3 } from 'cc';
|
||||
import { EDITOR } from 'cc/env';
|
||||
import { UtilVec3 } from '../core/util/util';
|
||||
import { Res } from '../core/res/res';
|
||||
const { ccclass, property, executeInEditMode } = _decorator;
|
||||
|
||||
@ccclass('TestStairs')
|
||||
@executeInEditMode
|
||||
export class TestStairs extends Component {
|
||||
|
||||
@property
|
||||
count = 10;
|
||||
|
||||
@property
|
||||
height = 10;
|
||||
|
||||
@property
|
||||
angle = 45;
|
||||
|
||||
@property(Vec3)
|
||||
vector = v3(0, 0, 0);
|
||||
|
||||
onEnable() {
|
||||
|
||||
if(EDITOR) {
|
||||
|
||||
if(this.node.children.length > 1) return;
|
||||
|
||||
let position = v3(0, 0, 0);
|
||||
|
||||
const board = this.node.children[0];
|
||||
|
||||
UtilVec3.copy(position, board.position);
|
||||
|
||||
for(let i = 10; i < this.count; i++) {
|
||||
position.add(this.vector);
|
||||
const newBoard = Res.instNode(board, this.node, position);
|
||||
newBoard.setScale(board.scale);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
9
assets/scripts/test/test-stairs.ts.meta
Normal file
9
assets/scripts/test/test-stairs.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f4cd044c-4ca9-49e6-93cd-fc76e0c79ce9",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
39
assets/scripts/test/test-stretched-billboard.ts
Normal file
39
assets/scripts/test/test-stretched-billboard.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { _decorator, Component, math, Node } from 'cc';
|
||||
import { EDITOR } from 'cc/env';
|
||||
import { GMath } from '../core/util/g-math';
|
||||
const { ccclass, property, executeInEditMode } = _decorator;
|
||||
|
||||
@ccclass('TestStretchedBillboard')
|
||||
@executeInEditMode
|
||||
export class TestStretchedBillboard extends Component {
|
||||
|
||||
@property(Node)
|
||||
target:Node | undefined;
|
||||
|
||||
@property(Node)
|
||||
current:Node | undefined;
|
||||
|
||||
@property
|
||||
updateTime:number = 3;
|
||||
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
if(EDITOR) {
|
||||
|
||||
const billboardAngle = GMath.StretchedBillboardAngle(this.current!.up, this.current!.worldPosition, this.target!.worldPosition, this.current!.forward);
|
||||
|
||||
if(billboardAngle) {
|
||||
const angle = this.node.eulerAngles;
|
||||
this.current!.setRotationFromEuler(angle.x, angle.y, billboardAngle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
9
assets/scripts/test/test-stretched-billboard.ts.meta
Normal file
9
assets/scripts/test/test-stretched-billboard.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "78620d10-0d96-4bac-a676-262775bbb653",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
17
assets/scripts/test/test-ui.ts
Normal file
17
assets/scripts/test/test-ui.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('test_ui')
|
||||
export class test_ui extends Component {
|
||||
|
||||
start() {
|
||||
|
||||
console.log(this.node.name, this.node.position, this.node.worldPosition);
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/test/test-ui.ts.meta
Normal file
9
assets/scripts/test/test-ui.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6af180fa-4dbb-4d1f-a018-84ae66be3b19",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user