コード例 #1
0
ファイル: HarmonyAudio.cs プロジェクト: die-mt/Test-It
    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);
            }
        }
    }
コード例 #2
0
ファイル: GenerateHarmonyMeta.cs プロジェクト: die-mt/Test-It
    public static void CreateOrUpdateGenericMetadata(GameObject rootObject)
    {
        HarmonyRenderer renderer = rootObject.GetComponent <HarmonyRenderer>();

        if (renderer == null)
        {
            return;
        }

        string projectFolder = renderer.projectFolder;

        if (!new DirectoryInfo(projectFolder).Exists)
        {
            projectFolder = Application.streamingAssetsPath + "/" + projectFolder;
        }

        //  Load custom metadata from XML
        XML_Types.XML_GenericMeta[] xmlMetas = XML_StageLoader.loadGenericMeta(projectFolder).ToArray();
        if (xmlMetas.Length > 0)
        {
            foreach (XML_Types.XML_GenericMeta xmlMeta in xmlMetas)
            {
                HarmonyMeta.MetaEntry entry = new HarmonyMeta.MetaEntry();
                entry.metaName  = xmlMeta._name;
                entry.nodeName  = xmlMeta._nodeName;
                entry.metaValue = xmlMeta._value;

                if (Array.Exists(renderer.clipNames, clipName => clipName == xmlMeta._clipName))
                {
                    if (!renderer.metadata.ContainsKey(xmlMeta._clipName))
                    {
                        renderer.metadata[xmlMeta._clipName] = new HarmonyMeta();
                    }

                    if (renderer.metadata[xmlMeta._clipName].GetMeta(entry.metaName, entry.nodeName) == null)
                    {
                        renderer.metadata[xmlMeta._clipName].AddMeta(entry);
                    }
                }
                else
                {
                    HarmonyProp[] propComponents = rootObject.GetComponentsInChildren <HarmonyProp>();
                    foreach (HarmonyProp propComponent in propComponents)
                    {
                        if (propComponent.playName == xmlMeta._playName)
                        {
                            if (propComponent.metadata.GetMeta(entry.metaName, entry.nodeName) == null)
                            {
                                propComponent.metadata.AddMeta(entry);
                            }
                            break;
                        }
                    }
                }
            }
        }
    }
コード例 #3
0
ファイル: DemoPhysics.cs プロジェクト: die-mt/Test-It
    void CreateCharacterAt(Vector3 pos)
    {
        //Message.Log( "Create Character at: " + pos );

    #if CLONE_ON_TOUCH
        GameObject rendererObject = GameObject.Instantiate(gameObjectToClone) as GameObject;
        rendererObject.transform.localPosition = new Vector3(pos.x, pos.y, pos.z);
        rendererObject.transform.parent        = gameObject.transform;

        HarmonyRenderer  renderer  = rendererObject.GetComponent <HarmonyRenderer>();
        HarmonyAnimation animation = rendererObject.GetComponent <HarmonyAnimation>();
    #else
        GameObject rendererObject = new GameObject("Space Duck");
        rendererObject.transform.localScale    = new Vector3(0.01f, 0.01f, 0.01f);
        rendererObject.transform.localPosition = new Vector3(pos.x, pos.y, pos.z);
        rendererObject.transform.parent        = gameObject.transform;


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

        Rigidbody2D       rigidBody = rendererObject.AddComponent <Rigidbody2D>();
        PolygonCollider2D collider  = rendererObject.AddComponent <PolygonCollider2D>();

        //  Set up clip collection in renderer.
        renderer.projectFolder = liveProjectFolder;
        renderer.clipNames     = XML_StageLoader.loadStageClipNames(renderer.projectFolder).ToArray();

        renderer.syncCollider  = HarmonyRenderer.SyncCollider.eAlways;
        renderer.colliderShape = colliderShape;
    #endif // CLONE_ON_TOUCH

        //  Randomly play a clip.
        if (renderer.clipNames.Length > 0)
        {
            animation.LoopAnimation(24.0f, rand.Next() % renderer.clipNames.Length);
        }
    }
コード例 #4
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();
                    }
                }
            }
        }
    }
