public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityInIndex)
            {
                NativeArray <Entity>        linkingTilesArray  = chunk.GetNativeArray(entityTypeHandle);
                NativeArray <TileComponent> tileComponentArray =
                    chunk.GetNativeArray(tileComponentTypeHandle);

                for (var i = 0; i < chunk.Count; ++i)
                {
                    Entity        tile          = linkingTilesArray[i];
                    TileComponent tileComponent = tileComponentArray[i];

                    for (var j = 0; j < 6; ++j)
                    {
                        Entity adjTile = tileComponent.AdjacentTiles[j];

                        if (adjTile != Entity.Null)
                        {
                            var tileLink = new TileLink
                            {
                                tile = adjTile, index = (j + 3) % 6, adjTile = tile
                            };
                            centerNodesMapWriter.Add(adjTile, tileLink);
                        }
                    }
                }
            }
Example #2
0
        public bool AddComponent(TileComponent tc, int index, bool sendMessage = true)
        {
            bool canAdd = CanAddComponent(tc, index);

            if (!canAdd)
            {
                Debug.Error($"Cannot add component {tc} to tile {this} at index {index}!");
                CanAddComponent(tc, index, out string code);
                Debug.Error($"Error: {code}");

                return(false);
            }

            // Tell the component that we are it's parent (also 'assigns' position).
            tc.Tile  = this;
            tc.Index = index;

            // Write it to the array.
            components[index] = tc;

            // Tell the component that it was just added.
            if (sendMessage)
            {
                tc.UponAdded(this);
            }

            return(true);
        }
Example #3
0
    public async UniTask <TileComponent> PlayAnim(TileComponent tileComponent)
    {
        currTileComponent = tileComponent;
        var willReachLocalPos = tileComponent.transform.localPosition;
        //放在地块左边
        var finalPos   = willReachLocalPos + new Vector3(-3.73f, -0.46f);
        var deltaVecor = finalPos - transform.localPosition;

        if (Mathf.Abs(deltaVecor.y) < float.Epsilon && Mathf.Abs(deltaVecor.x) < float.Epsilon)
        {
            return(currTileComponent);
        }
        currDirection = Vector3.Normalize(deltaVecor);
        totalDistance = Vector3.Distance(finalPos, transform.localPosition);
        if (totalDistance >= QuickReachCount * tileLength)
        {
            //瞬移
            isBeginMove             = false;//之前走的就不继续了
            transform.localPosition = finalPos;
            anim.Play(StateMove.Idle.ToString(), 0);
            return(currTileComponent);
        }
        currWalkDistance = 0f;
        isBeginMove      = true;
        this.finalPos    = finalPos;
        PlayAnimStateByDirection(deltaVecor);
        ctsWaitTileReach = new CancellationTokenSource();
        await UniTask.WaitUntil(() => isBeginMove == false, cancellationToken : ctsWaitTileReach.Token);

        return(currTileComponent);
    }
Example #4
0
    //删除第一次施肥
    public void DestroyFirstStageFertilizer(TileComponent tileComponent)
    {
        ItemFirstStageFertilizerComponent willGetItemFirstStageFertilizerComponent = null;

        ItemFirstStageFertilizerComponent[] itemFirstStageFertilizers = TransGoFirstStageRoot.GetComponentsInChildren <ItemFirstStageFertilizerComponent>();
        bool isFind = false;

        for (int i = 0; i < itemFirstStageFertilizers.Length; i++)
        {
            if (itemFirstStageFertilizers[i].seedGrowComponent == null)
            {
                continue;
            }
            if (itemFirstStageFertilizers[i].seedGrowComponent.tileComponent.SoilId == tileComponent.SoilId)
            {
                isFind = true;
                willGetItemFirstStageFertilizerComponent = itemFirstStageFertilizers[i];
                break;
            }
        }
        if (isFind)
        {
            Destroy(willGetItemFirstStageFertilizerComponent.gameObject);
        }
    }
