public void StartGame(int mapId, PlayerServerInfo[] playerInfos, int localPlayerId)
    {
        hasStart = true;
        curMapId = mapId;
        //navmesh init
        var txt = Resources.Load <TextAsset>("Maps/" + curMapId + ".navmesh");

        NavMeshManager.DoInit(txt.text);
        maxBspDepth       = BspTree.maxDepth;
        maxBspDepthNodeId = BspTree.maxDepthNodeId;

        this.playerCount       = playerInfos.Length;
        this.playerServerInfos = playerInfos;
        this.localPlayerId     = localPlayerId;
        Debug.TraceSavePath    = _traceLogPath;
        allPlayers.Clear();
        for (int i = 0; i < playerCount; i++)
        {
            Debug.Trace("CreatePlayer");
            allPlayers.Add(new Player()
            {
                localId = i
            });
        }

        //create Players
        for (int i = 0; i < playerCount; i++)
        {
            var playerInfo = playerInfos[i];
            var prefab     = ResourceManager.LoadPrefab(playerInfo.PrefabId);
            CollisionManager.Instance.RigisterPrefab(prefab, (int)EColliderLayer.Hero);
            HeroManager.InstantiateEntity(allPlayers[i], playerInfo.PrefabId, playerInfo.initPos);
        }
    }
Esempio n. 2
0
    public void SetTime(LFloat timer)
    {
        var idx = GetTimeIdx(timer);

        intiPos = owner.transform.Pos3 - CurAnimInfo[idx].pos;
        Debug.Trace(
            $"{owner.EntityId} SetTime  idx:{idx} intiPos {owner.transform.Pos3}",
            true);
        this.timer = timer;
    }
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
    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. 5
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. 7
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. 9
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. 10
0
 /// <summary>
 /// Shrink the octree if possible, else leave it the same.
 /// </summary>
 void Shrink()
 {
     Debug.Trace("Shrink");
     rootNode = rootNode.ShrinkIfPossible(initialSize);
 }