public KDtree(int MaxNestingLevel, List<GameObject> GameObjects)
        {
            this.MaxNestingLevel = MaxNestingLevel;

            DVector3 AA = new DVector3();
            DVector3 BB = new DVector3();

            for (int i = 0; i < GameObjects.Count; i++)
            {
                GameObject GO = GameObjects[i];
                if (GO != null)
                {
                    if (AA.X < GO.AABBMax.X) AA.X = GO.AABBMax.X;
                    if (AA.Y < GO.AABBMax.Y) AA.Y = GO.AABBMax.Y;
                    if (AA.Z < GO.AABBMax.Z) AA.Z = GO.AABBMax.Z;

                    if (BB.X > GO.AABBMin.X) BB.X = GO.AABBMin.X;
                    if (BB.Y > GO.AABBMin.Y) BB.Y = GO.AABBMin.Y;
                    if (BB.Z > GO.AABBMin.Z) BB.Z = GO.AABBMin.Z;
                }
            }

            DVector3 TAA = AA + (AA - BB) * 0.1d;
            DVector3 TBB = BB + (BB - AA) * 0.1d;

            Root = new Node(null, TAA, TBB, MaxNestingLevel);

            for (int t = 0; t < GameObjects.Count; t++)
            {
                if (GameObjects[t] != null)
                    Add(GameObjects[t], Root);
            }
        }
Beispiel #2
0
    /// <summary>
    /// 播放鱼竿动画
    /// </summary>
    /// <param name="uid"></param>
    /// <param name="aniName"></param>
    void PlayFishingRodAni(uint uid, string aniName)
    {
        Dictionary <uint, Engine.IRenderObj> playerFishingDic = DataManager.Manager <SuitDataManager>().PlayerFishingDic;

        Engine.IRenderObj yuganObj;
        if (playerFishingDic.TryGetValue(uid, out yuganObj))
        {
            Engine.Node node = yuganObj.GetNode();
            if (node == null)
            {
                return;
            }

            Transform transf = node.GetTransForm();
            if (transf == null)
            {
                return;
            }

            Animation[] anis = transf.gameObject.GetComponentsInChildren <Animation>();

            if (anis.Length > 0)
            {
                Animation animation = anis[0];
                animation.Play(aniName);
            }
        }
    }
Beispiel #3
0
    /// <summary>
    /// 获取状态条在世界坐标的位置
    /// </summary>
    /// <param name="uid"></param>
    /// <param name="strLocatorName"></param>
    /// <param name="offsetY"></param>
    /// <returns></returns>
    public Vector3 GetNodeWorldPos(long uid, string strLocatorName, float offsetY = 1)
    {
        Vector3 pos    = Vector3.zero;
        IEntity entity = GetEntity(uid);

        if (entity == null)
        {
            Engine.Utility.Log.Error("GetNodeWorldPos : entity is null");
            return(pos);
        }

        Engine.Node node = entity.GetNode();
        if (node == null)
        {
            //Engine.Utility.Log.Error("GetNodeWorldPos : entity node is null");
            return(pos);
        }

        Transform trans = node.GetTransForm();

        if (trans == null)
        {
            Engine.Utility.Log.Error("GetNodeWorldPos : entity transform is null");
            return(pos);
        }

        entity.GetLocatorPos(strLocatorName, Vector3.zero, Quaternion.identity, ref pos, true);

        pos.y += offsetY * trans.lossyScale.y;
        return(pos);
    }
Beispiel #4
0
 public Transform GetTransForm()
 {
     Engine.Node node = GetNode();
     if (node == null)
     {
         return(null);
     }
     return(node.GetTransForm());
 }
Beispiel #5
0
 private void UpdateEffectWidget()
 {
     if (null != m_effect)
     {
         Engine.Node node = m_effect.GetNode();
         if (node != null)
         {
             Transform trans = node.GetTransForm();
             if (trans != null)
             {
                 trans.parent = cachedTransform;
                 node.SetLocalPosition(Vector3.zero);
                 trans.localScale = Vector3.one;
                 trans.SetChildLayer(LayerMask.NameToLayer("UI"));
             }
         }
     }
 }
Beispiel #6
0
    private void OnKeyPress(KeyCode kc)
    {
        Engine.Node camNode = m_Camera.GetNode();
        Vector3     pos     = camNode.GetLocalPosition();

        //KeyCode kc = (KeyCode)param1;
        switch (kc)
        {
        case KeyCode.UpArrow:
        {
            pos.y += 1;
            camNode.SetLocalPosition(pos);
            break;
        }

        case KeyCode.DownArrow:
        {
            pos.y -= 1;
            camNode.SetLocalPosition(pos);
            break;
        }

        case KeyCode.LeftArrow:
        {
            pos.x -= 1;
            camNode.SetLocalPosition(pos);
            break;
        }

        case KeyCode.RightArrow:
        {
            pos.x += 1;
            camNode.SetLocalPosition(pos);
            break;
        }
        }
    }
