Exemple #1
0
        /// <summary>
        /// 新switch注册获取
        /// </summary>
        /// <param name="target"></param>
        /// <param name="grpId"></param>
        /// <param name="stateIndex"></param>
        /// <returns></returns>
        public AKSwitchAtom RegisterGetSwitch(GameObject target, int grpId, int stateIndex = -1)
        {
            AssertUtility.Assert(target != null);
            HashSet <AKSwitchAtom> switchAtoms;
            AKSwitchAtom           ret;

            if (gameobjectSwitchGrps.TryGetValue(target, out switchAtoms))
            {
                foreach (var atom in switchAtoms)
                {
                    if (atom.config.Id == grpId)
                    {
                        return(atom);
                    }
                }
                ret = new AKSwitchAtom(grpId, stateIndex, target);
                switchAtoms.Add(ret);
            }
            else
            {
                ret         = new AKSwitchAtom(grpId, stateIndex, target);
                switchAtoms = new HashSet <AKSwitchAtom>()
                {
                    ret
                };
                gameobjectSwitchGrps.Add(target, switchAtoms);
            }
            return(ret);
        }
Exemple #2
0
//        private void AssignAnimatorParameters(List<CompressedNetworkAnimatorParameter> leftParams,
//            List<CompressedNetworkAnimatorParameter> rightParams, float ratio)
        private void AssignAnimatorParameters(List <NetworkAnimatorParameter> leftParams, List <NetworkAnimatorParameter> rightParams, float ratio)
        {
//            AssertUtility.Assert(FloatAnimatorParameters.Count == leftParams.Count);
//            int count = FloatAnimatorParameters.Count;
//            for (int i = 0; i < count; i++)
//            {
//                FloatAnimatorParameters[i].Value = (short)(leftParams[i].Value + (rightParams[i].Value - leftParams[i].Value) * ratio);
//            }
//
//            if (AnimatorParameters != null)
//                ConvertCompressDataToStructureData();

            AssertUtility.Assert(AnimatorParameters.Count == leftParams.Count);
            int count = AnimatorParameters.Count;

            for (int i = 0; i < count; ++i)
            {
                var oldParam = AnimatorParameters[i];
                var newParam = leftParams[i];
                oldParam.ParamType  = newParam.ParamType;
                oldParam.IntValue   = newParam.IntValue;
                oldParam.FloatValue = newParam.FloatValue + (rightParams[i].FloatValue - newParam.FloatValue) * ratio;
                oldParam.BoolValue  = newParam.BoolValue;
                oldParam.NameHash   = newParam.NameHash;
            }
        }
        public static T Allocate()
        {
            var rc = _allocator.Allocate();

            AssertUtility.Assert(rc.GetType() == typeof(T));
            return((T)rc);
        }
        public override float DecreaseHp(VehiclePartIndex index, float amount, EUIDeadType damageType, EntityKey damageSource)
        {
            AssertUtility.Assert(amount >= 0);

            switch (index)
            {
            case VehiclePartIndex.FirstWheel:
                FirstWheelHp = FirstWheelHp < amount ? 0.0f : FirstWheelHp - amount;
                return(FirstWheelHp);

            case VehiclePartIndex.SecondWheel:
                SecondWheelHp = SecondWheelHp < amount ? 0.0f : SecondWheelHp - amount;
                return(SecondWheelHp);

            case VehiclePartIndex.ThirdWheel:
                ThirdWheelHp = ThirdWheelHp < amount ? 0.0f : ThirdWheelHp - amount;
                return(ThirdWheelHp);

            case VehiclePartIndex.FourthWheel:
                FourthWheelHp = FourthWheelHp < amount ? 0.0f : FourthWheelHp - amount;
                return(FourthWheelHp);

            default:
                return(base.DecreaseHp(index, amount, damageType, damageSource));
            }
        }
