Exemplo n.º 1
0
    static void CreateNewWwuEntry(AssetType in_type, out AkWwiseProjectData.WorkUnit out_wwu, out int out_wwuIndex)
    {
        out_wwu = AkWwiseProjectInfo.GetData().NewChildWorkUnit(in_type.RootDirectoryName);

        ArrayList list = AkWwiseProjectInfo.GetData().GetWwuListByString(in_type.RootDirectoryName);

        list.Add(out_wwu);
        out_wwuIndex = list.Count - 1;
    }
Exemplo n.º 2
0
    static void ReplaceWwuEntry(string in_currentPhysicalPath, AssetType in_type, out AkWwiseProjectData.WorkUnit out_wwu, out int out_wwuIndex)
    {
        ArrayList list = AkWwiseProjectInfo.GetData().GetWwuListByString(in_type.RootDirectoryName);

        out_wwuIndex = list.BinarySearch(new AkWwiseProjectData.WorkUnit(in_currentPhysicalPath), AkWwiseProjectData.s_compareByPhysicalPath);
        out_wwu      = AkWwiseProjectInfo.GetData().NewChildWorkUnit(in_type.RootDirectoryName);

        if (out_wwuIndex < 0)
        {
            out_wwuIndex = ~out_wwuIndex;
            list.Insert(out_wwuIndex, out_wwu);
        }
        else
        {
            list[out_wwuIndex] = out_wwu;
        }
    }
Exemplo n.º 3
0
    private static AkWwiseProjectData.WorkUnit ReplaceWwuEntry(string in_currentPhysicalPath, AssetType in_type, out int out_wwuIndex)
    {
        var list = AkWwiseProjectInfo.GetData().GetWwuListByString(in_type.RootDirectoryName);

        out_wwuIndex = list.BinarySearch(new AkWwiseProjectData.WorkUnit {
            PhysicalPath = in_currentPhysicalPath
        });
        AkWwiseProjectData.WorkUnit out_wwu = null;

        switch (in_type.Type)
        {
        case WwiseObjectType.Event:
            out_wwu = new AkWwiseProjectData.EventWorkUnit();
            break;

        case WwiseObjectType.StateGroup:
        case WwiseObjectType.SwitchGroup:
            out_wwu = new AkWwiseProjectData.GroupValWorkUnit();
            break;

        case WwiseObjectType.AuxBus:
        case WwiseObjectType.Soundbank:
        case WwiseObjectType.GameParameter:
        case WwiseObjectType.Trigger:
        case WwiseObjectType.AcousticTexture:
            out_wwu = new AkWwiseProjectData.AkInfoWorkUnit();
            break;
        }

        if (out_wwuIndex < 0)
        {
            out_wwuIndex = ~out_wwuIndex;
            list.Insert(out_wwuIndex, out_wwu);
        }
        else
        {
            list[out_wwuIndex] = out_wwu;
        }

        return(out_wwu);
    }
Exemplo n.º 4
0
    bool GatherModifiedFiles()
    {
        bool bChanged     = false;
        int  iBasePathLen = s_wwiseProjectPath.Length + 1;

        foreach (string dir in FoldersOfInterest)
        {
            List <int> deleted      = new List <int>();
            ArrayList  knownFiles   = AkWwiseProjectInfo.GetData().GetWwuListByString(dir);
            int        cKnownBefore = knownFiles.Count;

            DirectoryInfo di    = null;
            FileInfo[]    files = null;
            try
            {
                //Get all Wwus in this folder.
                di    = new DirectoryInfo(Path.Combine(s_wwiseProjectPath, dir));
                files = di.GetFiles("*.wwu", SearchOption.AllDirectories);
            }
            catch (Exception)
            {
                return(false);
            }
            Array.Sort(files, new FileInfo_CompareByPath());

            //Walk both arrays
            int iKnown = 0;
            int iFound = 0;

            while (iFound < files.Length && iKnown < knownFiles.Count)
            {
                AkWwiseProjectData.WorkUnit workunit = knownFiles[iKnown] as AkWwiseProjectData.WorkUnit;
                string foundRelPath = files[iFound].FullName.Substring(iBasePathLen);
                switch (workunit.PhysicalPath.CompareTo(foundRelPath))
                {
                case 0:
                {
                    //File was there and is still there.  Check the FileTimes.
                    try
                    {
                        DateTime lastParsed = workunit.GetLastTime();
                        if (files[iFound].LastWriteTime > lastParsed)
                        {
                            //File has been changed!
                            //If this file had a parent, parse recursively the parent itself
                            m_WwuToProcess.Add(files[iFound].FullName);
                            bChanged = true;
                        }
                    }
                    catch (Exception)
                    {
                        //Access denied probably (file does exists since it was picked up by GetFiles).
                        //Just ignore this file.
                    }
                    iFound++;
                    iKnown++;
                } break;

                case 1:
                {
                    m_WwuToProcess.Add(files[iFound].FullName);
                    iFound++;
                } break;

                case -1:
                {
                    //A file was deleted.  Can't process it now, it would change the array indices.
                    deleted.Add(iKnown);
                    iKnown++;
                } break;
                }
            }

            //The remainder from the files found on disk are all new files.
            for (; iFound < files.Length; iFound++)
            {
                m_WwuToProcess.Add(files[iFound].FullName);
            }

            //All the remainder is deleted.  From the end, of course.
            if (iKnown < knownFiles.Count)
            {
                knownFiles.RemoveRange(iKnown, knownFiles.Count - iKnown);
            }

            //Delete those tagged.
            for (int i = deleted.Count - 1; i >= 0; i--)
            {
                knownFiles.RemoveAt(deleted[i]);
            }

            bChanged |= cKnownBefore != knownFiles.Count;
        }
        return(bChanged || m_WwuToProcess.Count > 0);
    }
