//----------------------------------------------------------------------------

    private static void CreateDependencyAsset(PKFxFxAsset fxAsset, string dstPath, string dstFile, string srcFile)
    {
        //Case where PopedV1 keep shadow dependencies.
        if (!File.Exists(srcFile))
        {
            return;
        }

        bool fileExist = File.Exists(dstPath + dstFile);

        if (fileExist)
        {
            FileUtil.ReplaceFile(srcFile, dstPath + dstFile);
        }
        else
        {
            FileUtil.CopyFileOrDirectory(srcFile, dstPath + dstFile);
        }

        string keyPath = "Assets" + PKFxSettings.UnityPackFxPath + dstFile;
        int    key     = keyPath.ToLowerInvariant().GetHashCode();

        if (!PKFxManager.DependenciesLoading.ContainsKey(key))
        {
            PKFxManager.DependenciesLoading.Add(key, new List <PKFxFxAsset>());
            PKFxManager.DependenciesLoading[key].Add(fxAsset);
            AssetDatabase.ImportAsset(dstPath + dstFile, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);
        }
        else if (!PKFxManager.DependenciesLoading[key].Contains(fxAsset))
        {
            PKFxManager.DependenciesLoading[key].Add(fxAsset);
        }
        //AssetDatabase.ImportAsset(dstPath + dstFile, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);
    }
Пример #2
0
    //----------------------------------------------------------------------------

    #region PreloadEffect from asset

    public static void PreloadEffectFromAsset(PKFxFxAsset fxAsset)
    {
        PKFxManager.SetBuiltAsset(fxAsset);
        PKFxManager.PreloadEffectDependencies(fxAsset);
        PKFxManager.PreloadEffectIFN(fxAsset.m_AssetName, fxAsset.m_UsesMeshRenderer);
        PKFxManager.SetBuiltAsset(null);
    }
    //----------------------------------------------------------------------------

    private static void ImportAssetDependencies(PKFxFxAsset fxAsset)
    {
        foreach (PKFxFxAsset.DependencyDesc dependency in fxAsset.m_Dependencies)
        {
            dependency.m_Path = dependency.m_Path.Replace("\\", "/");
            string pkDependencyRelativePath = dependency.m_Path.Substring(PKFxSettings.UnityPackFxPath.Length);
            string sourceFile;

            CreateAssetFolderUpToPath(pkDependencyRelativePath);
            //Cases where we need originals assets without bake.
            if (dependency.m_IsTextureLinear)
            {
                sourceFile        = PKFxSettings.PopcornPackFxPath + pkDependencyRelativePath;
                dependency.m_Path = Path.GetDirectoryName(dependency.m_Path) + "/" + Path.GetFileNameWithoutExtension(dependency.m_Path) + "_linear" + Path.GetExtension(dependency.m_Path);
                CreateDependencyAsset(fxAsset, "Assets" + PKFxSettings.UnityPackFxPath, dependency.m_Path.Substring(PKFxSettings.UnityPackFxPath.Length), sourceFile);
            }
            else if (dependency.m_IsMeshRenderer)
            {
                sourceFile = PKFxSettings.PopcornPackFxPath + pkDependencyRelativePath;
                CreateDependencyAsset(fxAsset, "Assets" + PKFxSettings.UnityPackFxPath, pkDependencyRelativePath, sourceFile);
            }
            else            // if (dependency.m_IsMeshSampler)
            {
                sourceFile = "Temp/PopcornFx/Baked" + pkDependencyRelativePath;
                CreateDependencyAsset(fxAsset, "Assets" + PKFxSettings.UnityPackFxPath, pkDependencyRelativePath, sourceFile);
            }
        }
    }
Пример #4
0
 public PKFxAttributesContainer(PKFxFxAsset asset, int fxId)
 {
     m_WasModified      = false;
     m_FxAsset          = asset;
     m_FxGuid           = fxId;
     m_AttributesBuffer = PKFxManager.GetAttributesBuffer(fxId);
 }
