예제 #1
0
    private void UnloadTile()
    {
        Vector3    playerPos = main_player.transform.localPosition;
        EdgeVector unloadId  = new EdgeVector();

        for (int x = 0; x < 3; x++)
        {
            for (int z = 0; z < 3; z++)
            {
                if (activeWorld[x][z] == -1)
                {
                    continue;
                }

                int sceneDataId = sceneInstances[activeWorld[x][z]].sceneDataId;

                unloadId.x = GetWorldSlotToUnloadAlongAxis(playerPos.x, sceneData[sceneDataId].areaSize.width);
                unloadId.z = GetWorldSlotToUnloadAlongAxis(playerPos.z, sceneData[sceneDataId].areaSize.length);

                bool canUnload = unloadId.x != 1 || unloadId.z != 1;

                if (canUnload)
                {
                    ClearWorldSlot(unloadId.x, unloadId.z, true);
                    print("UNLOAD: " + unloadId.x + " , " + unloadId.z);
                }
            }
        }
    }
예제 #2
0
    private void Update()
    {
        EdgeVector migrateTo = GetMigrateScene();
        EdgeVector loadTo    = GetWorldSlotToLoadTo();

        bool canMigrate = migrateTo.x != 1 || migrateTo.z != 1;
        bool canLoad    = loadTo.x != 1 || loadTo.z != 1;

//		print( migrateTo.x + " :: " + migrateTo.z );
        print("Can Load: " + canLoad + " Can Migrate: " + canMigrate);
        DEBUG_PRINT_WORLD();

        if (canMigrate)
        {
            MigrateScene(migrateTo);
        }
        else if (canLoad)
        {
            LoadSceneAsync(GetRandomSceneId(), loadTo);

            // if its a conrer pice load the two ajcent tiles
            if (loadTo.x != 1 && loadTo.z != 1)
            {
                //TODO: FFS this only covers one corner
                LoadSceneAsync(GetRandomSceneId(), new EdgeVector(loadTo.x, loadTo.x + (loadTo.x != 0 ? -1 : 1)));
                LoadSceneAsync(GetRandomSceneId(), new EdgeVector(loadTo.z + (loadTo.z != 0 ? -1 : 1), loadTo.z));
            }
        }

        //UnloadTile();
    }
예제 #3
0
    // vector to outside of mother triangle
    private void moveEndOfEdgeAway(EdgeVector edge)
    {
        Vector3 move =
            -(vertices[0] - vertices[edge.from]
              + vertices[1] - vertices[edge.from]
              + vertices[2] - vertices[edge.from]);

        // float currentLength = Mathf.Abs(move.magnitude);
        // float wantedLength = currentLength + (edge.length - currentLength) * NORMALIZATION_STRENGTH * edge.strength;
        // vertices[edge.to] = vertices[edge.from] + move * (wantedLength / currentLength);
        vertices[edge.to] = vertices[edge.from] + move * Mathf.Abs(edge.length / move.magnitude);
    }
예제 #4
0
    private void ShiftScenes(EdgeVector newActiveSceneId)
    {
        if (newActiveSceneId.x != 1)
        {
            ShiftSceneX(!(newActiveSceneId.x == 0));
        }

        if (newActiveSceneId.z != 1)
        {
            ShiftSceneZ(newActiveSceneId.z != 0);
        }
    }
예제 #5
0
    private EdgeVector GetMigrateScene()
    {
        //	if ( ActiveSceneId == -1 ) return new EdgeVector(1, 1);

        EdgeVector sceneToMigrateTo = new EdgeVector();

        Vector3 playerPostion = main_player.transform.localPosition;

        sceneToMigrateTo.x = 1 + GetEdgeOutSideOfBoundsAlongAxis(playerPostion.x, sceneData[ActiveSceneDataId].areaSize.width);
        sceneToMigrateTo.z = 1 + GetEdgeOutSideOfBoundsAlongAxis(playerPostion.z, sceneData[ActiveSceneDataId].areaSize.length);


        return(sceneToMigrateTo);
    }
예제 #6
0
    private EdgeVector GetWorldSlotToLoadTo()
    {
        if (ActiveSceneId == -1)
        {
            return(new EdgeVector(1, 1));
        }

        Vector3    playerPos  = main_player.transform.localPosition;
        EdgeVector loadToSlot = new EdgeVector();

        loadToSlot.x = GetWorldSlotToLoadToAlongAxis(playerPos.x, sceneData[ActiveSceneDataId].areaSize.width);
        loadToSlot.z = GetWorldSlotToLoadToAlongAxis(playerPos.z, sceneData[ActiveSceneDataId].areaSize.length);

        return(loadToSlot);
    }
