Example #1
0
        public void PlaceRing()
        {
            //print ("PlaceRing!");

            foreach (var item in _ctrls)
            {
                _ctrlLst.Add(item.Key);
            }

            List <List <CellObjCtrl> > currentRings = new List <List <CellObjCtrl> > ();

            DetectRingCtrlsLst(ref currentRings);

            // detect obsolete rings
            List <List <CellObjCtrl> > obsoleteRings = new List <List <CellObjCtrl> > ();

            for (int i = _Rings.Count - 1; i >= 0; i--)
            {
                var  ringObjs = _Rings [i];
                bool bExist   = false;
                for (int j = currentRings.Count - 1; j >= 0; j--)
                {
                    var newRingObjs = currentRings [j];
                    bExist =
                        Lyu.DataStructureUtils.ContainsSame <CellObjCtrl> (ringObjs, newRingObjs);
                    if (bExist)
                    {
                        break;
                    }
                }

                if (!bExist)
                {
                    obsoleteRings.Add(ringObjs);
                    _Rings.RemoveAt(i);
                }
            }

            // detect new rings
            List <List <CellObjCtrl> > newCreateRings = new List <List <CellObjCtrl> > ();

            for (int i = currentRings.Count - 1; i >= 0; i--)
            {
                var  ringObjs = currentRings [i];
                bool bExist   = false;
                for (int j = _Rings.Count - 1; j >= 0; j--)
                {
                    var existRObjs = _Rings [j];
                    bExist =
                        Lyu.DataStructureUtils.ContainsSame <CellObjCtrl> (ringObjs, existRObjs);
                    if (bExist)
                    {
                        break;
                    }
                }

                if (!bExist)
                {
                    newCreateRings.Add(ringObjs);
                    _Rings.Add(ringObjs);
                }
            }

            //delete obsolete rings
            foreach (var lstCtrl in obsoleteRings)
            {
                //print ("Delete Ring:" + lstCtrl);
                MiroModelV1 miro = CellObjCtrlUtils.GetMiroModelFromCell(lstCtrl [0]);
                miro.ShrinkRing();
            }

            // create new ring
            foreach (var lstCtrl in newCreateRings)
            {
                //print ("new Ring:" + lstCtrl);
                List <GameObject> rObjs = new List <GameObject> ();
                foreach (CellObjCtrl ctrl in lstCtrl)
                {
                    rObjs.Add(ctrl._TgtObj);
                }
                _mgr.CreateRing(rObjs);
            }

            //_Rings = currentRings;

            ClearContainers();
        }
Example #2
0
        /*
         * override protected void _Calculate()
         * {
         *      List<CellObjCtrl> ringObjs = new List<CellObjCtrl>();
         *      bool bDetected =
         *              CellObjCtrlUtils.DetectNPCCloseChainFrom (_cellCtrl, ref ringObjs);
         *
         *      bool bRing = (ringObjs.Count > 2)&&bDetected;
         *
         *      if (bRing) {
         *              //Debug.Log ("SetUpRing");
         *              SetupRing (ringObjs);
         *      } else {
         *              //Debug.Log ("UnSetUpRing");
         *              UnSetupRing (ringObjs);
         *      }
         *
         *      bool bInRing = ringObjs.Contains (_cellCtrl);
         *      if (!bInRing) {
         *              MiroModelV1 model = CellObjCtrlUtils.GetMiroModelFromCell (_cellCtrl);
         *              model.ShrinkRing ();
         *      }
         *
         * }
         */


        void SetupRing(List <CellObjCtrl> ringObjs)
        {
            bool bExist = false;

            foreach (List <CellObjCtrl> ringObjLst in _Rings)
            {
                bool bSame = IsContainSame(ringObjs, ringObjLst);
                if (bSame)
                {
                    bExist = true;
                    IsContainSame(ringObjs, ringObjLst);
                    //Debug.Log ("bSame!");
                    return;
                }
            }
            bool bIdAdded = true;

            foreach (CellObjCtrl ctrl in ringObjs)
            {
                CCRing cc = ctrl.GetComponentInChildren <CCRing> ();
                bIdAdded = bIdAdded && cc.IsIdAdded();
            }
            if (!bExist && !bIdAdded)
            {
                ReorderRing(ref ringObjs);
                AddIdInRing(ringObjs);
                // shrink smaller ring
                for (int i = _Rings.Count - 1; i >= 0; i--)
                {
                    List <CellObjCtrl> lstCtrl = _Rings [i];
                    foreach (var ctrl in lstCtrl)
                    {
                        if (ringObjs.Contains(ctrl))
                        {
                            MiroModelV1 model = ctrl._TgtObj.GetComponent <MiroModelV1> ();
                            model.ShrinkRing();
                            Debug.Log("model.ShrinkRing (): " + model.name);
                            break;
                        }
                    }
                }
                foreach (List <CellObjCtrl> lstCtrl in _Rings)
                {
                    for (int i = lstCtrl.Count - 1; i >= 0; i--)
                    {
                    }
                    foreach (var ctrl in lstCtrl)
                    {
                        if (ringObjs.Contains(ctrl))
                        {
                            MiroModelV1 model = ctrl._TgtObj.GetComponent <MiroModelV1> ();
                            model.ShrinkRing();
                            Debug.Log("model.ShrinkRing (): " + model.name);
                        }
                    }
                }
                // create new ring
                List <GameObject> rObjs = new List <GameObject> ();
                foreach (CellObjCtrl ctrl in ringObjs)
                {
                    rObjs.Add(ctrl._TgtObj);
                }
                _mgr.CreateRing(rObjs);
                Debug.Log("_mgr.CreateRing (rObjs);");
                _Rings.Add(ringObjs);
            }
            if (_IdInRing == ringObjs.Count - 1)
            {
                ResetIdInRing(ringObjs);
            }
        }