Beispiel #1
0
    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);
        }
    }
Beispiel #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();
                    }
                }
            }
        }
    }
Beispiel #3
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);
            }
        }
    }