コード例 #1
0
    public void Edit(OuyaMod ouyaMod)
    {
        using (OuyaMod.Editor editor = ouyaMod.edit())
        {
            //Debug.Log("Access to Editor");

            // Required fields:
            editor.setTitle("edit title");
            editor.setCategory("edit category");
            editor.setDescription("edit description");

            // replace file
            editor.deleteFile("level.dat");

            using (OutputStream os = editor.newFile("level.dat"))
            {
                os.write(System.Text.UTF8Encoding.UTF8.GetBytes("edit file"));
                os.close();
            }

            // remove old screenshot
            List <OuyaModScreenshot> screenshots = ouyaMod.getScreenshots();
            for (int index = 0; index < screenshots.Count; ++index)
            {
                using (OuyaModScreenshot ouyaModScreenshot = screenshots[index])
                {
                    editor.removeScreenshot(ouyaModScreenshot);
                }
            }

            // add new screenshot
            if (m_bitmapScreenshots.Length > 1)
            {
                Debug.Log("Adding screenshot");
                editor.addScreenshot(m_bitmapScreenshots[1]);
            }
            else
            {
                Debug.LogError("Missing screenshot");
            }

            // remove old tags
            foreach (string tag in ouyaMod.getTags())
            {
                editor.removeTag(tag);
            }

            // Add optional tags:
            editor.addTag("edit tag");

            // Add optional metadata for your own display:
            editor.setMetadata("edit meta data");

            OuyaUnityPlugin.saveOuyaMod(ouyaMod, editor);
        }
    }
コード例 #2
0
    void AddWidgets(List <OuyaMod> ouyaMods, bool searchByInstalled, bool searchByPublished)
    {
        StringBuilder sb = new StringBuilder();

        foreach (OuyaMod ouyaMod in ouyaMods)
        {
            WidgetOuyaMod widget = new WidgetOuyaMod()
            {
                m_instance          = ouyaMod,
                m_category          = ouyaMod.getCategory(),
                m_description       = ouyaMod.getDescription(),
                m_isDownloading     = ouyaMod.isDownloading(),
                m_isFlagged         = ouyaMod.isFlagged(),
                m_isInstalled       = ouyaMod.isInstalled(),
                m_isPublished       = ouyaMod.isPublished(),
                m_metaData          = ouyaMod.getMetaData(),
                m_ratingCount       = ouyaMod.getRatingCount(),
                m_ratingAverage     = ouyaMod.getRatingAverage(),
                m_title             = ouyaMod.getTitle(),
                m_userRating        = ouyaMod.getUserRating(),
                m_searchByInstalled = searchByInstalled,
                m_searchByPublished = searchByPublished,
            };
            if (sb.Length > 0)
            {
                sb.Remove(0, sb.Length);
            }
            foreach (string filename in ouyaMod.getFilenames())
            {
                sb.Append(filename);
                sb.Append(",");

                using (InputStream inputStream = ouyaMod.openFile(filename))
                {
                    byte[] buffer     = new byte[100000];
                    int    readAmount = inputStream.read(ref buffer);
                    inputStream.close();

                    byte[] copy = new byte[readAmount];
                    Array.Copy(buffer, copy, readAmount);

                    sb.Append("***");
                    string content = System.Text.UTF8Encoding.UTF8.GetString(copy);
                    sb.Append(content);
                }
            }
            widget.m_filenames = sb.ToString();
            List <OuyaModScreenshot> screenshots = ouyaMod.getScreenshots();
            widget.m_screenshots = new Texture2D[screenshots.Count];
            widget.m_thumbnails  = new Texture2D[screenshots.Count];
            for (int index = 0; index < screenshots.Count; ++index)
            {
                using (OuyaModScreenshot ouyaModScreenshot = screenshots[index])
                {
                    if (null != ouyaModScreenshot)
                    {
                        using (Bitmap bitmap = ouyaModScreenshot.getImage())
                        {
                            if (null != bitmap)
                            {
                                using (ByteArrayOutputStream stream = new ByteArrayOutputStream())
                                {
                                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                    if (stream.size() >= 0)
                                    {
                                        Texture2D texture = new Texture2D(0, 0);
                                        texture.LoadImage(stream.toByteArray());
                                        widget.m_screenshots[index] = texture;
                                    }
                                    stream.close();
                                }
                            }
                        }

                        using (Bitmap bitmap = ouyaModScreenshot.getThumbnail())
                        {
                            if (null != bitmap)
                            {
                                using (ByteArrayOutputStream stream = new ByteArrayOutputStream())
                                {
                                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                    if (stream.size() >= 0)
                                    {
                                        Texture2D texture = new Texture2D(0, 0);
                                        texture.LoadImage(stream.toByteArray());
                                        widget.m_thumbnails[index] = texture;
                                    }
                                    stream.close();
                                }
                            }
                        }
                    }
                }
            }
            if (sb.Length > 0)
            {
                sb.Remove(0, sb.Length);
            }
            foreach (string tag in ouyaMod.getTags())
            {
                sb.Append(tag);
                sb.Append(",");
            }
            widget.m_tags = sb.ToString();

            m_widgets.Add(widget);

            if (m_widgets.Count == 1)
            {
                m_focusManager.Mappings[m_btnCreate].Down       = widget.m_buttonPublish;
                m_focusManager.Mappings[widget.m_buttonPublish] = new FocusManager.ButtonMapping()
                {
                    Up    = m_btnCreate,
                    Right = widget.m_buttonDelete,
                };
                m_focusManager.Mappings[widget.m_buttonDelete] = new FocusManager.ButtonMapping()
                {
                    Up    = m_btnCreate,
                    Left  = widget.m_buttonPublish,
                    Right = widget.m_buttonDownload,
                };
                m_focusManager.Mappings[widget.m_buttonDownload] = new FocusManager.ButtonMapping()
                {
                    Up    = m_btnCreate,
                    Left  = widget.m_buttonDelete,
                    Right = widget.m_buttonRate,
                };
                m_focusManager.Mappings[widget.m_buttonRate] = new FocusManager.ButtonMapping()
                {
                    Up    = m_btnCreate,
                    Left  = widget.m_buttonDownload,
                    Right = widget.m_buttonEdit,
                };
                m_focusManager.Mappings[widget.m_buttonEdit] = new FocusManager.ButtonMapping()
                {
                    Up    = m_btnCreate,
                    Left  = widget.m_buttonRate,
                    Right = widget.m_buttonFlag,
                };
                m_focusManager.Mappings[widget.m_buttonFlag] = new FocusManager.ButtonMapping()
                {
                    Up   = m_btnCreate,
                    Left = widget.m_buttonEdit,
                };
            }
            else
            {
                WidgetOuyaMod lastWidget = m_widgets[m_widgets.Count - 2];
                m_focusManager.Mappings[lastWidget.m_buttonPublish].Down  = widget.m_buttonPublish;
                m_focusManager.Mappings[lastWidget.m_buttonDelete].Down   = widget.m_buttonDelete;
                m_focusManager.Mappings[lastWidget.m_buttonDownload].Down = widget.m_buttonDownload;
                m_focusManager.Mappings[lastWidget.m_buttonRate].Down     = widget.m_buttonRate;
                m_focusManager.Mappings[lastWidget.m_buttonEdit].Down     = widget.m_buttonEdit;
                m_focusManager.Mappings[lastWidget.m_buttonFlag].Down     = widget.m_buttonFlag;
                m_focusManager.Mappings[widget.m_buttonPublish]           = new FocusManager.ButtonMapping()
                {
                    Up    = lastWidget.m_buttonPublish,
                    Right = widget.m_buttonDelete,
                };
                m_focusManager.Mappings[widget.m_buttonDelete] = new FocusManager.ButtonMapping()
                {
                    Up    = lastWidget.m_buttonDelete,
                    Left  = widget.m_buttonPublish,
                    Right = widget.m_buttonDownload,
                };
                m_focusManager.Mappings[widget.m_buttonDownload] = new FocusManager.ButtonMapping()
                {
                    Up    = lastWidget.m_buttonDownload,
                    Left  = widget.m_buttonDelete,
                    Right = widget.m_buttonRate,
                };
                m_focusManager.Mappings[widget.m_buttonRate] = new FocusManager.ButtonMapping()
                {
                    Up    = lastWidget.m_buttonRate,
                    Left  = widget.m_buttonDownload,
                    Right = widget.m_buttonEdit,
                };
                m_focusManager.Mappings[widget.m_buttonEdit] = new FocusManager.ButtonMapping()
                {
                    Up    = lastWidget.m_buttonEdit,
                    Left  = widget.m_buttonRate,
                    Right = widget.m_buttonFlag,
                };
                m_focusManager.Mappings[widget.m_buttonFlag] = new FocusManager.ButtonMapping()
                {
                    Up   = lastWidget.m_buttonFlag,
                    Left = widget.m_buttonEdit,
                };
            }
        }
    }