Exemple #5
0
        private void InitEventAllocator()
        {
            var types = FindAllGameComponentType(typeof(IEvent));

            foreach (var type in types)
            {
                try
                {
                    IEvent instance = (IEvent)Activator.CreateInstance(type);

                    int id = (int)instance.EventType;
                    if (ArrayUtility.SafeGet(_types, id) != null)
                    {
                        var msg = String.Format("component id already exist id {0}, type {1}, type {2}", id, _types[id],
                                                instance.GetType());
                        AssertUtility.Assert(false, msg);
                        _logger.Error(msg);
                    }
                    else
                    {
                        ArrayUtility.SafeSet(ref _types, id, type);
                        ArrayUtility.SafeSet(ref _allocators, id, ObjectAllocators.GetAllocator(type));
                    }

                    _maxId = Mathf.Max(id, _maxId);
                }
                catch (Exception e)
                {
                    _logger.ErrorFormat("construct instance of type {0} failed {1}", type, e);
                }
            }
        }
Exemple #6
0
 public virtual void AcquireReference()
 {
     SetCurrentThread();
     Interlocked.Increment(ref _refCount);
     AssertUtility.Assert(_refCount < MaxRef);
     ClearCurrentThread();
 }
Exemple #7
0
        public MemoryStream SerializeSinaglePackage(UpdateLatestPacakge msg)
        {
            MemoryStream stream = ObjectAllocatorHolder <MemoryStream> .Allocate();

            stream.Seek(0, SeekOrigin.Begin);
            var  binaryWriter = MyBinaryWriter.Allocate(stream);
            long bodyLength;
            var  old = MessagePool.GetPackageBySeq(msg.Head.BaseUserCmdSeq);

            if (old != null)
            {
                msg.Head.Serialize(binaryWriter);
                bodyLength = SerializeComponents(binaryWriter, old.UpdateComponents, msg.UpdateComponents);
            }
            else
            {
                msg.Head.BaseUserCmdSeq = -1;
                msg.Head.Serialize(binaryWriter);
                bodyLength = SerializeComponents(binaryWriter, _emptyUpdateComponents, msg.UpdateComponents);
            }

            AssertUtility.Assert(bodyLength < 65535);
            msg.Head.ReWriteBodyLength(binaryWriter, (short)bodyLength);
            binaryWriter.ReleaseReference();
            return(stream);
        }
        //监听AddComponent,每生产一个EntityKey就执行一个GetOrAddGameEntityComponent
        private void OnOnComponentAdded(IEntity entity, int index, IComponent component1)
        {
            try
            {
                if (index == indexLookUp.EntityKeyComponentIndex)
                {
                    AssertUtility.Assert(((EntityKeyComponent)component1).Value.EntityType == EntityType);
                    if (EntityAdded != null)
                    {
                        EntityAdded(GetGameEntity((TEntity)entity));
                    }
                }
                else
                {
                    if (index == indexLookUp.PositionComponentIndex)
                    {
                        AssertUtility.Assert(entity.HasComponent(indexLookUp.EntityKeyComponentIndex),
                                             "EntityKeyComponent must be added before PositionComponent");
                    }

                    NotifyComponentChanged(entity, index, null, component1);
                }
            }
            catch (Exception e)
            {
                logger.ErrorFormat("error {0},{1},{2}", entity.GetType(), index, e);
            }
        }
Exemple #9
0
        public VNetPacketMemSteam SerializeSinaglePackage(UpdateLatestPacakge msg)
        {
            VNetPacketMemSteam stream = VNetPacketMemSteam.Allocate();

            stream.Stream.Seek(0, SeekOrigin.Begin);
            var  binaryWriter = MyBinaryWriter.Allocate(stream.Stream);
            long bodyLength;
            var  old   = MessagePool.GetPackageBySeq(msg.Head.LastAckUserCmdSeq);
            int  count = 0;

            if (old != null)
            {
                msg.Head.Serialize(binaryWriter);
                bodyLength = SerializeComponents(binaryWriter, old.UpdateComponents, msg.UpdateComponents, out count);
            }
            else
            {
                msg.Head.LastAckUserCmdSeq = -1;
                msg.Head.Serialize(binaryWriter);
                bodyLength = SerializeComponents(binaryWriter, _emptyUpdateComponents, msg.UpdateComponents, out count);
            }

            AssertUtility.Assert(bodyLength < 65535);

            msg.Head.ReWriteComponentCountAndBodyLength(binaryWriter, (short)bodyLength, (byte)count);
            binaryWriter.ReleaseReference();
            return(stream);
        }
