добавлена возможность вывода дополнительного цвета
This commit is contained in:
parent
982271e42a
commit
5013fcb73d
Binary file not shown.
@ -1,12 +0,0 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"importer": "*",
|
||||
"imported": true,
|
||||
"uuid": "2dbb8e72-c7d3-4408-a894-7f9a7cdab6f9",
|
||||
"files": [
|
||||
".blend",
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@ -3830,6 +3830,13 @@
|
||||
"scenes": [
|
||||
"e4b19cae-fc01-427a-9539-1caf9ed336dc@9d8cd"
|
||||
]
|
||||
},
|
||||
"meshCompress": {
|
||||
"enable": true,
|
||||
"compress": true
|
||||
},
|
||||
"meshOptimize": {
|
||||
"enable": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
63
assets/Materials/YellowPulseMaterial.mtl
Normal file
63
assets/Materials/YellowPulseMaterial.mtl
Normal file
@ -0,0 +1,63 @@
|
||||
{
|
||||
"__type__": "cc.Material",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"__editorExtras__": {},
|
||||
"_native": "",
|
||||
"_effectAsset": {
|
||||
"__uuid__": "a3cd009f-0ab0-420d-9278-b9fdab939bbc",
|
||||
"__expectedType__": "cc.EffectAsset"
|
||||
},
|
||||
"_techIdx": 1,
|
||||
"_defines": [
|
||||
{
|
||||
"USE_INSTANCING": true,
|
||||
"USE_ALPHA_TEST": true
|
||||
},
|
||||
{},
|
||||
{}
|
||||
],
|
||||
"_states": [
|
||||
{
|
||||
"rasterizerState": {},
|
||||
"depthStencilState": {},
|
||||
"blendState": {
|
||||
"targets": [
|
||||
{}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"rasterizerState": {},
|
||||
"depthStencilState": {},
|
||||
"blendState": {
|
||||
"targets": [
|
||||
{}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"rasterizerState": {},
|
||||
"depthStencilState": {},
|
||||
"blendState": {
|
||||
"targets": [
|
||||
{}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"_props": [
|
||||
{
|
||||
"mainColor": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 0,
|
||||
"a": 255
|
||||
},
|
||||
"alphaThreshold": 0
|
||||
},
|
||||
{},
|
||||
{}
|
||||
]
|
||||
}
|
||||
1
assets/Materials/YellowPulseMaterial.mtl.meta
Normal file
1
assets/Materials/YellowPulseMaterial.mtl.meta
Normal file
@ -0,0 +1 @@
|
||||
{"ver":"1.0.21","importer":"material","imported":true,"uuid":"0bcb63aa-853b-43e8-a566-63acb47efa8d","files":[".json"],"subMetas":{},"userData":{}}
|
||||
@ -63,7 +63,7 @@ export class ModelSelector extends Component {
|
||||
const hitNode = results[0].collider.node;
|
||||
console.log(`🎯 Попадание по объекту: ${hitNode.name}`);
|
||||
|
||||
this._highlightModel(hitNode);
|
||||
this._highlightModel(hitNode , "red");
|
||||
this._moveCamera(hitNode); // 🔥 Вызываем камеру!
|
||||
} else {
|
||||
console.log('❌ Raycast ничего не нашел.');
|
||||
@ -73,16 +73,17 @@ export class ModelSelector extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
private _highlightModel(model: Node) {
|
||||
private _highlightModel(model: Node, color: string) {
|
||||
const switcher = model.getComponent(PulsatingHighlighter);
|
||||
if (switcher) {
|
||||
switcher.switchToRed();
|
||||
switcher.switchToColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
private _moveCamera(model: Node) {
|
||||
|
||||
private _moveCamera(model: Node ) {
|
||||
if (this.cameraMover) {
|
||||
this.cameraMover.moveToTarget(model);
|
||||
|
||||
} else {
|
||||
console.warn('🚨 CameraMover не подключен!');
|
||||
}
|
||||
|
||||
@ -4,91 +4,101 @@ const { ccclass, property } = _decorator;
|
||||
@ccclass('PulsatingHighlighter')
|
||||
export class PulsatingHighlighter extends Component {
|
||||
|
||||
@property(Material)
|
||||
redMaterial: Material = null!;
|
||||
|
||||
private _originalMaterials: Material[] = [];
|
||||
private _currentAlpha = 0;
|
||||
private _direction = 1;
|
||||
private _animationSpeed = 3; // Скорость изменения альфа-канала
|
||||
|
||||
onLoad() {
|
||||
this._storeOriginalMaterials();
|
||||
}
|
||||
|
||||
private _storeOriginalMaterials() {
|
||||
const renderer = this.node.getComponent(MeshRenderer);
|
||||
if (!renderer) return;
|
||||
|
||||
this._originalMaterials = renderer.materials
|
||||
.filter((m): m is Material => !!m)
|
||||
.map(m => {
|
||||
const newMat = new Material();
|
||||
newMat.copy(m);
|
||||
return newMat;
|
||||
});
|
||||
}
|
||||
|
||||
public switchToRed() {
|
||||
const renderer = this.node.getComponent(MeshRenderer);
|
||||
if (!renderer || !this.redMaterial) return;
|
||||
|
||||
// Создаем и настраиваем материал
|
||||
const redMat = new Material();
|
||||
redMat.copy(this.redMaterial);
|
||||
redMat.initialize({
|
||||
effectName: 'builtin-unlit',
|
||||
defines: { USE_TRANSPARENT: true }
|
||||
@property(Material)
|
||||
redMaterial: Material = null!;
|
||||
|
||||
@property(Material)
|
||||
yellowMaterial: Material = null!; // Новый желтый материал
|
||||
|
||||
private _originalMaterials: Material[] = [];
|
||||
private _currentAlpha = 0;
|
||||
private _direction = 1;
|
||||
private _animationSpeed = 3; // Скорость изменения альфа-канала
|
||||
|
||||
onLoad() {
|
||||
this._storeOriginalMaterials();
|
||||
}
|
||||
|
||||
private _storeOriginalMaterials() {
|
||||
const renderer = this.node.getComponent(MeshRenderer);
|
||||
if (!renderer) return;
|
||||
|
||||
this._originalMaterials = renderer.materials
|
||||
.filter((m): m is Material => !!m)
|
||||
.map(m => {
|
||||
const newMat = new Material();
|
||||
newMat.copy(m);
|
||||
return newMat;
|
||||
});
|
||||
redMat.setProperty('mainColor', new Color(255, 0, 0, 0));
|
||||
|
||||
renderer.materials = renderer.materials.map(() => redMat);
|
||||
|
||||
// Запускаем анимацию
|
||||
this._currentAlpha = 0;
|
||||
this._direction = 1;
|
||||
this.schedule(this._updateAlpha, 0.016);
|
||||
|
||||
// Возвращаем оригинал через 3 секунды
|
||||
this.scheduleOnce(() => {
|
||||
this._restoreOriginalMaterials();
|
||||
this.unschedule(this._updateAlpha);
|
||||
}, 10);
|
||||
}
|
||||
|
||||
public switchToColor(color: string) {
|
||||
const renderer = this.node.getComponent(MeshRenderer);
|
||||
if (!renderer) return;
|
||||
|
||||
let selectedMaterial: Material | null = null;
|
||||
|
||||
// Выбираем нужный материал
|
||||
if (color === 'red' && this.redMaterial) {
|
||||
selectedMaterial = this.redMaterial;
|
||||
} else if (color === 'yellow' && this.yellowMaterial) {
|
||||
selectedMaterial = this.yellowMaterial;
|
||||
} else {
|
||||
console.warn(`⚠️ Неизвестный цвет "${color}", используем оригинальный.`);
|
||||
return;
|
||||
}
|
||||
|
||||
private _updateAlpha() {
|
||||
this._currentAlpha += this._direction * this._animationSpeed;
|
||||
|
||||
// Ограничиваем значение между 0 и 255
|
||||
this._currentAlpha = math.clamp(this._currentAlpha, 0, 255);
|
||||
|
||||
// Меняем направление
|
||||
if (this._currentAlpha === 255 || this._currentAlpha === 0) {
|
||||
this._direction *= -1;
|
||||
}
|
||||
|
||||
const renderer = this.node.getComponent(MeshRenderer);
|
||||
if (renderer) {
|
||||
renderer.materials.forEach(mat => {
|
||||
const color = mat?.getProperty('mainColor') as Color;
|
||||
color.a = this._currentAlpha;
|
||||
mat?.setProperty('mainColor', color);
|
||||
});
|
||||
}
|
||||
|
||||
// Создаем и настраиваем материал
|
||||
const highlightMat = new Material();
|
||||
highlightMat.copy(selectedMaterial);
|
||||
|
||||
|
||||
|
||||
renderer.materials = renderer.materials.map(() => highlightMat);
|
||||
|
||||
// Запускаем анимацию
|
||||
this._currentAlpha = 0;
|
||||
this._direction = 1;
|
||||
this.schedule(this._updateAlpha, 0.016);
|
||||
|
||||
// Возвращаем оригинал через 10 секунд
|
||||
this.scheduleOnce(() => {
|
||||
this._restoreOriginalMaterials();
|
||||
this.unschedule(this._updateAlpha);
|
||||
}, 10);
|
||||
}
|
||||
|
||||
private _updateAlpha() {
|
||||
this._currentAlpha += this._direction * this._animationSpeed;
|
||||
|
||||
this._currentAlpha = math.clamp(this._currentAlpha, 0, 255);
|
||||
|
||||
if (this._currentAlpha === 255 || this._currentAlpha === 0) {
|
||||
this._direction *= -1;
|
||||
}
|
||||
|
||||
private _restoreOriginalMaterials() {
|
||||
const renderer = this.node.getComponent(MeshRenderer);
|
||||
if (!renderer) return;
|
||||
|
||||
renderer.materials = this._originalMaterials.map(m => {
|
||||
const mat = new Material();
|
||||
mat.copy(m);
|
||||
return mat;
|
||||
|
||||
const renderer = this.node.getComponent(MeshRenderer);
|
||||
if (renderer) {
|
||||
renderer.materials.forEach(mat => {
|
||||
const color = mat?.getProperty('mainColor') as Color;
|
||||
color.a = this._currentAlpha;
|
||||
mat?.setProperty('mainColor', color);
|
||||
});
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this.unscheduleAllCallbacks();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _restoreOriginalMaterials() {
|
||||
const renderer = this.node.getComponent(MeshRenderer);
|
||||
if (!renderer) return;
|
||||
|
||||
renderer.materials = this._originalMaterials.map(m => {
|
||||
const mat = new Material();
|
||||
mat.copy(m);
|
||||
return mat;
|
||||
});
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this.unscheduleAllCallbacks();
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/panels.meta
Normal file
9
assets/panels.meta
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "27fede78-8816-4ed8-bd44-2efd9184fc5d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user