コード例 #5
0
ファイル: GenerateHarmonyMeta.cs プロジェクト: die-mt/Test-It
    public static void CreateOrUpdateAnchorsFromMetadata(GameObject rootObject)
    {
        HarmonyRenderer renderer = rootObject.GetComponent <HarmonyRenderer>();

        if (renderer == null)
        {
            return;
        }

        string projectFolder = renderer.projectFolder;

        if (!new DirectoryInfo(projectFolder).Exists)
        {
            projectFolder = Application.streamingAssetsPath + "/" + projectFolder;
        }

        //  Load anchors metadata from XML
        XML_Types.XML_AnchorMeta[] xmlAnchors = XML_StageLoader.loadAnchorMeta(projectFolder).ToArray();
        if (xmlAnchors.Length > 0)
        {
            string     anchorObjectName      = "Anchors";
            GameObject anchorContainerObject = null;

            Transform[] childTransforms = rootObject.GetComponentsInChildren <Transform>(true /*includeInactive*/);
            foreach (Transform childTransform in childTransforms)
            {
                GameObject childObject = childTransform.gameObject;

                //  Direct child to root object
                if (childObject.transform.parent == rootObject.transform)
                {
                    //  Object matching preset Anchors game object name.
                    if (childObject.name == anchorObjectName)
                    {
                        anchorContainerObject = childObject;
                        break;
                    }
                }
            }

            HarmonyAnchor[] anchorComponents = rootObject.GetComponentsInChildren <HarmonyAnchor>(true /*includeInactive*/);

            foreach (XML_Types.XML_AnchorMeta xmlAnchor in xmlAnchors)
            {
                if (!Array.Exists(anchorComponents, anchor => (anchor.playName == xmlAnchor._playName) && (anchor.nodeName == xmlAnchor._nodeName)))
                {
                    if (anchorContainerObject == null)
                    {
                        //  Create container game object from anchors child to renderer object.
                        anchorContainerObject = new GameObject(anchorObjectName);
                        anchorContainerObject.transform.parent = rootObject.transform;
                    }

                    GameObject anchorObject = new GameObject(xmlAnchor._nodeName);
                    anchorObject.transform.parent = anchorContainerObject.transform;

                    HarmonyAnchor anchorComponent = anchorObject.AddComponent <HarmonyAnchor>();

                    anchorComponent.playName = xmlAnchor._playName;
                    anchorComponent.nodeName = xmlAnchor._nodeName;
                }
            }
        }
    }
コード例 #6
0
ファイル: GenerateHarmonyMeta.cs プロジェクト: die-mt/Test-It
    public static void CreateOrUpdatePropsFromMetadata(GameObject rootObject)
    {
        HarmonyRenderer renderer = rootObject.GetComponent <HarmonyRenderer>();

        if (renderer == null)
        {
            return;
        }

        string projectFolder = renderer.projectFolder;

        if (!new DirectoryInfo(projectFolder).Exists)
        {
            projectFolder = Application.streamingAssetsPath + "/" + projectFolder;
        }

        //  Load props metadata from XML
        XML_Types.XML_PropMeta[] xmlProps = XML_StageLoader.loadPropMeta(projectFolder).ToArray();
        if (xmlProps.Length > 0)
        {
            string     propObjectName      = "Props";
            GameObject propContainerObject = null;

            Transform[] childTransforms = rootObject.GetComponentsInChildren <Transform>(true /*includeInactive*/);
            foreach (Transform childTransform in childTransforms)
            {
                GameObject childObject = childTransform.gameObject;

                //  Direct child to root object
                if (childObject.transform.parent == rootObject.transform)
                {
                    //  Object matching preset Props game object name.
                    if (childObject.name == propObjectName)
                    {
                        propContainerObject = childObject;
                        break;
                    }
                }
            }

            HarmonyProp[] propComponents = rootObject.GetComponentsInChildren <HarmonyProp>(true /*includeInactive*/);

            foreach (XML_Types.XML_PropMeta xmlProp in xmlProps)
            {
                if (!Array.Exists(propComponents, prop => (prop.clipName == xmlProp._clipName) && (prop.playName == xmlProp._playName)))
                {
                    if (propContainerObject == null)
                    {
                        //  Create container game object from props child to renderer object.
                        propContainerObject = new GameObject(propObjectName);
                        propContainerObject.transform.parent = rootObject.transform;
                    }

                    GameObject propObject = new GameObject(xmlProp._playName);
                    propObject.transform.parent = propContainerObject.transform;

                    HarmonyProp propComponent = propObject.AddComponent <HarmonyProp>();

                    propComponent.clipName = xmlProp._clipName;
                    propComponent.playName = xmlProp._playName;
                }
            }
        }
    }
