예제 #1
0
        /// <summary>
        /// Returns the path to the given resource, if there is such a path.
        /// The path leads to the unity-compiled 'Resources' directory.
        /// </summary>
        /// <param name="resource"></param>
        /// <returns></returns>
        public string GetPathToResource(UnityEngine.Object resource)
        {
            Type resType = resource.GetType();

            if (resType == null)
            {
                return(null);
            }

            //UnityEditor.Animations.AnimatorController
            //APPEND NEW TYPES HERE
            if (resType == typeof(AnimationClip))
            {
                return(AnimationClips.GetPath(resource));
            }
            else if (resType == typeof(RuntimeAnimatorController))
            {
                return(AnimatorControllers.GetPath(resource));
            }
            //*sigh* we need a special case here since the animator controllers we get
            //from AssetDatabase at edit-time aren't of the correct type.
            else if (resType.IsSubclassOf(typeof(RuntimeAnimatorController)))
            {
                return(AnimatorControllers.GetPath(resource));
            }
            else if (resType == typeof(AudioClip))
            {
                return(AudioClips.GetPath(resource));
            }
            else if (resType == typeof(Material))
            {
                return(Materials.GetPath(resource));
            }
            else if (resType == typeof(Mesh))
            {
                return(Meshes.GetPath(resource));
            }
            else if (resType == typeof(Font))
            {
                return(Fonts.GetPath(resource));
            }
            else if (resType == typeof(GameObject))
            {
                return(GameObjects.GetPath(resource));
            }
            else if (resType == typeof(PhysicMaterial))
            {
                return(PhysicMaterials.GetPath(resource));
            }
            else if (resType == typeof(PhysicsMaterial2D))
            {
                return(PhysicsMaterial2Ds.GetPath(resource));
            }
            else if (resType == typeof(Shader))
            {
                return(Shaders.GetPath(resource));
            }
            else if (resType == typeof(Sprite))
            {
                return(Sprites.GetPath(resource));
            }
            else if (resType == typeof(Texture2D))
            {
                return(Texture2Ds.GetPath(resource));
            }
            else if (resType == typeof(Texture3D))
            {
                return(Texture3Ds.GetPath(resource));
            }
            return(null);
        }