Example #5
0
    private async System.Threading.Tasks.Task ResetToOldDecorate(bool isAutoPlayCloseDecorate = true)
    {
        if (isAutoPlayCloseDecorate)
        {
            isRotatingDecorate = false;
            //关闭界面
            goRebackAndRotate.SetActive(false);
        }
        //关闭提示
        TipsTileComponent._instance.CloseAll();
        //旋转
        //删除现在的装饰物
        Destroy(currClickDecorateComponent.gameObject);
        //生成老的装饰物
        var goDecorate = await Root2dSceneManager._instance.GenerateDecorate(BeforeRotateInfo.modelName, BeforeRotateInfo.CropGoodId);

        goDecorate.GetComponent <TileComponent>().SetDecorateInfo(BeforeRotateInfo.idxDecorateRotate, BeforeRotateInfo.SoilId, BeforeRotateInfo.CropGoodId, BeforeRotateInfo.regionId);
        goDecorate.transform.localPosition = BeforeRotateInfo.localPos;
        //重新设置当前的组件
        currClickDecorateComponent = goDecorate.GetComponent <TileComponent>();
        //重置旋转后的信息
        AfterRotateInfo = new RotateInfo();
        //排序
        Root2dSceneManager._instance.UpdateSortLayer(true);
    }
Example #6
0
        public bool CanAddComponent(TileComponent tc, int index, out string error)
        {
            if (tc == null)
            {
                // Null component!
                error = "Null component.";
                return(false);
            }
            if (index < 0 || index >= components.Length)
            {
                // Index out of bounds!
                error = $"Index out of bounds: got {index}, expected between 0 and {components.Length - 1} inclusive.";
                return(false);
            }
            if (tc.Tile != null)
            {
                // Component already has parent!
                error = $"Component {tc} already has a parent tile.";
                return(false);
            }
            if (components[index] != null)
            {
                // Component slot is not empty! (slot is already occupied)
                error = $"There is already a component in slot {index}.";
                return(false);
            }

            error = null;
            return(true);
        }
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                NativeArray <TileComponent> tileComponentArray =
                    chunk.GetNativeArray(tileComponentTypeHandle);
                NativeArray <Entity> tileEntityArray = chunk.GetNativeArray(entityTypeHandle);

                for (var i = 0; i < chunk.Count; ++i)
                {
                    Entity        tile          = tileEntityArray[i];
                    TileComponent tileComponent = tileComponentArray[i];

                    for (var j = 0; j < 6; ++j)
                    {
                        if (tileComponent.AdjacentTiles[j] != Entity.Null)
                        {
                            continue;
                        }

                        float3 gridPos = tileComponent.Position + hexTileOffsets[j];
                        mapWriter.Add(gridPos, new TileLink {
                            tile = tile, index = j
                        });
                    }
                }
            }
Example #8
0
    private static void GenerateServerInfo(List <TileComponent> listChildActive)
    {
        List <Generate.SCManorStruct> listManorTree = new List <SCManorStruct>();

        for (int i = 0; i < listChildActive.Count; i++)
        {
            if (listChildActive[i].typeTile == Company.Cfg.TypeManorDecorate.Tile ||
                listChildActive[i].typeTile == Company.Cfg.TypeManorDecorate.Decorate
                /*|| listChildActive[i].typeTile == Company.Cfg.TypeManorDecorate.GiftBox*/
                || listChildActive[i].typeTile == Company.Cfg.TypeManorDecorate.DogHouse)
            {
                SCManorStruct csManorStruct = new SCManorStruct();
                csManorStruct.SoilType       = (Game.Protocal.ManorScene)listChildActive[i].typeTile;
                csManorStruct.CropGoodId     = listChildActive[i].CropGoodId;
                csManorStruct.Xaxle          = listChildActive[i].transform.localPosition.x;
                csManorStruct.Yaxle          = listChildActive[i].transform.localPosition.y;
                csManorStruct.ParcelDivision = listChildActive[i].regionId;
                listManorTree.Add(csManorStruct);
                listChildActive[i].gameObject.SetActive(false);
            }
        }
        //增加NPC
        TileComponent TileNpc          = GameObject.Find("Root2DScene/FemaleManor").GetComponent <TileComponent>();
        SCManorStruct csManorStructNpc = new SCManorStruct();

        csManorStructNpc.SoilType = Game.Protocal.ManorScene.Npc;
        csManorStructNpc.Xaxle    = TileNpc.transform.localPosition.x;
        csManorStructNpc.Yaxle    = TileNpc.transform.localPosition.y;
        listManorTree.Add(csManorStructNpc);

        string jsonInitTreesInScenes = LitJson.JsonMapper.ToJson(listManorTree);

        StaticData.isShowSelfLog = true;
        StaticData.DebugGreen($"====jsonInitTreesInScenes:{jsonInitTreesInScenes}====");
    }
