Exemple #1
0
 void StartCreateAsset()
 {
     activeAsset = new LootLockerCommonAsset()
     {
         name = "untitleted", context = ContextNames[0]
     };
     currentView = LootLockerView.CreateAsset;
     SelectAssetBase();
 }
Exemple #2
0
        void DrawCreateFileView()
        {
            GUILayout.BeginArea(ContentSection);

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("Asset name: ");
            assetName = EditorGUILayout.TextField(assetName);

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("Asset Context ID: ");

            activeAsset = assetsResponse.assets[0];

            AssetContextIndex   = EditorGUILayout.Popup(AssetContextIndex, ContextNames);
            activeAsset.context = Contexts[AssetContextIndex].name;

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("Tags");

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("saperated by comma", new GUIStyle(GUI.skin.label)
            {
                fontSize = 10
            });
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            FileTags = EditorGUILayout.TextField(FileTags);

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();
            EditorGUILayout.Separator();

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button(string.IsNullOrEmpty(filePath) ? "Attach File" : "Choose a different file", GUILayout.Height(30), GUILayout.MaxWidth(200)))
            {
                filePath = EditorUtility.OpenFilePanel("Choose a file", "", "");
            }

            if (string.IsNullOrEmpty(filePath))
            {
                EditorGUILayout.Separator();
                EditorGUILayout.Separator();

                EditorGUILayout.LabelField("You must attach a file to be able to upload",
                                           new GUIStyle(GUI.skin.label)
                {
                    fontSize = 12, fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleLeft
                },
                                           GUILayout.MaxWidth(1000), GUILayout.Height(25));
            }
            else
            {
                EditorGUILayout.LabelField("File name: " + Path.GetFileName(filePath),
                                           new GUIStyle(GUI.skin.label)
                {
                    fontSize = 12, fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleLeft
                },
                                           GUILayout.MaxWidth(1000), GUILayout.Height(25));

                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Separator();
                EditorGUILayout.Separator();

                EditorGUILayout.BeginHorizontal();

                if (GUILayout.Button("Upload", GUILayout.Height(30)))
                {
                    currentView = LootLockerView.Loading;

                    var request = new LootLockerCreateAssetRequest()
                    {
                        name = assetName, context_id = Contexts[Array.IndexOf(ContextNames, activeAsset.context)].id
                    };

                    LootLockerSDKAdminManager.CreateAsset(request, (response) =>
                    {
                        if (response.success)
                        {
                            Debug.LogError("Asset created successfully. Uploading file..");

                            LootLockerSDKAdminManager.GetAssets((getAssetsResponse) =>
                            {
                                if (getAssetsResponse.success)
                                {
                                    Debug.Log("Successfully got uploaded asset: " + getAssetsResponse.text);

                                    LootLockerCommonAsset uploadedAsset = getAssetsResponse.assets[0];

                                    LootLockerSDKAdminManager.UploadAFile(filePath, uploadedAsset.id.ToString(), LootLockerAdminConfig.current.gameID, (uploadResponse) =>
                                    {
                                        if (uploadResponse.success)
                                        {
                                            Debug.Log("Successfully uploaded file: " + uploadResponse.text);
                                            PopulateFiles();
                                        }
                                        else
                                        {
                                            Debug.LogError("Failed to upload file: " + uploadResponse.Error);
                                            currentView = LootLockerView.CreateFile;
                                        }
                                    }, tags: FileTags.Split(','));
                                }
                                else
                                {
                                    Debug.LogError("Failed to get assets: " + getAssetsResponse.Error);
                                    currentView = LootLockerView.CreateFile;
                                }
                            });
                        }
                        else
                        {
                            Debug.LogError("failed to get create/update asset: " + response.Error);
                            currentView = LootLockerView.CreateFile;
                        }
                    });
                }
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();
            EditorGUILayout.Separator();
            EditorGUILayout.Separator();
            EditorGUILayout.Separator();

            if (GUILayout.Button("Back", GUILayout.Height(20)))
            {
                PopulateFiles();
            }

            GUILayout.EndArea();
        }