Esempio n. 1
0
 private void CreateMultipleConstructs(List <GameEvent> chunks, CountDownRoot holder)
 {
     foreach (GameEvent chunk in chunks)
     {
         CreateConstruct(chunk, holder);
     }
 }
Esempio n. 2
0
        public void Operate()
        {
            ClearList();

            int amountToCollect = UnityEngine.Random.Range(1, 9);


            CollectFromPool(EventPoolHolder <GameEvent> .mInstance.GetPool("eventPool"), amountToCollect);
            //CollectFromPool(EventPoolHolder<GameEvent>.m_GoodsPool, 3);

            Debug.Log(String.Format("EventSelector: collected {0} elements from pool, size of goods: {1}, size of obstacles: {2}"
                                    , amountToCollect, mGoods.Count, mObstacles.Count));

            //We can specify 0 in the tube since the greedy algo does not use this information.
            List <GameEvent>[] gameEventsToDeployArray = Assembel(EventAssemblerGreedy.Instance, 0);

            Debug.Log(String.Format("EventSelector: asseembled {0} ", gameEventsToDeployArray.ToString()));

            //DeploymentTubeManager.Instance.ApplyRequest(gameEventsToDeploy, SystemAIManager.m_Instance.Activate);


            float timeDelay = 0;

            holder2 = new CountDownRoot(WakeUpSystemAI);

            for (int i = 0; i < gameEventsToDeployArray.Length; i++)
            {
                //--If there are game events to deploy
                if (gameEventsToDeployArray[i].Count != 0)
                {
                    DeploymentTubeManager.Instance.ApplyRequestToTube(i, (Action callback) =>
                    {
                        Debug.Log("EventSelector: ApplyRequestToTube");

                        CountDownRoot holder = new CountDownRoot(callback);

                        holder2.IncreaseByOne();

                        timeDelay += UnityEngine.Random.Range(0f, 1f);;

                        //BluePrintConstruct bluePrint = LevelConstructUtil.ConvertFromLevelConstructToBluePrint(gameEventsToDeployArray[i]);

                        SubSceneMultiton.Instance.GetInstance(i).GetLocalLevelBuilder().Build(gameEventsToDeployArray[i], Vector3.zero, holder, timeDelay);
                    }, this);
                }
            }

            //deploymentTubes[0].ApplyRequest(gameEventsToDeploy);

            foreach (List <GameEvent> gel in gameEventsToDeployArray)
            {
                foreach (GameEvent ge in gel)
                {
                    Debug.Log(String.Format("EventSelector: applied request to deploy {0}", ge.mName));
                }
            }

            Debug.Log(String.Format("EventSelector: applied request to tube"));
        }
Esempio n. 3
0
        public override void Enter()
        {
            Init();

            //myEvent =new UnityEvent( GameEventManager.Instance.onPlayerJumpEvent);

            //--Display the fatui image
            //StartCoroutine(ExecuteAfterTime(10))
            TutorialSystem.Instance.DisplayImageOnPlaceHolder(TutorialImage, PrimaryScene, waitForEvent, delay);

            //--Instantiate the constructs using the json data

            //--Create a new list
            List <GameEvent>[] gameEvents = new List <GameEvent> [ApplicationConstants.NumberOfScenes];

            //--Initialize the lists
            for (int i = 0; i < ApplicationConstants.NumberOfScenes; i++)
            {
                gameEvents[i] = new List <GameEvent>();
            }

            //--Populate the lists using the PREvent data
            foreach (PREvent e in Events)
            {
                gameEvents[e.scene].Add(GameEventFactory.GetIntance().GenerateOne(e.type, e.level, e.index));
            }

            holder2 = new CountDownRoot(WakeUp);

            for (int i = 0; i < gameEvents.Length; i++)
            {
                //--If there are game events to deploy
                if (gameEvents[i].Count != 0)
                {
                    DeploymentTubeManager.Instance.ApplyRequestToTube(i, (Action callback) =>
                    {
                        Debug.Log("EventSelector: ApplyRequestToTube");

                        CountDownRoot holder = new CountDownRoot(callback);

                        holder2.IncreaseByOne();

                        //BluePrintConstruct bluePrint = LevelConstructUtil.ConvertFromLevelConstructToBluePrint(gameEvents[i]);

                        SubSceneMultiton.Instance.GetInstance(i).GetLocalLevelBuilder().Build(gameEvents[i], Vector3.zero, holder);
                    }, this);
                }
            }

            ////--Deploy request to tube.
            //for (int i = 0; i < ApplicationConstants.NumberOfScenes; i++)
            //{
            //    BluePrintConstruct bluePrint = LevelConstructUtil.ConvertFromLevelConstructToBluePrint(gameEvents[i]);

            //    DeploymentTubeManager.Instance.ApplyRequestToTube(i, TutorialSystem.Instance.MoveToNexTStep, this);
            //}
        }
    public override void DestroyObject()
    {
        gameObject.transform.parent = null;

        if (mIsSubscribedToRoot && mRoot != null)
        {
            mRoot.DecreaseByOne();
            mRoot = null;
            mIsSubscribedToRoot = false;
        }

        //if (child != null)
        //    child.DecreaseByOne();



        //child = null;

        base.DestroyObject();
    }
 public void SubscribeToRoot(CountDownRoot root)
 {
     mRoot = root;
     mRoot.IncreaseByOne();
     mIsSubscribedToRoot = true;
 }
 public CountDownLatch(CountDownRoot root)
 {
     this.root = root;
     root.IncreaseByOne();
 }