Example #9
0
    void Update()
    {
        if (!isSetup)
        {
            return;
        }
        Movement();
        Zoom();


        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

            if (hit.collider != null)
            {
                Popup.SetActive(true);
                Selected = hit.collider.gameObject;
                Popup.transform.position = new Vector3(Selected.transform.position.x, Selected.transform.position.y, 1);
                TileComponent tComp = Selected.GetComponent <TileComponent>();

                InfoText.text = tComp.GetText();
                if (tComp.TileData.Level > 0)
                {
                    DestroyBuilding.SetActive(true);
                }
                else
                {
                    DestroyBuilding.SetActive(false);
                }
                //Debug.Log("Target Position: " + go.transform.position);
            }
        }
    }
Example #10
0
    public void PlayWateringAnim(TileComponent tile)
    {
        var goWatering = ResourcesHelper.InstantiatePrefabFromABSetDefaultNotStretch(prefabUiWatering, TransWateringParent);

        //设置位置
        goWatering.GetComponent <RectTransform>().anchoredPosition = StaticData.ManorWorldPointToUICameraAnchorPos(tile.transform.position);
        goWatering.SetActive(true);
    }
Example #11
0
    public void PlayExpAnim(TileComponent tile, int addCount)
    {
        var goExp = ResourcesHelper.InstantiatePrefabFromABSetDefaultNotStretch(goPrefabItemExp, tranParentExp);

        //设置位置
        goExp.GetComponent <RectTransform>().anchoredPosition = StaticData.ManorWorldPointToUICameraAnchorPos(tile.transform.position) + new Vector2(-50f, 50f);
        goExp.GetComponent <UIItemExpEffect>().ShowInfo(addCount);
    }
Example #12
0
 public void SetCanPlace(Transform transParent, bool isCanPlace, TileComponent tileComponent)
 {
     transform.parent           = transParent;
     transform.localPosition    = Vector3.zero;
     transform.localEulerAngles = Vector3.zero;
     goCanPlace.SetActive(isCanPlace);
     goNotAllow.SetActive(!isCanPlace);
 }
        public static bool IsMoveComponentUp( TileComponent component )
        {
            Tile tile = component.tile;

            TileComponent[] components = tile.GetComponents<TileComponent>();
            int index = System.Array.IndexOf( components,component );

            return index > 0;
        }
