コード例 #1
0
    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        IAssetReferencer referencer = GetSaveableReferencer();

        assetName = referencer?.AssetName;
        relativePathFromResource = referencer?.RelativePathFromResource;
        assetExtension           = referencer?.AssetExtension;
        info.AddValue(nameof(assetName), assetName);
        info.AddValue(nameof(relativePathFromResource), relativePathFromResource);
        info.AddValue(nameof(assetExtension), assetExtension);
    }
コード例 #2
0
    /// <summary>
    /// returns the prefab in the resource folder with the given name
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    private GameObject getPrefabFromName(IAssetReferencer prefabRef)
    {
        string prefabPath = prefabRef.RelativePathFromResource;
        string name       = prefabRef.AssetName;

        if (prefabPath != "" && prefabPath[prefabPath.Length - 1] != '/')
        {
            prefabPath += "/";
        }

        GameObject result = Resources.Load <GameObject>(prefabPath + name);

        return(result);
    }
コード例 #3
0
    private static void checkAsset <T>(string currentPath, T assetRef, System.Func <T, string> getName, System.Action <T, string> onCheckDone = null) where T : Object, IAssetRefMaintainer
    {
        string newRelativeAssetPath;

        assetRef.GetInitializer().InitializeAsset(assetRef);
        IAssetReferencer r = assetRef.GetReferencer();

        r.AssetExtension = Path.GetExtension(currentPath).Remove(0, 1);
        ///check if the prefab is already in the correct directory
        if (currentPath.IndexOf(RelativeResourceFolderPath) != 0)
        {
            newRelativeAssetPath = currentPath.Insert
                                       (currentPath.IndexOf("/"), "/" + RESOURCE_FOLDER_NAME + "/" + r.AssetExtension);
        }
        else
        {
            newRelativeAssetPath = currentPath;
        }

        string newRelativePrefabDirectory = newRelativeAssetPath.Substring(0, newRelativeAssetPath.LastIndexOf('/'));
        string assetMoveErrorMessage      = null;

        ///only move the asset when its not already located in the resourceFolder
        if (currentPath.IndexOf(RelativeResourceFolderPath) != 0)
        {
            FolderSystem.createAssetPath(newRelativePrefabDirectory.Split('/'));
            assetMoveErrorMessage = AssetDatabase.MoveAsset(currentPath, newRelativeAssetPath);
        }

        if (string.IsNullOrEmpty(assetMoveErrorMessage))
        {
            r.AssetName = getName(assetRef);
            string pathFromAssetFolder = newRelativePrefabDirectory.Remove(0, RelativeResourceFolderPath.Length + 1);
            r.WasAlreadyValidated      = true;
            r.RelativePathFromResource = pathFromAssetFolder;
            onCheckDone?.Invoke(assetRef, newRelativeAssetPath);
        }
        else
        {
            Debug.LogError("Asset couldnt be moved to path: " + newRelativePrefabDirectory + ". Error: " + assetMoveErrorMessage);
        }
    }