Esempio n. 7
0
 public void Build(List <GameEvent> chunks, Vector3 position, CountDownRoot holder)
 {
     CreateMultipleConstructs(chunks, holder);
 }
Esempio n. 8
0
 public void Build(GameEvent chunk, Vector3 position, CountDownRoot holder)
 {
     CreateConstruct(chunk, holder);
 }
Esempio n. 9
0
        IEnumerator DelayBuild(List <GameEvent> chunks, Vector3 position, CountDownRoot holder, float time)
        {
            yield return(new WaitForSeconds(time));

            Build(chunks, position, holder);
        }
Esempio n. 10
0
 public void Build(List <GameEvent> chunks, Vector3 position, CountDownRoot holder, float time)
 {
     StartCoroutine(DelayBuild(chunks, position, holder, time));
 }
Esempio n. 11
0
        private void DrawPixelListInTilemap(ref Tilemap tilemap, List <Point> points, TilePainter tileData, CountDownRoot root)
        {
            tileData.Init(tilemap);

            foreach (Point point in points)
            {
                //tileData.Paint(new Vector3Int(point.x, -point.y, 0), root);
            }

            ////if (tileData == null)
            ////{
            ////    Debug.Log("tile data not set in specified map");
            ////}
            //else
            //{

            //    //new Vector3Int((int)xOffset + point.x, (int)(yOffset - point.y * hRatio), 0);

            //    //Init the object with the tilemap, if it is a rule tile it uses it to be attached to
            //    //if it is a worlf object it uses it to set it's location.



            //}
        }