Exemple #10
0
        public virtual void FromStateToComponent(VehicleAbstractState state, VehicleEntity vehicle)
        {
            var comp = vehicle.GetDynamicData();

            comp.Flag = (int)VehicleFlag.LocalSet;

            comp.IsAccelerated = state.IsAccelerated;
            comp.SteerInput    = state.SteerInput;
            comp.ThrottleInput = state.ThrottleInput;

            comp.Position        = state.BodyState.Position;
            comp.Rotation        = state.BodyState.Rotation;
            comp.LinearVelocity  = state.BodyState.LinearVelocity;
            comp.AngularVelocity = state.BodyState.AngularVelocity;
            comp.IsSleeping      = state.BodyState.IsSleeping;

            var wheelCount = state.WheelStates.Length;
            var indexArray = VehicleIndexHelper.GetWheelIndexArray();

            AssertUtility.Assert(wheelCount <= indexArray.Length);
            for (int i = 0; i < wheelCount; ++i)
            {
                var index = indexArray[i];
                if (WheelEntityUtility.HasWheel(vehicle, index))
                {
                    SetWheel(vehicle, index, state.WheelStates[i]);
                }
            }
        }
Exemple #11
0
        private void SafeSetHandler(EEventType eventType, IEventHandler handler)
        {
            var id = (int)eventType;

            // DebugUtil.MyLog("Safe set eventtype:"+eventType);
            if (ArrayUtility.SafeGet(_allocators, id) == null)
            {
                var msg = String.Format("_allocators id not exist id {0}, type {1}, type {2}", id, _types[id],
                                        handler.GetType());
                AssertUtility.Assert(false, msg);
                _logger.Error(msg);
            }
            else if (ArrayUtility.SafeGet(_eventHandlers, id) != null)
            {
                var msg = String.Format("IEventHandler id already exist id {0}, type {1}, type {2}", id, _types[id],
                                        handler.GetType());
                AssertUtility.Assert(false, msg);
                _logger.Error(msg);
            }
            else
            {
                ArrayUtility.SafeSet(ref _eventHandlers, id, handler);
            }
            _maxId = Mathf.Max(id, _maxId);
        }
Exemple #12
0
        public static IGameContexts GetReplicationGameContexts(Contexts contexts, IBin2DManager bin = null)
        {
            var entitasContextInfos = new Core.EntityComponent.GameContexts();

            entitasContextInfos.AddContextInfo(new PlayerGameContext(contexts.player,
                                                                     GetBin2D(bin, (int)EEntityType.Player)));
            entitasContextInfos.AddContextInfo(new BulletGameContext(contexts.bullet,
                                                                     GetBin2D(bin, (int)EEntityType.Bullet)));
            entitasContextInfos.AddContextInfo(new ThrowingGameContext(contexts.throwing,
                                                                       GetBin2D(bin, (int)EEntityType.Throwing)));
            entitasContextInfos.AddContextInfo(new ClientEffectGameContext(contexts.clientEffect,
                                                                           GetBin2D(bin, (int)EEntityType.ClientEffect)));
            entitasContextInfos.AddContextInfo(new VehicleGameContext(contexts.vehicle,
                                                                      GetBin2D(bin, (int)EEntityType.Vehicle)));
            entitasContextInfos.AddContextInfo(new FreeMoveGameContext(contexts.freeMove,
                                                                       GetBin2D(bin, (int)EEntityType.FreeMove)));
            entitasContextInfos.AddContextInfo(new SoundGameContext(contexts.sound,
                                                                    GetBin2D(bin, (int)EEntityType.Sound)));
            if (IsIncludeSceneObject)
            {
                entitasContextInfos.AddContextInfo(new SceneObjectGameContext(contexts.sceneObject,
                                                                              GetBin2D(bin, (int)EEntityType.SceneObject)));
                entitasContextInfos.AddContextInfo(new MapObjectGameContext(contexts.mapObject,
                                                                            GetBin2D(bin, (int)EEntityType.MapObject)));
            }
#if UNITY_EDITOR
            foreach (var context in entitasContextInfos.AllContexts)
            {
                AssertUtility.Assert(context.CanContainComponent <EntityKeyComponent>());
                AssertUtility.Assert(context.CanContainComponent <FlagDestroyComponent>());
                AssertUtility.Assert(context.CanContainComponent <EntityAdapterComponent>());
            }
#endif
            return(entitasContextInfos);
        }
        public void OnBulletFire(PlayerWeaponController controller, WeaponSideCmd cmd)
        {
            //            DebugUtil.MyLog("[seq:{1}]MuzzleP3Position:{0}",controller.RelatedFirePos.MuzzleP3Position,cmd.UserCmd.Seq);
            var bulletCfg = controller.HeldWeaponAgent.BulletCfg;

            AssertUtility.Assert(bulletCfg != null);
            var cmdSeq   = cmd.UserCmd.Seq;
            var fireAmmu = controller.RelatedCameraSNew.IsAiming() ? sightFireAmmu : normalFireAmmu;

            // 射出子弹
            for (int i = 0; i < bulletCfg.HitCount; i++)
            {
                var bulletData = PlayerBulletData.Allocate();
                bulletData.Dir =
                    PrecisionsVector3.MakePrecisionsV(
                        fireAmmu.GetFireDir(cmdSeq + i, controller, cmd.UserCmd.Seq), 3);
                var viewPos = PrecisionsVector3.MakePrecisionsV(fireAmmu.GetFireViewPosition(controller), 3);
                bulletData.ViewPosition = PrecisionsVector3.MakeRoundPrecisionsV(viewPos, 3);
                //枪口位置取原始精度
                bulletData.EmitPosition = fireAmmu.GetFireEmitPosition(controller);
                controller.AddAuxBullet(bulletData);
                // DebugUtil.AppendShootText(cmd.UserCmd.Seq, "[Bullet Fire]{0}", bulletData.ToStringExt());
            }

            controller.AfterAttack();
        }
