コード例 #1
0
        private void LoadMoveData(NetIncomingMessage msg, ServerControllable ctrl)
        {
            var moveSpeed    = msg.ReadFloat();
            var moveCooldown = msg.ReadFloat();
            var totalSteps   = (int)msg.ReadByte();
            var curStep      = (int)msg.ReadByte();

            pathData.Clear();
            if (totalSteps > 0)             //should always be true but whatever
            {
                pathData.Add(ReadPosition(msg));
                var i = 1;
                while (i < totalSteps)
                {
                    var b = msg.ReadByte();
                    pathData.Add(pathData[i - 1].AddDirection((Direction)(b >> 4)));
                    i++;
                    if (i < totalSteps)
                    {
                        pathData.Add(pathData[i - 1].AddDirection((Direction)(b & 0xF)));
                        i++;
                    }
                }
            }
            //for (var i = 0; i < totalSteps; i++)
            //	pathData.Add(ReadPosition(msg));

            //if(ctrl.Id == PlayerId)
            //	Debug.Log("Doing move for player!");

            ctrl.StartMove(moveSpeed, moveCooldown, totalSteps, curStep, pathData);
        }
コード例 #2
0
        private IEnumerator DamageEvent(int damage, float delay, int hitCount, ServerControllable target)
        {
            yield return(new WaitForSeconds(delay));

            if (target != null && target.SpriteAnimator.IsInitialized)
            {
                for (var i = 0; i < hitCount; i++)
                {
                    var go     = GameObject.Instantiate(DamagePrefab, target.transform.localPosition, Quaternion.identity);
                    var di     = go.GetComponent <DamageIndicator>();
                    var red    = target.SpriteAnimator.Type == SpriteType.Player;
                    var height = target.SpriteAnimator.SpriteData.Size / 50f;
                    di.DoDamage(damage, target.gameObject.transform.localPosition, height,
                                target.SpriteAnimator.Direction, red, false);
                    yield return(new WaitForSeconds(0.2f));
                }
            }
        }