Unity's Assetdatabase path format

Source: Internet
Author: User
Tags unity 5

Development Environment

Windows 7

Unity 5.3 and later

Objective

Use unity built-in editor such as assetdatabase.load or animatorcontroller.createanimatorcontrolleratpath API for file operations, often encountered loading resources are null, or reported that the path does not exist!

After debugging a breakpoint, it is found that most of the errors are due to the existence of two delimiters for the path: "/" and "\".

We use the System.IO.Path API to get the path, in fact, the "\" separated path.

We open the Explorer under Windows, the path to a directory or file is: E:\Code\GameFramework\ or \\192.168.80.100\XXX\

But using the Unity API, when printing Application.datapath, print out: E:/xxx/client/trunk/project/assets, so it's clear that its path and windows are reversed, So when we use a path that does not conform to Unity's specifications, it is often reported that the resource failed to load.

For example, an FBX path is: assets/art/characters/wing/fbx_3005/[email protected] , and if your input path or stitching path does not conform to the specification, it is very likely that the file will fail to load.

Normalize paths

Provides a way to format a path into Unity's readable path format:

/// <summary>    ///format the path into asset standard format/// </summary>    /// <param name= "FilePath" ></param>    /// <returns></returns>     Public Static stringFormatassetpath (stringFilePath) {        varNewFilePath1 = Filepath.replace ("\\","/"); varNewFilePath2 = Newfilepath1.replace ("//","/").        Trim (); NewFilePath2= Newfilepath2.replace ("///","/").        Trim (); NewFilePath2= Newfilepath2.replace ("\\\\","/").        Trim (); returnnewFilePath2; }

Unity's Assetdatabase path format

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.