protected override void AvatarEntityLoadedCallback(AvatarEntity avatar) { Console.WriteLine("LocalAvatarEntityLoadedCallback"); base.AvatarEntityLoadedCallback(avatar); mLocalAvatarEntity = avatar as LocalAvatarEntity; if (mLocalAvatarEntity == null) { throw new Exception("Could not cast avatarEntity as LocalAvatarEntity"); } PhysicMaterial physMaterial = new PhysicMaterial("Main Character Physics Material"); physMaterial.bouncyness = 0.0f; physMaterial.dynamicFriction = 0.0f; physMaterial.dynamicFriction2 = 0.0f; physMaterial.frictionDirection = Vector3.zero; physMaterial.frictionDirection2 = Vector3.zero; physMaterial.frictionCombine = PhysicMaterialCombine.Minimum; physMaterial.staticFriction = 0.0f; physMaterial.staticFriction2 = 0.0f; CapsuleCollider capsuleCollider = mAvatar.AddComponent(typeof(CapsuleCollider)) as CapsuleCollider; capsuleCollider.material = physMaterial; Rigidbody rigidbody = mAvatar.GetComponent(typeof(Rigidbody)) as Rigidbody; if (rigidbody == null) { rigidbody = mAvatar.AddComponent(typeof(Rigidbody)) as Rigidbody; } rigidbody.freezeRotation = true; rigidbody.detectCollisions = true; rigidbody.angularDrag = 0.0f; Component[] renderers = mAvatar.GetComponentsInChildren(typeof(Renderer)); foreach (Component c in renderers) { Renderer r = c as Renderer; for (int x = 0; x < r.materials.Length; ++x) { Texture2D tex = r.materials[x].mainTexture as Texture2D; Shader shader = Shader.Find("Avatar/Saturation Shader"); r.materials[x] = new Material(shader); r.materials[x].mainTexture = tex; } } XmlDocument avatarProperties = XmlUtility.LoadXmlDocument("resources://XmlDocuments/FirstMilestone/PrototypeAvatarProperties"); try { // Randomize the starting position in X and Z List <float> xPositions = new List <float>(); List <float> zPositions = new List <float>(); for (int i = -2; i <= 2; ++i) { xPositions.Add(0.5f * i); } for (int j = 0; j <= 6; ++j) { zPositions.Add(0.5f * j); } int xIndex = new System.Random().Next(xPositions.Count); int zIndex = new System.Random().Next(zPositions.Count); float xPosition = xPositions[xIndex]; float zPosition = zPositions[zIndex]; float yPosition = 0.02221f; mAvatar.transform.position = new Vector3(xPosition, yPosition, zPosition); XmlNode colliderNode = avatarProperties.SelectSingleNode("/Avatar/collider"); capsuleCollider.center = new Vector3(float.Parse(colliderNode.SelectSingleNode("center/x").InnerText), float.Parse(colliderNode.SelectSingleNode("center/y").InnerText), float.Parse(colliderNode.SelectSingleNode("center/z").InnerText)); capsuleCollider.height = float.Parse(colliderNode.SelectSingleNode("height").InnerText); capsuleCollider.radius = float.Parse(colliderNode.SelectSingleNode("radius").InnerText); } catch (NullReferenceException e) { throw new Exception("Error loading XML from 'resources://XmlDocuments/FirstMilestone/PrototypeAvatarProperties'", e); } catch (FormatException e) { throw new Exception("Error loading XML from 'resources://XmlDocuments/FirstMilestone/PrototypeAvatarProperties'", e); } catch (XmlException e) { throw new Exception("Error loading XML from 'resources://XmlDocuments/FirstMilestone/PrototypeAvatarProperties'", e); } this.Entity = mLocalAvatarEntity; this.Coroutines.Add(Scheduler.StartCoroutine(TelemetryBroadcast())); GameFacade.Instance.RetrieveMediator <AvatarMediator>().AddLocalAvatarEntity(mLocalAvatarEntity, this.DistributedObjectId); mLocalAvatarStateMachine = new LocalAvatarStateMachine(mLocalAvatarEntity); GameFacade.Instance.RegisterMediator(mLocalAvatarStateMachine); GameFacade.Instance.SendNotification(GameFacade.LOCAL_AVATAR_LOADED); base.AvatarEntityLoadedRunBufferedMessages(); }
/// <summary> /// Update store buttons from xml data returned by server /// </summary> private void UpdateStoreButtons() { if (mCurrentSearchResultsXml != null) { XmlNodeList itemOfferList = mCurrentSearchResultsXml.SelectNodes("/Response/store/itemOffers/itemOffer"); int i = 0; foreach (XmlElement itemOfferNode in itemOfferList) { //string description = itemOfferNode.GetAttribute("description"); XmlElement itemNode = (XmlElement)itemOfferNode.SelectSingleNode("item"); string thumbnailUrl = ConvertPaymentItemsUrl(itemNode.GetAttribute("smallImageUrl")); // Fill in details of button XmlElement itemOfferElement = itemOfferNode; Button currentButton = (Button)mGridItemButtons[i].Value; //currentButton.Text = itemName; GuiFrame buttonFrame = mGridItemButtons[i].Key; Image thumbnail = buttonFrame.SelectSingleElement <Image>("Thumbnail"); buttonFrame.Showing = true; Label price = buttonFrame.SelectSingleElement <Label>("PriceLabel"); XmlNode moneyNode = itemOfferNode.SelectSingleNode("price/money"); price.Text = FormatPrice(XmlUtility.GetStringAttribute(moneyNode, "amount")); Image priceIcon = buttonFrame.SelectSingleElement <Image>("PriceIcon"); if (XmlUtility.GetStringAttribute(moneyNode, "currencyName") == "VCOIN") { priceIcon.Texture = mGameCurrencyIcon; } else { priceIcon.Texture = mRealMoneyIcon; } currentButton.ClearOnPressedActions(); currentButton.Text = "Loading..."; currentButton.Enabled = false; currentButton.AddOnPressedAction(delegate() { GridItemSelected(buttonFrame, itemOfferElement, itemNode); }); // If no thumbnail, don't load anything. // TODO: should we load a default image? if (thumbnailUrl != "") { ApplyImageToButton(thumbnailUrl, currentButton, thumbnail); } else { currentButton.Text = "No Image."; } i++; } for (int j = i; j < mBlockSize; ++j) { ClearButton(mGridItemButtons[j].Value); } } else { Console.LogError("no items found in store response"); } }