当前位置: 首页 > news >正文

Unity3D仿星露谷物语开发47之砍树时落叶特效

1、目标

当橡树被砍伐时的落叶粒子效果。

2、创建粒子物体

Hierarchy -> PersistentScene下创建新物体命名为DeciduousLeavesFalling。

添加Particle System组件。

基础配置如下:(暂时勾选Looping实时可以看生成效果,后面反选即可)

配置Emission和Shape信息如下:

配置Color over Lifetime:

配置Size over Lifetime / Rotation over Lifetime / Noise 信息如下:

配置Texture / Renderer 信息如下:

将DeciduousLeavesFalling移到Assets -> Prefabs -> Crop -> Effect下

3、修改Crop.cs脚本

[Tooltip("This should be populated from child transform gameobject showing harvest effect spawn point")]
[SerializeField] private Transform harvestActionEffectTransform = null;

在ProcessToolAction函数中添加:

完整代码为:

public void ProcessToolAction(ItemDetails equippedItemDetails, bool isToolRight, bool isToolLeft, bool isToolDown, bool isToolUp)
{// Get grid property detailsGridPropertyDetails gridPropertyDetails = GridPropertiesManager.Instance.GetGridPropertyDetails(cropGridPosition.x, cropGridPosition.y);if (gridPropertyDetails == null)return;// Get seed item detailsItemDetails seedItemDetails = InventoryManager.Instance.GetItemDetails(gridPropertyDetails.seedItemCode);if(seedItemDetails == null) return;// Get crop detailsCropDetails cropDetails = GridPropertiesManager.Instance.GetCropDetails(seedItemDetails.itemCode);if (cropDetails == null) return;// Get animator for crop if presentAnimator animator = GetComponentInChildren<Animator>();// Trigger tool animationif(animator != null){if(isToolRight || isToolUp){animator.SetTrigger("usetoolright");}else if(isToolLeft || isToolDown){animator.SetTrigger("usetoolleft");}}// Trigger tool particle effect on cropif (cropDetails.isHarvestActionEffect){EventHandler.CallHarvestActionEffectEvent(harvestActionEffectTransform.position, cropDetails.harvestActionEffect);}// Get required harvest actions for tool(收获此农作物所需的操作次数)int requiredHarvestActions = cropDetails.RequiredHarvestActionsForTool(equippedItemDetails.itemCode);if (requiredHarvestActions == -1) return;// Increment harvest action countharvestActionCount++;// Check if required harvest actions madeif (harvestActionCount >= requiredHarvestActions)HarvestCrop(isToolRight, isToolUp, cropDetails, gridPropertyDetails, animator);}

4、修改CropTreeCanyonOak预设体

在CropSprite下新增一个物体命名为LeavesSpawnPoint,这个作为特效的参考点,修改其Position(Y)为4。

接着点击CropTreeCanyonOak进行变量赋值。

5、修改PoolManager对象

6、修改VFXManager.cs脚本及配置

添加定义:

 [SerializeField] private GameObject deciduousLeavesFallingPrefab = null;

在displayHarvestActionEffect中添加case信息如下:

case HarvestActionEffect.deciduousLeavesFalling:GameObject deciduousLeavesFalling = PoolManager.Instance.ReuseObject(deciduousLeavesFallingPrefab, effectPosition, Quaternion.identity);deciduousLeavesFalling.SetActive(true);StartCoroutine(DisableHarvestActionEffect(deciduousLeavesFalling, twoSeconds));break;

完整的代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class VFXManager : SingletonMonobehaviour<VFXManager>
{private WaitForSeconds twoSeconds;[SerializeField] private GameObject reapingPrefab = null;[SerializeField] private GameObject deciduousLeavesFallingPrefab = null;protected override void Awake(){base.Awake();twoSeconds = new WaitForSeconds(2f);}private void OnDisable(){EventHandler.HarvestActionEffectEvent -= displayHarvestActionEffect;}private void OnEnable(){EventHandler.HarvestActionEffectEvent += displayHarvestActionEffect;}private IEnumerator DisableHarvestActionEffect(GameObject effectGameObject, WaitForSeconds secondsToWait){yield return secondsToWait;effectGameObject.SetActive(false);}private void displayHarvestActionEffect(Vector3 effectPosition, HarvestActionEffect harvestActionEffect){switch(harvestActionEffect){case HarvestActionEffect.deciduousLeavesFalling:GameObject deciduousLeavesFalling = PoolManager.Instance.ReuseObject(deciduousLeavesFallingPrefab, effectPosition, Quaternion.identity);deciduousLeavesFalling.SetActive(true);StartCoroutine(DisableHarvestActionEffect(deciduousLeavesFalling, twoSeconds));break;case HarvestActionEffect.reaping:GameObject reaping = PoolManager.Instance.ReuseObject(reapingPrefab, effectPosition, Quaternion.identity);reaping.SetActive(true); StartCoroutine(DisableHarvestActionEffect(reaping, twoSeconds));break;case HarvestActionEffect.none:break;default:break;}}
}

配置VFXManager的信息如下:

7、运行游戏

http://www.xdnf.cn/news/556957.html

相关文章:

  • Wan2.1 加速推理方法
  • 使用cursor自动生成前后端分离的web应用程序
  • ROS2 pkg 创建功能包
  • [ 计算机网络 ] 深入理解OSI七层模型
  • 经验过程简介与suprema的集中(Guntuboyina理论统计学笔记)
  • QT高DPI支持
  • linux之 pcie MSI-X中断编程
  • 自动化测试核心知识梳理与 Java 代码详解
  • 基于正点原子阿波罗F429开发板的LWIP应用(3)——Netbiosns功能
  • 嵌入式培训之系统编程(一)标准IO、文件操作
  • Liquid Wire 柔性应变传感器:金属凝胶导体 | 仿生肌肉长度监测 | 高精度动作控制
  • 特定领域 RAG中细调嵌入模型能否提升效果?
  • IVX:重构 AI 原生开发范式,让模型调用成为指尖艺术​
  • PostgreSQL简单使用
  • 深入浅出人工智能:机器学习、深度学习、强化学习原理详解与对比!
  • 【深度学习-Day 14】从零搭建你的第一个神经网络:多层感知器(MLP)详解
  • 第六天的尝试
  • 服务器部署1Panel
  • 證券行業證券交易系統開發方案
  • 基于SpringBoot+Vue的学籍管理系统的设计与实现
  • Kubernetes在线练习平台深度对比:KillerCoda与Play with Kubernetes
  • 【开源工具】文件夹结构映射工具 | PyQt5实现多模式目录复制详解
  • 【鸿蒙开发】Hi3861学习笔记- MQTT通信
  • 统一端点管理(UEM):定义、优势与重要性
  • 从零开始:Python 从0到1轻松入门
  • 易路 AI 招聘:RPA+AI 颠覆传统插件模式,全流程自动化实现效率跃迁
  • 物业收费智能化:如何实现账单零差错自动生成?
  • SpringBean模块(三)具有生命周期管理能力的类(1)AutowireCapableBeanFactory
  • DOS常用命令及dos运行java
  • 协程+Flow:现代异步编程范式,替代RxJava的完整实践指南