Example #14
0
    private async void RotateDecorate(bool isLeft)
    {
        var listModel    = StaticData.configExcel.GetDecorateByDecorateId(currClickDecorateComponent.CropGoodId).Model;
        int idxPreRotate = currClickDecorateComponent.idxDecorateRotate;

        int idxCurrRotate = 0;

        if (isLeft)
        {//左旋
            idxCurrRotate = idxPreRotate - 1;
            if (idxCurrRotate < 0)
            {
                idxCurrRotate = listModel.Count - 1;
            }
        }
        else
        {//右旋
            idxCurrRotate = idxPreRotate + 1;
            if (idxCurrRotate > listModel.Count - 1)
            {
                idxCurrRotate = 0;
            }
        }

        //记录旋转之后的信息
        if (currClickDecorateComponent != null)
        {
            AfterRotateInfo.idxDecorateRotate = idxCurrRotate;
            AfterRotateInfo.SoilId            = currClickDecorateComponent.SoilId;
            AfterRotateInfo.CropGoodId        = currClickDecorateComponent.CropGoodId;
            AfterRotateInfo.regionId          = currClickDecorateComponent.regionId;
            AfterRotateInfo.modelName         = listModel[idxCurrRotate];
            AfterRotateInfo.localPos          = currClickDecorateComponent.transform.localPosition;
            //删除原来的装饰物
            Destroy(currClickDecorateComponent.gameObject);
        }
        //旋转
        //生成新的装饰物
        var goDecorate = await Root2dSceneManager._instance.GenerateDecorate(AfterRotateInfo.modelName, AfterRotateInfo.CropGoodId);

        goDecorate.GetComponent <TileComponent>().SetDecorateInfo(AfterRotateInfo.idxDecorateRotate, AfterRotateInfo.SoilId, AfterRotateInfo.CropGoodId, AfterRotateInfo.regionId);
        goDecorate.transform.localPosition = AfterRotateInfo.localPos;
        //重新设置当前的组件
        currClickDecorateComponent = goDecorate.GetComponent <TileComponent>();
        currClickDecorateComponent.CheckIsCanPlace(() =>
        {
            AfterRotateInfo.isCanPlace = false;
            //显示红色箭头
            TipsTileComponent._instance.SetCanPlace(currClickDecorateComponent.transform, false, currClickDecorateComponent);
        }, () =>
        {
            AfterRotateInfo.isCanPlace = true;
            //显示蓝色箭头
            TipsTileComponent._instance.SetCanPlace(currClickDecorateComponent.transform, true, currClickDecorateComponent);
        });
    }
Example #15
0
    private void AfterPlantCropSetInfo(TileComponent tileComponent)
    {
        //设置庄稼
        var seedGrowCom = goPlant.GetComponent <SeedGrowComponent>();

        seedGrowCom.SetCropId(CropGoodId, tileComponent);
        seedGrowCom.GenerateTimer();
        seedGrowCom.SetPeriod(SeedGrowComponent.PeriodGrow.Seed);
        Root2dSceneManager._instance.AddListSeedGrow(seedGrowCom);
    }
Example #16
0
    public NodeComponent GetNeighbour(Vector3 _direction)
    {
        TileComponent tile = TileComponent.GetTileAt(transform.position + _direction);

        if (tile == null)
        {
            return(null);
        }

        return(tile.GetComponent <NodeComponent>());
    }
Example #17
0
    //public void PlayCameraToUnLockRegionOld()
    //{
    //    DOTween.To(() => cameraWorld.orthographicSize, (size) => { cameraWorld.orthographicSize = size; }, 1.08f, 1f);
    //}

    public void PlayUIExceedReback(Vector3 deltaVecScreen, GameObject goUI, TileComponent tileComponent, UIWorldHandleManager.TypePointUI typePointUI)
    {
        float zoomRadio = Root2dSceneManager._instance.zoomRadio;

        deltaVecScreen = deltaVecScreen / radioUIToScene / zoomRadio * 1.2f;
        DOTween.To(() => cameraWorld.transform.localPosition, (pos) =>
        {
            SetCameraLocalPos(pos);
            StaticData.GetUIWorldHandleComponent().SetWorldPos(tileComponent, goUI, typePointUI);
        }, cameraWorld.transform.localPosition + deltaVecScreen, 1f);
    }
