Ejemplo n.º 1
0
        protected override IPromise <string> OnCreate()
        {
            Promise <string> result = Promise <string> .Create();

            Type linkType = fieldInfo.GetChildValueType();

            if (fieldInfo != null)
            {
                LinkFilterAttribute filter = fieldInfo.GetCustomAttribute <LinkFilterAttribute>();
                if (filter != null)
                {
                    if (filter.interfaceType.IsInterface)
                    {
                        TypeSelectorWindow.Open(filter.interfaceType, "Choose implementation").Done(selectedType =>
                        {
                            result.Resolve(CreateAsset(selectedType, linkType, fieldInfo));
                        });
                    }
                    else
                    {
                        result.Resolve(CreateAsset(filter.interfaceType, linkType, fieldInfo));
                    }
                }
                else
                {
                    result.Resolve(CreateAsset(type, linkType, fieldInfo));
                }
            }
            else
            {
                result.Resolve(CreateAsset(type, linkType, fieldInfo));
            }

            return(result);
        }
Ejemplo n.º 2
0
        protected override void Reload()
        {
            assets.Clear();

#if USE_ADDRESSABLES
            if (fieldInfo.GetChildValueType().BaseType.Name.Contains("LinkToScriptable"))
            {
                assets.AddRange(AddrHelper.GetScriptableObjectsWithInterface(type));
            }
            else
            {
                assets.AddRange(AddrHelper.GetPrefabsWithComponent(type));
            }
#else
            if (fieldInfo.GetChildValueType().BaseType.Name.Contains("LinkToScriptable"))
            {
                assets.AddRange(ResourcesAssetHelper.GetScriptableObjectsWithInterface(type));
            }
            else
            {
                assets.AddRange(ResourcesAssetHelper.GetPrefabsWithComponent(type));
            }
#endif

            if (fieldInfo != null)
            {
                LinkFilterAttribute interfaceFilter = fieldInfo.GetCustomAttribute <LinkFilterAttribute>();

                if (interfaceFilter != null)
                {
                    assets.RemoveAll(t =>
                    {
                        GameObject go = AssetDatabase.LoadAssetAtPath <GameObject>(t.AssetPath);
                        return(go.GetComponent(interfaceFilter.interfaceType) == null);
                    });
                }

                LinkTypeFilterAttribute typeFilter = fieldInfo.GetCustomAttribute <LinkTypeFilterAttribute>();

                if (typeFilter != null)
                {
                    assets.RemoveAll(t =>
                    {
                        GameObject go = AssetDatabase.LoadAssetAtPath <GameObject>(t.AssetPath);
                        return(go.GetComponent(typeFilter.type) != null);
                    });
                }
            }
        }
Ejemplo n.º 3
0
        protected override void Reload()
        {
            assets.Clear();


#if USE_ADDRESSABLES
            assets.AddRange(AddrHelper.GetAssets(type));
#else
            assets.AddRange(ResourcesAssetHelper.GetAssets(type));
#endif

            if (fieldInfo != null)
            {
                LinkFilterAttribute interfaceFilter = fieldInfo.GetCustomAttribute <LinkFilterAttribute>();

                if (interfaceFilter != null)
                {
                    assets.RemoveAll(t =>
                    {
                        Object asset = AssetDatabase.LoadAssetAtPath(t.AssetPath, typeof(Object));

                        if (type == typeof(MonoBehaviour))
                        {
                            return(((GameObject)asset).GetComponent(interfaceFilter.interfaceType) == null);
                        }

                        return(interfaceFilter.interfaceType.IsInstanceOfType(asset) == false);
                    });
                }

                LinkTypeFilterAttribute typeFilter = fieldInfo.GetCustomAttribute <LinkTypeFilterAttribute>();

                if (typeFilter != null)
                {
                    assets.RemoveAll(t =>
                    {
                        Object asset = AssetDatabase.LoadAssetAtPath(t.AssetPath, typeof(Object));
                        return(asset.GetType() != typeFilter.type);
                    });
                }
            }
        }