Exemple #1
0
    private void Awake()
    {
        EntityPrefabs = new Dictionary <ModelType, GameObject>();
        foreach (var entity in EntityCollection)
        {
            EntityPrefabs.Add(entity.GetComponent <Entity>().ModelType, entity);
        }

        _instance = this;
    }
        void HandleCollection(SpawnCollection collection)
        {
            collection.Clear();
            if (collection.spline == null)
            {
                return;
            }
            while (collection.objects.Count > spawnCount && collection.objects.Count >= 0)
            {
                collection.Destroy(collection.objects.Count - 1);
            }
            int orderIndex = 0;

            while (collection.objects.Count < spawnCount)
            {
                switch (iteration)
                {
                case Iteration.Ordered:
                    collection.Spawn(objects[orderIndex], Vector3.zero, Quaternion.identity);
                    orderIndex++;
                    if (orderIndex >= objects.Count)
                    {
                        orderIndex = 0;
                    }
                    break;

                case Iteration.Random:
                    collection.Spawn(objects[orderRandom.Next(objects.Count)], Vector3.zero, Quaternion.identity);
                    break;
                }
            }
            float splineLength = 0f;

            if (uniform)
            {
                splineLength = collection.spline.CalculateLength() * (float)(clipTo - clipFrom);
            }
            for (int i = 0; i < spawnCount; i++)
            {
                double percent = 0.0;
                if (spawnCount > 1)
                {
                    percent = (double)i / (spawnCount - 1);
                }
                double evaluate = 0.0;
                if (uniform)
                {
                    evaluate = collection.spline.Travel(clipFrom, splineLength * (float)percent, Spline.Direction.Forward);
                }
                else
                {
                    evaluate = DMath.Lerp(clipFrom, clipTo, percent);
                }
                //Handle uniform splines
                evaluate += positionOffset;
                if (evaluate > 1f)
                {
                    evaluate -= 1f;
                }
                else if (evaluate < 0f)
                {
                    evaluate += 1f;
                }
                collection.spline.Evaluate(result, evaluate);
                HandleObject(collection.objects[i]);
            }
        }
Exemple #3
0
    void Awake()
    {
        MasterClientManager = FindObjectOfType <MasterClientManager>();

        //Force SpawnCollection Awake() method for initialization
        SpawnCollection spawnCollection = FindObjectOfType <SpawnCollection>();

        spawnCollection.gameObject.SetActive(false);
        spawnCollection.gameObject.SetActive(true);

        //Force SkillCollection Awake() method for initialization
        SkillCollection skillList = FindObjectOfType <SkillCollection>();

        skillList.gameObject.SetActive(false);
        skillList.gameObject.SetActive(true);

        AuthoryClient = new AuthoryClient(MasterClientManager.GetMapServerAuthString());
        AuthoryClient.Connect(MasterClientManager.MapServerIP, MasterClientManager.MapServerPort, MasterClientManager.MapServerUID);

        NetIncomingMessage msgIn;
        bool     playerInfoArrived = false;
        DateTime start             = DateTime.Now.AddSeconds(5);

        while (playerInfoArrived != true)
        {
            if (start < DateTime.Now)
            {
                return;
            }
            else
            {
                while ((msgIn = AuthoryClient.Client.ReadMessage()) != null)
                {
                    if (msgIn.MessageType == NetIncomingMessageType.Data)
                    {
                        if (((MessageType)msgIn.ReadByte()) == MessageType.PlayerID)
                        {
                            ushort Id   = msgIn.ReadUInt16();
                            string Name = msgIn.ReadString();

                            int maxHealth = msgIn.ReadInt32();
                            int health    = msgIn.ReadInt32();

                            int maxMana = msgIn.ReadInt32();

                            int mana = msgIn.ReadInt32();

                            byte      level     = msgIn.ReadByte();
                            ModelType modelType = (ModelType)msgIn.ReadByte();


                            float x             = msgIn.ReadFloat();
                            float z             = msgIn.ReadFloat();
                            float movementSpeed = msgIn.ReadFloat();

                            ushort END = msgIn.ReadUInt16();
                            ushort STR = msgIn.ReadUInt16();
                            ushort AGI = msgIn.ReadUInt16();
                            ushort INT = msgIn.ReadUInt16();
                            ushort KNW = msgIn.ReadUInt16();
                            ushort LCK = msgIn.ReadUInt16();

                            long experience    = msgIn.ReadInt64();
                            long maxExperience = msgIn.ReadInt64();

                            AuthoryClient.Handler.SetMapSize(msgIn.ReadInt32());

                            GameObject entity = AuthoryClient.Handler.GetEntityObjectByModelType(modelType).gameObject;

                            GameObject.Destroy(entity.GetComponent <Entity>());

                            PlayerEntity playerEntity = entity.AddComponent <PlayerEntity>();
                            entity.AddComponent <PlayerMove>();

                            Camera.main.GetComponent <CameraOrbit>().Target = playerEntity.transform;

                            AuthoryData.Instance.SetPlayer(playerEntity, Id, Name);

                            playerEntity.transform.position = new Vector3(x, 0, z);

                            playerEntity.SetMaxHealth(maxHealth);
                            playerEntity.SetHealth((ushort)health);

                            playerEntity.SetMaxMana(maxMana);
                            playerEntity.SetMana((ushort)mana);

                            playerEntity.Level = level;

                            playerEntity.MovementSpeed = movementSpeed;

                            playerEntity.Attributes.Endurance    = END;
                            playerEntity.Attributes.Strength     = STR;
                            playerEntity.Attributes.Agility      = AGI;
                            playerEntity.Attributes.Intelligence = INT;
                            playerEntity.Attributes.Knowledge    = KNW;
                            playerEntity.Attributes.Luck         = LCK;

                            AuthoryClient.UIController.Player = playerEntity;
                            AuthoryClient.UIController.UpdateMaxExperience(maxExperience, experience);

                            playerInfoArrived = true;
                            break;
                        }
                    }
                }
            }
        }
        AuthorySender.Movement();
    }