Esempio n. 1
0
        public void Execute()
        {
            foreach (var entity in _destroyedGroup.GetEntities())
            {
                _gameAudioService.PlayMusicGetItem();
                var actor  = _actorContext.GetEntityWithActorId(entity.itemType.killerActorId);
                var player = _gameContext.GetEntityWithEntityId(actor.gameEntityId.value);
                Debug.Assert(actor != null, " player's tank have no owner");
                if (player != null && !player.isDestroyed && player.unit.health != 0)
                {
                    actor.score.value = actor.score.value + 500;
                    switch (entity.itemType.type)
                    {
                    case EItemType.Boom:
                        OnTriggerBoom(actor, player, _allEnmey);
                        break;

                    case EItemType.Upgrade:
                        OnTriggerUpgrade(actor, player, _allEnmey);
                        break;

                    case EItemType.AddLife:
                        OnTriggerAddLife(actor, player, _allEnmey);
                        break;
                    }
                }
            }
        }
Esempio n. 2
0
 //delete
 public void Remove(int idx)
 {
     Debug.Assert(idx < allOffsets.Count, "out of range");
     if (idx >= allOffsets.Count)
     {
         return;
     }
     allColliders.RemoveAt(idx);
     allOffsets.RemoveAt(idx);
 }
Esempio n. 3
0
        /// <summary>
        /// Removes the specified object at the given position. Makes the assumption that the object only exists once in the tree.
        /// </summary>
        /// <param name="obj">Object to remove.</param>
        /// <param name="objBounds">3D bounding box around the object.</param>
        /// <returns>True if the object was removed successfully.</returns>
        public bool Remove(ColliderProxy obj, LRect objBounds)
        {
            Debug.Trace($"ColliderProxy Add { obj.Id} objBounds  {objBounds}");
            bool removed = rootNode.Remove(obj, objBounds);

            // See if we can shrink the octree down now that we've removed the item
            if (removed)
            {
                Count--;
                Shrink();
            }

            return(removed);
        }
Esempio n. 4
0
        /// <summary>
        /// Constructor for the bounds octree.
        /// </summary>
        /// <param name="initialWorldSize">Size of the sides of the initial node, in metres. The octree will never shrink smaller than this.</param>
        /// <param name="initialWorldPos">Position of the centre of the initial node.</param>
        /// <param name="minNodeSize">Nodes will stop splitting if the new nodes would be smaller than this (metres).</param>
        /// <param name="loosenessVal">Clamped between 1 and 2. Values > 1 let nodes overlap.</param>
        public BoundsQuadTree(LFloat initialWorldSize, LVector2 initialWorldPos, LFloat minNodeSize, LFloat loosenessVal)
        {
            if (minNodeSize > initialWorldSize)
            {
                Debug.Log("Minimum node size must be at least as big as the initial world size. Was: " +
                          minNodeSize + " Adjusted to: " + initialWorldSize);
                minNodeSize = initialWorldSize;
            }

            Count       = 0;
            initialSize = initialWorldSize;
            minSize     = minNodeSize;
            looseness   = LMath.Clamp(loosenessVal, 1.ToLFloat(), 2.ToLFloat());
            rootNode    = new BoundsQuadTreeNode(null, initialSize, minSize, looseness, initialWorldPos);
        }
Esempio n. 5
0
        public void Initialize(IContext context)
        {
            var config = _gameConfigService;

            foreach (var spawner in config.SpawnInfos)
            {
                if (spawner.Count <= 0)
                {
                    continue;
                }
                var entity = _context.PostCmdCreateBoidSpawner();
                entity->Spawn.Count        = spawner.Count;
                entity->Spawn.Position     = spawner.Position;
                entity->Spawn.Radius       = spawner.Radius;
                entity->BoidPrefab.AssetId = spawner.AssetId;
            }

            int playerId = 0;
            var count    = _globalStateService.ActorCount;

            for (int i = 0; i < count; i++)
            {
                var obstacleInfo = config.ObstacleInfos[i % config.ObstacleInfos.Count];
                var entity       = _context.PostCmdCreateBoidObstacle();
                entity->Transform.Position = obstacleInfo.Position;
                entity->Transform.Forward  = obstacleInfo.Forward;
                entity->Transform.Scale    = obstacleInfo.Scale;
                entity->Skill          = obstacleInfo.SkillData;
                entity->Move           = obstacleInfo.MoveData;
                entity->Prefab.AssetId = obstacleInfo.AssetId;
                entity->Player.LocalId = playerId++;//
                Debug.Log("Create ObstacleInfos " + entity->Player.LocalId);
            }

            foreach (var target in config.TargetInfos)
            {
                var entity = _context.PostCmdCreateBoidTarget();
                entity->Transform.Position = target.MoveInfo.GetPosition(0);
                entity->Transform.Scale    = 1;
                entity->MoveInfo           = target.MoveInfo;
                entity->Prefab.AssetId     = target.AssetId;
            }

            foreach (var spawner in config.SpawnInfos)
            {
                _gameStateService.CurEnemyCount += spawner.Count;
            }
        }
    private void OnDestroy()
    {
        netClient?.Send(new Msg_QuitRoom());
        foreach (var mgr in _mgrs)
        {
            mgr.DoDestroy();
        }

        if (!IsReplay)
        {
            RecordHelper.Serialize(recordFilePath, this);
        }

        Debug.FlushTrace();
        DoDestroy();
    }
