Example #1
0
    public void LoadAudio(string projectFolder, string clipName)
    {
        //  Already loaded, bail out.
        if (audioSequences.ContainsKey(clipName))
        {
            return;
        }

        //  Create entry.
        audioSequences[clipName] = new List <AudioSequence>();

        //ClearAudio();

        //  Load sound sequences from xml data.
        List <XML_Types.XML_SoundSequence> soundSequences = XML_StageLoader.loadSoundSequences(projectFolder, clipName);

        foreach (XML_Types.XML_SoundSequence soundSequence in soundSequences)
        {
            //Message.Log( "sound sequence: " + soundSequence._name + " startFrame: " + soundSequence._startFrame );

            //  Retrieve audio clip from asset database.  If it's not already in asset database, copy clip
            //  from projectFolder to asset database.
            string soundName = Path.GetFileNameWithoutExtension(soundSequence._name);
            if (!string.IsNullOrEmpty(audioFolder))
            {
                soundName = audioFolder + "/" + soundName;
            }

            AudioClip clip = Resources.Load <AudioClip>(soundName);
            if (clip == null)
            {
                //  Download audio file into resources.  This is only useful to test Harmony Export in Unity.
                //  For final game, sound files should be copied in Resources.
                string soundFilename = projectFolder + "/audio/" + soundSequence._name;
                if (File.Exists(soundFilename))
                {
                    Message.Log("Copying from '" + soundFilename + "'");

                    WWW www = new WWW("file://" + System.Uri.EscapeUriString(soundFilename));
                    scheduledDownloads.Add(www); //  Add download to list of scheduled downloads.

                    clip = www.GetAudioClip(true /*threeD*/, false /*stream*/);
                }
            }

            //  Create new audio sequence with audio clip.
            //  Clip starts with a delay specified by startFrame when animation is initiated.
            if (clip != null)
            {
                AudioSequence audioSequence = new AudioSequence();
                audioSequence.audioClip  = clip;
                audioSequence.startFrame = soundSequence._startFrame;

                audioSequences[clipName].Add(audioSequence);
            }
        }
    }
Example #2
0
    static void Run()
    {
        projectFolder = EditorUtility.OpenFolderPanel("Import Harmony Game Engine Project", projectFolder, "");
        if (!string.IsNullOrEmpty(projectFolder) &&
            new DirectoryInfo(projectFolder).Exists)
        {
            string[] clipNames = XML_StageLoader.loadStageClipNames(projectFolder).ToArray();

            if (clipNames.Length > 0)
            {
                string name = Path.GetFileName(projectFolder);

                GameObject rendererObject = new GameObject(name);

                HarmonyRenderer renderer = rendererObject.AddComponent <HarmonyRenderer>();
                /*HarmonyAnimation animation = */ rendererObject.AddComponent <HarmonyAnimation>();

                //  Do not create audio components if there is no audio sequences in specified project folder...
                bool needAudio = false;
                foreach (string clipName in clipNames)
                {
                    List <XML_Types.XML_SoundSequence> soundSequences = XML_StageLoader.loadSoundSequences(projectFolder, clipName);
                    if (soundSequences.Count > 0)
                    {
                        needAudio = true;
                        break;
                    }
                }

                if (needAudio)
                {
                    /*HarmonyAudio audio = */ rendererObject.AddComponent <HarmonyAudio>();
                    /*AudioSource audioSource = */ rendererObject.AddComponent <AudioSource>();
                }

                //  Remove streaming assets path part of the specified project folder if
                //  applicable.  An absolute path will work on the user's machine but will
                //  likely not be found elsewhere.
                string streamingAssetsPath   = Application.streamingAssetsPath;
                string rendererProjectFolder = projectFolder;
                if (rendererProjectFolder.Contains(streamingAssetsPath))
                {
                    rendererProjectFolder = rendererProjectFolder.Substring(streamingAssetsPath.Length + 1);
                }

                renderer.projectFolder = rendererProjectFolder;
                renderer.clipNames     = clipNames;
                renderer.renderTarget  = HarmonyRenderer.RenderTarget.eRenderTexture;

                //  Create Mesh.
                GenerateHarmonyMesh.CreateOrUpdateTextureObjectMesh(rendererObject);

                //  Adjust texture scale factor if resolution is too small...
                MeshFilter meshFilter = rendererObject.GetComponent <MeshFilter>();
                if (meshFilter != null)
                {
                    if (meshFilter.sharedMesh != null)
                    {
                        Bounds bounds         = meshFilter.sharedMesh.bounds;
                        float  meshResolution = Mathf.Max(bounds.size.x, bounds.size.y);

                        if (meshResolution < 1024.0f)
                        {
                            //  Adjust texture scale.
                            float newTextureScale = 1024.0f / meshResolution;
                            renderer.renderTextureScale = newTextureScale;

                            //  Update mesh with new texture scale values.
                            GenerateHarmonyMesh.CreateOrUpdateTextureObjectMesh(rendererObject);
                        }
                    }
                }

                //  Create Metadata.
                GenerateHarmonyMeta.CreateOrUpdatePropsFromMetadata(rendererObject);
                GenerateHarmonyMeta.CreateOrUpdateAnchorsFromMetadata(rendererObject);
                GenerateHarmonyMeta.CreateOrUpdateGenericMetadata(rendererObject);

                //  If no Harmony cameras available, ask user if he wants to create one.
                HarmonyCamera[] harmonyCameras = FindObjectsOfType <HarmonyCamera>();
                if (harmonyCameras.Length == 0)
                {
                    string title = "Create HarmonyCamera components?";
                    string body  = "Only a camera with the HarmonyCamera component will render Harmony Game Objects.";

                    if (EditorUtility.DisplayDialog(title, body, "Create", "Do Not Create"))
                    {
                        //  Make sure there is at least one camera in the scene.
                        Camera[] cameras = FindObjectsOfType <Camera>();
                        if (cameras.Length == 0)
                        {
                            GameObject cameraObject = new GameObject("Main Camera");
                            /*Camera camera = */ cameraObject.AddComponent <Camera>();
                        }

                        CreateHarmonyCamera.ShowWindow();
                    }
                }
            }
        }
    }