예제 #1
0
        // Retrieve all the config values we need to start up
        public void SetConfiguration(ConfigManagerClient configManager)
        {
            GameFacade.Instance.RetrieveMediator <LoggerMediator>().Logger.Log("SetConfiguration start", LogLevel.Info);
            mIpAddress = configManager.GetString("state_server_location", "127.0.0.1");
            mStageName = configManager.GetString("instance_name", "DEV");


            mWebEntryPointId = configManager.GetString("web_entry_point", FunnelGlobals.FASHION_MINIGAME);

            mAssetBaseUrl = configManager.GetString("asset_base_url", ProtocolUtility.GetAssetDataPath());
            GameFacade.Instance.RetrieveMediator <LoggerMediator>().Logger.Log("asssetBaseUrl " + mAssetBaseUrl, LogLevel.Info);

            mWebServicesBaseUrl = configManager.GetString("web_services_base_url", "http://services.hangoutdev.net");
            GameFacade.Instance.RetrieveMediator <LoggerMediator>().Logger.Log("web_services_base_url " + mWebServicesBaseUrl, LogLevel.Info);

            mCampaignId = configManager.GetString("campaign_id", "NO_VALUE_FROM_JS");
            mReferrerId = configManager.GetString("inviter_id", "NO_VALUE_FROM_JS");
            GameFacade.Instance.RetrieveMediator <LoggerMediator>().Logger.Log("campaign_id " + mCampaignId, LogLevel.Info);

            GameFacade.Instance.RetrieveMediator <LoggerMediator>().Logger.Log("inviter_id " + mReferrerId, LogLevel.Info);
            mSelectedAvatar = new AvatarId((uint)configManager.GetInt("selected_avatar", 1));
            GameFacade.Instance.RetrieveMediator <LoggerMediator>().Logger.Log("mSelectedAvatar " + mSelectedAvatar, LogLevel.Info);

            mFacebookAccountId = configManager.GetLong("fb_account_id", 0);
            GameFacade.Instance.RetrieveMediator <LoggerMediator>().Logger.Log("mFacebookAccountId " + mFacebookAccountId, LogLevel.Info);
            mSessionKey = configManager.GetString("fb_session_key", "");
            GameFacade.Instance.RetrieveMediator <LoggerMediator>().Logger.Log("mSessionKey " + mSessionKey, LogLevel.Info);
            mNickName  = configManager.GetString("fake_nickname", "");
            mFirstName = configManager.GetString("fake_first_name", "");
            mLastName  = configManager.GetString("fake_last_name", "");
            GameFacade.Instance.RetrieveMediator <LoggerMediator>().Logger.Log("fake_nickname " + mNickName, LogLevel.Info);
            GameFacade.Instance.RetrieveMediator <LoggerMediator>().Logger.Log("fake_first_name " + mFirstName, LogLevel.Info);
            GameFacade.Instance.RetrieveMediator <LoggerMediator>().Logger.Log("fake_last_name " + mLastName, LogLevel.Info);
            GameFacade.Instance.RetrieveMediator <LoggerMediator>().Logger.Log("SetConfiguration finished", LogLevel.Info);
        }
예제 #2
0
        public static XmlDocument LoadXmlDocument(string documentPath)
        {
            Pair <string, string> split = ProtocolUtility.SplitProtocol(documentPath);
            string protocol             = split.First;
            string path = split.Second;

            if (protocol == "assets")
            {
                throw new Exception("LoadXmlDocument does not support asynchronous protocols (" + protocol + ").  Use Client Asset Repository.");
            }

            XmlDocument result = new XmlDocument();

            switch (protocol)
            {
            case "resources":
                TextAsset styleTextAsset = (TextAsset)Resources.Load(path);
                if (styleTextAsset == null)
                {
                    throw new FileNotFoundException("Unable to load the TextFile from resource path: " + path);
                }
                result.LoadXml(styleTextAsset.text);
                break;

            case "file":
                FileInfo file = new FileInfo(path);
                if (!file.Exists)
                {
                    throw new FileNotFoundException(documentPath + " must point to an existing file on disk.", file.FullName);
                }
                result.Load(file.FullName);
                break;

            default:
                throw new Exception("Unrecognized protocol (" + protocol + ")");
            }

            // Remove all the comment nodes (this feels like it shouldn't be necessary, but the comments end up getting parsed in weird places as Nodes)
            List <XmlNode> toRemove = new List <XmlNode>();

            foreach (XmlNode node in result.SelectNodes("//comment()"))
            {
                toRemove.Add(node);
            }
            foreach (XmlNode node in toRemove)
            {
                node.ParentNode.RemoveChild(node);
            }

            return(result);
        }