コード例 #7
0
    private void OnGUI()
    {
        Camera mainCamera = Camera.main;

        float width  = mainCamera.pixelWidth;
        float height = mainCamera.pixelHeight;

        SceneSettings settings = FindObjectOfType(typeof(SceneSettings)) as SceneSettings;

        if (settings == null)
        {
            // no settings available, let's create new game object.
            GameObject settingsObject = new GameObject("Settings");
            settings = settingsObject.AddComponent <SceneSettings>();
        }

        int nProjects = projectFolders.Count;

        float fontMult = 1.0f / 120.0f;
        int   fontSize = 15;

        GUIStyle buttonStyle = new GUIStyle(GUI.skin.GetStyle("button"));

        buttonStyle.fontSize = (Screen.dpi != 0) ? (int)(Screen.dpi * fontMult * fontSize) : fontSize;

        GUIStyle boxStyle = new GUIStyle(GUI.skin.GetStyle("box"));

        boxStyle.fontSize = (Screen.dpi != 0) ? (int)(Screen.dpi * fontMult * fontSize) : fontSize;

        int boxWidth = (int)(width / 3);

        int buttonWidth  = boxWidth - leftSpacing - rightSpacing;
        int buttonHeight = buttonWidth / 5;

        int boxHeight = topSpacing + (buttonHeight * nProjects) + (buttonSpacing * nProjects - 1) + bottomSpacing;

        // Top of the menu
        if ((deltaTouch + deltaOld) > topSpacing)
        {
            deltaOld   = topSpacing;
            deltaTouch = 0;
        }

        //Bottom of the menu
        if (-(deltaTouch + deltaOld) > boxHeight + bottomSpacing - height)
        {
            deltaOld   = -(boxHeight + bottomSpacing - height);
            deltaTouch = 0;
        }

        Rect boxRect = new Rect((width - boxWidth) / 2, deltaTouch + deltaOld, boxWidth, boxHeight);
        //Rect boxRect = new Rect( (width - boxWidth) / 2, (height - boxHeight) / 2, boxWidth, boxHeight );

        //  Make a background box.
        GUIContent boxText = new GUIContent("Loader Menu");

        GUI.Box(boxRect, boxText, boxStyle);

        for (int i = 0; i < nProjects; ++i)
        {
            Rect buttonRect = new Rect(boxRect.x + leftSpacing,
                                       boxRect.y + topSpacing + i * (buttonHeight + buttonSpacing),
                                       buttonWidth,
                                       buttonHeight);

            GUIContent buttonText = new GUIContent(new DirectoryInfo((projectFolders[i] as string)).Name);

            string temp;
            if (!ResolveProjectFolder(projectFolders[i], out temp))
            {
                continue;
            }

            if (GUI.Button(buttonRect, buttonText, buttonStyle))
            {
                if (ResolveProjectFolder(projectFolders[i], out settings.projectFolder))
                {
                    settings.clipNames = XML_StageLoader.loadStageClipNames(settings.projectFolder).ToArray();
                    settings.clipIdx   = 0;
                }
#if UNITY_WEBGL && !UNITY_EDITOR
                lastPreparedProjectFolderidx++;
                lastPreparedProjectFolderidx = lastPreparedProjectFolderidx % projectFolders.Count;
                PrepareProjectFolder(projectFolders[lastPreparedProjectFolderidx]);
#endif

                //  Load new scene.  Enable viewer group game object hierarchy.
                settings.viewerGroup.SetActive(true);
                settings.browserGroup.SetActive(false);
            }
        }
    }