Beispiel #7
0
    /// <summary>
    /// 关闭画鱼线
    /// </summary>
    /// <param name="uid"></param>
    void CloseFishingLine(uint uid)
    {
        Dictionary <uint, Engine.IRenderObj> playerFishingDic = DataManager.Manager <SuitDataManager>().PlayerFishingDic;

        Engine.IRenderObj yuganObj;
        if (playerFishingDic.TryGetValue(uid, out yuganObj))
        {
            Engine.Node node = yuganObj.GetNode();
            if (node != null)
            {
                Transform transf = node.GetTransForm();
                if (transf != null)
                {
                    LineRenderer[] lrs = transf.gameObject.GetComponentsInChildren <LineRenderer>();

                    if (lrs.Length > 0)
                    {
                        LineRenderer lr = lrs[0];
                        lr.enabled = false;
                    }
                }
            }
        }
    }
Beispiel #8
0
    /// <summary>
    /// 画鱼线
    /// </summary>
    /// <param name="uid"></param>
    /// <returns></returns>
    IEnumerator DrawFishingLine(uint uid)
    {
        yield return(new WaitForSeconds(0.9f));

        Dictionary <uint, Engine.IRenderObj> playerFishingDic = DataManager.Manager <SuitDataManager>().PlayerFishingDic;

        Engine.IRenderObj yuganObj;
        if (playerFishingDic.TryGetValue(uid, out yuganObj))
        {
            Engine.Node node = yuganObj.GetNode();
            if (node != null)
            {
                Transform transf = node.GetTransForm();
                if (transf != null)
                {
                    LineRenderer[] lrs = transf.gameObject.GetComponentsInChildren <LineRenderer>();

                    if (lrs.Length > 0)
                    {
                        LineRenderer lr = lrs[0];
                        lr.enabled = true;

                        Vector3 startPos = lr.gameObject.transform.position;
                        Vector3 endPos   = new Vector3(startPos.x, startPos.y - 8, startPos.z);

                        lr.SetPosition(0, startPos);
                        lr.SetPosition(1, endPos);
                    }
                    else
                    {
                        Engine.Utility.Log.Error("没有鱼竿顶点 ,鱼线会出错!!! 找罗宇辉");
                    }
                }
            }
        }
    }
 public Node(Node parent, DVector3 AA, DVector3 BB, int nestingLevel)
 {
     Parent = parent;
     this.AA = AA;
     this.BB = BB;
     NestingLevel = nestingLevel;
     ListBSSO = new List<GameObject>();
     Children = new List<Node>();
 }
        private void TestIntercept(List<GameObject> TLInd, Node N, Vector3 Start, Vector3 Origin)
        {
            if (Utils.HitBoundingBox(N.BB, N.AA, Start, Origin))
            {
                //TLInd.AddRange(N.ListBSSO);
                for (int i = 0; i < N.ListBSSO.Count; i++)
                {
                    GameObject BSSO = N.ListBSSO[i];
                    if (BSSO != null)
                    {
                        if (Utils.HitBoundingBox(BSSO.AABBMin, BSSO.AABBMax, Start, Origin))
                        {
                            TLInd.Add(BSSO);
                        }
                    }
                }

                if (N.Children.Count > 0)
                {
                    TestIntercept(TLInd, N.Children[0], Start, Origin);
                    TestIntercept(TLInd, N.Children[1], Start, Origin);
                }
            }
        }
        private void TestInCam(bool Pol, Node N, BoundingFrustum BF)
        {
            if (!Pol)
            {
                for (int tx = 0; tx < N.ListBSSO.Count; tx++)
                //foreach (BaseSunSystemObject Num in N.ListBSSO)
                {
                    GameObject Num = N.ListBSSO[tx];
                    if (Num != null)
                    {
                        int t = TestFrustum(new BoundingBox(Conversion.ToVector3(Num.AABBMin - Position), Conversion.ToVector3(Num.AABBMax - Position)), BF);
                        if (t == 1 || t == 2)
                            TL.Add(Num);
                    }
                }
            }
            else
            {
                TL.AddRange(N.ListBSSO);
            }

            int t1 = TestFrustum(new BoundingBox(Conversion.ToVector3(N.BB - Position), Conversion.ToVector3(N.AA - Position)), BF);
            if (t1 == 1 || t1 == 2)
            {
                for (int tx = 0; tx < N.Children.Count; tx++)
                //foreach (Node N_ in N.Children)
                {
                    if (t1 == 1)
                        TestInCam(false, N.Children[tx], BF);
                    else
                        TestInCam(true, N.Children[tx], BF);
                }
            }
        }
        private void TestIn(bool Pol, Node N, DVector3 Pos, double Radius, DVector3 AA, DVector3 BB)
        {
            if (!Pol)
            {
                for (int tx = 0; tx < N.ListBSSO.Count; tx++ )
                {
                    if (N.ListBSSO[tx] != null)
                    {
                        int t = TestTwoSphere(Pos, Radius, N.ListBSSO[tx].Position,
                            Math.Max((N.ListBSSO[tx].Position - N.ListBSSO[tx].AABBMax).Length(), (N.ListBSSO[tx].Position - N.ListBSSO[tx].AABBMin).Length()));
                        if (t == 1 || t == 2) TL.Add(N.ListBSSO[tx]);
                    }
                }
            }
            else
            {
                TL.AddRange(N.ListBSSO);
            }

            if (N.Children.Count > 0)
            {
                int tt;
                bool B = false;
                Node N_ = N.Children[0];
                tt = TestTwoAABB(AA, BB, N_.AA, N_.BB);
                if (tt == 1)
                {
                    B = false;
                    TestIn(false, N_, Pos, Radius, AA, BB);
                }
                if (tt == 2)
                {
                    B = true;
                    TestIn(true, N_, Pos, Radius, AA, BB);
                }

                N_ = N.Children[1];
                tt = TestTwoAABB(AA, BB, N_.AA, N_.BB);
                if (tt == 1)
                {
                    TestIn(false, N_, Pos, Radius, AA, BB);
                }
                if (tt == 2)
                {
                    TestIn(true, N_, Pos, Radius, AA, BB);
                }
            }
        }
        // DVector3 AA_2, DVector3 BB_2)
        private bool Add(GameObject BSSO, Node N)
        {
            //Достигнут минимальный уровень
            if (N.NestingLevel < 1)
            {
                N.Parent.ListBSSO.Add(BSSO);
                return true;
            }

            int rez = TestTwoAABB(N.AA, N.BB, BSSO.AABBMax, BSSO.AABBMin);
            //Не поподает
            if (rez == 0) return false;
            //Поподает частично
            if (rez == 1)
            {
                N.Parent.ListBSSO.Add(BSSO);
                return true;
            }

            double X = N.AA.X - N.BB.X;
            double Y = N.AA.Y - N.BB.Y;
            double Z = N.AA.Z - N.BB.Z;

            if (X + Y + Z < NodeMinSize)
            {
                N.ListBSSO.Add(BSSO);
                return true;
            }

            //Поподает полностью
            if (N.Children.Count < 1)
            {
                int Level = N.NestingLevel - 1;

                if (X > Math.Max(Y, Z))
                {
                    N.Children.Add(new Node(N, N.AA, new DVector3(N.AA.X - X / 2f, N.BB.Y, N.BB.Z), Level));
                    N.Children.Add(new Node(N, new DVector3(N.AA.X - X / 2f, N.AA.Y, N.AA.Z),  N.BB, Level));
                    if (BSSO.Position.X > N.AA.X - X / 2f)
                    {
                        if (Add(BSSO, N.Children[0])) return true;
                        if (Add(BSSO, N.Children[1])) return true;
                    }
                    else
                    {
                        if (Add(BSSO, N.Children[1])) return true;
                        if (Add(BSSO, N.Children[0])) return true;
                    }
                }
                else
                {
                    if (Y > Math.Max(X, Z))
                    {
                        N.Children.Add(new Node(N, N.AA, new DVector3(N.BB.X, N.AA.Y - Y / 2f, N.BB.Z), Level));
                        N.Children.Add(new Node(N, new DVector3(N.AA.X, N.AA.Y - Y / 2f, N.AA.Z), N.BB, Level));
                        if (BSSO.Position.Y > N.AA.Y - Y / 2f)
                        {
                            if (Add(BSSO, N.Children[0])) return true;
                            if (Add(BSSO, N.Children[1])) return true;
                        }
                        else
                        {
                            if (Add(BSSO, N.Children[1])) return true;
                            if (Add(BSSO, N.Children[0])) return true;
                        }
                    }
                    else
                    {
                        N.Children.Add(new Node(N, N.AA, new DVector3(N.BB.X, N.BB.Y, N.AA.Z - Z / 2f), Level));
                        N.Children.Add(new Node(N, new DVector3(N.AA.X, N.AA.Y, N.AA.Z - Z / 2f), N.BB, Level));
                        if (BSSO.Position.Z > N.AA.Z - Z / 2f)
                        {
                            if (Add(BSSO, N.Children[0])) return true;
                            if (Add(BSSO, N.Children[1])) return true;
                        }
                        else
                        {
                            if (Add(BSSO, N.Children[1])) return true;
                            if (Add(BSSO, N.Children[0])) return true;
                        }
                    }
                }
            }

            if (Add(BSSO, N.Children[0])) return true;
            if (Add(BSSO, N.Children[1])) return true;

            return false;
        }
 private static void RecursyKD(Node N, Vector3 Color)
 {
     if (N != null)
     {
         DebugDraw.DrawAABB(N.AA, N.BB, Color);
         if (N.Children != null && N.Children.Count > 0)
         {
             RecursyKD(N.Children[0], Color);
             if (N.Children.Count > 1)
             {
                 RecursyKD(N.Children[1], Color);
             }
         }
     }
 }