예제 #3
0
        private string UniqueKey(AssetInfo assetInfo)
        {
            string path = assetInfo.Path;

            if (path == null)
            {
                Console.Log("NULL Path");
                Console.Log("Null path assetinfo = " + assetInfo);                //, assetId = " + assetInfo.AssetId.Value.ToString());
                Console.Log("Null path asstId = " + assetInfo.AssetId);           //, assetId = " + assetInfo.AssetId.Value.ToString());
            }
            if (path == "" || ProtocolUtility.SplitProtocol(path).First == "resources")
            {
                return(AssetId.AssetIdNamespace + assetInfo.AssetId.Value.ToString());
            }
            else
            {
                return(path);
            }
        }
예제 #4
0
        public TweakablesHandler(string path, object objectWithTweakableFields)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (objectWithTweakableFields == null)
            {
                throw new ArgumentNullException("objectWithTweakableFields");
            }

            mTweakedObject = objectWithTweakableFields;

            if (Application.isEditor)
            {
                string   pathInResources = ProtocolUtility.SplitProtocol(path).Second;
                FileInfo fileInfo        = new FileInfo(Application.dataPath + "/Resources/" + pathInResources + ".xml");

                if (!fileInfo.Exists)
                {
                    throw new FileNotFoundException(fileInfo.FullName);
                }

                mWatcher = new FileWatcher(fileInfo);

                mWatcher.Changed += delegate()
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(fileInfo.FullName);
                    LoadTweakables(doc);
                };
            }

            XmlDocument resourcesDoc = XmlUtility.LoadXmlDocument(path);

            LoadTweakables(resourcesDoc);
        }
예제 #5
0
        private void LoadUnityObjectFromPath <T>(string path, Action <UnityEngine.Object> loadedAssetCallback) where T : Asset
        {
            try
            {
                //This hack is here because we don't have an empty texture on the web yet.  We need to figure out how to handle that.
                if (path == "")
                {
                    UnityEngine.Object unityEngineObject = Resources.Load("EmptyTexture");
                    if (unityEngineObject == null)
                    {
                        throw new Exception("Could not instantiate Empty Texture.");
                    }

                    loadedAssetCallback(unityEngineObject);
                    return;
                }

                Pair <string> protocolAndPath   = ProtocolUtility.SplitAndResolve(path);
                string        loadAssetProtocol = protocolAndPath.First;
                string        resourcePath      = protocolAndPath.Second;
                if (loadAssetProtocol == "http" || loadAssetProtocol == "file" || loadAssetProtocol == "assets")
                {
                    //If the repo is already downloading from the path, the callback
                    //is added to this dictionary which gets called when the object at
                    //said path is finished downloading.
                    if (mCallbacksForFinishedDownloadAtPath.ContainsKey(resourcePath))
                    {
                        //If we've downloaded the path before we'll have the key but nothing in
                        //the list so we have to download it again.
                        mCallbacksForFinishedDownloadAtPath[resourcePath].Add(loadedAssetCallback);
                    }
                    else
                    {
                        List <Action <UnityEngine.Object> > downloadCompleteCallbacks = new List <Action <UnityEngine.Object> >();
                        downloadCompleteCallbacks.Add(loadedAssetCallback);
                        mCallbacksForFinishedDownloadAtPath.Add(resourcePath, downloadCompleteCallbacks);

                        if (typeof(T) == typeof(TextureAsset) || typeof(T) == typeof(ImageAsset) || typeof(T) == typeof(Asset))
                        {
                            LoadTextureAssetFromWeb(resourcePath, loadedAssetCallback);
                        }
                        else if (typeof(T) == typeof(SoundAsset))
                        {
                            LoadSoundAssetFromWeb(resourcePath, loadedAssetCallback);
                        }
                        else if (typeof(T) == typeof(UnityEngineAsset) || typeof(T) == typeof(RigAnimationAsset))
                        {
                            LoadLateBoundUnityObject(resourcePath, loadedAssetCallback);
                        }
                        else
                        {
                            throw new Exception("ClientAssetRepository doesn't know how to handle type: " + typeof(T).Name);
                        }
                    }
                }
                else if (loadAssetProtocol == "resources")
                {
                    if (resourcePath == "Avatar/Gabriella Templates")
                    {
                        loadedAssetCallback(mAvatarTemplate);
                        return;
                    }
                    UnityEngine.Object unityEngineObject = Resources.Load(resourcePath);
                    if (unityEngineObject == null)
                    {
                        throw new Exception("Could not instantiate object from path " + resourcePath + ".");
                    }

                    loadedAssetCallback(unityEngineObject);
                    return;
                }
                else
                {
                    throw new Exception("ClientAssetRepo does not know how to load an object with protocol: " + loadAssetProtocol);
                }
            }
            catch (System.Exception ex)
            {
                Console.LogError("Exception in LoadUnityObjectFromPath: " + path + " " + ex.ToString());
            }
        }