Example #18
0
    public async void PlayItemHarvestEffect(TileComponent tile, int addCount)
    {
        var goPlant = ResourcesHelper.InstantiatePrefabFromABSetDefaultNotStretch(goPrefabItemPlant, transParentOneKey);

        //设置位置
        goPlant.GetComponent <RectTransform>().anchoredPosition = StaticData.ManorWorldPointToUICameraAnchorPos(tile.transform.position);
        //设置图片个数
        int    cropId       = tile.CropGoodId;
        int    gameDefineId = StaticData.configExcel.GetManorCropByCropId(cropId).IdGainGameItem;
        string iconName     = StaticData.configExcel.GetGameItemByID(gameDefineId).Icon;

        goPlant.GetComponent <UIItemPlantEffect>().ShowInfo(iconName, addCount);
    }
        public static void CopyComponent( TileComponent component )
        {
            if( _CopiedComponent != null )
            {
                Object.DestroyImmediate( _CopiedComponent );
                _CopiedComponent = null;
            }

            System.Type classType = component.GetType();
            _CopiedComponent = ScriptableObject.CreateInstance( classType ) as TileComponent;
            _CopiedComponent.hideFlags = HideFlags.HideAndDontSave;

            EditorUtility.CopySerialized( component,_CopiedComponent );
        }
            public void Execute(int i)
            {
                Entity        tile = tileBufferMapKeys[i];
                TileBuffer    updatedTileBuffer    = tileBufferMap[tile];
                TileComponent curTileComponent     = tileComponentLookup[tile];
                var           updatedTileComponent = new TileComponent
                {
                    Position      = curTileComponent.Position,
                    State         = curTileComponent.State,
                    AdjacentTiles = updatedTileBuffer
                };

                ecbWriter.SetComponent(i, tile, updatedTileComponent);
            }
Example #21
0
        public void Convert(Entity entity,
                            EntityManager entityManager,
                            GameObjectConversionSystem conversionSystem)
        {
            Vector3 pos           = transform.position;
            var     gridPos       = new float3(pos.x, pos.y - .3f, pos.z);
            var     tileComponent = new TileComponent
            {
                Position = gridPos, State = 0, AdjacentTiles = TileBuffer.Empty
            };

            entityManager.AddComponentData(entity, tileComponent);
            entityManager.AddSharedComponentData(entity, GridGenerationComponent.ExpansionPhase);
            entityManager.AddBuffer <StatefulTriggerEvent>(entity);
        }
Example #22
0
    public void DestroyAllTiles()
    {
        for (int i = 0; i < tiles.Length; i++)
        {
            if (tiles[i])
            {
                TileComponent tile = tiles[i].GetComponent <TileComponent>();
                if (tile)
                {
                    tile.CombineAndDestroyTile();
                }
            }

            tiles[i] = null;
        }
    }
Example #23
0
    // on collision with tiles, add them to list
    void OnTriggerEnter(Collider other)
    {
        TileComponent tile = other.gameObject.GetComponent <TileComponent>();

        if (tile)
        {
            for (int i = 0; i < MAX_TILE_COUNT; ++i)
            {
                if (tiles[i] == null)
                {
                    tiles[i] = other.gameObject;
                    break;
                }
            }
        }
    }
Example #24
0
        private void GetMergedComponent(TileComponent neighbourComponent, TileComponent component, out BoardComponent merged)
        {
            var bcComponent = _boardComponentRepository.Get(component.BoardComponentId) ?? component.BoardComponent;
            var bcNeighbour = _boardComponentRepository.Get(neighbourComponent.BoardComponentId) ?? neighbourComponent.BoardComponent;

            merged = bcNeighbour;

            // join new component to existing bc
            if (bcComponent != null)
            {
                merged = MergeBoardComponents(bcComponent, bcNeighbour);
            }

            merged.Components.Add(component);
            component.BoardComponent   = merged;
            component.BoardComponentId = merged.BoardComponentId;
        }
Example #25
0
    public int getNumEnergyTiles()
    {
        int numEnergy = 0;

        for (int j = 0; j < tiles.Length; j++)
        {
            if (tiles[j] != null)
            {
                TileComponent tc = tiles[j].GetComponent <TileComponent>();
                if (tc != null && tc.type == TileType.Energy)
                {
                    numEnergy++;
                }
            }
        }
        return(numEnergy);
    }
Example #26
0
    public List <TileType> getAllValidTiles()
    {
        var tiles = new List <TileType>();

        for (int j = 0; j < this.tiles.Length; j++)
        {
            if (this.tiles[j] != null)
            {
                TileComponent tc = this.tiles[j].GetComponent <TileComponent>();
                if (tc != null && tc.type != TileType.Invalid)
                {
                    tiles.Add(tc.type);
                }
            }
        }
        return(tiles);
    }