Exemple #14
0
        public float DecreaseRemainingFuel(float amount)
        {
            AssertUtility.Assert(amount >= 0);

            RemainingFuel = RemainingFuel < amount ? 0.0f : RemainingFuel - amount;
            return(RemainingFuel);
        }
Exemple #15
0
        private void SetCurrentThread()
        {
#if UNITY_EDITOR
            AssertUtility.Assert(_currentThread == 0, _msg);
            _currentThread = Thread.CurrentThread.ManagedThreadId;
#endif
        }
Exemple #16
0
        public UpdateLatestPacakge CreateClientUpdateLatestPacakge(EntityKey selfKey)
        {
            var entity = gameContexts.GetGameEntity(selfKey);

            if (entity == null)
            {
                return(null);
            }
#pragma warning disable RefCounter001,RefCounter002
            UpdateLatestPacakge pacakge = UpdateLatestPacakge.Allocate();
#pragma warning restore RefCounter001,RefCounter002

            pacakge.Head.LastAckUserCmdSeq = LastAckUserCmdSeq;
            pacakge.Head.LastUserCmdSeq    = LastLocalUserCmd;
            pacakge.Head.LastSnapshotId    = LastAckSnapshotId;
            var components = entity.GetUpdateLatestComponents();
            AssertUtility.Assert(components.Count < 255);
            pacakge.Head.ComponentCount = (byte)components.Count;
            foreach (var gameComponent in components)
            {
                IUpdateComponent copy =
                    (IUpdateComponent)GameComponentInfo.Instance.Allocate(gameComponent.GetComponentId());
                copy.CopyFrom(gameComponent);
                pacakge.UpdateComponents.Add(copy);
            }

            return(pacakge);
        }
 /*public WeaponBagSlotData HeldSlotData { get { return slotWeapons[HeldSlotPointer]; } }
  *
  * public WeaponBagSlotData LastSlotData { get { return slotWeapons[LastSlotPointer]; } }
  */
 public WeaponBagSlotData this[EWeaponSlotType slot]
 {
     get
     {
         AssertUtility.Assert((int)slot < GlobalConst.WeaponSlotMaxLength);
         return(slotWeapons[(int)slot]);
     }
 }
        public void UnloadResource(TEntity entity, int index)
        {
            AssertUtility.Assert(index < GetActionsLength());
            var comp = GetCommonResource(entity);
            var old  = UnloadResource(comp, index);

            PushToOldResource(old, GetActions(index));
        }
