/// <summary>Gets or creates a script engine of the given type.</summary>
        public ScriptEngine GetScriptEngine(string type)
        {
            type = type.ToLower().Trim();

            if (Engines == null)
            {
                // Create:
                Engines = new Dictionary <string, ScriptEngine>();
            }

            ScriptEngine engine;

            if (Engines.TryGetValue(type, out engine))
            {
                return(engine);
            }

            // Try and instance it now! Get the global engine:
            engine = ScriptEngines.Get(type);

            if (engine == null)
            {
                // Don't know how to handle this type of script.
                Dom.Log.Add("Warning: Some script has been ignored due to its type ('" + type + "'). Did you mean 'text/javascript'?");
                return(null);
            }

            // Instance it:
            engine = engine.Instance(this);

            if (engine == null)
            {
                // Security problem (it would've logged it for us).
                return(null);
            }

            // Set doc:
            engine.Document = this;

            // Hook it up for each of this engines types:
            string[] types = engine.GetTypes();

            for (int i = 0; i < types.Length; i++)
            {
                Engines[types[i].ToLower().Trim()] = engine;
            }

            Dom.Event e = new Dom.Event("scriptengineload");
            dispatchEvent(e);

            return(engine);
        }
예제 #2
0
    /// <summary>Used internally - don't call this one. Startup the UI for use in the Editor with AOT Nitro.</summary>
    /// <param name="nitroAot">True if no gameobject should be generated.</param>
    public static void Start(bool nitroAot)
    {
        if (_Started)
        {
            return;
        }

        _Started = true;

        // Setup atlas stacks:
        AtlasStacks.Start();

        // Hookup the wrench logging method:
        Dom.Log.OnLog += OnLogMessage;

        // Hookup the InfiniText logging method:
        InfiniText.Fonts.OnLog += OnLogMessage;

                #if !NoBIDI
        // Setup bidi character metadata:
        InfiniText.DirectionCategory.Setup();
                #endif

        // Setup the character entities such as &nbsp;
        CharacterEntities.Setup();

        // Start modules now! UI is always available so we use that:
        Modular.Start.Now(typeof(UI));

        // Setup language metadata:
        Languages.globalLoader.Setup();

        // Setup alert/confirm dialogues:
        BlockingDialogues.Setup();

        // Setup input:
        PowerUI.Input.Setup();

        // Setup the text/language service:
        if (Variables == null)
        {
            Variables = new FullVariableSet();

            if (!nitroAot)
            {
                // Sign up to the variable on change event - whenever a custom var is changed, we need to refresh the screen.
                Variables.OnChange += OnVariableChange;
                // Sign on to the event that occurs when the language changes.
                Dom.Text.OnLanguageChanged += OnLanguageChange;
                // Sign on to the event that occurs when the gender changes.
                Dom.Text.OnGenderChanged += ResolveAllVariables;
            }
        }

        // Setup the callback queue:
        Callbacks.Start();

        // Setup the character providers (for e.g. Emoji):
        CharacterProviders.Setup();

        Layer = LayerMask.NameToLayer("PowerUI");

                #if !NO_LAYER_CHECK
        if (Layer < 0)
        {
            // Invalid layer.
                        #if UNITY_EDITOR
            // Create the new layer now (this will actually be a permanent change):
            Layer = PowerUI.LayerManager.Add();
                        #else
            // On device - make one up:
            Layer = 21;
                        #endif
        }
                #endif

        // Default FPS:
        SetRate(DefaultRate);

                #if !NoNitroRuntime
        // Link up the text/javascript type by creating the engine:
        ScriptEngines.Add(new JavaScriptEngine());
                #endif

        if (nitroAot)
        {
            return;
        }

        GUINode = GameObject.Find("#PowerUI");

        if (GUINode == null)
        {
            // Not started yet.

            // Create the UI game object:
            GUINode      = new GameObject();
            GUINode.name = "#PowerUI";

            // Create the camera:
            CameraNode      = new GameObject();
            CameraNode.name = "Camera";

            // Create the updater:
            GlobalUpdater = GUINode.AddComponent <StandardUpdater>();

            // Setup the camera:
            GUICamera = CameraNode.AddComponent <Camera>();

            // Apply the new settings to the camera:
            GUICamera.orthographic = (CurrentCameraMode == CameraMode.Orthographic);
        }
        else
        {
            // Already started, but we might have updated.

            if (CameraNode == null)
            {
                // This can happen if the PowerUI assembly is actively reloaded (e.g. runtime updates).
                CameraNode      = GameObject.Find("#PowerUI/Camera");
                CameraTransform = CameraNode.transform;
                GUICamera       = CameraNode.GetComponent <Camera>();
            }
            else
            {
                // Already started!
                return;
            }
        }

        // Hide the PowerUI layer from all cameras other than GUICamera:
        Camera[] cameras = Camera.allCameras;

        int layerMask = ~(1 << UI.Layer);

        for (int i = 0; i < cameras.Length; i++)
        {
            // Grab the camera:
            Camera camera = cameras[i];

            // Is it the GUICamera?
            if (camera == GUICamera)
            {
                continue;
            }

            // Hide the UI layer from it:
            camera.cullingMask &= layerMask;
        }

        // Setup the transform:
        CameraTransform        = CameraNode.transform;
        CameraTransform.parent = GUINode.transform;

        GUICamera.nearClipPlane = 0.2f;
        GUICamera.depth         = CameraDepth;
        GUICamera.clearFlags    = CameraClearFlags.Depth;
        GUICamera.cullingMask   = (1 << UI.Layer);
        GUICamera.renderingPath = RenderingPath.Forward;

        SetCameraDistance(60f);
        SetFieldOfView(60f);

        Renderer = new Renderman();

        // Render Mesh.OutputGameObject with the GUI camera:
        Renderer.RenderWithCamera(UI.Layer);
        document            = Renderer.RootDocument as HtmlDocument;
        document.window.top = document.window;

        // Fire the camera event:
        CameraGotCreated(GUICamera);
    }