96SEO 2026-02-20 08:56 9
可以在不增加场景中对象数量的情况下,管理和存储复杂的数据结构、配置信息、游戏状态等。

2、作用:用于存储大量数据,而不必依附于游戏场景中的某个GameObject。
可以在不增加场景中对象数量的情况下,管理和存储复杂的数据结构、配置信息、游戏状态等。
4、适用:非常适合用来管理游戏中的各种数据,如角色属性、关卡配置、道具列表等。
使数据的管理更加集中和高效,避免将大量数据直接硬编码在脚本中或在多个GameObject上重复配置相同的数据。
还可以用于实现游戏数据的序列化,方便在游戏运行时保存和加载游戏状态。
创建一个ScriptableObject.cs,名字自取,例如
UnityEngine;[CreateAssetMenu(fileName
1、在Unity编辑器中通过CreateAssetMenu定义的菜单项创建ScriptableObject实例
2、在其他脚本中,通过Resources.LoadT()或其他方式加载这个ScriptableObject实例,并使用它的属性,例如
Resources.LoadItem("Path/To/Your/Item");
1、食谱名称和食谱成分:在Scripts/ScriptableObject文件夹下,新建RecipeSO.cs
2、在ScriptableObjects文件夹下,新建RecipeSO文件夹
3、复制Burger,重命名为Cheeseburger,更改名称、添加CheeseSlicesSO(如上图)
4、同样的方法制作RecipeSO对象:MEGAburger、Salad
(1)在Scripts/ScriptableObjects中新建RecipeListSO.cs
创建RecipeListSO对象,命名为_RecipeListSO,设置菜单
Empty,命名为DeliveryManager,Reset它的Transform
2、随机订单:为DeliveryManager添加DeliveryManager.cs
当倒计时结束时,将spawnRecipeTimer重置为spawnRecipeTimeMaxspawnRecipeTimer
recipeListSO.recipeSOList[Random.Range(0,
recipeListSO.recipeSOList.Count)];//
在控制台打印出所选食谱的名称Debug.Log(waitingRecipeSO.recipeName);waitingRecipeSOList.Add(waitingRecipeSO);}}}
recipeListSO.recipeSOList[Random.Range(0,
recipeListSO.recipeSOList.Count)];Debug.Log(waitingRecipeSO.recipeName);waitingRecipeSOList.Add(waitingRecipeSO);}}}//
DeliverRecipe(PlateKitchenObject
(waitingRecipeSO.kitchenObjectSOList.Count
plateKitchenObject.GetKitchenObjectsSOList().Count){//
waitingRecipeSO.kitchenObjectSOList){//
初始化一个标志,用于表示是否在当前盘子上找到了食谱中的食材bool
plateKitchenObject.GetKitchenObjectsSOList()){//
设置标志为true,表示找到了食材ingredientFound
设置盘子与食谱不匹配的标志plateContentsMatchesRecipe
(plateContentsMatchesRecipe){//
在控制台打印消息表示玩家提交了正确的食谱Debug.Log("Player
从订单列表中移除这个食谱waitingRecipeSOList.RemoveAt(i);//
recipe在控制台打印消息表示玩家没有提交正确的食谱Debug.Log("Player
false;if(a){Debug.Log("如果a为true,则输出文字。
");}//这段代码不会被执行,因为不符合条件
false;if(!a){Debug.Log("如果!a为true,则输出文字。
");}//这段代码会被执行
(player.GetKitchenObject().TryGetPlate(out
PlatesDeliveryManager.Instance.DeliverRecipe(plateKitchenObject);player.GetKitchenObject().DestroySelf();}}}
设置结果:Canvas上的UI在游戏窗口宽度改变时不会改变,在高度改变时会等比例缩小,
设置目的:只关心UI的横向排布,而当纵向改变时该组件会自动缩放
设置面板:Alt+Stretch,Left、Top、Right、Bottom都为0。
(1)以DeliveryManagerUI为父物体,UI-Text(TMP),重命名为TitleText。
将锚点设置到左上角,Width和Hight都为0,Wrapping设为Disabled,
+选择左上角图标,设置Width和Height分别为250,100
字号为20,加粗,Width、Hight都为0,Wrapping设为Disabled,文本内容为Recipe,白色
7、显示订单图标:给DeliveryManagerUI添加DeliveryManagerUI.cs组件
Awake(){recipeTemplate.gameObject.SetActive(false);}private
continue;//立即结束当前循环迭代Destroy(child.gameObject);}//
DeliveryManager.Instance.GetOrdersList()){Transform
Instantiate(recipeTemplate,container);recipeTransform.gameObject.SetActive(true);}}
recipeListSO.recipeSOList[UnityEngine.Random.Range(0,
recipeListSO.recipeSOList.Count)];waitingRecipeSOList.Add(waitingRecipeSO);OnRecipeSpawned?.Invoke(this,EventArgs.Empty);}}}public
DeliverRecipe(PlateKitchenObject
(waitingRecipeSO.kitchenObjectSOList.Count
plateKitchenObject.GetKitchenObjectsSOList().Count){//
waitingRecipeSO.kitchenObjectSOList){//
plateKitchenObject.GetKitchenObjectsSOList()){//
plateplateContentsMatchesRecipe
(plateContentsMatchesRecipe){//
recipe!waitingRecipeSOList.RemoveAt(i);OnRecipeCompleted?.Invoke(this,EventArgs.Empty);return;}}}}public
GetWaitingRecipeSOList(){return
订阅事件和事件处理程序:编辑DeliveryManagerUI.cs
Awake(){recipeTemplate.gameObject.SetActive(false);}private
Start(){DeliveryManager.Instance.OnRecipeSpawned
DeliveryManager_OnRecipeSpawned;DeliveryManager.Instance.OnRecipeCompleted
DeliveryManager_OnRecipeCompleted;UpdateVisul();}private
DeliveryManager_OnRecipeCompleted(object
DeliveryManager_OnRecipeSpawned(object
continue;Destroy(child.gameObject);}foreach
DeliveryManager.Instance.GetWaitingRecipeSOList()){Transform
(recipeTemplate,container);recipeTransform.gameObject.SetActive(true);}}
10、组织脚本文件夹:在Scripts文件夹下新建文件夹,命名为UI
11、显示订单内容:编辑DeliveryManagerUI.cs
continue;Destroy(child.gameObject);}foreach
DeliveryManager.Instance.GetWaitingRecipeSOList()){Transform
(recipeTemplate,container);recipeTransform.gameObject.SetActive(true);recipeTransform.GetComponentDeliveryManagerSingleUI().SetRecipeSO(recipeSO);}
Image,命名为IconTemplate,Width和Height都为40、
(5)显示订单图标:编辑DeliveryManagerSingleUI.cs
recipeNameText;[SerializeField]
Awake(){iconTemplate.gameObject.SetActive(false);}public
continue;Destroy(child.gameObject);}foreach
recipeSO.kitchenObjectSOList){Transform
iconContainer);iconTransform.gameObject.SetActive(true);iconTransform.GetComponentImage().sprite
在Scripts/ScripatableObjects文件夹下新建AudioClipRefsSO.cs
在ScriptableObjects文件夹,制作AudioClipRefsSO对象,命名为AudioClipRefsSO
2、在DeliveryManager.cs中,声明两个EventHandler委托事件
recipeListSO.recipeSOList[UnityEngine.Random.Range(0,
recipeListSO.recipeSOList.Count)];waitingRecipeSOList.Add(waitingRecipeSO);OnRecipeSpawned?.Invoke(this,EventArgs.Empty);}}}public
DeliverRecipe(PlateKitchenObject
(waitingRecipeSO.kitchenObjectSOList.Count
plateKitchenObject.GetKitchenObjectsSOList().Count){//
waitingRecipeSO.kitchenObjectSOList){//
plateKitchenObject.GetKitchenObjectsSOList()){//
plateplateContentsMatchesRecipe
(plateContentsMatchesRecipe){//
recipe!waitingRecipeSOList.RemoveAt(i);OnRecipeCompleted?.Invoke(this,EventArgs.Empty);//
触发成功事件OnRecipeSuccess?.Invoke(this,EventArgs.Empty);return;}}}//
触发失败事件OnRecipeFailed?.Invoke(this,EventArgs.Empty);}public
GetWaitingRecipeSOList(){return
4、为SoundManager添加SoundManager.cs
Start(){DeliveryManager.Instance.OnRecipeSuccess
DeliveryManager_OnRecipeSuccess;DeliveryManager.Instance.OnRecipeFailed
DeliveryManager_OnRecipeFailed;}private
DeliveryManager_OnRecipeFailed(object
e){PlaySound(audioClipRefsSO.deliveryFail,Camera.main.transform.position);}private
DeliveryManager_OnRecipeSuccess(object
e){PlaySound(audioClipRefsSO.deliverySuccess,
Camera.main.transform.position);}private
1f){PlaySound(audioClipArray[Random.Range(0,audioClipArray.Length)],position,volume);}private
1f){AudioSource.PlayClipAtPoint(audioClip,position,volume);}
(player.GetKitchenObject().TryGetPlate(out
PlatesDeliveryManager.Instance.DeliverRecipe(plateKitchenObject);player.GetKitchenObject().DestroySelf();}}}
Start(){DeliveryManager.Instance.OnRecipeSuccess
DeliveryManager_OnRecipeSuccess;DeliveryManager.Instance.OnRecipeFailed
DeliveryManager_OnRecipeFailed;}private
DeliveryManager_OnRecipeFailed(object
DeliveryCounter.Instance;PlaySound(audioClipRefsSO.deliveryFail,
deliveryCounter.transform.position);}private
DeliveryManager_OnRecipeSuccess(object
DeliveryCounter.Instance;PlaySound(audioClipRefsSO.deliverySuccess,
deliveryCounter.transform.position);}private
1f){PlaySound(audioClipArray[Random.Range(0,audioClipArray.Length)],position,volume);}private
1f){AudioSource.PlayClipAtPoint(audioClip,position,volume);}}
1、声明、触发委托(按F时播放音效):编辑CuttingCounter.cs
场景存在多个处理台,不能用配送台的单例模式。
所以使用静态委托:
以便使多个CuttingCounter实例能够共享同一个事件响应逻辑(共享OnAnyCut事件)
HasRecipeWithInput(GetKitchenObject().GetKitchenObjectSO())){cuttingProgress++;Oncut?.Invoke(this,
EventArgs.Empty);OnAnyCut?.Invoke(this,
UnityEngine.EventSystems;public
EventHandlerIHasProgress.OnprogressChangedEventArgs
(HasRecipeWithInput(player.GetKitchenObject().GetKitchenObjectSO())){//
cutplayer.GetKitchenObject().SetKitchenObjectParent(this);cuttingProgress
GetCuttingRecipeSOWithInput(GetKitchenObject().GetKitchenObjectSO());OnProgressChanged?.Invoke(this,
IHasProgress.OnprogressChangedEventArgs{progressNormalized
cuttingRecipeSO.cuttingProgressMax});}}else{//
(player.GetKitchenObject().TryGetPlate(out
(plateKitchenObject.TryAddIngredient(GetKitchenObject().GetKitchenObjectSO())){GetKitchenObject().DestroySelf();}}}else{//
anythingGetKitchenObject().SetKitchenObjectParent(player);}}}public
HasRecipeWithInput(GetKitchenObject().GetKitchenObjectSO())){//
cutcuttingProgress++;Oncut?.Invoke(this,
EventArgs.Empty);OnAnyCut?.Invoke(this,
EventArgs.Empty);CuttingRecipeSO
GetCuttingRecipeSOWithInput(GetKitchenObject().GetKitchenObjectSO());OnProgressChanged?.Invoke(this,
IHasProgress.OnprogressChangedEventArgs
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback