public GameLiftClient(GameLift _gl)
    {
        gl       = _gl;
        playerId = Guid.NewGuid().ToString();
        Credentials.Install();
        CreateGameLiftClient();

        // Use command line alias if possible, otherwise use default (hard coded alias)
        string[] args = System.Environment.GetCommandLineArgs();
        for (int i = 0; i < args.Length - 1; i++)
        {
            if (args[i] != "--alias")
            {
                continue;
            }

            string pattern = @"alias-[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}";
            Match  m       = Regex.Match(args[i + 1], pattern);
            if (m.Success)
            {
                aliasId = m.Value;
                Debug.Log(":) ALIAS RECOGNIZED. Alias " + aliasId + " found on command line");
                break;
            }
        }

        // verify alias exists
        if (aglc != null)
        {
            try
            {
                var dareq = new Amazon.GameLift.Model.DescribeAliasRequest();
                dareq.AliasId = aliasId;
                Amazon.GameLift.Model.DescribeAliasResponse dares = aglc.DescribeAlias(dareq);
                Amazon.GameLift.Model.Alias alias = dares.Alias;
                Debug.Log((int)dares.HttpStatusCode + " ALIAS NAME: " + alias.Name + " (" + aliasId + ")");
                if (alias.RoutingStrategy.Type == Amazon.GameLift.RoutingStrategyType.TERMINAL)
                {
                    Debug.Log("             (TERMINAL ALIAS)");
                }
            }
            catch (Exception e)
            {
                Debug.Log("AWS Credentials found but probably invalid. Check IAM permissions for the credentials.");
                Debug.Log(e.Message);
            }
        }
    }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>  
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            DescribeAliasResponse response = new DescribeAliasResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;
            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Alias", targetDepth))
                {
                    var unmarshaller = AliasUnmarshaller.Instance;
                    response.Alias = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return response;
        }
    public GameLiftClient(GameLift _gl)
    {
        gl       = _gl;
        playerId = Guid.NewGuid().ToString();
        Credentials.Install();

        // Use command line alias if possible, otherwise use default (hard coded alias)
        string[] args = System.Environment.GetCommandLineArgs();
        for (int i = 0; i < args.Length - 1; i++)
        {
            if (args[i] != "--alias")
            {
                //Debug.Log(":( Unrecognized command line parameter: " + args[i] + " (consider --alias <aliasId>)" + Environment.NewLine);
                continue;
            }

            string pattern = @"alias-[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}";
            Match  m       = Regex.Match(args[i + 1], pattern);
            if (m.Success)
            {
                aliasId = m.Value;
                Debug.Log(":) ALIAS RECOGNIZED. Alias " + aliasId + " found on command line");
                break;
            }
        }

        // verify alias exists
        var config = new AmazonGameLiftConfig();

        config.RegionEndpoint = Amazon.RegionEndpoint.USEast1;
        AmazonGameLiftClient aglc = null;
        AWSCredentials       credentials;

        var  chain        = new CredentialProfileStoreChain();
        bool profileFound = chain.TryGetAWSCredentials("demo-gamelift-unity", out credentials);

        if (profileFound)
        {
            Debug.Log("demo-gamelift-unity profile");
            aglc = new AmazonGameLiftClient(credentials, config);
        }
        else
        {
            Debug.Log("regular profile search");
            try
            {
                aglc = new AmazonGameLiftClient(config);
            }
            catch (AmazonServiceException e)
            {
                Debug.Log(e.Message);
                Debug.Log("AWS Credentials not found. Cannot connect to GameLift. Start application with -credentials <file> flag where credentials are the credentials.csv file containing the access and secret key.");
            }
        }
        if (aglc != null)
        {
            try
            {
                var dareq = new Amazon.GameLift.Model.DescribeAliasRequest();
                dareq.AliasId = aliasId;
                Amazon.GameLift.Model.DescribeAliasResponse dares = aglc.DescribeAlias(dareq);
                Amazon.GameLift.Model.Alias alias = dares.Alias;
                Debug.Log((int)dares.HttpStatusCode + " ALIAS NAME: " + alias.Name + " (" + aliasId + ")");
                if (alias.RoutingStrategy.Type == Amazon.GameLift.RoutingStrategyType.TERMINAL)
                {
                    Debug.Log("             (TERMINAL ALIAS)");
                }
            }
            catch (Exception e)
            {
                Debug.Log("AWS Credentials found but probably invalid. Check IAM permissions for the credentials.");
                Debug.Log(e.Message);
            }
            finally
            {
                aglc.Dispose();
            }
        }
    }