public void Init() { ClientAssetRepository clientAssetRepo = GameFacade.Instance.RetrieveProxy <ClientAssetRepository>(); XmlDocument mXmlSoundDocument = XmlUtility.LoadXmlDocument(SOUND_LOOKUP_TABLE_XML_PATH); // TODO: Remove this loading hack. XmlNodeList soundNodes = mXmlSoundDocument.SelectNodes("Sounds/Sound"); mSoundsLeftToLoad = soundNodes.Count; foreach (XmlNode soundNode in soundNodes) { string name = soundNode.SelectSingleNode("Name").InnerText; SoundName soundName = (SoundName)Enum.Parse(typeof(SoundName), name); string path = soundNode.SelectSingleNode("Path").InnerText; //Console.WriteLine("Loading sound: " + name + ", " + path); clientAssetRepo.LoadAssetFromPath <SoundAsset>(path, delegate(SoundAsset asset) { RetrieveSoundAssetFromRepoOnLoad(soundName, asset); }); } mMainCamera = GameFacade.Instance.RetrieveMediator <CameraManagerMediator>().MainCamera; }
public DefaultAvatarAnimationStateMachine(AvatarEntity avatarEntity) : base(avatarEntity) { mWalkSpeedDocument = XmlUtility.LoadXmlDocument(PATH_TO_ANIMATION_SPEEDS); mAvatarEntity = avatarEntity; // Build the walk and idle states GetWalkAnimationFromAvatar(); GetIdleAnimationFromAvatar(); avatarEntity.RegisterForWalkAnimationChange(GetWalkAnimationFromAvatar); avatarEntity.RegisterForIdleAnimationChange(GetIdleAnimationFromAvatar); }
public LocalAvatarEntity(GameObject avatarBodyGameObject, GameObject headGameObject) : base(avatarBodyGameObject, headGameObject) { mAvatarDna = new Dna(); mChangesToDna = new Dna(); List <AssetInfo> assetInfos = new List <AssetInfo>(); XmlDocument defaultsDoc = XmlUtility.LoadXmlDocument("resources://Avatar/DefaultAssetList"); foreach (XmlNode defaultAssetNode in defaultsDoc.SelectNodes("DefaultAssets/Asset")) { string stringSubType = XmlUtility.GetStringAttribute(defaultAssetNode, "AssetSubType"); if (stringSubType == null) { throw new XmlException("Could not retrieve asset sub type string from node: " + defaultAssetNode); } AssetInfo assetInfo = new ClientAssetInfo(defaultAssetNode); assetInfos.Add(assetInfo); } mDefaultDna.SetDna(assetInfos); }
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); }
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(); }