예제 #6
0
        public void LoadAssetFromPath <T>(string path, Action <T> loadedAssetCallback) where T : Asset
        {
            string uniqueKey = path;

            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            Asset loadedAsset;

            if (mAssetDictionary.TryGetValue(uniqueKey, out loadedAsset))
            {
                if (!(loadedAsset is T))
                {
                    throw new Exception("Asset loaded from " + path + " expected to be type: " + typeof(T).Name + ", actually was: " + loadedAsset.GetType());
                }
                loadedAssetCallback((T)loadedAsset);
            }
            // This might not ever be called.
            else if (typeof(T) == typeof(RigAnimationAsset))
            {
                LoadUnityObjectFromPath <RigAnimationAsset>(path, delegate(UnityEngine.Object loadedUnityObject)
                {
                    GameObject gameObject = (GameObject)GameObject.Instantiate(loadedUnityObject);
                    try
                    {
                        Animation animation = gameObject.GetComponent <Animation>();

                        Asset asset = new RigAnimationAsset(AssetSubType.NotSet, animation.clip, path, path, path, RigAnimationName.None);

                        if (!mAssetDictionary.ContainsKey(uniqueKey))
                        {
                            mAssetDictionary.Add(uniqueKey, asset);
                        }

                        loadedAssetCallback((T)asset);
                    }
                    finally
                    {
                        GameObject.Destroy(gameObject);
                    }
                });
            }
            else if (typeof(T) == typeof(UnityEngineAsset))
            {
                LoadUnityObjectFromPath <UnityEngineAsset>(path, delegate(UnityEngine.Object loadedUnityObject)
                {
                    Asset asset = new UnityEngineAsset(loadedUnityObject, path);
                    if (!mAssetDictionary.ContainsKey(uniqueKey))
                    {
                        mAssetDictionary.Add(uniqueKey, asset);
                    }

                    loadedAssetCallback((T)asset);
                });
            }
            else if (typeof(T) == typeof(SoundAsset))
            {
                LoadUnityObjectFromPath <SoundAsset>(path, delegate(UnityEngine.Object loadedUnityObject)
                {
                    AudioClip audioClip = loadedUnityObject as AudioClip;
                    if (audioClip == null)
                    {
                        throw new Exception("audioClip could not be cast from UnityEngine.Object");
                    }
                    Asset asset = new SoundAsset(audioClip, path);
                    if (!mAssetDictionary.ContainsKey(uniqueKey))
                    {
                        mAssetDictionary.Add(uniqueKey, asset);
                    }
                    loadedAssetCallback((T)asset);
                });
            }
            else if (typeof(T) == typeof(ImageAsset))
            {
                LoadUnityObjectFromPath <ImageAsset>(path, delegate(UnityEngine.Object loadedUnityObject)
                {
                    Texture2D texture = loadedUnityObject as Texture2D;
                    if (texture == null)
                    {
                        throw new Exception("texture could not be cast from UnityEngine.Object");
                    }
                    Asset asset = new ImageAsset(texture, path);
                    if (!mAssetDictionary.ContainsKey(uniqueKey))
                    {
                        mAssetDictionary.Add(uniqueKey, asset);
                    }
                    loadedAssetCallback((T)asset);
                });
            }
            else if (typeof(T) == typeof(XmlAsset))
            {
                string resolvedPath = ProtocolUtility.SplitAndResolve(path).Second;
                Console.WriteLine("resolved path for XmlAsset: " + resolvedPath + ", path = " + path);
                GameFacade.Instance.RetrieveMediator <SchedulerMediator>().Scheduler.StartCoroutine(DownloadText(resolvedPath, delegate(string wwwData)
                {
                    Asset result = new XmlAsset(wwwData, uniqueKey);
                    loadedAssetCallback((T)result);
                }));
            }
            else
            {
                throw new Exception("LoadAssetFromPath doesn't support " + typeof(T).Name);
            }
        }