Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

How to use from UnityEditor script? #37

Closed
bugttle opened this issue Mar 26, 2015 · 7 comments
Closed

How to use from UnityEditor script? #37

bugttle opened this issue Mar 26, 2015 · 7 comments

Comments

@bugttle
Copy link

bugttle commented Mar 26, 2015

Hi, thanks nice the sdk.
I have tried a sample project, it looks nice. There seems to be created instance of AWSPrefab(AmazonInitializer). But, I'd like to connect to S3 server from UnityEditor script. Not in game, for example:

[MenuItem("AWS/ListObjects")]
public static void AWSListObjects() {
    // It's a just sample. It's called when menu selected.
    var client = new AmazonS3Client();
    client.ListObjectsAsync();
}

I got the error:

Exception: AWSPrefab is not added to the scene
Amazon.S3.AmazonS3Client.ListObjectsAsync (Amazon.S3.Model.ListObjectsRequest request, Amazon.Runtime.AmazonServiceCallback callback, System.Object state) (at Assets/SDK/AWSUnitySDK/S3/Amazon.S3/AmazonS3Client.cs:252)

How to use or do you have any plan?
Thank you.

@karthiksaligrama
Copy link
Contributor

You can add the AWSPrefab dynamically using something like PrefabUtility and add it as a component before you make any client calls.

@bugttle
Copy link
Author

bugttle commented Mar 27, 2015

Thank you for the response.
Yes, I did it, and got same error before question. First, AWSPrefab drag and drop on the current scene Hierarchy. Second, create the below script in my project. Third, invoke script from menu ([AWS] > [ListObjectsRequest]). *Important: I don't push Play button.

using UnityEngine;
using UnityEditor;
using Amazon.S3;
using Amazon.S3.Model;
using Amazon.Unity3D;
using Amazon.Runtime;

public class AWSTest {
    static string bucketName = "";
    static string awsAccessKeyId = "";
    static string awsSecretAccessKey = "";
    static AWSRegion region = AWSRegion.APNortheast1;

    [MenuItem("AWS/ListObjectsRequest")]
    static void AWSListObjectsRequest() {
        // load service endpoints from config file
        Amazon.RegionEndpoint.LoadEndpointDefinitions ();

        var aws = GameObject.Find("AWSPrefab").gameObject;
        // add other scripts
        aws.AddComponent<AmazonMainThreadDispatcher> ();
        aws.AddComponent<AmazonNetworkStatusInfo> ();

        // create client instance
        var client = new AmazonS3Client(awsAccessKeyId, awsSecretAccessKey, region.GetRegionEndpoint());
        var request = new ListObjectsRequest () {
            BucketName = bucketName
        };
        client.ListObjectsAsync (request, ListObjectsCallback, null);
    }

    static void ListObjectsCallback(AmazonServiceResult result) {
        if (result.Exception == null) {
            var response = result.Response as ListObjectsResponse;
            foreach (var obj in response.S3Objects) {
                Debug.Log ("Find object: " + obj.Key);
            }
        } else {
            Debug.LogException (result.Exception);
        }
    }
}

AmazonInitializer.IsInitialized is false. Unity has Editor extension system. Do you have workaround?

        public void ListObjectsAsync (ListObjectsRequest request, AmazonServiceCallback callback, object state)
        {
            if (!AmazonInitializer.IsInitialized)
                throw new Exception ("AWSPrefab is not added to the scene");

@karthiksaligrama
Copy link
Contributor

Looks like with the current SDK you cant completely implement the API's in the editor. It will need some tweaking in the design. I'll add this as a feature request and into our backlog.

@bugttle
Copy link
Author

bugttle commented Apr 5, 2015

I understand, thanks! I'm looking forward to it.

@lordmortis
Copy link

Is there any movement on this?

@lordmortis
Copy link

I guess for now i'll work around it by having the game running but paused when doing an editor thing

@karthiksaligrama
Copy link
Contributor

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants