예제 #1
0
    void Awake()
    {
        instance = this;

        float screenRatio = (float)Screen.width / (float)Screen.height;
        float targetRatio = ((float)GridWidth * CellSize) / ((float)GridHeight * CellSize);

        if (screenRatio >= targetRatio)
        {
            Camera.main.orthographicSize = ((float)GridHeight * CellSize) / 2;
        }
        else
        {
            float differenceInSize = targetRatio / screenRatio;
            Camera.main.orthographicSize = ((float)GridHeight * CellSize) / 2 * differenceInSize;
        }

        //Grab Entity Manager
        em = World.DefaultGameObjectInjectionWorld.EntityManager;

        //Cell ArchType
        CellArchtype = em.CreateArchetype(
            typeof(LocalToWorld),
            typeof(Translation),
            typeof(Rotation),
            typeof(NonUniformScale),
            typeof(CellComponent));

        // Generate our grid
        CreateGrid();
    }
예제 #2
0
    // Property
    #region Property

    #endregion

    // MonoBehaviour
    #region MonoBehaviour
    private void Awake()
    {
        if (m_CreateTileMap == null)
        {
            m_CreateTileMap = GameObject.Find(Common.TileGrideName).GetComponent <CreateTileMap>();
        }

        m_Camera.orthographic     = true;
        m_Camera.orthographicSize = 1.2f;
        CameraWidthHeight.y       = 2 * m_Camera.orthographicSize;
        CameraWidthHeight.x       = CameraWidthHeight.y * m_Camera.aspect;
    }
예제 #3
0
    protected override void OnUpdate()
    {
        entityQuery = GetEntityQuery(ComponentType.ReadOnly <CellComponent>());

        NativeArray <CellComponent> cellSpriteDataArray = entityQuery.ToComponentDataArray <CellComponent>(Allocator.TempJob);

        MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();

        Vector4[] uv               = new Vector4[1];
        Camera    mainC            = Camera.main;
        Material  SpriteSheetMat   = CreateTileMap.GetInstance().SpriteSheetMat;
        Mesh      mesh             = CreateTileMap.GetInstance().quadMesh;
        int       shaderPropertyId = Shader.PropertyToID("_MainTex_UV");

        //Account for limitations of DrawMeshInstanced
        int sliceCount = 1023;

        for (int i = 0; i < cellSpriteDataArray.Length; i += sliceCount)
        {
            int sliceSize = math.min(cellSpriteDataArray.Length - i, sliceCount);

            List <Matrix4x4> matrixList = new List <Matrix4x4>();
            List <Vector4>   uvList     = new List <Vector4>();
            for (int j = 0; j < sliceSize; j++)
            {
                CellComponent cellComponentData = cellSpriteDataArray[i + j];
                matrixList.Add(cellComponentData.matrix);
                uvList.Add(cellComponentData.uv);
            }

            materialPropertyBlock.SetVectorArray(shaderPropertyId, uvList);

            Graphics.DrawMeshInstanced(
                mesh,
                0,
                SpriteSheetMat,
                matrixList,
                materialPropertyBlock);
        }

        cellSpriteDataArray.Dispose();
    }
예제 #4
0
 void Start()
 {
     tileMap         = GameObject.FindGameObjectWithTag("TileMap");
     createTileMap   = tileMap.GetComponent <CreateTileMap>();
     buildingManager = GameObject.FindGameObjectWithTag("BuildingManager").GetComponent <BuildingManager>();
 }
예제 #5
0
 private void Awake()
 {
     playerHandler = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerHandler>();
     cTM           = GameObject.FindGameObjectWithTag("TileMap").GetComponent <CreateTileMap>();
     resManager    = playerHandler.resourceManager;
 }
예제 #6
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        //Get Entity Query of CellComponents
        entityQuery = GetEntityQuery(ComponentType.ReadOnly <CellComponent>());

        //Create Readable Current Array
        var current = entityQuery.ToComponentDataArray <CellComponent>(Allocator.TempJob);

        //Create Writable next(Future) Array
        var next = new NativeArray <CellComponent>(current.Length, Allocator.TempJob);

        //Set next = current to preserve data
        next.CopyFrom(current);

        // Max and min cell liquid values
        float MaxLiquid = 1.0f;
        float MinLiquid = 0.005f;

        // Extra liquid a cell can store than the cell above it
        float MaxCompression = 0.25f;

        // Lowest and highest amount of liquids allowed to flow per iteration
        float MinFlow = 0.005f;
        float MaxFlow = 4f;

        // Adjusts flow speed (0.0f - 1.0f)
        float FlowSpeed = 1f;

        //Grid Width of Map
        int GridWidth = CreateTileMap.GetInstance().GridWidth;

        //Calculate Water Physics
        inputDeps = new CalculateWaterPhysics()
        {
            current        = current,
            next           = next,
            MaxLiquid      = MaxLiquid,
            MinLiquid      = MinLiquid,
            MaxCompression = MaxCompression,
            MinFlow        = MinFlow,
            MaxFlow        = MaxFlow,
            FlowSpeed      = FlowSpeed,
            GridWidth      = GridWidth,
            deltaTime      = Time.DeltaTime //Delta Time is applied to Flow
        }.Schedule(current.Length, 32);

        //Complete Physics Job
        inputDeps.Complete();

        //Make Current = Water Physics Job's Next array
        current.CopyFrom(next);

        //Apply Water Physics
        inputDeps = new ApplyWaterPhysics()
        {
            current = current,
            next    = next
        }.Schedule(current.Length, 32);

        inputDeps.Complete();

        //Update Entities
        entityQuery.CopyFromComponentDataArray(next);

        //Clean Native Arrays
        current.Dispose();
        next.Dispose();

        return(inputDeps);
    }