欢迎光临网站建设系统开发公司网站,优秀技术团队,诚心诚意为您服务

网站建设系统开发

cms企业网站建设系统,营销网站管理系统设计

Odin Inspector 系列教程 --- Odin工具箱【一键批量更改Raycast Target选项】

作者:jcmp      发布时间:2021-04-18      浏览量:0
一、打开Odin工具箱二、将需要处理的物

一、打开Odin工具箱

二、将需要处理的物体拖入即可

三、示例完整代码

using Sirenix.OdinInspector;using System.Collections.Generic;using UnityEditor;using UnityEngine;using UnityEngine.UI;[TypeInfoBox("批量选中或者取消对应UI上的Raycast")]public class OneKeyChangeRaycastTarget : SerializedScriptableObject{ private bool selectRaycastComplete; private bool cancelRaycastComplete; [PreviewField(50)] [OnValueChanged("SelectRaycastListValueChangeCallBack")] [HorizontalGroup("Raycast")] [PropertySpace(10, 10)] [BoxGroup("Raycast/Left", false)] [LabelText("需要选中Raycast拖入进来")] public List SelectRaycastList = new List(); public void SelectRaycastListValueChangeCallBack() { selectRaycastComplete = false; } [PreviewField(50)] [OnValueChanged("CancelRaycastListValueChangeCallBack")] [PropertySpace(10, 10)] [BoxGroup("Raycast/Right", false)] [LabelText("需要取消Raycast拖入进来")] public List CancelRaycastList = new List(); public void CancelRaycastListValueChangeCallBack() { cancelRaycastComplete = false; } [HideIf("@selectRaycastComplete==true||SelectRaycastList.Count==0")] [BoxGroup("Raycast/Left")] [Button("勾选所有射线检测", ButtonSizes.Large, ButtonStyle.FoldoutButton)] public void SelectRaycast() { for (int i = 0; i < SelectRaycastList.Count; i++) { if (SelectRaycastList[i] == null) { continue; } Graphic[] graphicArray = SelectRaycastList[i].GetComponentsInChildren(); for (int k = 0; k < graphicArray.Length; k++) { graphicArray[k].raycastTarget = true; EditorUtility.SetDirty(graphicArray[k]); } GameObject tempObject = SelectRaycastList[i]; bool isPrefabInstance = PrefabUtility.IsPartOfPrefabInstance(tempObject); bool isPrefabAsset = PrefabUtility.IsPartOfPrefabAsset(tempObject); if (isPrefabAsset) { PrefabUtility.SavePrefabAsset(SelectRaycastList[i]); } if (isPrefabInstance) { PrefabUtility.ApplyPrefabInstance(SelectRaycastList[i], InteractionMode.UserAction); } } selectRaycastComplete = true; AssetDatabase.Refresh(); } [HideIf("@cancelRaycastComplete==true||CancelRaycastList.Count==0")] [BoxGroup("Raycast/Right")] [Button("取消所有射线检测", ButtonSizes.Large, ButtonStyle.FoldoutButton)] public void CancelRaycast() { for (int i = 0; i < CancelRaycastList.Count; i++) { if (CancelRaycastList[i] == null) { continue; } Graphic[] graphicArray = CancelRaycastList[i].GetComponentsInChildren(); for (int k = 0; k < graphicArray.Length; k++) { graphicArray[k].raycastTarget = false; EditorUtility.SetDirty(graphicArray[k]); } GameObject tempObject = CancelRaycastList[i]; bool isPrefabInstance = PrefabUtility.IsPartOfPrefabInstance(tempObject); bool isPrefabAsset = PrefabUtility.IsPartOfPrefabAsset(tempObject); if (isPrefabAsset) { PrefabUtility.SavePrefabAsset(CancelRaycastList[i]); } if (isPrefabInstance) { PrefabUtility.ApplyPrefabInstance(CancelRaycastList[i], InteractionMode.UserAction); } } cancelRaycastComplete = true; AssetDatabase.Refresh(); }}

四、更多教程内容详见: 革命性Unity 编辑器扩展工具 --- Odin Inspector 系列教程。