Ejemplo n.º 1
0
        public void DropAreaGUI()
        {
            //Ok - set up for drag and drop
            Event evt       = Event.current;
            Rect  drop_area = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true));

            GUI.Box(drop_area, "Drop Here To Scan", m_boxStyle);

            switch (evt.type)
            {
            case EventType.DragUpdated:
            case EventType.DragPerform:
            {
                if (!drop_area.Contains(evt.mousePosition))
                {
                    break;
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                if (evt.type == EventType.DragPerform)
                {
                    DragAndDrop.AcceptDrag();
                    m_rawFilePath   = null;
                    m_assumedRawRes = 0;

                    //First lets determine whether we got something we are interested in

                    //Is it a saved file - only raw files are processed this way
                    if (DragAndDrop.paths.Length > 0)
                    {
                        string filePath = DragAndDrop.paths[0];

                        //Update in case unity has messed with it
                        if (filePath.StartsWith("Assets"))
                        {
                            filePath = Path.Combine(Application.dataPath, filePath.Substring(7)).Replace('\\', '/');
                        }

                        //Check file type and process as we can
                        string fileType = Path.GetExtension(filePath).ToLower();

                        //Handle raw files
                        if (fileType == ".r16" || fileType == ".raw")
                        {
                            m_rawFilePath = filePath;
                            m_scanner.LoadRawFile(filePath, m_rawByteOrder, ref m_rawBitDepth, ref m_assumedRawRes);
                            return;
                        }
                    }

                    //Is it something that unity knows about - may or may not have been saved
                    if (DragAndDrop.objectReferences.Length > 0)
                    {
                        //Debug.Log("Name is " + DragAndDrop.objectReferences[0].name);
                        //Debug.Log("Type is " + DragAndDrop.objectReferences[0].GetType());

                        //Check for textures
                        if (DragAndDrop.objectReferences[0].GetType() == typeof(UnityEngine.Texture2D))
                        {
                            GaiaUtils.MakeTextureReadable(DragAndDrop.objectReferences[0] as Texture2D);
                            GaiaUtils.MakeTextureUncompressed(DragAndDrop.objectReferences[0] as Texture2D);
                            m_scanner.LoadTextureFile(DragAndDrop.objectReferences[0] as Texture2D);
                            return;
                        }

                        //Check for terrains
                        if (DragAndDrop.objectReferences[0].GetType() == typeof(UnityEngine.GameObject))
                        {
                            GameObject go = DragAndDrop.objectReferences[0] as GameObject;
                            Terrain    t  = go.GetComponentInChildren <Terrain>();

                            //Handle a terrain
                            if (t != null)
                            {
                                m_scanner.LoadTerain(t);
                                return;
                            }
                        }

                        //Check for something with a mesh
                        if (DragAndDrop.objectReferences[0].GetType() == typeof(UnityEngine.GameObject))
                        {
                            GameObject go = DragAndDrop.objectReferences[0] as GameObject;

                            //Check for a mesh - this means we can scan it
                            MeshFilter[] filters = go.GetComponentsInChildren <MeshFilter>();
                            for (int idx = 0; idx < filters.Length; idx++)
                            {
                                if (filters[idx].mesh != null)
                                {
                                    m_scanner.LoadGameObject(go);
                                    return;
                                }
                            }
                        }
                    }

                    //If we got to here then we couldnt process it
                    Debug.LogWarning("Object type not supported by scanner. Ignored");
                }

                break;
            }
            }
        }
