Виктор Шейко %!s(int64=4) %!d(string=hai) anos
pai
achega
f57c212263

+ 7 - 0
Assets/Scripts/Controllers/CompanyController.cs

@@ -41,6 +41,7 @@ public class CompanyController : MonoBehaviour
     // Start is called before the first frame update
     void Start()
     {
+        DebugHelper.ActivateConsole();
         player = Player.GetComponent<PlayerController>();
         editor = Editor.GetComponent<EditorController>();
         client = Client.instance;
@@ -273,4 +274,10 @@ public class CompanyController : MonoBehaviour
             zones_view = ToggleZones.isOn;
         }
     }
+
+    void OnGUI()
+    {
+        //if (Input.GetKeyDown(KeyCode.BackQuote)) 
+        DebugHelper.DrawConsole();
+    }
 }

+ 15 - 73
Assets/Scripts/Controllers/FileBrowserController.cs

@@ -62,69 +62,15 @@ public class FileBrowserController : MonoBehaviour, IPointerDownHandler
         // Open file
         string[] paths = new string[0];
 
-        // Open file with filter
-        //var es = new[] {new ExtensionFilter("Image Files", "png", "jpg", "jpeg" )};
-
-        //es = new[] {new ExtensionFilter("Image Files", "png", "jpg", "jpeg" )};
         paths = StandaloneFileBrowser.OpenFilePanel($"Выбор изображения", "", "png,jpg", false);
      
-        //var paths = StandaloneFileBrowser.OpenFilePanel("Open File", "", extensions, true);
-
-        // Open file async
-        //StandaloneFileBrowser.OpenFilePanelAsync(name_view, "", es, false, (string[] paths) => {
-        //    if (paths.Length > 0)
-        //    {
-        //        StartCoroutine(OutputRoutine(new System.Uri(paths[0]).AbsoluteUri));
-        //    }
-        //});
-
-        //var paths = StandaloneFileBrowser.OpenFilePanel(name_view, "", "txt", true);
         if (paths.Length > 0)
         {
             Debug.Log(paths[0]);
-            //StartCoroutine(UpLoadUserData(new System.Uri(paths[0]).AbsoluteUri));
             StartCoroutine(UpLoadUserData(paths[0]));
         }
     }
 
-    private IEnumerator OutputRoutine(string url)
-    {
-        //var loader = new WWW(url);
-        Debug.Log($"file url pc {url}");
-
-        var server_url = $"{Application.streamingAssetsPath}/Targets/{Path.GetFileName(url)}";
-
-        Debug.Log($"file url server {server_url}");
-        var request = UnityWebRequest.Get(url);
-        yield return request.SendWebRequest();
-        //yield return loader;
-        if (!File.Exists(url))
-        {
-            while (!request.isDone)
-            {
-                yield return null;
-            }
-            if (!string.IsNullOrEmpty(request.error))
-            {
-                Debug.LogError("Error unpacking:" + request.error + " path: " + request.url);
-                yield break; //skip it                
-            }
-            else
-            {
-                if (!Directory.Exists(Path.GetDirectoryName(server_url)))
-                {
-                    Directory.CreateDirectory(Path.GetDirectoryName(server_url));
-                }
-                File.WriteAllBytes(server_url, request.downloadHandler.data);
-                Debug.Log($"success file load {server_url}");
-                inputField.text = server_url;
-                //could add to some kind of uninstall list?
-            }
-        }
-        yield return 0;
-        //output.texture = loader.texture;
-    }
-
     /// <summary>
     /// Отправка файла на сервер
     /// </summary>