Esempio n. 7
0
    public void Play(string name, bool isCrossfade = false)
    {
        if (CurAnimName == name)
        {
            return;
        }
        var idx = animNames.IndexOf(name);

        if (idx == -1)
        {
            UnityEngine.Debug.LogError("miss animation " + name);
            return;
        }

        Debug.Trace($"{owner.EntityId} PlayAnim {name} rawName {CurAnimName}");
        var hasChangedAnim = CurAnimName != name;

        CurAnimName     = name;
        animState       = animComp[CurAnimName];
        CurAnimInfo     = animInfos[idx];
        CurAnimBindInfo = config.events.Find((a) => a.name == name);
        if (CurAnimBindInfo == null)
        {
            CurAnimBindInfo = AnimBindInfo.Empty;
        }
        if (hasChangedAnim)
        {
            //owner.TakeDamage(0, owner.transform2D.Pos3);
            ResetAnim();
        }

        var state = animComp[CurAnimName];

        if (state != null)
        {
            if (isCrossfade)
            {
                animComp.CrossFade(CurAnimName);
            }
            else
            {
                animComp.Play(CurAnimName);
            }
        }
    }
Esempio n. 8
0
        /// <summary>
        /// Add an object.
        /// </summary>
        /// <param name="obj">Object to add.</param>
        /// <param name="objBounds">3D bounding box around the object.</param>
        public void Add(ColliderProxy obj, LRect objBounds)
        {
            Debug.Trace($"ColliderProxy Add { obj.Id} objBounds  {objBounds}");
            // Add object or expand the octree until it can be added
            int count = 0; // Safety check against infinite/excessive growth

            while (!rootNode.Add(obj, objBounds))
            {
                Debug.LogError("Grow");
                Grow(objBounds.center - rootNode.Center);
                if (++count > 20)
                {
                    Debug.LogError("Aborted Add operation as it seemed to be going on forever (" + (count - 1) +
                                   ") attempts at growing the octree.");
                    return;
                }
            }

            Count++;
        }
    public void DoStart()
    {
        if (_instance != this)
        {
            Debug.LogError("Duplicate CollisionSystemAdapt!");
            return;
        }

        var collisionSystem = new CollisionSystem()
        {
            worldSize    = worldSize,
            pos          = pos,
            minNodeSize  = minNodeSize,
            loosenessval = loosenessval
        };

        Debug.Trace($"worldSize:{worldSize} pos:{pos} minNodeSize:{minNodeSize} loosenessval:{loosenessval}");
        this.collisionSystem = collisionSystem;
        collisionSystem.DoStart(InterestingMasks, allTypes);
        collisionSystem.funcGlobalOnTriggerEvent += GlobalOnTriggerEvent;
    }
Esempio n. 10
0
        public void UpdateObj(ColliderProxy obj, LRect bound)
        {
            Debug.Trace($"ColliderProxy UpdateObj { obj.Id} objBounds  {bound}");
            var node = GetNode(obj);

            if (node == null)
            {
                Add(obj, bound);
            }
            else
            {
                if (!node.ContainBound(bound))
                {
                    Remove(obj);
                    Add(obj, bound);
                }
                else
                {
                    node.UpdateObj(obj, bound);
                }
            }
        }
    private void _Start()
    {
        DoStart();
        foreach (var mgr in _mgrs)
        {
            mgr.DoStart();
        }

        Debug.Trace("Before StartGame _IdCounter" + BaseEntity._IdCounter);
        if (!IsReplay)
        {
            netClient = new NetClient();
            netClient.Start();
            netClient.Send(new Msg_JoinRoom()
            {
                name = Application.dataPath
            });
        }
        else
        {
            StartGame(0, playerServerInfos, localPlayerId);
        }
    }
Esempio n. 12
0
        /// <summary>
        /// Grow the octree to fit in all objects.
        /// </summary>
        /// <param name="direction">Direction to grow.</param>
        void Grow(LVector2 direction)
        {
            Debug.Trace("Grow");
            int xDirection               = direction.x >= 0 ? 1 : -1;
            int yDirection               = direction.y >= 0 ? 1 : -1;
            BoundsQuadTreeNode oldRoot   = rootNode;
            LFloat             half      = rootNode.BaseLength / 2;
            LFloat             newLength = rootNode.BaseLength * 2;
            LVector2           newCenter = rootNode.Center + new LVector2(xDirection * half, yDirection * half);

            // Create a new, bigger octree root node
            rootNode = new BoundsQuadTreeNode(null, newLength, minSize, looseness, newCenter);

            if (oldRoot.HasAnyObjects())
            {
                // Create 7 new octree children to go with the old root as children of the new root
                int rootPos = rootNode.BestFitChild(oldRoot.Center);
                BoundsQuadTreeNode[] children = new BoundsQuadTreeNode[NUM_CHILDREN];
                for (int i = 0; i < NUM_CHILDREN; i++)
                {
                    if (i == rootPos)
                    {
                        children[i] = oldRoot;
                    }
                    else
                    {
                        xDirection  = i % 2 == 0 ? -1 : 1;
                        yDirection  = i > 1 ? -1 : 1;
                        children[i] = new BoundsQuadTreeNode(rootNode, oldRoot.BaseLength, minSize, looseness,
                                                             newCenter + new LVector2(xDirection * half, yDirection * half));
                    }
                }

                // Attach the new children to the new root node
                rootNode.SetChildren(children);
            }
        }
Esempio n. 13
0
 // Token: 0x060000B0 RID: 176 RVA: 0x00005E46 File Offset: 0x00004046
 protected virtual void Awake()
 {
     this._referenceHolder = base.GetComponent <IReferenceHolder>();
     Debug.Assert(this._referenceHolder != null, base.GetType() + " miss IReferenceHolder ");
     this.DoAwake();
 }
Esempio n. 14
0
 /// <summary>
 /// Shrink the octree if possible, else leave it the same.
 /// </summary>
 void Shrink()
 {
     Debug.Trace("Shrink");
     rootNode = rootNode.ShrinkIfPossible(initialSize);
 }