Ejemplo n.º 2
0
        private void DropAreaGUI()
        {
            //Ok - set up for drag and drop
            Event evt       = Event.current;
            Rect  drop_area = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true));

            GUI.Box(drop_area, ">> Drop Objects Here To Scan <<", m_dropBoxStyle);
            EditorGUILayout.HelpBox(m_scanMessage, MessageType.Info);

            switch (evt.type)
            {
            case EventType.DragUpdated:
            case EventType.DragPerform:
            {
                if (!drop_area.Contains(evt.mousePosition))
                {
                    break;
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                if (evt.type == EventType.DragPerform)
                {
                    DragAndDrop.AcceptDrag();
                    m_rawFilePath   = null;
                    m_assumedRawRes = 0;

                    //Is it a saved file - only raw files are processed this way
                    if (DragAndDrop.paths.Length > 0)
                    {
                        string filePath = DragAndDrop.paths[0];

                        //Update in case unity has messed with it
                        if (filePath.StartsWith("Assets"))
                        {
                            filePath = Path.Combine(Application.dataPath, filePath.Substring(7)).Replace('\\', '/');
                        }

                        //Check file type and process as we can
                        string fileType = Path.GetExtension(filePath).ToLower();

                        //Handle raw files
                        if (fileType == ".r16" || fileType == ".raw")
                        {
                            m_scanMessage = "Dropped Object recognized as a raw file";
                            m_scanner.m_scannerObjectType = ScannerObjectType.Raw;
                            m_scanner.m_objectScanned     = true;
                            m_rawFilePath = filePath;
                            m_scanner.LoadRawFile(filePath, m_rawByteOrder, ref m_rawBitDepth, ref m_assumedRawRes);
                            return;
                        }
                    }

                    //Is it something that unity knows about - may or may not have been saved
                    bool finished = false;
                    if (DragAndDrop.objectReferences.Length > 0)
                    {
                        switch (DragAndDrop.objectReferences[0])
                        {
                        //Check for textures
                        case Texture2D _:
                        {
                            EditorUtility.DisplayProgressBar("Processing Texture", "Processing texture to mask texture", 0.5f);
                            GaiaUtils.MakeTextureReadable(DragAndDrop.objectReferences[0] as Texture2D);
                            GaiaUtils.MakeTextureUncompressed(DragAndDrop.objectReferences[0] as Texture2D);
                            m_scanner.LoadTextureFile(DragAndDrop.objectReferences[0] as Texture2D);
                            m_scanMessage = "Dropped Object recognized as a texture";
                            m_scanner.m_scannerObjectType = ScannerObjectType.Texture;
                            finished = true;
                            EditorUtility.ClearProgressBar();
                            break;
                        }

                        //Check for terrains
                        case GameObject _:
                        {
                            GameObject go = DragAndDrop.objectReferences[0] as GameObject;
                            Terrain    t  = go.GetComponentInChildren <Terrain>();
                            //Handle a terrain
                            if (t != null)
                            {
                                EditorUtility.DisplayProgressBar("Processing Terrain", "Processing terrain to mask texture", 0.5f);
                                m_scanner.LoadTerain(t);
                                m_scanMessage = "Dropped Object recognized as terrain";
                                m_scanner.m_scannerObjectType = ScannerObjectType.Terrain;
                                finished = true;
                                EditorUtility.ClearProgressBar();
                            }

                            //Check for a mesh - this means we can scan it
                            if (!finished)
                            {
                                MeshFilter[] filters = go.GetComponentsInChildren <MeshFilter>();
                                for (int idx = 0; idx < filters.Length; idx++)
                                {
                                    if (filters[idx].sharedMesh != null)
                                    {
                                        m_scanMessage = "Dropped Object recognized as mesh";
                                        m_scanner.m_scannerObjectType = ScannerObjectType.Mesh;
                                        m_scanner.m_lastScannedMesh   = go;
                                        m_scanner.LoadGameObject(go);
                                        finished = true;
                                    }
                                }
                            }
                            break;
                        }
                        }
                    }

                    //If we got to here then we couldnt process it
                    if (!finished)
                    {
                        Debug.LogWarning("Object type not supported by scanner. Ignored");
                        m_scanMessage = "Object type not supported by scanner.";
                        m_scanner.m_scannerObjectType = ScannerObjectType.Unkown;
                        m_scanner.m_objectScanned     = false;
                    }
                    else
                    {
                        m_scanner.m_objectScanned = true;
                    }
                }
                break;
            }
            }
        }