Esempio n. 1
0
    public bool IsInvalidGrid(FarmField farmField, int[] gridIndexs)
    {
        bool result = false;

        FarmField.Field field = farmField.GetField();
        foreach (int num in gridIndexs)
        {
            if (0 > num || field.grids.Count <= num || field.grids[num].invalid)
            {
                result = true;
                break;
            }
        }
        return(result);
    }
Esempio n. 2
0
    public static int ChooseAroundGridIndex(FarmObject farmObject)
    {
        FarmRoot  instance = FarmRoot.Instance;
        FarmField field    = instance.Field;

        FarmGrid.GridPosition gridPosition = field.Grid.GetGridPosition(farmObject.transform.localPosition);
        int[] gridIndexs         = farmObject.GetGridIndexs(field.GetField(), field.Grid.GetGridIndex(gridPosition));
        int[] aroundGridIndexs   = FarmDigimonUtility.GetAroundGridIndexs(gridIndexs);
        int[] passableGridIndexs = field.Grid.GetPassableGridIndexs(aroundGridIndexs);
        if (0 < passableGridIndexs.Length)
        {
            int num = UnityEngine.Random.Range(0, passableGridIndexs.Length);
            return(passableGridIndexs[num]);
        }
        return(-1);
    }
Esempio n. 3
0
    private IEnumerator HitCheckBuild()
    {
        FarmRoot             farmRoot  = FarmRoot.Instance;
        FarmField            farmField = farmRoot.Field;
        List <FarmGrid.Grid> grids     = farmField.GetField().grids;

        while (base.gameObject.activeSelf)
        {
            while (!this.digimon.activeSelf)
            {
                yield return(new WaitForSeconds(1f));
            }
            while (!this.CheckHitBuild(farmField.Grid, grids))
            {
                yield return(new WaitForSeconds(0.5f));
            }
        }
        yield break;
    }
Esempio n. 4
0
 public bool OnDrag(InputControll inputControll)
 {
     if (this.farmObject.gameObject == inputControll.rayHitColliderObject)
     {
         FarmRoot  instance = FarmRoot.Instance;
         FarmField field    = instance.Field;
         if (field.Grid.isSelectedGrid)
         {
             FarmField.Field field2     = field.GetField();
             int[]           gridIndexs = this.farmObject.GetGridIndexs(field2, field.Grid.selectedGridIndex);
             if (!this.farmObject.IsInvalidGrid(field, gridIndexs))
             {
                 this.farmObject.SetPosition(field.gridHorizontal, field.gridVertical, field.Grid.GetPositionGridCenter(field.Grid.selectedGridIndex, false));
                 this.farmObject.DisplayedInFront(true);
                 bool placeable = false == this.farmObject.IsPutGrid(field2, gridIndexs);
                 this.farmObject.SetPlaceable(placeable);
             }
         }
         return(true);
     }
     return(false);
 }
Esempio n. 5
0
    public bool SetEditFarmObject(FarmObject farmObject, Vector3 basePos3D)
    {
        FarmRoot  instance = FarmRoot.Instance;
        FarmField field    = instance.Field;

        FarmField.Field field2 = field.GetField();
        this.farmObject  = farmObject;
        this.settingMode = FarmObjectSetting.SettingMode.EDIT;
        FarmGrid.GridPosition gridPosition = field.Grid.GetGridPosition(basePos3D);
        bool flag = field.IsOutsideField(gridPosition);

        if (flag)
        {
            gridPosition = field.Grid.GetGridPosition(Vector3.zero);
        }
        int     gridIndex          = field.Grid.GetGridIndex(gridPosition);
        Vector3 positionGridCenter = field.Grid.GetPositionGridCenter(gridIndex, false);

        this.farmObject.SetPosition(field.gridHorizontal, field.gridVertical, positionGridCenter);
        this.farmObject.DisplayedInFront(true);
        int[] gridIndexs = this.farmObject.GetGridIndexs(field2, gridIndex);
        this.farmObject.isPlaceable = (!this.farmObject.IsInvalidGrid(field, gridIndexs) && !this.farmObject.IsPutGrid(field2, gridIndexs));
        return(flag);
    }
Esempio n. 6
0
    public bool SetFarmObject(FarmObject farmObject, Vector3 basePos3D)
    {
        FarmField field = FarmRoot.Instance.Field;

        this.farmObject  = farmObject;
        this.settingMode = FarmObjectSetting.SettingMode.BUILD;
        this.farmObject.SetSettingMark(field, FarmRoot.Instance.SettingMark);
        FarmGrid.GridPosition gridPosition = field.Grid.GetGridPosition(basePos3D);
        bool flag = field.IsOutsideField(gridPosition);

        if (flag)
        {
            gridPosition = field.Grid.GetGridPosition(Vector3.zero);
        }
        int     gridIndex          = field.Grid.GetGridIndex(gridPosition);
        Vector3 positionGridCenter = field.Grid.GetPositionGridCenter(gridIndex, false);

        this.farmObject.SetPosition(field.gridHorizontal, field.gridVertical, positionGridCenter);
        this.farmObject.DisplayedInFront(true);
        FarmField.Field field2 = field.GetField();
        this.farmObject.SetMarkColor(field2, gridIndex);
        FarmRoot.Instance.Input.AddTouchDragEvent(new Func <InputControll, bool>(this.OnDrag));
        return(flag);
    }