Beispiel #1
0
        public static Unit Create(Scene currentScene, UnitInfo unitInfo)
        {
            UnitComponent unitComponent = currentScene.GetComponent <UnitComponent>();
            Unit          unit          = unitComponent.AddChildWithId <Unit, int>(unitInfo.UnitId, unitInfo.ConfigId);

            unitComponent.Add(unit);

            unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z);
            unit.Forward  = new Vector3(unitInfo.ForwardX, unitInfo.ForwardY, unitInfo.ForwardZ);
            switch (unit.Type)
            {
            case UnitType.Monster:
            case UnitType.Player:
            {
                NumericComponent numericComponent = unit.AddComponent <NumericComponent>();
                for (int i = 0; i < unitInfo.Ks.Count; ++i)
                {
                    if (unitInfo.Ks[i] > NumericType.Max)                 //不需要同步最终值
                    {
                        numericComponent.Set(unitInfo.Ks[i], unitInfo.Vs[i], true);
                    }
                }

                unit.AddComponent <MoveComponent>();
                if (unitInfo.MoveInfo != null)
                {
                    if (unitInfo.MoveInfo.X.Count > 0)
                    {
                        using (ListComponent <Vector3> list = ListComponent <Vector3> .Create())
                        {
                            list.Add(unit.Position);
                            for (int i = 0; i < unitInfo.MoveInfo.X.Count; ++i)
                            {
                                list.Add(new Vector3(unitInfo.MoveInfo.X[i], unitInfo.MoveInfo.Y[i], unitInfo.MoveInfo.Z[i]));
                            }

                            unit.MoveToAsync(list).Coroutine();
                        }
                    }
                }
                unit.AddComponent <AOIUnitComponent, Vector3, Quaternion, UnitType>(unit.Position, unit.Rotation, unit.Type);
                CombatUnitComponent combatU;
                if (unitInfo.SkillIds != null)
                {
                    combatU = unit.AddComponent <CombatUnitComponent, List <int> >(unitInfo.SkillIds);
                }
                else
                {
                    combatU = unit.AddComponent <CombatUnitComponent>();
                }

                if (unitInfo.BuffIds != null && unitInfo.BuffIds.Count > 0)
                {
                    var buffC = combatU.GetComponent <BuffComponent>();
                    buffC.Init(unitInfo.BuffIds, unitInfo.BuffTimestamp);
                }

                unit.AddComponent <ObjectWait>();

                unit.AddComponent <XunLuoPathComponent>();
                break;
            }

            case UnitType.Skill:
            {
                NumericComponent numericComponent = unit.AddComponent <NumericComponent>();
                if (unitInfo.Ks != null && unitInfo.Ks.Count > 0)
                {
                    for (int i = 0; i < unitInfo.Ks.Count; ++i)
                    {
                        if (unitInfo.Ks[i] > NumericType.Max)                         //不需要同步最终值
                        {
                            numericComponent.Set(unitInfo.Ks[i], unitInfo.Vs[i], true);
                        }
                    }
                }
                unit.AddComponent <MoveComponent>();
                if (unitInfo.MoveInfo != null && unitInfo.MoveInfo.X.Count > 0)
                {
                    using (ListComponent <Vector3> list = ListComponent <Vector3> .Create())
                    {
                        list.Add(unit.Position);
                        for (int i = 0; i < unitInfo.MoveInfo.X.Count; ++i)
                        {
                            list.Add(new Vector3(unitInfo.MoveInfo.X[i], unitInfo.MoveInfo.Y[i], unitInfo.MoveInfo.Z[i]));
                        }

                        unit.MoveToAsync(list).Coroutine();
                    }
                }
                unit.AddComponent <AOIUnitComponent, Vector3, Quaternion, UnitType>(unit.Position, unit.Rotation, unit.Type);
                unit.AddComponent <ObjectWait>();
                break;
            }

            default:
            {
                Log.Error("没有处理 " + unit.Type);
                break;
            }
            }
            Game.EventSystem.PublishAsync(new EventType.AfterUnitCreate()
            {
                Unit = unit
            }).Coroutine();
            return(unit);
        }
Beispiel #2
0
        public static UnitInfo CreateUnitInfo(Unit unit)
        {
            UnitInfo unitInfo = new UnitInfo();

            unitInfo.UnitId   = unit.Id;
            unitInfo.ConfigId = unit.ConfigId;
            unitInfo.Type     = (int)unit.Type;
            Vector3 position = unit.Position;

            unitInfo.X = position.x;
            unitInfo.Y = position.y;
            unitInfo.Z = position.z;
            Vector3 forward = unit.Forward;

            unitInfo.ForwardX = forward.x;
            unitInfo.ForwardY = forward.y;
            unitInfo.ForwardZ = forward.z;

            #region 移动信息
            MoveComponent moveComponent = unit.GetComponent <MoveComponent>();
            if (moveComponent != null)
            {
                if (!moveComponent.IsArrived())
                {
                    unitInfo.MoveInfo = new MoveInfo();
                    for (int i = moveComponent.N; i < moveComponent.Targets.Count; ++i)
                    {
                        Vector3 pos = moveComponent.Targets[i];
                        unitInfo.MoveInfo.X.Add(pos.x);
                        unitInfo.MoveInfo.Y.Add(pos.y);
                        unitInfo.MoveInfo.Z.Add(pos.z);
                    }
                }
            }


            #endregion

            #region 数值信息

            NumericComponent nc = unit.GetComponent <NumericComponent>();
            if (nc != null)
            {
                foreach ((int key, long value) in nc.NumericDic)
                {
                    if (key > NumericType.Max) //不需要同步最终值
                    {
                        unitInfo.Ks.Add(key);
                        unitInfo.Vs.Add(value);
                    }
                }
            }
            #endregion

            #region 战斗数据

            var cuc = unit.GetComponent <CombatUnitComponent>();
            if (cuc != null)
            {
                //技能
                unitInfo.SkillIds.AddRange(cuc.IdSkillMap.Keys);
                var buffC = cuc.GetComponent <BuffComponent>();
                if (buffC != null)
                {
                    foreach (var item in buffC.Groups)
                    {
                        var buff = item.Value;
                        unitInfo.BuffIds.Add(buff.ConfigId);
                        unitInfo.BuffTimestamp.Add(buff.Timestamp);
                    }
                }
            }

            #endregion


            return(unitInfo);
        }