Example #27
0
    public void OpenRootPlant(TileComponent tileComponent)
    {
        //打开种植的时候情况列表
        Root2dSceneManager._instance.PlantData.PlantInfo.Clear();
        currClickComponent = tileComponent;
        SetWorldPos(tileComponent, goPlant, TypePointUI.Plant);
        goPlant.SetActive(true);

        var listSeed = StaticData.GetPlantSeeds();

        loopHorizontalScrollRect.ClearCells();
        loopHorizontalScrollRect.totalCount = listSeed.Count;
        //计算适配器初始值
        loopHorizontalScrollRect.GetComponent <UIPlantScrollViewAdapter>().CalcAdapterSizeByCount(listSeed.Count);
        //只有是显示状态刷新才有效
        loopHorizontalScrollRect.RefillCells();
        scrollCameraWhenBoundsOutScreenPlant.PlayCameraAnimWhenOutScreen(goPlant, tileComponent, TypePointUI.Plant);
    }
Example #28
0
    //点击地块直接施肥
    public void ClickTileToFirstFertilizer(TileComponent tileComponent)
    {
        ItemFirstStageFertilizerComponent willSetItemFirstStageFertilizerComponent = null;

        ItemFirstStageFertilizerComponent[] itemFirstStageFertilizers = TransGoFirstStageRoot.GetComponentsInChildren <ItemFirstStageFertilizerComponent>();
        bool isFind = false;

        for (int i = 0; i < itemFirstStageFertilizers.Length; i++)
        {
            if (itemFirstStageFertilizers[i].seedGrowComponent.tileComponent.SoilId == tileComponent.SoilId)
            {
                isFind = true;
                willSetItemFirstStageFertilizerComponent = itemFirstStageFertilizers[i];
                break;
            }
        }
        if (isFind)
        {
            willSetItemFirstStageFertilizerComponent.OnButtonFertilizerClick();
        }
    }
    void GenerateEndObject(Vector3 _position)
    {
        Vector3 raisedPosition = new Vector3(_position.x, _position.y, 1);

        RaycastHit2D mouseRaycast = Physics2D.Raycast(raisedPosition, Vector3.forward, 2);

        if (mouseRaycast.collider != null && mouseRaycast.collider.tag == "Tile")
        {
            TileComponent tile = mouseRaycast.collider.GetComponent <TileComponent>();

            if (!tile.HasStartObject() && !tile.HasEndObject())
            {
                if (EndObject != null)
                {
                    Destroy(EndObject);
                }

                EndObject = Instantiate(EndPrototype);
                EndObject.transform.position = new Vector3(Mathf.RoundToInt(_position.x), Mathf.RoundToInt(_position.y), 0);
            }
        }
    }
Example #30
0
    void SpawnObjects()
    {
        for (int x = 0; x < width; x++)
        {
            tileGrid.Add(new List <TileComponent>());   // tileGrid.append([])
            for (int y = 0; y < height; y++)
            {
                int        randomIndex      = Random.Range(0, tilePrefabList.Count);
                GameObject randomTilePrefab = tilePrefabList[randomIndex];
                Vector3    spawnPosition    = new Vector3(x, y, 0);

                //Instantiate(randomTilePrefab, spawnPosition, Quaternion.identity, this.transform);
                //GameObject newTileObject = Instantiate(randomTilePrefab, spawnPosition, Quaternion.identity);
                //newTileObject.transform.SetParent(this.transform);

                GameObject newTileObject = Instantiate(randomTilePrefab, this.transform);
                newTileObject.transform.localPosition = spawnPosition;
                TileComponent newTileComponent = newTileObject.GetComponent <TileComponent>();
                newTileComponent.Init(x, y);

                newTileComponent.OnClickedEvent.AddListener(FlipTilesAdjacentTo);

                tileGrid[x].Add(newTileComponent);
            }
        }

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                bool coinFlip = Random.value <= 0.5f;
                if (coinFlip)
                {
                    //newTileComponent.ToggleMaterial();
                    FlipTilesAdjacentTo(x, y);
                }
            }
        }
    }
