protected override void initWorld()
    {
        // Auto Adjust.

        GameObject tmpPackageUIIcon = GameObject.Find("PackageUIIcon");
        GameObject tmpBananaUIIcon = GameObject.Find("BananaUIIcon");
        GameObject tmpPersonPortrait = GameObject.Find("PersonPortrait");
        GameObject tmpPauseButton = GameObject.Find("PauseButton");
        GameObject tmpBackdrop = GameObject.Find("Backdrop").gameObject;
        SpawnNormaliser.adjustGameObjectsToNwBounds(SpawnNormaliser.get2DBounds(tmpBackdrop.renderer.bounds),
                                                    WorldSpawnHelper.getCameraViewWorldBounds(tmpBackdrop.transform.position.z,true),
                                                    new List<GameObject>() { tmpPackageUIIcon, tmpBananaUIIcon, tmpPersonPortrait, tmpBackdrop });

        tmpPackageUIIcon.transform.parent = GameObject.Find("Main Camera").transform;
        tmpBananaUIIcon.transform.parent = GameObject.Find("Main Camera").transform;
        tmpPersonPortrait.transform.parent = GameObject.Find("Main Camera").transform;
        tmpPauseButton.transform.parent = GameObject.Find("Main Camera").transform;

        tmpPackageUIIcon.transform.FindChild("PackageUICounter").gameObject.renderer.sortingOrder = (tmpPackageUIIcon.renderer.sortingOrder+1);
        tmpBananaUIIcon.transform.FindChild("BananaUICounter").gameObject.renderer.sortingOrder = (tmpBananaUIIcon.renderer.sortingOrder+1);
        CommonUnityUtils.setSortingOrderOfEntireObject(tmpPersonPortrait,100);
        CommonUnityUtils.setSortingOrderOfEntireObject(tmpPauseButton,200);

        uiBounds.Add("PackageCounter",WorldSpawnHelper.getWorldToGUIBounds(tmpPackageUIIcon.renderer.bounds,upAxisArr));
        uiBounds.Add("PersonPortrait",WorldSpawnHelper.getWorldToGUIBounds(tmpPersonPortrait.renderer.bounds,upAxisArr));
        uiBounds.Add("PauseBtn",WorldSpawnHelper.getWorldToGUIBounds(tmpPauseButton.renderer.bounds,upAxisArr));
        Destroy(tmpBackdrop);

        // Init world bounds data.
        gPropMapWorldBounds = calculateWorldMapBounds(mapSize);
        WorldSpawnHelper.initObjWithinWorldBounds(blankCollisionBox,
                                                  blankCollisionBox.transform.renderer.bounds.size.x,
                                                  blankCollisionBox.transform.renderer.bounds.size.y,
                                                  "WorldColBox",
                                                  new Rect(gPropMapWorldBounds.x,gPropMapWorldBounds.y,gPropMapWorldBounds.totalWidth,gPropMapWorldBounds.totalHeight),
                                                  null,
                                                  gPropMapWorldBounds.z,
                                                  upAxisArr);

        // Init Nav Graph.
        string bnwMapFilePath = "Textures/AcDelivery/Map";
        ImgToWorldNavGraphBuilderV2 navBuilder = new ImgToWorldNavGraphBuilderV2(bnwMapFilePath,gPropMapWorldBounds);

        List<ColorGraphTypeInfo> graphRequirements = new List<ColorGraphTypeInfo>()
        {
            new ColorGraphTypeInfo(new string[] { "FreeSpace", "MonkeySpawn", "HouseDeliveryPoint", "PlayerSpawn" },
                                   new Color[] { Color.white, ColorUtils.convertColor(153,76,0), Color.blue, Color.red })
        };

        List<ColoredNavGraph> graphList = navBuilder.constructColorGraphs(graphRequirements);
        worldNavGraph = graphList[0];

        List<System.Object> paramList = new List<System.Object>();
        paramList.Add(worldNavGraph);
        paramList.Add(gPropMapWorldBounds);
        terrainHandle = new BasicTerrainHandler();
        terrainHandle.constructTerrainStructures(paramList);

        // Render Nav Graph. (For Debug Purposes).
        //GameObject navGraphRenderObj = NavGraphUnityUtils.renderNavGraph("WorldNavGraphRender",worldNavGraph,graphNodePrefab);
        //navGraphRenderObj.SetActive(false);

        // Spawn Player.
        List<int> playerSpawnPtList = worldNavGraph.getNodesOfType(worldNavGraph.getTypeIDByName("PlayerSpawn"));
        WorldNode playerSpawnNode = (WorldNode) worldNavGraph.getNode(playerSpawnPtList[Random.Range(0,playerSpawnPtList.Count)]);
        Vector3 tmpV = playerSpawnNode.getWorldPt();
        Vector3 playerSpawnPt = new Vector3(tmpV.x,tmpV.y,-2f);
        Transform nwPlayerAvatar = (Transform) Instantiate(mainAvatarPrefab,playerSpawnPt,Quaternion.identity);
        nwPlayerAvatar.gameObject.name = "MainAvatar";
        NewCharacterNavMovement cnm = nwPlayerAvatar.gameObject.AddComponent<NewCharacterNavMovement>();
        cnm.faceDirection("S");

        // Apply player clothing.
        applyPlayerAvatarClothing();

        // Spawn MonkeyManager.
        PDMonkeyManager monkeyMang = transform.gameObject.AddComponent<PDMonkeyManager>();
        monkeyMang.init(monkeyPrefab,sfxPrefab,mapSize,gPropMapWorldBounds,worldNavGraph,terrainHandle);

        // Input detectors.
        inputDetectors = new List<AbsInputDetector>();
        ClickDetector cd = transform.gameObject.AddComponent<ClickDetector>();
        cd.setMaxDelayBetweenClicks(0.01f);
        cd.registerListener("AcScen",this);
        inputDetectors.Add(cd);

        // Mechanics variables.
        currNumKnocks = 0;
        mainCam = GameObject.Find("Main Camera").GetComponent<Camera>();
        numOfPackagesInInventory = reqDeliveriesForWin;
        numOfBananasInInventory = 30;
        refreshInventoryCounterDisplay();
        stolenPackageToMonkeyQueue = new List<string[]>();
        stoleQueueIndexPointer = 0;

        // Select prefabs for packages.
        selectedPackagePrefabIndexes = new List<int>();
        for(int i=0; i<reqDeliveriesForWin; i++)
        {
            selectedPackagePrefabIndexes.Add(Random.Range(0,packagePrefabs.Length));
        }
    }