Exemplo n.º 5
0
    int RecurseWorkUnit(AssetType in_type, FileInfo in_workUnit, string in_currentPathInProj, string in_currentPhysicalPath, LinkedList <AkWwiseProjectData.PathElement> in_pathAndIcons, string in_parentPhysicalPath = "")
    {
        m_WwuToProcess.Remove(in_workUnit.FullName);
        XmlReader reader   = null;
        int       wwuIndex = -1;

        try
        {
            //Progress bar stuff
            string msg = "Parsing Work Unit " + in_workUnit.Name;
            EditorUtility.DisplayProgressBar(s_progTitle, msg, (float)m_currentWwuCnt / (float)m_totWwuCnt);
            m_currentWwuCnt++;

            in_currentPathInProj = Path.Combine(in_currentPathInProj, Path.GetFileNameWithoutExtension(in_workUnit.Name));
            in_pathAndIcons.AddLast(new AkWwiseProjectData.PathElement(Path.GetFileNameWithoutExtension(in_workUnit.Name), AkWwiseProjectData.WwiseObjectType.WORKUNIT));
            string WwuPhysicalPath = Path.Combine(in_currentPhysicalPath, in_workUnit.Name);

            AkWwiseProjectData.WorkUnit wwu = null;

            ReplaceWwuEntry(WwuPhysicalPath, in_type, out wwu, out wwuIndex);

            wwu.ParentPhysicalPath = in_parentPhysicalPath;
            wwu.PhysicalPath       = WwuPhysicalPath;
            wwu.Guid = "";
            wwu.SetLastTime(File.GetLastWriteTime(in_workUnit.FullName));

            reader = XmlReader.Create(in_workUnit.FullName);

            reader.MoveToContent();
            reader.Read();
            while (!reader.EOF && reader.ReadState == ReadState.Interactive)
            {
                if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals("WorkUnit"))
                {
                    if (wwu.Guid.Equals(""))
                    {
                        wwu.Guid = reader.GetAttribute("ID");
                    }

                    string persistMode = reader.GetAttribute("PersistMode");
                    if (persistMode == "Reference")
                    {
                        // ReadFrom advances the reader
                        var      matchedElement  = XNode.ReadFrom(reader) as XElement;
                        string   newWorkUnitPath = Path.Combine(in_workUnit.Directory.FullName, matchedElement.Attribute("Name").Value + ".wwu");
                        FileInfo newWorkUnit     = new FileInfo(newWorkUnitPath);

                        // Parse the referenced Work Unit
                        if (m_WwuToProcess.Contains(newWorkUnit.FullName))
                        {
                            RecurseWorkUnit(in_type, newWorkUnit, in_currentPathInProj, in_currentPhysicalPath, in_pathAndIcons, WwuPhysicalPath);
                        }
                    }
                    else
                    {
                        // If the persist mode is "Standalone" or "Nested", it means the current XML tag
                        // is the one corresponding to the current file. We can ignore it and advance the reader
                        reader.Read();
                    }
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals("AuxBus"))
                {
                    in_currentPathInProj = Path.Combine(in_currentPathInProj, reader.GetAttribute("Name"));
                    in_pathAndIcons.AddLast(new AkWwiseProjectData.PathElement(reader.GetAttribute("Name"), AkWwiseProjectData.WwiseObjectType.AUXBUS));
                    bool isEmpty = reader.IsEmptyElement;
                    AddElementToList(in_currentPathInProj, reader, in_type, in_pathAndIcons, wwuIndex);

                    if (isEmpty)
                    {
                        in_currentPathInProj = in_currentPathInProj.Remove(in_currentPathInProj.LastIndexOf(Path.DirectorySeparatorChar));
                        in_pathAndIcons.RemoveLast();
                    }
                }
                // Busses and folders act the same for the Hierarchy: simply add them to the path
                else if (reader.NodeType == XmlNodeType.Element && (reader.Name.Equals("Folder") || reader.Name.Equals("Bus")))
                {
                    //check if node has children
                    if (!reader.IsEmptyElement)
                    {
                        // Add the folder/bus to the path
                        in_currentPathInProj = Path.Combine(in_currentPathInProj, reader.GetAttribute("Name"));
                        if (reader.Name.Equals("Folder"))
                        {
                            in_pathAndIcons.AddLast(new AkWwiseProjectData.PathElement(reader.GetAttribute("Name"), AkWwiseProjectData.WwiseObjectType.FOLDER));
                        }
                        else if (reader.Name.Equals("Bus"))
                        {
                            in_pathAndIcons.AddLast(new AkWwiseProjectData.PathElement(reader.GetAttribute("Name"), AkWwiseProjectData.WwiseObjectType.BUS));
                        }
                    }
                    // Advance the reader
                    reader.Read();
                }
                else if (reader.NodeType == XmlNodeType.EndElement && (reader.Name.Equals("Folder") || reader.Name.Equals("Bus") || reader.Name.Equals("AuxBus")))
                {
                    // Remove the folder/bus from the path
                    in_currentPathInProj = in_currentPathInProj.Remove(in_currentPathInProj.LastIndexOf(Path.DirectorySeparatorChar));
                    in_pathAndIcons.RemoveLast();

                    // Advance the reader
                    reader.Read();
                }
                else if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals(in_type.XmlElementName))
                {
                    // Add the element to the list
                    AddElementToList(in_currentPathInProj, reader, in_type, in_pathAndIcons, wwuIndex);
                }
                else
                {
                    reader.Read();
                }
            }
            // Sort the newly populated Wwu alphabetically
            SortWwu(in_type.RootDirectoryName, wwuIndex);
        }
        catch (Exception e)
        {
            Debug.LogError(e.ToString());
            wwuIndex = -1;
        }

        if (reader != null)
        {
            reader.Close();
        }

        in_pathAndIcons.RemoveLast();
        return(wwuIndex);
    }