Example #31
0
        /// <summary>
        /// Called when the tile has been send from the server to this client.
        /// Here the data needs to be read and immediately applied.
        /// Default implementation reads the <see cref="BaseSpriteTint"/>, and all components.
        /// </summary>
        /// <param name="msg">The message to read data from.</param>
        /// <param name="forSpawn">If <see langword="true"/>, then all required data should be read, since this client knows nothing about this tile. If <see langword="false"/>, then only data that might have changed since spawned needs to be read.</param>
        public virtual void ReadData(NetBuffer msg, bool forSpawn)
        {
            this.BaseSpriteTint = msg.ReadColor();

            byte compCount = msg.ReadByte();

            for (int i = 0; i < compCount; i++)
            {
                byte index = msg.ReadByte();

                if (forSpawn)
                {
                    ushort id      = msg.ReadUInt16();
                    var    newComp = TileComponent.Create(id);
                    RemoveComponent(index, false);
                    AddComponent(newComp, index, false);
                }

                var current = components[index];
                current.ReadData(msg, forSpawn);
            }
        }
Example #32
0
    internal void SetGrowUpInfo(TileComponent tileComponent, SeedGrowComponent seedGrowComponent)
    {
        this.seedGrowComponent = seedGrowComponent;
        currClickComponent     = tileComponent;
        var cropDefine = StaticData.configExcel.GetManorCropByCropId(tileComponent.CropGoodId);

        seedName = StaticData.GetMultiLanguageByGameItemId(cropDefine.IdGainGameItem);
        if (Root2dSceneManager._instance.isFriendManor)
        {
            isShowGrowUpUIFriendManor = true;
            SetWorldPos(tileComponent, goGrowUpFriendManor, TypePointUI.GrowUp);
        }
        else
        {
            if (!isFertiliezeringAnimPlay)
            {
                SetWorldPos(tileComponent, SelfGrowUpComponent.gameObject, TypePointUI.GrowUp);
                SelfGrowUpComponent.seedGrowComponent = seedGrowComponent;
                isShowGrowUpUI = true;
            }
        }
    }