Exemplo n.º 2
0
    void Start()
    {
        float iconifiedBounds_Width = Screen.width * 0.15f;
        float iconifiedBounds_Height = Screen.height * 0.15f;
        if(iconifiedBounds_Width > iconifiedBounds_Height) { iconifiedBounds_Width = iconifiedBounds_Height; }
        else { iconifiedBounds_Height = iconifiedBounds_Width; }
        float iconifiedBounds_X = Screen.width - iconifiedBounds_Width;
        float iconifiedBounds_Y = Screen.height - iconifiedBounds_Height;

        clickableArea = new Rect(iconifiedBounds_X,iconifiedBounds_Y,iconifiedBounds_Width,iconifiedBounds_Height);

        walkers = new GameObject[LocalisationMang.getNPCnames().Count];
        visibleWalkers = new List<int>();

        isPaused = false;
        currPlayerDestCell = new int[2] {-1,-1};
        playerNavigationFlag = true;

        dialogEventRequired = false;
        dialogTargetCharID = -1;

        // Disable any debug scene related things.
        makeAllClickablesTransparent();

        // Apply Clothing Config to Main Avatar.
        applyPlayerAvatarClothing();
        clonePlayerAv();

        // Calculate World Bounds.
        gPropMapWorldBounds = calculateWorldMapBounds(mapSize);
        WorldSpawnHelper.initObjWithinWorldBounds(blankCollisionBox,
                                                  blankCollisionBox.transform.renderer.bounds.size.x,
                                                  blankCollisionBox.transform.renderer.bounds.size.y,
                                                  "WorldColBox",
                                                  new Rect(gPropMapWorldBounds.x,gPropMapWorldBounds.y,gPropMapWorldBounds.totalWidth,gPropMapWorldBounds.totalHeight),
                                                  null,
                                                  gPropMapWorldBounds.z,
                                                  upAxisArr);

        // Remove Scroll Cam and use Follow Cam.
        Destroy(GameObject.Find("GlobObj").GetComponent(typeof(ScrollCam)));
        FollowScript followScrpt = Camera.main.transform.gameObject.AddComponent<FollowScript>();
        followScrpt.init(GameObject.Find("MainAvatar"),new bool[3] { true, true, false });

        // Init Nav Graph.
        string bnwMapFilePath = "Textures/WorldView/WorldView_B&W";
        ImgToWorldNavGraphBuilderV2 navBuilder = new ImgToWorldNavGraphBuilderV2(bnwMapFilePath,gPropMapWorldBounds);
        List<ColorGraphTypeInfo> graphRequirements = new List<ColorGraphTypeInfo>()
        {
            new ColorGraphTypeInfo(new string[] { "FreeSpace", "MainCharacterSpawns" },
            new Color[] { Color.white, Color.red })
        };
        List<ColoredNavGraph> graphList = navBuilder.constructColorGraphs(graphRequirements);
        worldNavGraph = graphList[0];

        List<System.Object> paramList = new List<System.Object>();
        paramList.Add(worldNavGraph);
        paramList.Add(gPropMapWorldBounds);
        terrainHandle = new BasicTerrainHandler();
        terrainHandle.constructTerrainStructures(paramList);

        Animator mainPlayerAvatarAni = GameObject.Find("MainAvatar").GetComponent<Animator>();
        //mainPlayerAvatarAni.Play("MainAvatar_walkDown");
        mainPlayerAvatarAni.speed = 0;

        SoundPlayerScript sps = transform.GetComponent<SoundPlayerScript>();
        //sps.triggerSoundLoopAtCamera("WindAmbient","WorldAmbientBox",0.3f,true);
        ambientSound = sps.triggerSoundLoopAtCamera("Serenade Band Tracks/Serenade_Bass_01.00","WorldAmbientBox",0.3f,true);

        // Init input detectors.
        inputDetectors = new List<AbsInputDetector>();
        ClickDetector cd = transform.gameObject.AddComponent<ClickDetector>();
        cd.registerListener("WorldScript",this);
        cd.setMaxDelayBetweenClicks(0.0001f);
        inputDetectors.Add(cd);

        // Persistent Obj Check.

        int index = 0;

        //Hide all recognised characters and destroy extra ones
        foreach(string para_namePrefix in new string[]{"AvatarChar-","SecChar-"}){

            int counter = 0;
            bool foundItem = true;
            while(foundItem)
            {
                GameObject tmpObj = GameObject.Find(para_namePrefix+""+counter);
                counter++;
                if(tmpObj == null)
                {
                    foundItem = false;
                }
                else
                {
                    if(index >= walkers.Length){
                        Destroy(tmpObj);

                    }else{
                        rootItemToMapGrid(tmpObj);
                        walkers[index++] = tmpObj;
                        List<SpriteRenderer> sRends = CommonUnityUtils.getSpriteRendsOfChildrenRecursively(tmpObj);
                        if(sRends != null)
                        {
                            for(int i=0; i<sRends.Count; i++)
                            {
                                sRends[i].enabled = false;
                            }
                        }
                        tmpObj.collider.enabled = false;
                    //tmpObj.SetActive(false);
                    }
                }

            }
        }

        isStillPerformingUnlockSequence = false;

        GameObject poRef = PersistentObjMang.getInstance();
        control = poRef.GetComponent<ProgressScript>();
        if(control == null)
        {
            control = poRef.AddComponent<ProgressScript>();
        }/*else{
            Debug.Log("Enable progress script");
            control.enabled = true;
        }*/

        Debug.LogWarning("Position of avatar not initialised");
        //placeExistingItemInCell("MainAvatar",int[]{});//NEW
        control.attemptActivityDebrief(this);

        // Switch player controls off until the intro effect is over.
        togglePlayerInputState(false);
        setupReady = false;

        Debug.Log("Fading removed");

        respondToEvent("", "FadeEffectDone", null);
    }