protected virtual Type GetDrawerTypeForAssets([NotNull] Object[] assets, [CanBeNull] out Object[] assetImporters, [CanBeNull] out Type customEditorType)
        {
            assetImporters   = null;
            customEditorType = null;

            // handle mismatching types
            if (!assets.AllSameType())
            {
                return(typeof(MultipleAssetDrawer));
            }

            if (AssetImporters.TryGet(assets, ref assetImporters))
            {
                var assetImporterType = assetImporters[0].GetType();
                if (!CustomEditorUtility.TryGetCustomEditorType(assetImporterType, out customEditorType))
                {
                                        #if DEV_MODE
                    Debug.LogWarning("GetDrawerTypeForAssets(" + assets[0].GetType().Name + ") Setting assetImporters of type " + assetImporterType.Name + " to null because could not find CustomEditor type for them.");
                                        #endif

                    assetImporters = null;
                    CustomEditorUtility.TryGetCustomEditorType(assets[0].GetType(), out customEditorType);
                }
            }
            else
            {
                CustomEditorUtility.TryGetCustomEditorType(assets[0].GetType(), out customEditorType);
                                #if DEV_MODE && PI_ASSERTATIONS
                Debug.Assert(assetImporters == null);
                                #endif
            }

            return(GetDrawerTypeForAsset(assets[0]));
        }
Exemple #2
0
 /// <inheritdoc />
 protected override void Setup(Object[] setTargets, Object[] setEditorTargets, Type setEditorType, IParentDrawer setParent, IInspector setInspector)
 {
     if (setEditorTargets == null)
     {
         AssetImporters.TryGet(setTargets, ref setEditorTargets);
     }
     base.Setup(setTargets, setEditorTargets, setEditorType, setParent, setInspector);
 }
 /// <inheritdoc />
 protected override void Setup(Object[] setTargets, Object[] setEditorTargets, Type setEditorType, IParentDrawer setParent, IInspector setInspector)
 {
     if (setEditorTargets == null)
     {
         AssetImporters.TryGet(setTargets, ref setEditorTargets);
     }
     //#if UNITY_2018_2_OR_NEWER //not sure which version exactly prompted this change, so won't do branching
     base.Setup(setTargets, setEditorTargets, null, setParent, setInspector);
     //#else
     //base.Setup(setTargets, setEditorTargets, typeof(UnityEditorInternal.AssemblyDefinitionImporter), setParent, setInspector);
     //#endif
 }
Exemple #4
0
        /// <inheritdoc />
        protected override void Setup(Object[] setTargets, Object[] setEditorTargets, Type setEditorType, IParentDrawer setParent, IInspector setInspector)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            UnityEngine.Debug.Assert(AssetDatabase.IsMainAsset(setTargets[0]) || setTargets[0].GetType() == typeof(UnityEngine.AnimationClip), StringUtils.ToColorizedString("ModelGUI.Setup called with setTargets=", setTargets, ", setEditorType=", setEditorType, ", IsMainAsset=", false));
                        #endif

            if (setEditorTargets == null)
            {
                AssetImporters.TryGet(setTargets, ref setEditorTargets);
            }
            base.Setup(setTargets, setEditorTargets, setEditorType, setParent, setInspector);
        }
        /// <summary> Sets up an instance of the drawers for usage. </summary>
        /// <param name="setTargets"> The targets that the drawers represent. Can not be null. </param>
        /// <param name="setEditorTargets"> The targets for which the main Editor is created. E.g. the asset importers for targets. Can be null. </param>
        /// <param name="setParent"> The parent drawers of the created drawers. Can be null. </param>
        /// <param name="setInspector"> The inspector in which the IDrawer are contained. Can not be null. </param>
        /// <param name="setEditorType"> The type of the custom editor. Can be null. </param>
        protected virtual void Setup([NotNull] Object[] setTargets, [CanBeNull] Object[] setEditorTargets, [CanBeNull] Type setEditorType, [CanBeNull] IParentDrawer setParent, [NotNull] IInspector setInspector)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(setTargets.Length > 0);
                        #endif

            headerHeight           = DrawGUI.Active.AssetTitlebarHeight(false);
            headerHeightDetermined = false;

            allSameType = setTargets.AllSameType();

            if (setEditorTargets == null)
            {
                if (!allSameType)
                {
                    setEditorTargets = setTargets;
                }
                else
                {
                    if (AssetImporters.TryGet(setTargets, ref setEditorTargets))
                    {
                        var assetImporterType = setEditorTargets[0].GetType();
                        CustomEditorUtility.TryGetCustomEditorType(assetImporterType, out setEditorType);
                    }
                    else
                    {
                        setEditorTargets = setTargets;
                    }
                }
            }
            else if (setEditorTargets[0] == null)
            {
                ArrayPool <Object> .Dispose(ref setEditorTargets);

                setEditorTargets = setTargets;
            }

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(setEditorTargets != null || !allSameType);
            Debug.Assert(!allSameType || setEditorTargets.Length > 0);
                        #endif

            editorTargets = setEditorTargets;

            Sisus.AssetLabels.Get(setTargets, ref assetLabels, ref assetLabelsOnlyOnSomeTargets);
            Sisus.AssetLabels.OnAssetLabelsChanged += OnAssetLabelsChanged;

            var target = setTargets[0];
            localPath      = setTargets.Length == 1 ? AssetDatabase.GetAssetPath(target) : "";
            isPackageAsset = FileUtility.IsPackageAsset(localPath);

            // base handles calling UpdateEditor
            base.Setup(setTargets, setParent, setInspector, setEditorType);

            FetchAssetEditor();

                        #if DEV_MODE && PI_ASSERTATIONS && UNITY_2017_2_OR_NEWER
            if (!isAssetImporter && editor != HeaderEditor)
            {
                                #if DEV_MODE && DEBUG_SETUP_EDITOR
                Debug.LogError(Msg(ToString(), " non-asset importer editor did not match HeaderEditor! - targets=", StringUtils.TypesToString(setTargets), ", editorTargets=", StringUtils.TypesToString(setEditorTargets), ", editorType=", setEditorType, ", editor=", StringUtils.TypeToString(editor), ", HeaderEditor=", HeaderEditor));
                                #endif
            }
                        #endif

                        #if DEV_MODE && DEBUG_SETUP_EDITOR
            Debug.Log(Msg(ToString(), " Setup with targets=", StringUtils.TypesToString(setTargets), ", editorTargets=", StringUtils.TypesToString(setEditorTargets), ", editorType=", setEditorType, ", editor=", StringUtils.TypeToString(editor)));
                        #endif

                        #if DEV_MODE && PI_ASSERTATIONS
            if (editor == null)
            {
                Debug.LogWarning(Msg(ToString(), " editor was null after Setup with canHaveEditor=", canHaveEditor, " and targets: ", StringUtils.TypesToString(targets)));
            }
                        #endif

                        #if DEV_MODE && PI_ASSERTATIONS
            if (assetEditor == null)
            {
                Debug.LogWarning(Msg(ToString(), " headerEditor was null after Setup with canHaveEditor=", canHaveEditor, " and targets: ", StringUtils.TypesToString(targets)));
            }
                        #endif
        }