Example #33
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            camera = new Camera2D(new Vector2(0f, 0f), new Vector2(1f), new Vector2(3f));

            this.Services.AddService(typeof(SpriteBatch), spriteBatch);
            this.Services.AddService(typeof(Camera2D), camera);

            texture1 = this.Content.Load<Texture2D>("tex");
            TileCatalog cat1 = new TileCatalog(texture1, 15, 15);

            Random rand = new Random(DateTime.Now.Millisecond);
            TileMap map1 = new TileMap(100, 100);
            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    map1.SetTile(i, j, new Tile(rand.Next(1, cat1.TilePositions.Count)));
                }
            }

            TileLayer layer1 = new TileLayer(cat1, map1, 0.5f, false, new Vector2(0, 0), new Vector2(1f, 1f), new Vector2(3f), false, LayerMovementDirection.None);

            texture2 = this.Content.Load<Texture2D>("tiles2");

            TileCatalog cat2 = new TileCatalog(texture2, 48, 48);
            TileMap map2 = new TileMap(10, 500);
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 500; j++)
                {
                    map2.SetTile(i, j, new Tile(rand.Next(1, cat2.TilePositions.Count)));
                }
            }
            TileLayer layer2 = new TileLayer(cat2, map2, 1.0f, false, new Vector2(0, 0), new Vector2(1f, 1f), new Vector2(3f), true, LayerMovementDirection.Up);

            scene = new TileScene();
            scene.AddLayer(layer2);
            scene.AddLayer(layer1);

            TileComponent component = new TileComponent(this, scene, baseScreenSize, resultionIndependent);
            this.Components.Add(component);

            TextureLayer tLayer1 = new TextureLayer(this.texture1, 1f, false, new Vector2(20f), Vector2.One, new Vector2(1.5f,1.5f), true, Anchor.LowerRight);
            TextureLayer tLayer2 = new TextureLayer(this.texture2, 0.5f, false, new Vector2(10f), Vector2.One, new Vector2(5f), true, Anchor.LowerLeft);

            TextureScene tScene = new TextureScene();
            tScene.AddLayer(tLayer1);
            tScene.AddLayer(tLayer2);
            TextureComponent tComponent = new TextureComponent(this, tScene, baseScreenSize, resultionIndependent);
            this.Components.Add(tComponent);

            texture1 = this.Content.Load<Texture2D>("megax");
            SpriteCatalog scatalog = new SpriteCatalog(texture1, 36, 42);

            SpriteSequence[] spriteSecuences = new SpriteSequence[2];

            SpriteSequence spriteSecuence1 = new SpriteSequence(7, 0);
            spriteSecuence1.StepTime = 400;
            spriteSecuence1.SetFrame(0,new SpriteFrame(1));
            spriteSecuence1.SetFrame(1, new SpriteFrame(1));
            spriteSecuence1.SetFrame(2, new SpriteFrame(1));
            spriteSecuence1.SetFrame(3, new SpriteFrame(1));
            spriteSecuence1.SetFrame(4, new SpriteFrame(2));
            spriteSecuence1.SetFrame(5, new SpriteFrame(3));
            spriteSecuence1.SetFrame(6, new SpriteFrame(1));
            spriteSecuences[0] = spriteSecuence1;

            SpriteSequence spriteSecuence2 = new SpriteSequence(10, 0);
            spriteSecuence2.StepTime = 90;
            spriteSecuence2.SetFrame(0, new SpriteFrame(5));
            spriteSecuence2.SetFrame(1, new SpriteFrame(6));
            spriteSecuence2.SetFrame(2, new SpriteFrame(7));
            spriteSecuence2.SetFrame(3, new SpriteFrame(8));
            spriteSecuence2.SetFrame(4, new SpriteFrame(9));
            spriteSecuence2.SetFrame(5, new SpriteFrame(10));
            spriteSecuence2.SetFrame(6, new SpriteFrame(11));
            spriteSecuence2.SetFrame(7, new SpriteFrame(12));
            spriteSecuence2.SetFrame(8, new SpriteFrame(13));
            spriteSecuence2.SetFrame(9, new SpriteFrame(14));

            spriteSecuences[1] = spriteSecuence2;

            SpriteLayer spLayer = new SpriteLayer(scatalog, spriteSecuences, 1.0f, true, new Vector2(10f), Vector2.One, Vector2.Zero, SpriteEffects.None, true, Anchor.None);
            spLayer.CurrentSequence = 2;
            SpriteScene spScene = new SpriteScene();
            spScene.AddLayer(spLayer);
            SpriteComponent spComponent = new SpriteComponent(this, spScene, baseScreenSize, resultionIndependent);
            this.Components.Add(spComponent);
        }
        public static void MoveComponentDown( TileComponent component )
        {
            Tile tile = component.tile;

            TileComponent[] components = tile.GetComponents<TileComponent>();
            int index = System.Array.IndexOf( components,component );

            Undo.RecordObject( tile,"Move Down" );

            tile.MoveComponent( index,index+1 );
        }
 public static bool IsPasteComponent( TileComponent component )
 {
     return _CopiedComponent != null && component.GetType () == _CopiedComponent.GetType();
 }
        public static void Reset( TileComponent component )
        {
            Tile tile = component.tile;

            System.Type classType = component.GetType();
            Undo.RecordObject( component,"Reset " + classType.Name );

            TileComponent initializeComponent = ScriptableObject.CreateInstance( classType ) as TileComponent;
            EditorUtility.CopySerialized( initializeComponent,component );

            tileField.SetValue( component,tile );

            MethodInfo resetMethod = classType.GetMethod( "Reset",BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic );
            if( resetMethod != null )
            {
                resetMethod.Invoke( component,null );
            }
        }
        public static void PasteComponentValues( TileComponent component )
        {
            if( !IsPasteComponent( component ) )
            {
                Debug.LogError( "Not copied component." );
                return;
            }

            Tile tile = component.tile;

            System.Type classType = _CopiedComponent.GetType();

            Undo.RecordObject( component,"Paste " + classType.Name + " Values" );

            EditorUtility.CopySerialized( _CopiedComponent,component );

            tileField.SetValue( component,tile );
        }