Esempio n. 12
0
        /// <summary>
        /// This is the actual level builder API, it is a given the json data holding the construct's information
        /// the scene the object should be deployed to and a holder.
        /// </summary>
        /// <param name="jsonData"></param>
        /// <param name="scene"></param>
        /// <param name="holder"></param>
        /// <returns></returns>
        private GameObject CreateConstruct(GameEvent chunk, CountDownRoot holder)
        {
            //Get Bounds data
            ConstructData constructData = chunk.ConstructData;

            //int h = constructData.h;
            int w = constructData.w;

            int offset = constructData.Offset + (int)mScene.mScreenWidthInWorld;

            //float hRatio = scene.mScreenHeightInWorld / h;


            //float yOffset = scene.mScreenHeightInWorld / 2 + scene.transform.position.y;
            //float xOffset = scene.mScreenWidthInWorld / 2 + scene.transform.position.x;

            //--Instantiate a new grid
            GameObject grid = GameObject.Instantiate(m_GridPrefab, Vector3.zero, Quaternion.identity);

            //--Set the grid as child of the scene
            grid.transform.parent = mScene.transform;

            //GameObject tilemapGameObject = GameObject.Instantiate(m_TilemapPlatformPrefab, scene.transform.position, Quaternion.identity);
            //Tilemap tilemap = tilemapGameObject.GetComponent<Tilemap>();
            //tilemap.SendMessage("SubscribeToRoot", holder);
            //Tilemap tilemap = grid.GetComponentInChildren<Tilemap>();

            //tilemap.transform.parent = grid.transform;

            //WorldFiniteObject wfo = tilemap.GetComponent<WorldFiniteObject>();

            //--For each of the <color,list> objects in the construct data draw a list of objects
            //--according to the list <x,y> and color parameter.
            foreach (PixelData pixel in constructData.data)
            {
                if (pixel == null)
                {
                    Debug.Log("pixel is null ");
                }
                if (m_ColorToObjectDict == null)
                {
                    Debug.Log("m_ColorToObjectDict is null ");
                }

                //--Get the tile data from the color to object fictionary
                m_ColorToObjectDict.TryGetValue(pixel.color, out TilePainter tilePainter);

                if (tilePainter == null)
                {
                    Debug.Log("tile data not set in specified map: " + pixel.color);
                }

                GameObject tilemapTemplate = m_TilemapPrefab_Default;

                if (tilePainter.GetType().Equals(typeof(RuleTilePainter)))
                {
                    TilemapType tileMapType = ((RuleTilePainter)tilePainter).GetTilemapType();

                    switch (tileMapType)
                    {
                    case TilemapType.TilemapPlatform:
                        tilemapTemplate = m_TilemapPrefab_Platform;
                        break;

                    case TilemapType.TilemapSolid:
                        tilemapTemplate = m_TilemapPrefab_Solid;
                        break;
                    }
                }


                //get pixel collider type and get the corrseponfing tilemap .

                //--Generate a tilemap layer to draw the objects unto.
                GameObject tilemapGameObject = GameObject.Instantiate(tilemapTemplate, Vector3.zero, Quaternion.identity);
                tilemapGameObject.transform.parent = grid.transform;
                tilemapGameObject.SendMessage("SubscribeToRoot", holder);
                tilemapGameObject.SendMessage("Init");

                Tilemap tilemap = tilemapGameObject.GetComponent <Tilemap>();


                //--Draw the objects unto the tilemap
                DrawPixelListInTilemap(ref tilemap, pixel.points, tilePainter, holder);

                //Cleam tile data pointer
                tilePainter = null;

                //--This is a hack, if the tilemap is empty (only coins for example which is a prefab)
                //--then I still want to know when the grid is out of bound, hence I draw this extra pixel
                PixelData pd = new PixelData("ff00ff", new List <Point>()
                {
                    new Point(w, 0)
                });
                m_ColorToObjectDict.TryGetValue(pd.color, out tilePainter);
                DrawPixelListInTilemap(ref tilemap,
                                       pd.points,
                                       tilePainter,
                                       holder);

                //--offset the tile map position
                grid.transform.position =
                    mScene.transform.position +
                    new Vector3(
                        offset * grid.GetComponent <Grid>().cellSize.x - 40,
                        mScene.mScreenHeightInWorld / 2 + 1);
                tilemap.transform.position = grid.transform.position;
            }

            ////--This is a hack, if the tilemap is empty (only coins for example which is a prefab)
            ////--then I still want to know when the grid is out of bound, hence I draw this extra pixel
            //PixelData pd = new PixelData("ff00ff", new List<Point>() { new Point(w, 0) });
            //DrawPixelInTilemap(ref tilemap, pd, holder);

            //wfo.SubscribeToRoot(holder);
            //wfo.StartCoroutine("SetAsChildOfGrid", holder);

            ////--offset the tile map position
            //grid.transform.position =
            //    scene.transform.position +
            //    new Vector3(
            //        scene.mScreenWidthInWorld / 2,
            //        scene.mScreenHeightInWorld / 2 + 1);
            //tilemap.transform.position = grid.transform.position;

            //Debug.Log("Created constructat time: {0} at " + Time.time);



            Debug.unityLogger.Log(TAG, string.Format("Created chunk {3} in offset {0}, of size {1} at time {2}", offset, w, Time.time, chunk.mName));

            //--Updates the offset
            offset = offset += w;

            //If the tilemap doesnt have any tiles in it we want to desrtroy it
            //TODO optimize
            //if(tilemap.layoutGrid.transform.childCount == 0)
            //{
            //    wfo.DestroyMe();
            //}

            return(grid);
        }