Close

First SO: WatsonCredentials (username, password, url)

A project log for Watson Speech AI meets Unity 3D ScriptableObject

Connecting IBM Watson AI Speech-Text and Tonal Analysis web services with Unity3d ScriptableObject Data Architecture

jerry-isdaleJerry Isdale 04/19/2018 at 07:120 Comments

Project in UnityCollab with mashup import of my older, IBM cs code, Hipple SO github. Then started playing with how to merge in ScriptableObject...

First step is noticing that the IBM Credentials (username, password, url) are perfect candidates for ScriptableObject.  So I created two tests

one using strings, one using StringVariables.  

To the client code (WatsonService) the SO and SO_Simple are identical.  Using StringVariables takes more steps in Editor setting up SOs etc.  May be easier to do it _Simple way.  There are fewer steps and Assets created, unless you want to compose at that granularity.

I’ll leave both techniques in the code to show alternatives and how it affects the project.

Here is the basic code for now…

public class WatsonCredentialsSO_Simple : ScriptableObject 
{
    [SerializeField]
    private string _username ;
    [SerializeField]
    private string _password ;
    [SerializeField]
    private string _url ;

    public string Username
    {
        get { return _username; }
        set { _username = value; }
    }
    public string Password
    {
        get { return _password; }
        set { _password = value; }
    }
    public string URL
    {
        get { return _url; }
        set { _url.Value = value; }
    }

}

[CreateAssetMenu]
public class WatsonCredentialsSO : ScriptableObject 
{
    [SerializeField]
    private StringVariable _username ;
    [SerializeField]
    private StringVariable _password ;
    [SerializeField]
    private StringVariable _url ;

    public string Username
    {
        get { return _username.Value; }
        set { _username.Value = value; }
    }
    public string Password
    {
        get { return _password.Value; }
        set { _password.Value = value; }
    }
    public string URL
    {
        get { return _url.Value; }
        set { _url.Value = value; }
    }

}


ublic class WatsonSTT_TAService : MonoBehaviour 
{

    [SerializeField]
    WatsonCredentialsSO stt_credentialSO;
    [SerializeField]
    WatsonCredentialsSO_Simple ta_credentialSO;

    private Credentials credentials_STT;
    private Credentials credentials_TA;

    void Awake (){
        print("Speech2Text user: " + stt_credentialSO.Username);
        print("Speech2Text  pwd: " + stt_credentialSO.Password);
        print("Speech2Text  url: " + stt_credentialSO.URL);

        print("ToneAnalysis user: " + ta_credentialSO.Username);
        print("ToneAnalysis  pwd: " + ta_credentialSO.Password);
        print("ToneAnalysis  url: " + ta_credentialSO.URL);

        credentials_STT = new Credentials(
            stt_credentialSO.Username,
            stt_credentialSO.Password,
            stt_credentialSO.URL);
        
        credentials_TA = new Credentials(
            ta_credentialSO.Username,
            ta_credentialSO.Password,
            ta_credentialSO.URL);

    }
    
    // Update is called once per framevoid Update () {
        
    }
}


oh my that doesnt paste in very well at all does it? 

Discussions