Exemple #19
0
        public WeaponPropertyConfigItem FindByWeaponId(int id)
        {
            WeaponPropertyConfigItem item = null;

            _weaponPropertyDic.TryGetValue(id, out item);
            AssertUtility.Assert(item != null);
            return(item);
        }
Exemple #20
0
 public WeaponBagSlotData this[EWeaponSlotType slot]
 {
     get
     {
         int index = ToIndex(slot);
         AssertUtility.Assert(index < slotWeapons.Length);
         return(slotWeapons[index]);
     }
 }
 public UnityCharacterController(UnityEngine.CharacterController controller, Action <Transform> initAction = null, bool isUseCapsuleCollider = false)
 {
     _controller           = controller;
     _capsuleCollider      = controller.gameObject.GetComponent <CapsuleCollider>();
     _isUseCapsuleCollider = isUseCapsuleCollider;
     _initAction           = initAction;
     AssertUtility.Assert(_capsuleCollider != null);
     InitGroundDetection();
 }
        public void LoadResource(TEntity entity, int index, AssetInfo assetInfo, bool forceReload)
        {
            var time = (int)(MyGameTime.time * 1000);

            AssertUtility.Assert(index < GetActionsLength());
            var comp = GetCommonResource(entity);
            var old  = LoadResource(comp, index, assetInfo, time, forceReload);

            PushToOldResource(old, GetActions(index));
        }
Exemple #23
0
 public virtual void ReleaseReference()
 {
     SetCurrentThread();
     if (Interlocked.Decrement(ref _refCount) == 0)
     {
         OnCleanUp();
     }
     AssertUtility.Assert(_refCount >= 0);
     ClearCurrentThread();
 }
Exemple #24
0
 public static Action <Transform> InitActionWithOffset()
 {
     return(transform =>
     {
         var thirdModelOffset = GetThirdModelParent(transform);
         AssertUtility.Assert(thirdModelOffset != transform);
         thirdModelOffset.transform.localPosition = new Vector3(0, -PlayerEntityUtility.CcSkinWidth, 0);
         thirdModelOffset.transform.localRotation = Quaternion.identity;
         thirdModelOffset.transform.localScale = Vector3.one;
     });
 }
Exemple #25
0
 public static void RestoreCollider(GameObject gameObject, List <bool> restoreValue)
 {
     _colliderList.Clear();
     gameObject.GetComponentsInChildren <Collider>(_colliderList);
     AssertUtility.Assert(restoreValue.Count == _colliderList.Count);
     for (int i = 0; i < restoreValue.Count; ++i)
     {
         _colliderList[i].enabled = restoreValue[i];
     }
     _colliderList.Clear();
 }
        protected void SetComponent(int id, IGameComponent component)
        {
            if (component != null)
            {
                AssertUtility.Assert(!_components.ContainsKey(id));
                AssertUtility.Assert(component.GetComponentId() == id);
            }

            SetDirty();
            _components[id] = component;
        }
        public void Divide(float val)
        {
            AssertUtility.Assert(val > 0);

            _keysList.Clear();
            _keysList.AddRange(_dataSet.Keys);
            foreach (var key in _keysList)
            {
                _dataSet[key] = _dataSet[key] / val;
            }
        }
Exemple #28
0
        public void Write(MyBinaryWriter writer)
        {
            AssertUtility.Assert((int)EEventType.End < 255);

            writer.Write((byte)_events.Count);
            foreach (var v in _events.Values)
            {
                writer.Write((byte)v.EventType);
                v.WriteBody(writer);
            }
        }
Exemple #29
0
 public static Action <Transform> InitActionWithNoOffset()
 {
     return(transform =>
     {
         var thirdModelOffset = GetThirdModelParent(transform);
         AssertUtility.Assert(thirdModelOffset != transform);
         thirdModelOffset.transform.localPosition = Vector3.zero;
         thirdModelOffset.transform.localRotation = Quaternion.identity;
         thirdModelOffset.transform.localScale = Vector3.one;
     });
 }
Exemple #30
0
        public IGameEntity GetGameEntity(EntityKey entityKey)
        {
            var info = infos[entityKey.EntityType];

            if (info == null)
            {
                AssertUtility.Assert(false, "infos[" + entityKey.EntityType + "] == null");
                return(null);
            }

            return(info.GetEntity(entityKey));
        }