示例#1
0
    Color GetColor(Vector3Int position)
    {
        Color c = defaultColor;

        if (WantsTint(position))
        {
            c = gi.GetPositionProperty(position, "TintColor", defaultColor);
        }

        int shadowStrength = ShadowStrength(position);

        if (shadowStrength == 1)
        {
            c *= Color.Lerp(shadowColor, Color.white, 0.5f);
        }
        else if (shadowStrength == 2)
        {
            c *= shadowColor;
        }

        if (!LevelBrush.IsFloorFast(position))
        {
            c = Color.Lerp(c, Color.black, DistanceToLevel(position) / 10);
        }

        return(c);
    }
示例#2
0
    bool InitializeCachedReferences()
    {
        if (floor == null)
        {
            floor = LevelBrush.GetFloor();
        }
        if (wall == null)
        {
            wall = LevelBrush.GetWall();
        }
        if (gi == null)
        {
            gi = GetComponentInParent <GridInformation>();
        }

        if (tintTexture == null)
        {
            tintTexture            = new Texture2D(256, 256, TextureFormat.ARGB32, false);
            tintTexture.wrapMode   = TextureWrapMode.Clamp;
            tintTexture.filterMode = FilterMode.Bilinear;
        }
        colorArray = new Color32[tintTexture.width * tintTexture.height];

        LevelBrush.InitializeLevelCacheIfNecessary();

        return(floor && wall & gi & tintTexture);
    }
示例#3
0
    public static void PrepareScene()
    {
        GameObject rig                  = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/Cameras.prefab");
        GameObject walls                = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/Walls.prefab");
        GameObject floor                = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/Floor.prefab");
        GameObject hero                 = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/Hero.prefab");
        GameObject gameState            = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/Game state manager.prefab");
        GameObject canvas               = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/Canvas stack.prefab");
        GameObject start                = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/Level Start.prefab");
        GameObject goal                 = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/Level Goal.prefab");
        GameObject swarmSpawner         = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/Swarm Spawner.prefab");
        GameObject tintTextureGenerator = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/Tint Texture Generator.prefab");

        if (rig != null && walls != null && floor != null && hero != null && gameState != null && canvas != null && start != null && goal != null && swarmSpawner != null)
        {
            RenderSettings.ambientLight = Color.white;
            foreach (var cam in Object.FindObjectsOfType <Camera>())
            {
                Object.DestroyImmediate(cam.gameObject, false);
            }
            Grid grid = BrushUtility.GetRootGrid(true);

            PrefabUtility.InstantiatePrefab(rig);
            GameObject wallsGo = PrefabUtility.InstantiatePrefab(walls) as GameObject;
            PrefabUtility.UnpackPrefabInstance(wallsGo, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction);
            wallsGo.transform.SetParent(grid.transform);
            GameObject floorGo = PrefabUtility.InstantiatePrefab(floor) as GameObject;
            PrefabUtility.UnpackPrefabInstance(floorGo, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction);
            floorGo.transform.SetParent(grid.transform);
            PrefabUtility.InstantiatePrefab(gameState);
            PrefabUtility.InstantiatePrefab(swarmSpawner);
            GameObject canvasObject = PrefabUtility.InstantiatePrefab(canvas) as GameObject;
            canvasObject.GetComponentInChildren <UIRenderTextureCamera>().UpdateCamera();

            GameObject startGo = PrefabUtility.InstantiatePrefab(start) as GameObject;
            startGo.transform.SetParent(grid.transform);
            startGo.transform.position = grid.GetCellCenterWorld(new Vector3Int(-6, 1, 0));

            GameObject goalGo = PrefabUtility.InstantiatePrefab(goal) as GameObject;
            goalGo.transform.SetParent(grid.transform);
            goalGo.transform.position = grid.GetCellCenterWorld(new Vector3Int(5, -2, 0));

            GameObject swarmSpawnerGo = PrefabUtility.InstantiatePrefab(swarmSpawner) as GameObject;
            swarmSpawnerGo.transform.SetParent(grid.transform);

            grid.gameObject.AddComponent <GridInformation>();

            GameObject tintTextureGo = PrefabUtility.InstantiatePrefab(tintTextureGenerator) as GameObject;
            tintTextureGo.transform.SetParent(grid.transform);

            LevelBrush.ResetLevelCache();
            TintTextureGenerator.RefreshTintmap();
        }
        else
        {
            Debug.LogWarning("Some prefabs for initializing the scene are missing.");
        }
    }
示例#4
0
 public override void OnInspectorGUI()
 {
     EditorGUI.BeginChangeCheck();
     base.OnInspectorGUI();
     if (GUILayout.Button("Refresh") || EditorGUI.EndChangeCheck())
     {
         LevelBrush.ResetLevelCache();
         TintTextureGenerator.RefreshTintmap();
     }
 }
示例#5
0
    float DistanceToLevel(Vector3Int position)
    {
        int result = int.MaxValue;

        foreach (var pos in new BoundsInt(position + new Vector3Int(-2, -2, 0), new Vector3Int(5, 5, 1)).allPositionsWithin)
        {
            if (LevelBrush.IsFloorFast(pos))//, wall, floor))
            {
                result = Mathf.Min((pos - position).sqrMagnitude, result);
            }
        }
        return(result - 2);
    }
    public override void OnPaintSceneGUI(GridLayout grid, GameObject layer, BoundsInt position, GridBrushBase.Tool tool, bool executing)
    {
        LevelBrush.InitializeLevelCacheIfNecessary();
        var invalidFloors = LevelBrush.GetAllInvalidFloors();

        BrushEditorUtility.BeginQuads(new Color(1f, 0f, 0f, 0.5f));
        foreach (var pos in invalidFloors)
        {
            BrushEditorUtility.DrawQuadBatched(grid, pos);
        }
        BrushEditorUtility.EndQuads();

        base.OnPaintSceneGUI(grid, layer, position, tool, executing);
    }
示例#7
0
    void Refresh()
    {
        if (!BeginUpdate())
        {
            return;
        }

        foreach (var pos in LevelBrush.GetWall().cellBounds.allPositionsWithin)
        {
            colorArray[WorldToIndex(pos)] = GetColor(pos);
        }

        EndBatchedUpdate();

        Shader.SetGlobalTexture("_TintMap", tintTexture);
    }
示例#8
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        if (GUILayout.Button("Generate Collider"))
        {
            LevelBrush brush = target as LevelBrush;

            MeshCollider collider = brush.GetComponent <MeshCollider>();
            if (collider == null)
            {
                collider = brush.gameObject.AddComponent <MeshCollider>();
            }

            MeshFilter filter = brush.GetComponent <MeshFilter>();
            collider.sharedMesh = filter.sharedMesh;
        }
    }
 public override void RegisterUndo(GameObject layer, GridBrushBase.Tool tool)
 {
     Undo.RegisterCompleteObjectUndo(LevelBrush.GetWall(), "Paint");
     Undo.RegisterCompleteObjectUndo(LevelBrush.GetFloor(), "Paint");
 }
 public override void OnToolActivated(GridBrushBase.Tool tool)
 {
     LevelBrush.ResetLevelCache();
 }
 private void UndoRedoPerformed()
 {
     LevelBrush.ResetLevelCache();
     TintTextureGenerator.RefreshTintmap();
 }