/// <summary> /// Called once in every frame. /// </summary> void Update() { // Check selected asset type in every frame and enable/disable button if selected gender has assets. if (m_lastSelectedAssetType != AvatarCreatorContext.selectedAssetType) { if (m_assetGender == AssetGender.NoGender) { m_assetList = AvatarCreatorContext.GetLoadedAssetsByType(AvatarCreatorContext.selectedAssetType); } else { m_assetList = AvatarCreatorContext.GetLoadedAssetsByTypeAndGender(AvatarCreatorContext.selectedAssetType, m_assetGender); } if (m_assetList.Count > 0) { gameObject.GetComponent <Button>().interactable = true; } else { gameObject.GetComponent <Button>().interactable = false; } m_lastSelectedAssetType = AvatarCreatorContext.selectedAssetType; } }
/// <summary> /// Loads file from given URL. /// </summary> /// <param name="url">File URL.</param> /// <returns>Return variable not used.</returns> IEnumerator LoadFile(string url) { WWW file = new WWW(url); yield return(file); AvatarCreatorContext.LoadAvatarFromFile(file.text); }
/// <summary> /// Populates scroll list with assets in selected asset type. /// </summary> /// <param name="assetType">Asset type</param> private void FillScrollList(AssetType assetType) { // Fetch all assets in given asset type and instantiate buttons for them. foreach (CBaseAsset asset in AvatarCreatorContext.GetLoadedAssetsByType(assetType)) { GameObject btn = Instantiate(Resources.Load <GameObject>("asset_selection_button")); btn.GetComponent <UIScrollViewButtonController>().faceAsset = asset; btn.transform.SetParent(scrollView, false); } }
/// <summary> /// Called in every button press. /// </summary> public void OnButtonClick() { // Generate random avatar. AvatarCreatorContext.faceObject.GenerateRandomAvatar(); // Update asset category list. AvatarCreatorContext.UpdateAssetCategoryList(); // Log user action. AvatarCreatorContext.logManager.LogAction("UIButtonClick", "CreateRandomAvatar"); }
/// <summary> /// Saves user's all of recorded logs to server. /// </summary> /// <returns></returns> public string DumpLogs() { Debug.Log("LogManager:DumpLogs(): Dumping logs to server."); m_actionLogs.Append("</Actions>\n"); string data = "<SaveFile>\n" + AvatarCreatorContext.SerializeUIFields() + AvatarCreatorContext.faceObject.Serialize() + "\n" + m_actionLogs.ToString() + "</SaveFile>"; StartCoroutine(PHPRequest(data)); return(data); }
/// <summary> /// Called in every value change. /// </summary> public void ValueChangeCheck() { // Get the value and convert it to integer. int realismLevel = System.Convert.ToInt32(gameObject.GetComponent <Slider>().value); // Set current realism level. AvatarCreatorContext.currentRealismLevel = (RealismLevel)realismLevel; // Invoke SetFaceObjectPart. It will update the asset with current selected realism level. AvatarCreatorContext.faceObject.SetFaceObjectPart(null); // Update category list. AvatarCreatorContext.UpdateAssetCategoryList(); // Log user action. AvatarCreatorContext.logManager.LogAction("RealismLevelChanged", AvatarCreatorContext.currentRealismLevel.ToString()); }
/// <summary> /// Called once in every frame. /// </summary> void Update() { // Enable/disable the button according to current selected asset's modify flags. if (m_lastSelectedAsset != AvatarCreatorContext.selectedAssetType) { CBaseAsset checkAsset = AvatarCreatorContext.GetLoadedAssetsByType(AvatarCreatorContext.selectedAssetType)[0]; if ((checkAsset.GetModifyFlags() & m_buttonType) != 0) { gameObject.GetComponent <Button>().interactable = true; } else { gameObject.GetComponent <Button>().interactable = false; } m_lastSelectedAsset = AvatarCreatorContext.selectedAssetType; } }
/// <summary> /// Called in every button press. /// </summary> public void OnButtonPointerDown() { // Delegate the operation according to button type. if (m_buttonType == ButtonType.ScreenShotButton) { AvatarCreatorContext.takeScreenShot = true; } else if (m_buttonType == ButtonType.LoadButton) { AvatarCreatorContext.fileTransferManager.UploadFile(); } else if (m_buttonType == ButtonType.SaveButton) { AvatarCreatorContext.SaveAvatarToFile(); } // Log user action. AvatarCreatorContext.logManager.LogAction("UIButtonClick", m_buttonType.ToString()); }
/// <summary> /// Deserializes given data and loads it to FaceObject. /// </summary> /// <param name="data">Serialized XML data.</param> public void Unserialize(string data) { Debug.Log("FaceObjectController:Unserialize()\n" + data); // Initialization AssetType assetType = AssetType.None; string objectName = ""; string assetName = ""; Vector3 position = new Vector3(); Quaternion rotation = new Quaternion(); Vector3 scale = new Vector3(); Color color = new Color(); XmlDocument doc = new XmlDocument(); doc.LoadXml(data); XmlNode root = doc.DocumentElement.SelectSingleNode("/SaveFile/FaceObject"); foreach (XmlNode node in root.ChildNodes) { foreach (XmlAttribute attr in node.Attributes) { switch (attr.Name) { case "name": { objectName = attr.Value; break; } case "asset": { assetName = attr.Value; break; } case "type": { assetType = (AssetType)System.Enum.Parse(typeof(AssetType), attr.Value); break; } case "posx": { position.x = float.Parse(attr.Value); break; } case "posy": { position.y = float.Parse(attr.Value); break; } case "posz": { position.z = float.Parse(attr.Value); break; } case "rotx": { rotation.x = float.Parse(attr.Value); break; } case "roty": { rotation.y = float.Parse(attr.Value); break; } case "rotz": { rotation.z = float.Parse(attr.Value); break; } case "rotw": { rotation.w = float.Parse(attr.Value); break; } case "scalex": { scale.x = float.Parse(attr.Value); break; } case "scaley": { scale.y = float.Parse(attr.Value); break; } case "scalez": { scale.z = float.Parse(attr.Value); break; } case "color": { ColorUtility.TryParseHtmlString("#" + attr.Value, out color); break; } } } Debug.Log(objectName + " " + assetName); if (assetName == "") { continue; } CBaseAsset asset = AvatarCreatorContext.FindAssetByName(assetName); if (asset == null) { asset = new CBaseAsset(AssetGender.NoGender, assetType, 0, ""); } GameObject gObject = GameObject.Find(objectName); if (gObject) { gObject.transform.position = position; gObject.transform.rotation = rotation; gObject.transform.localScale = scale; if (gObject.GetComponent <Image>() != null) { gObject.GetComponent <Image>().color = color; } } SetFaceObjectPart(asset, false); } }
/// <summary> /// Generates a random avatar. /// </summary> public void GenerateRandomAvatar() { // Head shape List <CBaseAsset> tempAssets = AvatarCreatorContext.GetLoadedAssetsByType(AssetType.HeadShape); SetFaceObjectPart(tempAssets[Random.Range(0, tempAssets.Count)], false); // Ears tempAssets = AvatarCreatorContext.GetLoadedAssetsByType(AssetType.Ears); SetFaceObjectPart(tempAssets[Random.Range(0, tempAssets.Count)], false); // Hair tempAssets = AvatarCreatorContext.GetLoadedAssetsByType(AssetType.Hair); SetFaceObjectPart(tempAssets[Random.Range(0, tempAssets.Count)], false); // Eyes tempAssets = AvatarCreatorContext.GetLoadedAssetsByType(AssetType.Eyes); SetFaceObjectPart(tempAssets[Random.Range(0, tempAssets.Count)], false); // Eyebrows tempAssets = AvatarCreatorContext.GetLoadedAssetsByType(AssetType.Eyebrows); SetFaceObjectPart(tempAssets[Random.Range(0, tempAssets.Count)], false); // Nose tempAssets = AvatarCreatorContext.GetLoadedAssetsByType(AssetType.Nose); SetFaceObjectPart(tempAssets[Random.Range(0, tempAssets.Count)], false); // Lips tempAssets = AvatarCreatorContext.GetLoadedAssetsByType(AssetType.Mouth); SetFaceObjectPart(tempAssets[Random.Range(0, tempAssets.Count)], false); // Moustache - Removed due to request //tempAssets = AvatarCreatorContext.GetLoadedAssetsByType(AssetType.Moustache); //SetFaceObjectPart(tempAssets[Random.Range(0, tempAssets.Count)], false); // Beard - Removed due to request //tempAssets = AvatarCreatorContext.GetLoadedAssetsByType(AssetType.Beard); //SetFaceObjectPart(tempAssets[Random.Range(0, tempAssets.Count)], false); // Body tempAssets = AvatarCreatorContext.GetLoadedAssetsByType(AssetType.Body); SetFaceObjectPart(tempAssets[Random.Range(0, tempAssets.Count)], false); //// Facetexture //tempAssets = AvatarCreatorContext.GetLoadedAssetsByType(AssetType.FaceTexture); //SetFaceObjectPart(tempAssets[Random.Range(0, tempAssets.Count)], false); // Skin color AvatarCreatorContext.selectedAssetType = AssetType.HeadShape; List <Color> colorList = AvatarCreatorContext.GetPaletteColors(ColorPalette.Skin); Color skinColor = colorList[Random.Range(0, colorList.Count)]; ChangeAssetColor(skinColor); // FaceTexture AvatarCreatorContext.selectedAssetType = AssetType.FaceTexture; ChangeAssetColor(skinColor); if (m_transforms[AssetType.FaceTexture].GetComponent <Image>().sprite != null) { tempAssets = AvatarCreatorContext.GetLoadedAssetsByType(AssetType.FaceTexture); SetFaceObjectPart(tempAssets[Random.Range(0, tempAssets.Count)], false); } // Hair color AvatarCreatorContext.selectedAssetType = AssetType.Hair; colorList = AvatarCreatorContext.GetPaletteColors(ColorPalette.Default); Color color = colorList[Random.Range(0, colorList.Count)]; ChangeAssetColor(color); // Beard color AvatarCreatorContext.selectedAssetType = AssetType.Beard; ChangeAssetColor(color); // Moustache color AvatarCreatorContext.selectedAssetType = AssetType.Moustache; ChangeAssetColor(color); // Eyebrows color AvatarCreatorContext.selectedAssetType = AssetType.Eyebrows; ChangeAssetColor(color); // Background tempAssets = AvatarCreatorContext.GetLoadedAssetsByType(AssetType.BackgroundTexture); AvatarCreatorContext.selectedAssetType = AssetType.BackgroundTexture; SetFaceObjectPart(tempAssets[Random.Range(0, tempAssets.Count)], false); ChangeAssetColor(colorList[Random.Range(0, colorList.Count)]); // Default selected category AvatarCreatorContext.selectedAssetType = AssetType.Body; }