Example #1
0
    private void UpdateTemp()
    {
        switch (myState)
        {
        case MyStates.Pointer:
            if (environment != null)
            {
                DestroyImmediate(environment);
            }
            if (tile != null)
            {
                DestroyImmediate(tile);
            }
            if (mapFolderInspector == null)
            {
                mapFolderInspector = FindObjectOfType <MapFolderInspector>();
            }
            if (mapFolderInspector != null && mapFolderInspector.map != null)
            {
                Collider2D col = mapFolderInspector.map.GetComponent <Collider2D>();
                if (col != null)
                {
                    DestroyImmediate(col);
                }
            }
            Tools.lockedLayers &= ~(1 << LayerMask.NameToLayer(tilesLayer));
            break;

        default:
            if (mapFolderInspector == null)
            {
                mapFolderInspector = FindObjectOfType <MapFolderInspector>();
            }
            if (mapFolderInspector != null && mapFolderInspector.map != null)
            {
                Collider2D col = mapFolderInspector.map.GetComponent <Collider2D>();
                if (col == null)
                {
                    mapFolderInspector.map.gameObject.AddComponent <BoxCollider2D>().isTrigger = true;
                }
            }
            Tools.lockedLayers |= 1 << LayerMask.NameToLayer(tilesLayer);
            break;
        }
    }
Example #2
0
    private void UpdateStuff()
    {
        mapFolderInspector = FindObjectOfType <MapFolderInspector>();

        List <Texture> tilesList = new List <Texture>();

        string[] paths = AssetDatabase.FindAssets("t:Prefab", new string[] { "Assets/TD2D/Prefabs/Tiles" });
        foreach (string str in paths)
        {
            GameObject tilePrefab = AssetDatabase.LoadAssetAtPath <GameObject>(AssetDatabase.GUIDToAssetPath(str));
            if (tilePrefab != null)
            {
                SpriteRenderer sprite = tilePrefab.GetComponent <SpriteRenderer>();
                if (sprite != null && sprite.sprite != null)
                {
                    tilePrefabs.Add(tilePrefab);
                    tilesList.Add(sprite.sprite.texture);
                }
            }
        }
        tileTextures = tilesList.ToArray();

        List <Texture> environmentList = new List <Texture>();

        paths = AssetDatabase.FindAssets("t:Prefab", new string[] { "Assets/TD2D/Prefabs/Environment" });
        foreach (string str in paths)
        {
            GameObject environmentPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(AssetDatabase.GUIDToAssetPath(str));
            if (environmentPrefab != null)
            {
                SpriteRenderer sprite = environmentPrefab.GetComponent <SpriteRenderer>();
                if (sprite != null && sprite.sprite != null)
                {
                    environmentPrefabs.Add(environmentPrefab);
                    environmentList.Add(sprite.sprite.texture);
                }
            }
        }
        environmentTextures = environmentList.ToArray();

        tileIdx             = -1;
        environmentIdx      = -1;
        Tools.lockedLayers |= 1 << LayerMask.NameToLayer(mapLayer);
        Tools.lockedLayers &= ~(1 << LayerMask.NameToLayer(tilesLayer));
        myState             = MyStates.Pointer;

        tilesGuiSkin = (GUISkin)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/TilesGuiSkin.guiskin", typeof(GUISkin));

        // Set labels for prebas. Label will use in picker window
        string[] prefabs;
        prefabs = AssetDatabase.FindAssets("t:Sprite", new string[] { "Assets/TD2D/Sprites/Maps/Backgrounds" });
        foreach (string str in prefabs)
        {
            Object obj = AssetDatabase.LoadAssetAtPath <Object>(AssetDatabase.GUIDToAssetPath(str));
            AssetDatabase.SetLabels(obj, new string[] { mapSpriteLabel });
        }

        contents.rotateLeft  = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/RotateLeft.png", typeof(Texture)));
        contents.rotateRight = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/RotateRight.png", typeof(Texture)));
        contents.pointer     = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/Pointer.png", typeof(Texture)));
    }