Exemple #1
0
        /// <summary>
        /// try to find a given type. If not found, try to search in project,
        /// and select the [index] in the array of items found
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="found"></param>
        /// <param name="pathWhereToSearch"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static T GetLastObjectOfThisTypeOrFindItByIndexInAsset <T>(ref UnityEngine.Object found, string pathWhereToSearch = "Assets/", int index = 0) where T : UnityEngine.Object
        {
            bool hasFound = PeekLogic.GetLastObjectOfThisType <T>(ref found);

            if (hasFound)
            {
                return(found as T);
            }
            else
            {
                List <T> elements = ExtFindEditor.GetAssetsByGenericType <T>(pathWhereToSearch);
                if (elements.Count == 0)
                {
                    return(null);
                }
                if (index < 0)
                {
                    return(elements[0]);
                }
                if (index >= elements.Count)
                {
                    return(elements[elements.Count - 1]);
                }
                return(elements[index]);
            }
        }
Exemple #2
0
        /// <summary>
        /// Useful to search a given scriptableObject
        /// Find the last object of the given type in the project
        /// (if this type has never been selected, search in project)
        /// usage:
        /// UnityEngine.Object found = null;
        /// PeekLogic.GetLastObjectOfThisTypeOrFindItInAsset<YourScriptType>(ref found, "Assets/");
        /// </summary>
        /// <typeparam name="T">type of asset to search</typeparam>
        /// <param name="found"></param>
        /// <param name="pathWhereToSearch"></param>
        /// <returns></returns>
        public static T GetLastObjectOfThisTypeOrFindItInAsset <T>(ref UnityEngine.Object found, string pathWhereToSearch = "Assets/") where T : UnityEngine.Object
        {
            T    element;
            bool hasFound = PeekLogic.GetLastObjectOfThisType <T>(ref found);

            if (hasFound)
            {
                return(found as T);
            }
            else
            {
                element = ExtFindEditor.GetAssetByGenericType <T>(pathWhereToSearch);
                return(element);
            }
        }