示例#1
0
        /// <summary>Creates a new World UI with the given pixels of space and a given name.
        /// The gameobjects origin sits at the middle of the UI by default. See <see cref="PowerUI.WorldUI.SetOrigin"/>.
        /// By default, 100 pixels are 1 world unit. See <see cref="PowerUI.WorldUI.SetResolution"/>.</summary>
        /// <param name="name">The name for the UI's gameobject.</param>
        /// <param name="widthPX">The width in pixels of this UI.</param>
        /// <param name="heightPX">The height in pixels of this UI.</param>
        public WorldUI(string name, int widthPX, int heightPX)
        {
            // Start the UI:
            UI.Start();

            // Create the gameobject:
            gameObject      = new GameObject();
            gameObject.name = name;

            // Grab the name:
            Name = name;

            transform = gameObject.transform;
            Renderer  = new Renderman(this);
            SetDepthResolution(1f);

            // Apply the default scale:
            transform.localScale = new Vector3(1 / 100f, 1 / 100f, 1 / 100f);

            document = Renderer.RootDocument as HtmlDocument;

            // Add it to the UI update linked list:
            if (UI.FirstWorldUI == null)
            {
                UI.FirstWorldUI = UI.LastWorldUI = this;
            }
            else
            {
                UIBefore       = UI.LastWorldUI;
                UI.LastWorldUI = UI.LastWorldUI.UIAfter = this;
            }

            SetDimensions(widthPX, heightPX);
        }
示例#2
0
        // OnEnable is called when the game starts, or when the manager script component is enabled.
        public virtual void OnEnable()
        {
                        #if UNITY_EDITOR && !UNITY_WEBPLAYER
            if (HtmlFile != null && WatchForChanges)
            {
                // Get the full asset path:
                string fullPath = UnityEditor.AssetDatabase.GetAssetPath(HtmlFile);

                // Create the loader:
                Reloader = new LiveHtml(fullPath,
                                        delegate(string path, string html){
                    // Write the innerHTML now:
                    Document.innerHTML = html;
                }
                                        );
            }
                        #endif

            // Start:
            UI.Start();

            // Load the main UI from the above HtmlFile or Url. Note that UI's don't have to be loaded like this! You
            // can also just set a string of text if needed.
            Navigate(UI.document);
        }
        /// <summary>Holds the given information about a translation.</summary>
        /// <param name="from">The lower case language code to translate from, e.g. en.</param>
        /// <param name="to">The lower case language code to translate to, e.g. fr.</param>
        public TranslationInfo(string from, string to)
        {
            FromCode = from;
            ToCode   = to;

            // Make sure the parser is ready to go:
            UI.Start(true);
        }
示例#4
0
        // OnEnable is called when the game starts, or when the manager script component is enabled.
        public virtual void OnEnable()
        {
            // Watch for changes:
            Watch();

            // Start:
            UI.Start();

            // Load the main UI from the above HtmlFile or Url. Note that UI's don't have to be loaded like this! You
            // can also just set a string of text if needed.
            Navigate(UI.document);
        }
        /// <summary>AOT compiles the given HTML file. It gets searched for any Nitro, and a DLL may be generated from it.</summary>
        /// <param name="htmlFile">The path to a html file.</param>
        public static void Compile(string htmlFile)
        {
            // Grab the HTML:
            string htmlText = File.ReadAllText(htmlFile);

            // Make sure the parser and compiler is ready to go:
            UI.Start(true);

            // Hook up the AOT file:
            NitroCode.OnAotFileExists = OnAotFileExists;

            // Drop the HTML into a document:
            Document uiDocument = new Document(new Renderman(true), null, true);

            // Set the location so it knows where it came from for error reporting:
            uiDocument.ScriptLocation = htmlFile;
            // Write the HTML:
            uiDocument.body.innerHTML = htmlText;
        }
        /// <summary>Performs the translation.</summary>
        /// <param name="from">The filename of the file in the Languages/UI folder, without it's type.</param>
        /// <param name="to">The language code that will be translated to, e.g. "fr".</param>
        /// <param name="toName">The language name that will be translated to, e.g. "French".</param>
        /// <param name="allowExists">True if we can safely overwrite the file if it exists.</param>
        public static bool Perform(string from, string to, string toName, bool allowExists)
        {
            // Make sure the parser is ready to go:
            UI.Start(true);

            // 1. Parse the original file:
            string slash = System.IO.Path.DirectorySeparatorChar + "";
            string sourceLanguageFile = LanguagePath + slash + from + ".html";

            if (!File.Exists(sourceLanguageFile))
            {
                Debug.LogError("Translate source file not found: " + sourceLanguageFile);
                return(false);
            }

            // Read the source text:
            string sourceFile = File.ReadAllText(sourceLanguageFile);

            // And parse it into a language set (of variables):
            LanguageSet source = new LanguageSet(sourceFile);

            // Grab the from language code:
            string fromCode = source.Code;

            string toTranslate = "";

            foreach (KeyValuePair <string, string> kvp in source.Map)
            {
                string varName  = kvp.Key;
                string varValue = kvp.Value;

                // Rather interestingly, bing translate doesn't like <var> but does like <v>, and <v> is supported by the parser anyway!
                toTranslate += "<v name='" + varName + "'>" + varValue + "</v>\n";
            }

            return(Perform(toTranslate, fromCode, to, toName, allowExists));
        }