コード例 #3
0
        public static List <OuyaModScreenshot> getOuyaModScreenshotList(IntPtr list)
        {
#if VERBOSE_LOGGING
            Debug.Log(string.Format("Invoking {0}...", MethodBase.GetCurrentMethod().Name));
#endif
            JNIFind();

            if (_jcOuyaUnityPlugin == IntPtr.Zero)
            {
                Debug.LogError("_jcOuyaUnityPlugin is not initialized");
                return(null);
            }
            if (_jmGetOuyaModScreenshotArray == IntPtr.Zero)
            {
                Debug.LogError("_jmGetOuyaModScreenshotArray is not initialized");
                return(null);
            }

            IntPtr result = AndroidJNI.CallStaticObjectMethod(_jcOuyaUnityPlugin, _jmGetOuyaModScreenshotArray, new jvalue[] { new jvalue()
                                                                                                                               {
                                                                                                                                   l = list
                                                                                                                               } });
            if (result == IntPtr.Zero)
            {
                Debug.LogError("_jmGetOuyaModScreenshotArray returned null");
                return(null);
            }

            List <OuyaModScreenshot> items = new List <OuyaModScreenshot>();

#if VERBOSE_LOGGING
            Debug.Log("Invoking AndroidJNI.FromObjectArray...");
#endif

            IntPtr[] resultArray = AndroidJNI.FromObjectArray(result);
            AndroidJNI.DeleteLocalRef(result);

#if VERBOSE_LOGGING
            Debug.Log("Invoked AndroidJNI.FromObjectArray.");
#endif

            foreach (IntPtr ptr in resultArray)
            {
#if VERBOSE_LOGGING
                Debug.Log("Found Bitmap making Global Ref...");
#endif
                IntPtr globalRef = AndroidJNI.NewGlobalRef(ptr);
                AndroidJNI.DeleteLocalRef(ptr);
#if VERBOSE_LOGGING
                Debug.Log("Made global ref for Bitmap.");
#endif
                OuyaModScreenshot item = new OuyaModScreenshot(globalRef);
#if VERBOSE_LOGGING
                Debug.Log("Deleting old local ref...");
#endif
                items.Add(item);
            }
#if VERBOSE_LOGGING
            Debug.Log("Deleting OuyaModScreenshot list reference...");
#endif
            return(items);
        }