Notifications
Article
Odin Inspector 系列教程 --- Assets Only Attribute
Updated 5 months ago
85
0
Odin Inspector 系列教程 --- Assets Only Attribute
Assets Only Attribute特性有两类
  • AssetsOnly: 点击需要序列化的资源字段时,在出现的弹窗中只有Project中的资源文件,不会出现Hierachy(场景)的资源
  • SceneObjectsOnly: 点击需要序列化的资源字段时,在出现的弹窗中只有Hierachy中的资源文件,不会出现Project中的资源
注意:例如:预制体等资源在Scene或者Project中都含有,出现的弹窗中也都会含有对应的资源

选中场景中的资源

[SceneObjectsOnly] public List<GameObject> onlySceneObjectList; [SceneObjectsOnly] public GameObject someSceneObject; [SceneObjectsOnly] public MeshRenderer someMeshRendererInScene;

选中工程中的资源

[AssetsOnly] public List<GameObject> assetsOnlyPrefabList; [AssetsOnly] public GameObject ssetsOnlyPrefab; [AssetsOnly] public Material assetsOnlyMaterial; [AssetsOnly] public MeshRenderer someMeshRendererOnPrefab;

完整示例代码

using Sirenix.OdinInspector; using System.Collections; using System.Collections.Generic; using UnityEngine; public class AssetsOnlyExample : MonoBehaviour { [AssetsOnly] public List<GameObject> OnlyPrefabs; [AssetsOnly] public GameObject SomePrefab; [AssetsOnly] public Material MaterialAsset; [AssetsOnly] public MeshRenderer SomeMeshRendererOnPrefab; [SceneObjectsOnly] public List<GameObject> OnlySceneObjects; [SceneObjectsOnly] public GameObject SomeSceneObject; [SceneObjectsOnly] public MeshRenderer SomeMeshRenderer; }

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

海澜
低端打杂人员 - Programmer
18
Comments