Exemplo n.º 6
0
    private bool CreateWorkUnit(string in_relativePath, string in_wwuType, string in_fullPath)
    {
        var ParentID = string.Empty;

        try
        {
            using (var reader = System.Xml.XmlReader.Create(in_fullPath))
            {
                reader.MoveToContent();

                //We check if the current work unit has a parent and save its guid if its the case
                while (!reader.EOF && reader.ReadState == System.Xml.ReadState.Interactive)
                {
                    if (reader.NodeType == System.Xml.XmlNodeType.Element && reader.Name.Equals("WorkUnit"))
                    {
                        if (reader.GetAttribute("PersistMode").Equals("Nested"))
                        {
                            ParentID = reader.GetAttribute("OwnerID");
                        }
                        break;
                    }

                    reader.Read();
                }
            }
        }
        catch (System.Exception e)
        {
            UnityEngine.Debug.Log("WwiseUnity: A changed Work unit wasn't found. It must have been deleted " + in_fullPath);
            return(false);
        }

        if (!string.IsNullOrEmpty(ParentID))
        {
            var parentGuid = System.Guid.Empty;

            try
            {
                parentGuid = new System.Guid(ParentID);
            }
            catch
            {
                UnityEngine.Debug.LogWarning("WwiseUnity: \"OwnerID\" in <" + in_fullPath + "> cannot be converted to a GUID (" + ParentID + ")");
                return(false);
            }

            var    list                     = AkWwiseProjectInfo.GetData().GetWwuListByString(in_wwuType);
            var    PathAndIcons             = new System.Collections.Generic.LinkedList <AkWwiseProjectData.PathElement>();
            string PathInProj               = string.Empty;
            AkWwiseProjectData.WorkUnit wwu = null;

            if (parentGuid != System.Guid.Empty)
            {
                for (var i = 0; i < list.Count; i++)
                {
                    wwu = list[i] as AkWwiseProjectData.WorkUnit;
                    if (wwu.Guid.Equals(parentGuid))
                    {
                        PathInProj   = wwu.ParentPath;
                        PathAndIcons = new System.Collections.Generic.LinkedList <AkWwiseProjectData.PathElement>(wwu.PathAndIcons);
                        break;
                    }
                    else
                    {
                        var WwuChildren = wwu.GetChildrenArrayList();
                        foreach (AkWwiseProjectData.AkInformation child in WwuChildren)
                        {
                            if (child.Guid.Equals(parentGuid))
                            {
                                PathInProj   = child.Path;
                                PathAndIcons = new System.Collections.Generic.LinkedList <AkWwiseProjectData.PathElement>(child.PathAndIcons);
                                break;
                            }
                        }
                    }
                }
            }
            if (!string.IsNullOrEmpty(PathInProj))
            {
                RecurseWorkUnit(AssetType.Create(in_wwuType), new System.IO.FileInfo(in_fullPath), PathInProj,
                                in_relativePath.Remove(in_relativePath.LastIndexOf(System.IO.Path.DirectorySeparatorChar)), PathAndIcons,
                                wwu.PhysicalPath);
                return(true);
            }

            //Not found.  Wait for it to load
            return(false);
        }

        //Root Wwu
        UpdateWorkUnit(in_fullPath, in_wwuType, in_relativePath);
        return(true);
    }