@@ -132,38 +78,34 @@ public class FileBrowserController : MonoBehaviour, IPointerDownHandler
     /// <returns></returns>
     IEnumerator UpLoadUserData(string url)
     {
-        //var file = UnityWebRequest.Get(url);
-        //yield return file;
         Debug.Log(url);
-        
         WWWForm form = new WWWForm();
-        //form.AddBinaryData("file", file.downloadHandler.data);
-
-        //var screenShotURL = URL_OF_SERVER_PHP_PAGE;
-        //var bytes = Encoding.UTF8.GetBytes(url);
-        //var form = new WWWForm();
-
-        // string data = JsonUtility.ToJson(DataBaseManager.DataBase[username]);
-        //WWWForm form = new WWWForm();
-        //form.AddField("name", username);
-        //form.AddField("data", data);
         UnityWebRequest www;
         string file_name;
+        string php = "";
         if (Application.platform == RuntimePlatform.WebGLPlayer)
         {
             var deserialize = JsonConvert.DeserializeObject<List<urls>>(url);
             file_name = deserialize[0].file_name;
-            byte[] bytes = Encoding.UTF8.GetBytes(deserialize[0].reader);
+            Debug.Log($"file image {file_name}");
+            byte[] bytes = Encoding.UTF8.GetBytes(deserialize[0].base64);
+            Debug.Log($"bytes {bytes.Length}");
             form.AddBinaryData("file", bytes, deserialize[0].file_name);
-            www = UnityWebRequest.Post($"{Application.streamingAssetsPath}/upload.php", form);
+            php = $"{Application.streamingAssetsPath}/upload.php";
         }
         else
         {
             file_name = Path.GetFileName(url);
-            var bytes = File.ReadAllBytes(url);
-            form.AddBinaryData("file", bytes, file_name);
-            www = UnityWebRequest.Post($"http://dev.prmsys.net/positionviewer/StreamingAssets/upload.php", form);
+            using (FileStream fstream = File.OpenRead(url))
+            {
+                // преобразуем строку в байты
+                byte[] bytes = new byte[fstream.Length];
+                fstream.Read(bytes, 0, bytes.Length);
+                form.AddBinaryData("file", bytes, file_name);//{Path.GetExtension(url)}
+                php = $"http://dev.prmsys.net/positionviewer/StreamingAssets/upload.php";
+            }           
         }
+        www = UnityWebRequest.Post(php, form);
         yield return www.SendWebRequest();
         if (www.isHttpError)
             Debug.Log(www.error);
@@ -179,7 +121,7 @@ public class FileBrowserController : MonoBehaviour, IPointerDownHandler
     {
         public string url { get; set; }
         public string file_name { get; set; }
-        public string reader { get; set; }
+        public string base64 { get; set; }
     }
 }
 

+ 1 - 7
Assets/Scripts/Controllers/PlayerController.cs

@@ -329,13 +329,7 @@ public class PlayerController : MonoBehaviour
     //    beacon.transform.GetChild(0).GetChild(0).GetChild(0).GetComponent<Text>().text = $"{b.id}\nuuid={b.uuid}\nmajor={b.major}\nminor={b.minor}";
 
     //    b.beacon = beacon;
-    //}
-
-    void OnGUI()
-    {
-        //if (Input.GetKeyDown(KeyCode.BackQuote)) 
-        DebugHelper.DrawConsole();
-    }
+    //}   
 
     /// <summary>
     /// Остановка отрисовки при смене режима история/онлайн

+ 12 - 15
Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.jslib

@@ -37,29 +37,26 @@ var StandaloneFileBrowserWebGLPlugin = {
         fileInput.onchange = function (event) {
             // multiselect works
             var urls = [];
-            
+            var encoded;
             for (var i = 0; i < event.target.files.length; i++) {
                 //urls.push(URL.createObjectURL(event.target.files[i]));
                 var reader = new FileReader();
-
-                var binaryString;
-    reader.readAsArrayBuffer(event.target.files[i]);
+                //reader.readAsArrayBuffer(event.target.files[i]);
+               
+                var fileByteArrayLenth = 0;
+   
     reader.onloadend = function(e) {                     
-        var buffer = reader.result;
+        var buffer = e.target.result;
         var uintArray = new Uint8Array(buffer);
-        binaryString = String.fromCharCode.apply(null, uintArray);
-
-        //let resourceModel = new Model({
-            //contentType: myFile.type,                            
-            //fileName: myFile.name,
-            //fileContent: binaryString
-         //});                  
-    } 
-
+        /*for (var i = 0; i < uintArray.length; i++) {
+            fileByteArray.push(uintArray[i]);
+         }           */
+         fileByteArrayLenth=uintArray.length;
+    }   
                 urls.push({
                     "url": URL.createObjectURL(event.target.files[i]),
                     "file_name": event.target.files[i].name,
-                    "reader": binaryString
+                    "base64":  fileByteArrayLenth
                 });                
             }
             // File selected

+ 5 - 3
Assets/StreamingAssets/Upload.php

@@ -1,11 +1,13 @@
 <?php
+echo '<pre>';
+print_r($_FILES);
+echo '</pre>';
      $file = $_FILES["file"];
  
-     if (!empty($file)){
-         echo "Got file";   
+     if (!empty($file)){ 
    
       move_uploaded_file($file['tmp_name'], "./" . $file['name']);
-      
+      echo 'File save: ' . $file['name'];
      }
      else
          echo "Failed to get File";