Пример #5
0
    //----------------------------------------------------------------------------

    public static int CreateEffect(PKFxFxAsset fxAsset, Matrix4x4 m, bool autoDestroy)
    {
        PKFxManager.SetBuiltAsset(fxAsset);
        int res = CreateEffect(fxAsset.m_AssetName, m, fxAsset.m_UsesMeshRenderer, autoDestroy);

        PKFxManager.SetBuiltAsset(null);
        return(res);
    }
Пример #6
0
    public static int CreateEffect(PKFxFxAsset fxAsset, Transform t, bool autoDestroy)
    {
        PKFxManager.SetBuiltAsset(fxAsset);
        int res = CreateEffect(fxAsset.m_AssetName, t.localToWorldMatrix, fxAsset.m_UsesMeshRenderer, autoDestroy);

        PKFxManager.SetBuiltAsset(null);
        return(res);
    }
    //----------------------------------------------------------------------------

    public static bool UpdateAndRenamePKFXAsset(PKFxFxAsset fxAsset, string oldPath, string newPath)
    {
        fxAsset.m_AssetName = newPath;
        if (ProcessAssetChangeData(fxAsset, oldPath) == false)
        {
            return(false);
        }
        UpdateAssetDependency(fxAsset);
        return(true);
    }
Пример #8
0
    //----------------------------------------------------------------------------

    public static int CreateEffect(PKFxFxAsset fxAsset, Vector3 position, Quaternion rotation, Vector3 scale, bool autoDestroy)
    {
        PKFxManager.SetBuiltAsset(fxAsset);
        Matrix4x4 m = Matrix4x4.identity;

        m.SetTRS(position, rotation, scale);
        int res = CreateEffect(fxAsset.m_AssetName, m, fxAsset.m_UsesMeshRenderer, autoDestroy);

        PKFxManager.SetBuiltAsset(null);
        return(res);
    }
    //----------------------------------------------------------------------------

    public static bool UpdatePKFXAsset(PKFxFxAsset fxAsset, string path)
    {
        fxAsset.m_AssetName = path;
        if (ProcessAssetChangeData(fxAsset, path) == false)
        {
            return(false);
        }
        UpdateAssetDependency(fxAsset);
        EditorUtility.SetDirty(fxAsset);         // Seems like the asset is never serialized if we do not flag it dirty
        return(true);
    }
    //----------------------------------------------------------------------------

    private static void UpdateAssetDependency(PKFxFxAsset fxAsset)
    {
        foreach (var dependency in fxAsset.m_Dependencies)
        {
            string             path = "Assets" + dependency.m_Path;
            UnityEngine.Object obj  = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(path);
            if (obj)
            {
                dependency.m_Object = obj;
                ApplyPKImportSetting(dependency, path);
            }
        }
    }
    public static void OnAssetChange(ref SAssetChangesDesc assetChange)
    {
        PKFxManager.ImportedAssetName = Path.GetFileName(assetChange.m_Path);
        string relativepath = "Assets" + PKFxSettings.UnityPackFxPath;
        string assetPath    = assetChange.m_Path + ".asset";

        LockPackWatcherChanges();
        if (assetChange.m_Type == (int)EAssetChangesType.Add)
        {
            PKFxAssetCreationUtils.CreatePKFXAsset(assetChange);
        }
        else if (assetChange.m_Type == (int)EAssetChangesType.Remove)
        {
            AssetDatabase.DeleteAsset(Path.Combine(relativepath, assetPath));
        }
        else if (assetChange.m_Type == (int)EAssetChangesType.Update)
        {
            PKFxFxAsset fxAsset = (PKFxFxAsset)AssetDatabase.LoadAssetAtPath(Path.Combine(relativepath, assetPath), typeof(PKFxFxAsset));
            if (fxAsset != null)
            {
                fxAsset.Clean();
                fxAsset.m_Data = File.ReadAllBytes("Temp/PopcornFx/Baked/" + assetChange.m_Path);
                PKFxAssetCreationUtils.UpdatePKFXAsset(fxAsset, assetChange.m_Path);
            }
            else
            {
                PKFxAssetCreationUtils.CreatePKFXAsset(assetChange);
            }
        }
        else if (assetChange.m_Type == (int)EAssetChangesType.Rename)
        {
            AssetDatabase.RenameAsset(Path.Combine(relativepath, assetChange.m_PathOld + ".asset"), Path.GetFileName(assetChange.m_Path));
            PKFxFxAsset fxAsset = (PKFxFxAsset)AssetDatabase.LoadAssetAtPath(Path.Combine(relativepath, assetPath), typeof(PKFxFxAsset));

            if (fxAsset != null)
            {
                fxAsset.Clean();
                fxAsset.m_Data = File.ReadAllBytes("Temp/PopcornFx/Baked/" + assetChange.m_Path);
                PKFxAssetCreationUtils.UpdateAndRenamePKFXAsset(fxAsset, assetChange.m_PathOld, assetChange.m_Path);
            }
            else
            {
                PKFxAssetCreationUtils.CreatePKFXAsset(assetChange);
            }
        }
        UnlockPackWatcherChanges();
    }
    //----------------------------------------------------------------------------

    private static bool ProcessAssetChangeData(PKFxFxAsset fxAsset, string fxPathToPatch)
    {
        GCHandle handle         = GCHandle.Alloc(fxAsset.m_Data, GCHandleType.Pinned);
        IntPtr   fileContentPtr = handle.AddrOfPinnedObject();

        PKFxManager.SetImportedAsset(fxAsset);

        if (PKFxManager.BrowseEffectContent(fileContentPtr, fxAsset.m_Data.Length, "Temp/PopcornFx/Baked/" + fxAsset.m_AssetName) == false)
        {
            handle.Free();
            Debug.LogError("Reimport of " + fxAsset.m_AssetName + "failed");
            return(false);
        }

        fxAsset.ComputeAttributesAndSamplersHash();

        // Fix all references in the current scene:
        bool sceneHasChanged = false;

        UnityEngine.Object[] effects = UnityEngine.Object.FindObjectsOfType(typeof(PKFxFX));

        foreach (UnityEngine.Object obj in effects)
        {
            PKFxFX effect = obj as PKFxFX;

            if (effect.m_FxName == fxPathToPatch)             // Sometimes the effect.m_FxAsset is null here, so we test against the m_FxName
            {
                if (effect.UpdateEffectAsset(fxAsset, false, false))
                {
                    sceneHasChanged = true;
                }
            }
        }

        if (sceneHasChanged)
        {
            Scene currentScene = SceneManager.GetActiveScene();
            EditorSceneManager.MarkSceneDirty(currentScene);
        }

        PKFxManager.SetImportedAsset(null);
        handle.Free();

        ImportAssetDependencies(fxAsset);
        return(true);
    }
    //----------------------------------------------------------------------------

    private static bool ProcessAssetCreationData(PKFxManagerImpl.SAssetChangesDesc assetChange)
    {
        PKFxFxAsset fxAsset = ScriptableObject.CreateInstance <PKFxFxAsset>();

        if (fxAsset != null)
        {
            fxAsset.m_Data      = File.ReadAllBytes("Temp/PopcornFx/Baked/" + assetChange.m_Path);
            fxAsset.m_AssetName = assetChange.m_Path;
            if (ProcessAssetChangeData(fxAsset, assetChange.m_Path) == false)
            {
                return(false);
            }
            CreateAssetFolderUpToPath(assetChange.m_Path);
            AssetDatabase.CreateAsset(fxAsset, Path.Combine("Assets" + PKFxSettings.UnityPackFxPath, assetChange.m_Path + ".asset"));
        }
        return(true);
    }
Пример #14
0
 public static void SetImportedAsset(PKFxFxAsset value)
 {
     m_CurrentlyImportedAsset = value;
 }
Пример #15
0
 public static void SetBuiltAsset(PKFxFxAsset value)
 {
     m_CurrentlyBuildAsset = value;
 }
Пример #16
0
 public static bool PreloadEffectDependencies(PKFxFxAsset fxAsset)
 {
     return(_PreloadFxDependencies(fxAsset));
 }