예제 #7
0
    private Vector3 GetWorldPositionForEdge(EdgeVector edge)
    {
        if (ActiveSceneId == -1)
        {
            return(Vector3.zero);
        }

        Vector3 wPos = Vector3.zero;

        wPos.x = GetPositionAlongAxis(edge.x, sceneInstances[ActiveSceneId].areaPosition.width, sceneData[ActiveSceneDataId].areaSize.width);
        wPos.z = GetPositionAlongAxis(edge.z, sceneInstances[ActiveSceneId].areaPosition.length, sceneData[ActiveSceneDataId].areaSize.length);



        return(wPos);
    }
예제 #8
0
    private IEnumerator LoadScene(int sceneId, EdgeVector edge, Vector3 worldPosition)
    {
        while (loadingScene)
        {
            yield return(null);
        }

        if (activeWorld[edge.x][edge.z] >= 0)
        {
            Debug.Log("Unable to load scene, world slot already contains a scene :( ");
            yield break;
        }

        loadingScene = true;

        AsyncOperation scene = SceneManager.LoadSceneAsync(sceneData[sceneId].name, LoadSceneMode.Additive);

        while (!scene.isDone)
        {
            yield return(null);
        }

        int sceneIndex = SceneManager.sceneCount - 1;

        SceneInstance sceneInst = new SceneInstance();

        sceneInst.sceneDataId = sceneId;
        sceneInst.scene       = SceneManager.GetSceneAt(sceneIndex);    // SceneManager.GetSceneByName( sceneData[ sceneId ].name );
        sceneInst.SetAreaPosition(worldPosition);

        sceneInstances.Add(sceneInst);

        activeWorld[edge.x][edge.z] = sceneInstances.Count - 1;             //sceneId;


        if (autoMigrate)
        {
            MigrateScene(edge);
            autoMigrate = false;
        }

        loadingScene = false;
    }
예제 #9
0
    private void MigrateScene(EdgeVector sceneToMigrateTo)
    {
        int sceneId = activeWorld[sceneToMigrateTo.x][sceneToMigrateTo.z];

        Debug.LogWarning("(SceneDataID: " + sceneId + " :: " + sceneToMigrateTo.x + " :: " + sceneToMigrateTo.z + " )");

        if (sceneId < 0 || !sceneInstances[sceneId].SceneIsAvailable())
        {
            Debug.LogError("Scene has not been loaded or is invalid :( ");
            return;
        }

        SceneManager.SetActiveScene(sceneInstances[sceneId].scene);

        ShiftScenes(sceneToMigrateTo);

        main_player.transform.parent = null;

        SceneManager.MoveGameObjectToScene(gameObject, sceneInstances[sceneId].scene);
        SceneManager.MoveGameObjectToScene(main_player.gameObject, sceneInstances[sceneId].scene);

        main_player.transform.parent = sceneInstances[sceneId].scene.GetRootGameObjects()[0].transform;
    }
예제 #10
0
    private void LoadSceneAsync(int sceneId, EdgeVector edge)
    {
        Vector3 loadToPosition = GetWorldPositionForEdge(edge);

        StartCoroutine(LoadScene(sceneId, edge, loadToPosition));
    }
예제 #11
0
 /// <summary>
 /// Deconstruct keyvaluepairs
 /// </summary>
 /// <typeparam name="T1"></typeparam>
 /// <typeparam name="T2"></typeparam>
 /// <param name="tuple"></param>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public static void Deconstruct(this EdgeVector edge, out Vertex pointsTo, out EdgeVector nextEdge)
 {
     pointsTo = edge.pointsTo;
     nextEdge = edge.nextEdge;
 }
예제 #12
0
 /// <summary>
 /// Deconstruct keyvaluepairs
 /// </summary>
 /// <typeparam name="T1"></typeparam>
 /// <typeparam name="T2"></typeparam>
 /// <param name="tuple"></param>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public static void Deconstruct(this Polygon shape, out Vertex firstPoint, out EdgeVector nextEdge)
 {
     firstPoint = shape.firstEdge.pointsTo;
     nextEdge   = shape.firstEdge.nextEdge;
 }