Example #1
0
 public void RegisterForeignAvatar(AvatarEntity foreignAvatar, DistributedObjectId doId)
 {
     mForeignAvatarEntities.Add(new KeyValuePair <DistributedObjectId, AvatarEntity>(doId, foreignAvatar));
     if (mHideForeignAvatars)
     {
         HideForeignAvatars();
     }
 }
Example #2
0
        private void SetupDownloadedAvatar(AvatarEntity avatarEntity, IEnumerable <Asset> loadedAssets, Action <AvatarEntity> avatarEntityLoadedCallback)
        {
            avatarEntity.AvatarAssetController.SetAssets(loadedAssets);

            // TODO: Make these paths less hard coded.
            CharacterMediator.AddAnimationClipToRig(avatarEntity.UnityGameObject, "Avatar/F_walk_normal_loop");
            CharacterMediator.AddAnimationClipToRig(avatarEntity.UnityGameObject, "Avatar/F_idle_normal_loop");

            avatarEntityLoadedCallback(avatarEntity);
        }
Example #3
0
        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);
        }
Example #4
0
        public DefaultAvatarState(AvatarEntity avatarEntity)
        {
            if (avatarEntity == null)
            {
                throw new ArgumentNullException("avatarEntity");
            }

            mAvatarAnimationComponent = avatarEntity.UnityGameObject.GetComponent(typeof(Animation)) as Animation;
            if (mAvatarAnimationComponent == null)
            {
                throw new Exception("Could not find animation component on the Avatar entity.");
            }
        }
Example #5
0
        public void RemoveForeignAvatarEntity(DistributedObjectId foreignAvatarDistributedObjectId)
        {
            AvatarEntity        foreignAvatarEntity    = null;
            List <AvatarEntity> foreignAvatarsToRemove = new List <AvatarEntity>();

            if (mForeignAvatarEntities.TryGetValue(foreignAvatarDistributedObjectId, out foreignAvatarEntity))
            {
                foreignAvatarsToRemove.Add(foreignAvatarEntity);
                foreignAvatarEntity.Dispose();
            }

            mForeignAvatarEntities.Remove(foreignAvatarDistributedObjectId);

            foreignAvatarsToRemove.Clear();
        }
Example #6
0
        protected virtual void LoadAssetsCoroutine(XmlDocument assetItemsDoc, AvatarEntity avatarEntity)
        {
            ClientAssetRepository clientAssetRepository = GameFacade.Instance.RetrieveProxy <ClientAssetRepository>();

            if (clientAssetRepository == null)
            {
                throw new Exception("Cannot LoadAssets until the ClientAssetRepository is set up (it's set up during the APPLICATION_INIT notification.");
            }

            List <AssetInfo> requestedAssetInfos = new List <AssetInfo>(ParseAssetInfos(assetItemsDoc));

            clientAssetRepository.GetAssets <Asset>(requestedAssetInfos, delegate(IEnumerable <Asset> assets)
            {
                avatarEntity.SetAssetsWithCallback(requestedAssetInfos as IEnumerable <AssetInfo>, AvatarEntityLoadedCallback);
            });
        }
        public override void EnterState()
        {
            //Console.WriteLine("GreenScreenRoomDefaultCameraState.EnterState");
            AvatarEntity localAvatar = GameFacade.Instance.RetrieveMediator <AvatarMediator>().LocalAvatarEntity;

            //TODO: Get rid of these hardcoded values, have them be set up by the room object or the avatar object.
            Vector3 position = new Vector3(0.0f, 2.35f, 6.15f);
            Vector3 scale    = new Vector3(2.0f, 0.4f, 0.5f);

            mBoxContainer = new BoxContainer(position, scale);

            mFixedAngleFollowView = new FixedAngleFollowView(mCameraTargetTransform, localAvatar.UnityGameObject.transform, new Vector3(0.0f, 180.0f, 0.0f), mBoxContainer);
            mFixedAngleFollowView.TargetOffset      = AVATAR_TRANSFORM_OFFSET;
            mFixedAngleFollowView.minFollowDistance = 1.0f;

            mFixedAngleFollowView.StartTracking();
        }
        public AvatarAnimationStateMachine(AvatarEntity avatarEntity)
        {
            if (avatarEntity == null)
            {
                throw new ArgumentNullException("avatarEntity");
            }
            Animation animationComponent = avatarEntity.UnityGameObject.GetComponent(typeof(Animation)) as Animation;

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

            mAnimationComponent = animationComponent;
            mAnimationComponent.playAutomatically = false;
            mAnimationComponent.Stop();
        }
        protected override void AvatarEntityLoadedCallback(AvatarEntity avatar)
        {
            base.AvatarEntityLoadedCallback(avatar);

            this.Entity = avatar;

            IState avatarStartState = new DefaultForeignAvatarState(avatar as ForeignAvatarEntity);

            this.StateMachine.CurrentState.AddTransition(avatarStartState);
            this.StateMachine.TransitionToState(avatarStartState);

            // TODO: This next line might not be doing anything.
            mAvatar.SetActiveRecursively(true);

            GameFacade.Instance.RetrieveMediator <AvatarMediator>().RegisterForeignAvatar(this.AvatarEntity, this.DistributedObjectId);

            base.AvatarEntityLoadedRunBufferedMessages();
        }
Example #10
0
        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();
        }
Example #11
0
        protected IEnumerator <IYieldInstruction> WaitForAnimationProxyToLoadThenLoadAvatar(XmlDocument assetItemsDoc, AvatarEntity avatarEntity)
        {
            yield return(new YieldWhile(delegate()
            {
                return !GameFacade.Instance.RetrieveProxy <ClientAssetRepository>().Loaded;
            }));

            LoadAssetsCoroutine(assetItemsDoc, avatarEntity);
        }
Example #12
0
 protected virtual void AvatarEntityLoadedCallback(AvatarEntity avatar)
 {
     // TODO: Make these paths less hard coded.
     //CharacterMediator.AddAnimationClipToRig(avatar.UnityGameObject, "Avatar/F_walk_normal_loop");
     //CharacterMediator.AddAnimationClipToRig(avatar.UnityGameObject, "Avatar/F_idle_normal_loop");
 }