private void InitializeLayers()
    {
        // Let the rest of this function assume that we have at least 1 background layer to work with.
        if (scrollLayers.Length == 0)
        {
            return;
        }

        cameraWidth  = Camera.main.orthographicSize * Camera.main.aspect * 2f;
        cameraHeight = Camera.main.orthographicSize * 2f;

        levelBoundaryManager  = GameObject.Find("LevelBoundaryManager").GetComponent <LevelBoundaryManager>();
        maxBoundaryDimensions = levelBoundaryManager.GetMaxBoundaryDimensions();

        minScale = Mathf.Max(cameraWidth / maxBoundaryDimensions.x, cameraHeight / maxBoundaryDimensions.y);

        // We go off of the assumption that the background should be the same size as the level boundary (otherwise we
        // wouldn't see portions of it), so let's resize based on the size of the first background layer image. The ratio of
        // this to the smallest dimension we can shink to line up perfectly with the levelBoundary dimensions themselves.
        // I.e. shrink the background layers until they fit on top of the LevelBoundary as defined by tilemap.
        GameObject     firstBackground       = scrollLayers[0].entityParent;
        SpriteRenderer firstBackgroundSprite = firstBackground.GetComponentInChildren <SpriteRenderer>();
        Vector2        firstBackgroundSize   = firstBackgroundSprite.sprite.bounds.size;
        float          backgroundRescale     = Mathf.Max(maxBoundaryDimensions.x / firstBackgroundSize.x, maxBoundaryDimensions.y / firstBackgroundSize.y);

        this.transform.localScale = Vector3.one * backgroundRescale;

        foreach (ScrollLayer layer in scrollLayers)
        {
            // Rescale the layer so that when we are centered on a given point, all layers line up as if they were on the same spot
            layer.scale = Mathf.Lerp(minScale, 2f - minScale, ((float)(vanishingDistance - layer.distance) / (2f * vanishingDistance)));
            layer.entityParent.transform.localScale = Vector2.one * layer.scale;
        }
    }
Ejemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        LevelBoundaryManager levelBoundaryManager = target as LevelBoundaryManager;

        LevelBoundaryManager.LevelDoorDictionary oldDoorMap = levelBoundaryManager.doorMap;
        //EditorGUILayout.ObjectField(levelBoundaryManager, typeof(LevelBoundaryManager), false);

        serializedObject.Update();

        EditorGUI.BeginChangeCheck();

        doorways.Clear();
        foreach (LevelBoundaryManager.DoorLocation doorLocation in doorLocations)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(doorLocation.ToString());
            Doorway oldDoorway = oldDoorMap.ContainsKey(doorLocation) ? oldDoorMap[doorLocation] : null;
            doorways.Add(EditorGUILayout.ObjectField(oldDoorway, typeof(Doorway), true) as Doorway);
            EditorGUILayout.EndHorizontal();
        }
        //SceneAsset newScene = EditorGUILayout.ObjectField("scene", oldScene, typeof(SceneAsset), false) as SceneAsset;
        //EditorGUILayout.PropertyField(serializedObject.FindProperty("doorways"));


        if (EditorGUI.EndChangeCheck())
        {
            SerializedProperty doorMap = serializedObject.FindProperty("_doorMap");

            /*
             * SerializedProperty itr = serializedObject.GetIterator();
             * while (itr.Next(true)) {
             *  Debug.Log(itr.name);
             * }
             */

            SerializedProperty doorMapKeys   = doorMap.FindPropertyRelative("keys");
            SerializedProperty doorMapValues = doorMap.FindPropertyRelative("values");

            doorMapKeys.ClearArray();
            doorMapValues.ClearArray();
            for (int i = 0; i < doorLocations.Length; i++)
            {
                doorMapKeys.InsertArrayElementAtIndex(i);
                doorMapKeys.GetArrayElementAtIndex(i).enumValueIndex = doorLocations.GetValue(i).GetHashCode();

                doorMapValues.InsertArrayElementAtIndex(i);
                doorMapValues.GetArrayElementAtIndex(i).objectReferenceValue = doorways[i];
            }
        }

        serializedObject.ApplyModifiedProperties();
    }
    private void OnLevelWasLoaded(int level)
    {
        FindNeededObjects();
        Load();

        LevelBoundaryManager levelBoundaryManager = GameObject.Find("LevelBoundaryManager").GetComponent <LevelBoundaryManager>();
        Doorway playerEnteredFrom = levelBoundaryManager.doorMap[whereToAppear];

        if (playerEnteredFrom != null)
        {
            player.TeleportAfterSceneLoad(playerEnteredFrom.playerSpawnMarker.transform.position);
        }
    }