Ejemplo n.º 1
0
 protected override void Start()
 {
     base.Start();
     this._firstLabelPosition = this.LabelPoint.get_position();
     ObservableExtensions.Subscribe <int>(Observable.DistinctUntilChanged <int>((IObservable <M0>) this._commandAreaIndex), (Action <M0>)(index =>
     {
         Transform labelPoint = this.LabelPoint;
         if (Object.op_Equality((Object)labelPoint, (Object)null))
         {
             return;
         }
         if (0 <= index && !((IReadOnlyList <PetHomePoint.CommandAreaInfo>) this._commandAreaInfos).IsNullOrEmpty <PetHomePoint.CommandAreaInfo>() && index < this._commandAreaInfos.Length)
         {
             PetHomePoint.CommandAreaInfo commandAreaInfo = this._commandAreaInfos[index];
             if (commandAreaInfo != null && Object.op_Inequality((Object)commandAreaInfo.LabelPoint, (Object)null))
             {
                 labelPoint.set_position(commandAreaInfo.LabelPoint.get_position());
                 return;
             }
         }
         labelPoint.set_position(this._firstLabelPosition);
     }));
     if (!Singleton <Resources> .IsInstance())
     {
         return;
     }
     if (Object.op_Equality((Object)this._commandBasePoint, (Object)null))
     {
         GameObject loop = ((Component)this).get_transform().FindLoop(Singleton <Resources> .Instance.DefinePack.MapDefines.CommandTargetName);
         this._commandBasePoint = !Object.op_Inequality((Object)loop, (Object)null) ? ((Component)this).get_transform() : loop.get_transform();
     }
     if (Object.op_Equality((Object)this._labelPoint, (Object)null))
     {
         GameObject loop = ((Component)this).get_transform().FindLoop(Singleton <Resources> .Instance.DefinePack.MapDefines.PetHomePointLabelTargetName);
         this._labelPoint = !Object.op_Inequality((Object)loop, (Object)null) ? ((Component)this).get_transform() : loop.get_transform();
     }
     if (((IReadOnlyList <Transform>) this._rootPoints).IsNullOrEmpty <Transform>())
     {
         this.SetSizeRootPoints();
         if (((IReadOnlyList <Transform>) this._rootPoints).IsNullOrEmpty <Transform>())
         {
             this._rootPoints = new Transform[1]
             {
                 ((Component)this).get_transform()
             }
         }
         ;
     }
     this.InitializeCommandLabels();
 }
Ejemplo n.º 2
0
        public bool IsReachable(NavMeshAgent nmAgent, float radiusA, float radiusB)
        {
            if (Object.op_Equality((Object)nmAgent, (Object)null) || !((Behaviour)nmAgent).get_isActiveAndEnabled())
            {
                return(false);
            }
            if (this._pathForCalc == null)
            {
                this._pathForCalc = new NavMeshPath();
            }
            bool flag = true;

            if (((Behaviour)nmAgent).get_isActiveAndEnabled())
            {
                switch (this._homeKind)
                {
                case PetHomePoint.HomeKind.PetMat:
                    nmAgent.CalculatePath(this.Position, this._pathForCalc);
                    flag &= this._pathForCalc.get_status() == 0;
                    break;

                case PetHomePoint.HomeKind.FishTank:
                    flag = false;
                    int num1 = -1;
                    if (!((IReadOnlyList <PetHomePoint.CommandAreaInfo>) this._commandAreaInfos).IsNullOrEmpty <PetHomePoint.CommandAreaInfo>())
                    {
                        List <ValueTuple <int, Vector3> > toRelease = ListPool <ValueTuple <int, Vector3> > .Get();

                        for (int index = 0; index < this._commandAreaInfos.Length; ++index)
                        {
                            PetHomePoint.CommandAreaInfo commandAreaInfo = this._commandAreaInfos[index];
                            if (commandAreaInfo != null && commandAreaInfo.IsActive)
                            {
                                toRelease.Add(new ValueTuple <int, Vector3>(index, commandAreaInfo.BasePoint.get_position()));
                            }
                        }
                        Vector3 position = ((Component)nmAgent).get_transform().get_position();
                        toRelease.Sort((Comparison <ValueTuple <int, Vector3> >)((x, y) => (int)((double)Vector3.SqrMagnitude(Vector3.op_Subtraction((Vector3)x.Item2, position)) - (double)Vector3.SqrMagnitude(Vector3.op_Subtraction((Vector3)y.Item2, position)))));
                        for (int index = 0; index < toRelease.Count; ++index)
                        {
                            ValueTuple <int, Vector3> valueTuple = toRelease[index];
                            nmAgent.CalculatePath((Vector3)valueTuple.Item2, this._pathForCalc);
                            if (flag = this._pathForCalc.get_status() == 0)
                            {
                                num1 = (int)valueTuple.Item1;
                                break;
                            }
                        }
                        ListPool <ValueTuple <int, Vector3> > .Release(toRelease);
                    }
                    ((ReactiveProperty <int>) this._commandAreaIndex).set_Value(num1);
                    if (!flag)
                    {
                        nmAgent.CalculatePath(this.Position, this._pathForCalc);
                        flag = this._pathForCalc.get_status() == 0;
                        break;
                    }
                    break;
                }
                float     num2    = 0.0f;
                Vector3[] corners = this._pathForCalc.get_corners();
                for (int index = 0; index < corners.Length - 1; ++index)
                {
                    float num3 = Vector3.Distance(corners[index], corners[index + 1]);
                    num2 += num3;
                    float num4 = this.CommandType != CommandType.Forward ? radiusB : radiusA;
                    if ((double)num2 > (double)num4)
                    {
                        flag = false;
                        break;
                    }
                }
            }
            return(flag);
        }