Exemplo n.º 1
0
        public ServerControllable InstantiateMonster(ref MonsterSpawnParameters param)
        {
            if (!isInitialized)
            {
                Initialize();
            }

            var mData = monsterClassLookup[4000];             //poring

            if (monsterClassLookup.TryGetValue(param.ClassId, out var lookupData))
            {
                mData = lookupData;
            }
            else
            {
                Debug.LogWarning("Failed to find monster with id of " + param.ClassId);
            }

            if (mData.SpriteName.Contains(".prefab"))
            {
                return(PrefabMonster(mData, ref param));
            }

            var go = new GameObject(mData.Name);

            go.layer = LayerMask.NameToLayer("Characters");
            go.transform.localScale = new Vector3(1.5f * mData.Size, 1.5f * mData.Size, 1.5f * mData.Size);
            var control = go.AddComponent <ServerControllable>();

            control.CharacterType = CharacterType.Monster;
            control.SpriteMode    = ClientSpriteType.Sprite;
            go.AddComponent <Billboard>();

            var child = new GameObject("Sprite");

            child.layer = LayerMask.NameToLayer("Characters");
            child.transform.SetParent(go.transform, false);
            child.transform.localPosition = Vector3.zero;

            var sprite = child.AddComponent <RoSpriteAnimator>();

            sprite.Controllable = control;

            control.SpriteAnimator = sprite;
            control.SpriteAnimator.SpriteOffset = mData.Offset;
            control.ShadowSize = mData.ShadowSize;
            control.IsAlly     = false;

            control.ConfigureEntity(param.ServerId, param.Position, param.Facing);

            AddressableUtility.LoadRoSpriteData(go, "Assets/Sprites/Monsters/" + mData.SpriteName, control.SpriteAnimator.OnSpriteDataLoad);
            if (mData.ShadowSize > 0)
            {
                AddressableUtility.LoadSprite(go, "shadow", control.AttachShadow);
            }

            return(control);
        }
Exemplo n.º 2
0
        public ServerControllable InstantiatePlayer(ref PlayerSpawnParameters param)
        {
            if (!isInitialized)
            {
                Initialize();
            }

            var pData = playerClassLookup[0];             //novice

            if (playerClassLookup.TryGetValue(param.ClassId, out var lookupData))
            {
                pData = lookupData;
            }
            else
            {
                Debug.LogWarning("Failed to find player with id of " + param.ClassId);
            }

            var hData = playerHeadLookup[0];             //default;

            if (playerHeadLookup.TryGetValue(param.HeadId, out var lookupData2))
            {
                hData = lookupData2;
            }
            else
            {
                Debug.LogWarning("Failed to find player head with id of " + param.ClassId);
            }


            var go = new GameObject(pData.Name);

            go.layer = LayerMask.NameToLayer("Characters");
            go.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f);
            var control = go.AddComponent <ServerControllable>();

            go.AddComponent <Billboard>();

            var body = new GameObject("Sprite");

            body.layer = LayerMask.NameToLayer("Characters");
            body.transform.SetParent(go.transform, false);
            body.transform.localPosition = Vector3.zero;
            body.AddComponent <SortingGroup>();

            var head = new GameObject("Head");

            head.layer = LayerMask.NameToLayer("Characters");
            head.transform.SetParent(body.transform, false);
            head.transform.localPosition = Vector3.zero;

            var bodySprite = body.AddComponent <RoSpriteAnimator>();
            var headSprite = head.AddComponent <RoSpriteAnimator>();

            control.SpriteAnimator = bodySprite;
            control.CharacterType  = CharacterType.Player;
            control.SpriteMode     = ClientSpriteType.Sprite;
            control.IsAlly         = true;
            control.IsMale         = param.IsMale;

            bodySprite.Controllable = control;
            if (param.State == CharacterState.Moving)
            {
                bodySprite.ChangeMotion(SpriteMotion.Walk);
            }
            bodySprite.ChildrenSprites.Add(headSprite);
            bodySprite.SpriteOffset = 0.5f;
            bodySprite.HeadFacing   = param.HeadFacing;

            if (param.State == CharacterState.Sitting)
            {
                bodySprite.State = SpriteState.Sit;
            }
            if (param.State == CharacterState.Moving)
            {
                bodySprite.State = SpriteState.Walking;
            }

            headSprite.Parent      = bodySprite;
            headSprite.SpriteOrder = 1;

            control.ShadowSize = 0.5f;

            var bodySpriteName = param.IsMale ? pData.SpriteMale : pData.SpriteFemale;
            var headSpriteName = param.IsMale ? hData.SpriteMale : hData.SpriteFemale;

            if (param.ClassId == 0)
            {
                var weaponSpriteFile = param.IsMale ? "Assets/Sprites/Weapons/Novice/Male/초보자_남_1207.spr" : "Assets/Sprites/Weapons/Novice/Female/초보자_여_1207.spr";

                var weapon = new GameObject("Weapon");
                weapon.layer = LayerMask.NameToLayer("Characters");
                weapon.transform.SetParent(body.transform, false);
                weapon.transform.localPosition = Vector3.zero;

                var weaponSprite = weapon.AddComponent <RoSpriteAnimator>();

                weaponSprite.Parent      = bodySprite;
                weaponSprite.SpriteOrder = 2;

                bodySprite.ChildrenSprites.Add(weaponSprite);

                AddressableUtility.LoadRoSpriteData(go, weaponSpriteFile, weaponSprite.OnSpriteDataLoad);
            }

            control.ConfigureEntity(param.ServerId, param.Position, param.Facing);

            AddressableUtility.LoadRoSpriteData(go, bodySpriteName, bodySprite.OnSpriteDataLoad);
            AddressableUtility.LoadRoSpriteData(go, headSpriteName, headSprite.OnSpriteDataLoad);
            AddressableUtility.LoadSprite(go, "shadow", control.AttachShadow);

            return(control);
        }