/// <summary>
        /// Authenticate with the server using secret client credentials
        /// </summary>
        protected void OnClientAuthenticateRequest(KnetikCloudClientAuthenticateRequestEvent e)
        {
            if (e.CloudCredentials == null)
            {
                KnetikLogger.LogError("The 'CloudCredentials' cannot be null!");
                return;
            }

            if (!e.CloudCredentials.IsConfigured)
            {
                KnetikLogger.LogError("The cloud credentials are not configured properly.  Please set them up in the editor window!");
                return;
            }

            SetupAccessTokenHelper();

            try
            {
                // Get access token
                mAccessTokenApi.GetOAuthToken(e.CloudCredentials.GrantType, mProjectSettings.ClientId, e.CloudCredentials.ClientSecret, null, null, null, null);
            }
            catch (KnetikException)
            {
                // Error is already logged
            }
        }
        /// <summary>
        /// Authenticate with the server using either a Google or Facebook open auth token.
        /// </summary>
        protected void OnTokenAuthenticateRequest(KnetikCloudTokenAuthenticateRequestEvent e)
        {
            if (e.TokenCredentials == null)
            {
                KnetikLogger.LogError("The 'tokenCredentials' cannot be null!");
                return;
            }

            if (!e.TokenCredentials.IsConfigured)
            {
                KnetikLogger.LogError("The token credentials are not configured properly.  Please set the token from the auth provider correctly.");
                return;
            }

            SetupAccessTokenHelper();

            try
            {
                // Get access token
                mAccessTokenApi.GetOAuthToken(e.TokenCredentials.GrantType, mProjectSettings.ClientId, null, null, null, e.TokenCredentials.Token, null);
            }
            catch (KnetikException)
            {
                // Error is already logged
            }
        }
Example #3
0
        private static void CreateDirectoriesInPath(string directoryPath)
        {
            if (string.IsNullOrEmpty(directoryPath))
            {
                KnetikLogger.LogError("Unity directory is empty!");
                return;
            }

            if (!DoesPathContainTrailingSlash(directoryPath))
            {
                directoryPath += KnetikAssetDatabaseUtils.DirectorySeparator;
            }

            // Ensure directory separators are correct
            directoryPath = directoryPath.Replace(KnetikAssetDatabaseUtils.OppositeDirectorySeparator, KnetikAssetDatabaseUtils.DirectorySeparator);

            string[] folders = directoryPath.Split(KnetikAssetDatabaseUtils.DirectorySeparator);

            // Error if path does NOT start from Assets
            if (folders[0] != KnetikAssetDatabaseUtils.AssetsFolderName)
            {
                string exceptionMessage = string.Format("Create Directories requires a full Unity path, including '{0}{1}'.", KnetikAssetDatabaseUtils.AssetsFolderName, KnetikAssetDatabaseUtils.DirectorySeparator);
                throw new KnetikException(0, exceptionMessage);
            }

            string pathToFolder = string.Empty;

            foreach (string folder in folders)
            {
                // Don't check for or create empty folders
                if (string.IsNullOrEmpty(folder))
                {
                    continue;
                }

                // Create folders that don't exist
                pathToFolder = string.Concat(pathToFolder, folder);

                if (!AssetDatabase.IsValidFolder(pathToFolder))
                {
                    string pathToParent = Directory.GetParent(pathToFolder).ToString();
                    AssetDatabase.CreateFolder(pathToParent, folder);
                    AssetDatabase.Refresh();
                }

                pathToFolder = string.Concat(pathToFolder, KnetikAssetDatabaseUtils.DirectorySeparator);
            }
        }
Example #4
0
        public void Publish(IKnetikEvent e)
        {
            UnityEngine.Debug.Assert(e != null, "Event System - parameter 'e' cannot be null!");

            EventPublisherBase subscriber = GetEventPublisherBase(e.GetType());

            if (subscriber != null)
            {
                try
                {
                    subscriber.PostEvent(e);
                }
                catch (Exception ex)
                {
                    KnetikLogger.LogError(string.Format("There was an error processing an event! Event: {0} : {1}, Reason: {2}.", e.GetType(), e, ex));
                }
            }
        }
        protected override void Awake()
        {
            // Load project settings
            mProjectSettings = KnetikCloudProjectSettings.Load();
            if (mProjectSettings == null)
            {
                KnetikLogger.LogError("Unable to load project settings - please set them up in the editor window!");
                return;
            }

            if (!mProjectSettings.IsConfiguredProperly)
            {
                KnetikLogger.LogError("The project settings are not setup correctly - please set them in the editor window!");
                return;
            }

            KnetikGlobalEventSystem.Subscribe <KnetikCloudUserAuthenticateRequestEvent>(OnUserAuthenticateRequest);
            KnetikGlobalEventSystem.Subscribe <KnetikCloudClientAuthenticateRequestEvent>(OnClientAuthenticateRequest);
            KnetikGlobalEventSystem.Subscribe <KnetikCloudTokenAuthenticateRequestEvent>(OnTokenAuthenticateRequest);

            base.Awake();
        }