// Raw binary data
		public override void OnGetData(DataPackage package,FilePath path){
			
			// Get the bytes:
			byte[] data=System.IO.File.ReadAllBytes(path.Path);
			
			// Let the package know:
			package.GotData(data,null);
			
		}
		public override void OnGetData(DataPackage package,FilePath path){
			
			if(Callback.WillDelay){
				
				// Buffer this call until later - we're not on the main thread.
				
				// Create the callback:
				ResourcesProtocolCallback callback=new ResourcesProtocolCallback(package,path);
				
				// Hook up the protocol handler for speed later:
				callback.Protocol=this;
				
				// Request it to run:
				callback.Go();
				
				return;
			}
			
			// Getting a files text content from resources.
			byte[] data=null;
			string error=null;
			string resPath=path.Path;
			
			TextAsset asset=(TextAsset)Resources.Load(resPath);
			
			if(asset==null){
				
				error="File not found in resources ("+path.Directory+path.Filename+" from URL '"+path.Url+"'). Does your file in Unity end with .bytes?";
				
			}else{
				data=asset.bytes;
			}
			
			package.GotData(data,error);
			
		}
		/// <summary>Get generic binary at the given path using this protocol. Used for e.g. fonts.
		/// Once it's been retrieved, this must call package.GotData(theText) internally.</summary>
		public virtual void OnGetData(DataPackage package,FilePath path){}
		public override void OnGetData(DataPackage package,FilePath path){
			HttpRequest request=new HttpRequest(path.Url,GotDataResult);
			request.ExtraData=package;
			request.Send();
		}
Beispiel #5
0
        private void GotDataResult(HttpRequest request)
        {
            DataPackage package = (DataPackage)request.ExtraData;

            package.GotData(request.Bytes, request.Error);
        }
		public ResourcesProtocolCallback(DataPackage package,FilePath path){
			Data=package;
			Path=path;
		}
Beispiel #7
0
        /// <summary>Submits this form using the given button. It may override the action etc.</summary>
        public void submit(HtmlElement clickedButton)
        {
            // Generate a nice dictionary of the form contents.

            // Step 1: find the unique names of the elements:
            Dictionary <string, string> uniqueValues = new Dictionary <string, string>();

            // Get submittable elements:
            HTMLFormControlsCollection allInputs = GetAllInputs(InputSearchMode.Submittable);

            foreach (Element element in allInputs)
            {
                if (element is HtmlButtonElement)
                {
                    // No buttons.
                    continue;
                }

                string type = element["type"];
                if (type == "submit")
                {
                    // No submit either.
                    continue;
                }

                string name = element["name"];
                if (name == null)
                {
                    name = "";
                }

                // Step 2: For each one, get their value.
                // We might have a name repeated, in which case we check if they are radio boxes.

                if (uniqueValues.ContainsKey(name))
                {
                    // Ok the element is already added - we have two with the same name.
                    // If they are radio, then only overwrite value if the new addition is checked.
                    // Otherwise, overwrite - furthest down takes priority.
                    if (element.Tag == "input")
                    {
                        HtmlInputElement tag = (HtmlInputElement)element;

                        if (tag.Type == InputType.Radio && !tag.Checked)
                        {
                            // Don't overwrite.
                            continue;
                        }
                    }
                }
                string value = (element as HtmlElement).value;
                if (value == null)
                {
                    value = "";
                }
                uniqueValues[name] = value;
            }

            // Get the action:
            string action = GetOverriden("action", clickedButton);

            FormEvent formData = new FormEvent(uniqueValues);

            formData.SetTrusted(true);
            formData.EventType = "submit";
            // Hook up the form element:
            formData.form = this;

            if (dispatchEvent(formData))
            {
                // Get ready to post now!
                DataPackage package = new DataPackage(action, document.basepath);
                package.AttachForm(formData.ToUnityForm());

                // Apply request to the data:
                formData.request = package;

                // Apply load event:
                package.onload = package.onerror = delegate(UIEvent e){
                    // Attempt to run ondone (doesn't bubble):
                    formData.Reset();
                    formData.EventType = "done";

                    if (dispatchEvent(formData))
                    {
                        // Otherwise the ondone function quit the event.

                        // Load the result into target now.
                        string target = GetOverriden("target", clickedButton);

                        HtmlDocument targetDocument = ResolveTarget(target);

                        if (targetDocument == null)
                        {
                            // Posting a form to an external target.

                            Log.Add("Warning: Unity cannot post forms to external targets. It will be loaded a second time.");

                            // Open the URL outside of Unity:
                            UnityEngine.Application.OpenURL(package.location.absoluteNoHash);
                        }
                        else
                        {
                            // Change the location:
                            targetDocument.SetRawLocation(package.location);

                            // History entry required:
                            targetDocument.window.history.DocumentNavigated();

                            // Apply document content:
                            targetDocument.GotDocumentContent(package.responseText, package.statusCode, true);
                        }
                    }
                };

                // Send now!
                package.send();
            }
        }
 /// <summary>Get generic binary at the given path using this protocol. Used for e.g. fonts.
 /// Once it's been retrieved, this must call package.GotData(theText) internally.</summary>
 public virtual void OnGetData(DataPackage package, FilePath path)
 {
 }