コード例 #1
0
    private void OnLoadLevel(LevelAsset levelAsset)
    {
        towerParentObject.DestroyChildren();
        var towerPrefab = levelAsset.TowerPrefab;

        Instantiate(towerPrefab, towerParentObject.transform);
    }
コード例 #2
0
    internal void SetData(LevelAsset data, LevelAsset save)
    {
        Texture2D image         = new Texture2D(data.Width, data.Height);
        float     pixelsPerUnit = 0.2f;

        if (data.Height > data.Width)
        {
            pixelsPerUnit = data.Height / Configs.LEVEL_ENTRANCE_FRAME_SIZE / Configs.SCREEN_WIDTH;
        }
        else
        {
            pixelsPerUnit = data.Width / Configs.LEVEL_ENTRANCE_FRAME_SIZE / Configs.SCREEN_WIDTH;
        }
        if (save != null)
        {
            image.SetPixels(save.Data);
        }
        else
        {
            Color[] greyed = new Color[data.Data.Length];
            for (int i = 0; i < data.Data.Length; i++)
            {
                greyed[i] = SmallTricks.Utils.ConvertGreyscale(data.Data[i]);
            }
            image.SetPixels(greyed);
        }
        image.filterMode = FilterMode.Point;
        image.Apply();
        Art.sprite = Sprite.Create(image, new Rect(0.0f, 0.0f, image.width, image.height), new Vector2(0.5f, 0.5f), pixelsPerUnit);
        mData      = data;

        mSave = save;
        StartCoroutine(UpdateLoves());
    }
コード例 #3
0
    public static List <LevelAsset> ConstructFromFolderCONFIG(string path)
    {
        Debug.LogWarning("ConstructFromFolderCONFIG is deprecated, please use ConstructFromFolder instead");

        string[]          Levels      = Directory.GetFiles(path, "*.config");
        List <LevelAsset> levelAssets = new List <LevelAsset>();

        for (int i = 0; i < Levels.Length; i++)
        {
            string[] content   = File.ReadAllLines(Levels[i]);
            string   imagePath = content[2];

            byte[]    imageData = File.ReadAllBytes(Environment.GetPath("demo") + "/" + imagePath);
            Texture2D texture   = new Texture2D(2, 2);
            texture.LoadImage(imageData);

            LevelAsset level = ScriptableObject.CreateInstance <LevelAsset>();
            level.LevelName    = content[0];
            level.Difficulty   = (DifficultyLevel)int.Parse(content[1]);
            level.LevelTexture = texture;

            levelAssets.Add(level);
            Debug.Log("Created Level");
        }

        return(levelAssets);
    }
コード例 #4
0
    public void EnterLevelSelect(WorldPin worldPin)
    {
        lastUsedPin = worldPin;
        levelSelect.SetActive(true);
        LevelAsset      asset = DataUtils.loadLevelAsset(worldPin.worldType);
        TextMeshProUGUI title = levelSelect.transform.GetChild(0).Find("title").GetComponent <TextMeshProUGUI>();

        title.text = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(worldPin.worldType.ToString());
        int i            = 0;
        int lastUnlocked = 0;

        for (; i < asset.stageNames.Length; i++)
        {
            buttons[i].Init(this, asset.stageNames[i], title);
            if (buttons[i].Unlocked && i > lastUnlocked)
            {
                lastUnlocked = i;
            }
        }
        for (; i < buttons.Length; i++)
        {
            buttons[i].gameObject.SetActive(false);
        }
        buttons[lastUnlocked].GetComponent <Button>().onClick.Invoke();
    }
コード例 #5
0
        public static void StartLevel(LevelAsset levelAsset)
        {
            s_CurrentLevel = levelAsset;
            AsyncOperation operation = SceneManager.LoadSceneAsync(levelAsset.SceneAsset.name);

            operation.completed += StartPlayer;
        }
コード例 #6
0
    //Initialises panel using LevelAsset
    private void InitPanel(LevelAsset _level)
    {
        LevelName.text = _level.LevelName;

        /*Black magic - The ternery operator is a condensed form of 'if' statement
         * if you wanna find out more google "C# ternery" */
        Difficulty.text = (_level.Difficulty == DifficultyLevel.Easy ? "Easy" :
                           _level.Difficulty == DifficultyLevel.Medium ? "Medium" :
                           _level.Difficulty == DifficultyLevel.Hard ? "Hard" : "Extreme");

        //Sets panel color based on level difficulty
        if (Difficulty.text == "Easy")
        {
            gameObject.GetComponent <Image>().color = Easy;
        }
        else if (Difficulty.text == "Medium")
        {
            gameObject.GetComponent <Image>().color = Medium;
        }
        else if (Difficulty.text == "Hard")
        {
            gameObject.GetComponent <Image>().color = Hard;
        }
        else if (Difficulty.text == "Extreme")
        {
            gameObject.GetComponent <Image>().color = Extreme;
        }
        else   //If there are something horrible has happened and there is no level

        // difficulty default to gray.
        {
            gameObject.GetComponent <Image>().color = Color.gray;
        }
    }
コード例 #7
0
ファイル: LevelAssetEditor.cs プロジェクト: Matt343/hexdef
 //custom element to display the hex grid as toggle buttons and return the selection
 Vector2 hexGrid(Vector2 selection, LevelAsset level, int hexSize, Rect gridRect)
 {
     GUILayout.BeginVertical();
     for (int y = 0; y < level.gridHeight; y++)
     {
         GUILayout.BeginHorizontal();
         if (y % 2 == 1)
         {
             GUILayout.Space(hexSize / 2);
         }
         for (int x = 0; x < level.gridWidth; x++)
         {
             Rect hexRect = new Rect(gridRect.x + x * hexSize + (y % 2 == 1 ? hexSize / 2 : 0), gridRect.y + y * hexSize, hexSize, hexSize);
             if (level.grid[y][x] == null)
             {
                 level.grid[y][x] = new HexInfo(x, y);
             }
             if (level.grid[y][x].pathId >= nextPathPoint)
             {
                 nextPathPoint = level.grid[y][x].pathId + 1;
             }
             if (hexDisplay((x == selection.x && y == selection.y), level, level.grid[y][x], hexSize, hexRect))
             {
                 selection = new Vector2(x, y);
             }
         }
         if (y % 2 == 0)
         {
             GUILayout.Space(hexSize / 2);
         }
         GUILayout.EndHorizontal();
     }
     GUILayout.EndVertical();
     return(selection);
 }
コード例 #8
0
 public static void GameOver()
 {
     Debug.Log("GameOver");
     StopPlaying();
     SceneManager.UnloadSceneAsync(s_CurrentLevel.name);
     s_CurrentLevel = AssetRoot.Levels[AssetRoot.Levels.Count - 1];
     AsyncOperation operation = SceneManager.LoadSceneAsync("Scenes/GameOver");
 }
コード例 #9
0
    private void ConstructLevel()
    {
        LevelAsset myTarget = (LevelAsset)target;

        rootContainer = new GameObject();
        rootContainer.transform.position = new Vector3(0, 0, -100);

        cameraGameObject = new GameObject();
        cameraGameObject.transform.position    = new Vector3(0, 4, -100);
        cameraGameObject.transform.eulerAngles = new Vector3(90, 0, 0);
        var camera = cameraGameObject.AddComponent <Camera> ();

        cameraGameObject.hideFlags = HideFlags.HideAndDontSave;
        camera.orthographic        = true;
        camera.clearFlags          = CameraClearFlags.Color;
        camera.backgroundColor     = windowBackgroundColor;
        editorRenderTexture        = Resources.Load("EditorRenderTexture") as RenderTexture;
        camera.targetTexture       = editorRenderTexture;

        if (editorMode == EditorMode.Select)
        {
            var editorSelect = GameObject.Instantiate(Resources.Load <GameObject> ("EditorSelect"));
            AssignObjectToGrid(editorSelect, (int)selectPos.x, (int)selectPos.z);
            editorSelect.transform.localPosition = new Vector3(editorSelect.transform.localPosition.x, 2, editorSelect.transform.localPosition.z);
        }

        foreach (var tile in myTarget.Tiles)
        {
            var gameObjectTile = GameObject.Instantiate(Resources.Load <GameObject>("Tile"));
            foreach (var piece in tile.Pieces)
            {
                GameObject tilePiece = null;
                if (piece.PieceType == PieceType.Hero)
                {
                    tilePiece = GameObject.Instantiate(Resources.Load <GameObject>("Hero"));
                }
                if (piece.PieceType == PieceType.GoalPos)
                {
                    tilePiece = GameObject.Instantiate(Resources.Load <GameObject>("GoalPos"));
                }
                if (piece.PieceType == PieceType.Cube)
                {
                    tilePiece = GameObject.Instantiate(Resources.Load <GameObject>("Stand"));
                }

                if (tilePiece != null)
                {
                    tilePiece.transform.parent           = gameObjectTile.transform;
                    tilePiece.transform.localEulerAngles = new Vector3(0, 0, 0);
                    tilePiece.transform.localPosition    = new Vector3(0, -0.5f, 0);
                }
            }
            AssignObjectToGrid(gameObjectTile, (int)tile.Pos.x, (int)tile.Pos.z);
        }

        SetHideFlagsRecursively(rootContainer);
    }
コード例 #10
0
 public static void DispatchSetGameData(LevelAsset level, LevelAsset save)
 {
     ReceivedActions.Enqueue(() =>
     {
         self.Level = level;
         self.Save  = save;
         self.InitWorld();
         self.InitPallete();
     });
 }
コード例 #11
0
 public void LoadLevel(LevelAsset level)
 {
     if (level == null || level.LevelTexture == null)
     {
         Debug.LogError("Incomplete level asset: " + level.name);
         return;
     }
     GameStarted   = false;
     m_LevelToLoad = level;
     SceneManager.LoadScene("LevelScene");
 }
コード例 #12
0
ファイル: DataManager.cs プロジェクト: yatyricky/pixel-paint
 internal void UpdateSavedData(string key, LevelAsset data)
 {
     if (AllSaves.ContainsKey(key))
     {
         AllSaves[key] = data;
     }
     else
     {
         AllSaves.Add(key, data);
     }
 }
コード例 #13
0
    public LevelAsset Convert()
    {
        LevelAsset level = ScriptableObject.CreateInstance <LevelAsset>();

        level.LevelName  = name;
        level.Difficulty = (DifficultyLevel)difficulty;
        level.PublicKey  = PublicKey;
        level.PrivateKey = PrivateKey;
        level.SaveKey    = Savekey;
        Texture2D tex = new Texture2D(1, 1);

        tex.LoadImage(image);
        level.LevelTexture = tex;
        return(level);
    }
コード例 #14
0
    // Use this for initialization
    void Awake()
    {
        //Parses our inspector list to a dictionary
        for (int i = 0; i < pairs.Length; i++)
        {
            pairs[i].tile.name = pairs[i].Name;
            objectDictionary.Add(pairs[i].Key, pairs[i].tile);
        }

        //TODO: WTF is this! The map creator class should probably be a service clas
        //      that could have a level object passes to it along with a world object
        //      to attach the necessary objects to
        currentLevel = GameManager.ins.LevelToLoad;
        Player       = GameManager.ins.Player;
    }
コード例 #15
0
        private void OnLoadLevel(LevelAsset level)
        {
            switch (type)
            {
            case Type.Title:
                textComponent.text = level.LevelName;
                break;

            case Type.Description:
                textComponent.text = level.LevelDescription;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #16
0
    private void InitWorld()
    {
        GameCamera.transform.position = new Vector3(Level.Width / 2, Level.Height / 2, -20);
        if (Save == null)
        {
            Save = new LevelAsset(Level, true);
        }
        for (int i = 0; i < Level.Data.Length; i++)
        {
            int   y     = i / Level.Width;
            int   x     = i - y * Level.Width;
            Color color = Level.Data[i];

            Vector3Int pos = new Vector3Int(x, y, 0);
            Canvas.SetTileFlags(pos, TileFlags.None);
            Canvas.SetTile(pos, WhiteTile);
            Canvas.SetTileFlags(pos, TileFlags.None);
            Canvas.SetColor(pos, Save.Data[i]);

            MarkerOverlay.SetTileFlags(pos, TileFlags.None);
            if (color.a != 0f)
            {
                MarkerOverlay.SetTile(pos, Markers[Array.IndexOf(Level.Palette, color)]);
            }
        }

        // zoom camera properly
        int   heightPixels = (int)(Level.Height / Configs.ART_IN_WINDOW_RATIO);
        int   widthPixels  = (int)(Level.Width / Configs.ART_IN_WINDOW_RATIO);
        float camSize      = Configs.ZOOM_MIN;

        if (heightPixels / widthPixels > Configs.WINDOW_RATIO)
        {
            // too high
            camSize = heightPixels / Configs.WINDOW_RATIO / Configs.PIXEL_WIDTH_CAM_RATIO;
        }
        else
        {
            // too wide
            camSize = widthPixels / Configs.PIXEL_WIDTH_CAM_RATIO;
        }
        GameController.ZoomTo(camSize);
    }
コード例 #17
0
ファイル: HexGridController.cs プロジェクト: Matt343/hexdef
    public void loadLevel(LevelAsset level, Spawner start)
    {
        clearGrid();
        setUpGrid(level.gridWidth, level.gridHeight);

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                grid[y, x].setHeight(level.grid[y][x].height);
                grid[y, x].locked = level.grid[y][x].path;
                grid[y, x].path   = level.grid[y][x].path;
                grid[y, x].pathId = level.grid[y][x].pathId;
                grid[y, x].setColor(level.colors[level.grid[y][x].color]);
                if (level.grid[y][x].start)
                {
                    GameObject newSpawn = Instantiate(start.gameObject, grid[y, x].transform.position + grid[y, x].spawnOffset, Quaternion.identity) as GameObject;
                    Spawner    spawn    = newSpawn.GetComponent <Spawner>();
                    spawn.startNode = grid[y, x];
                    spawn.setWave(0);

                    spawners.Add(spawn);
                }
                grid[y, x].nextNodes = new List <HexController>();

                for (int i = 0; i < 6; i++)
                {
                    bool active = ((level.grid[y][x].nextPositions & (1 << i)) != 0);
                    if (active)
                    {
                        Vector2 pathPoint = (y % 2 == 0) ? HexInfo.pathPointsEven[i] : HexInfo.pathPointsOdd[i];

                        Vector2 next = level.grid[y][x].position + pathPoint;
                        if (next.x >= 0 && next.y >= 0 && next.x < width && next.y < height)
                        {
                            grid[y, x].nextNodes.Add(grid[(int)next.y, (int)next.x]);
                        }
                    }
                }
            }
        }
    }
コード例 #18
0
    private void ConstructLevel()
    {
        LevelAsset myTarget = (LevelAsset)target;

        rootContainer = new GameObject();
        rootContainer.transform.position = new Vector3(0, 0, 0);

        cameraGameObject = new GameObject();
        cameraGameObject.transform.position = new Vector3(0, 0, -100);
        var camera = cameraGameObject.AddComponent <Camera> ();

        cameraGameObject.hideFlags = HideFlags.HideAndDontSave;
        camera.orthographic        = true;
        camera.clearFlags          = CameraClearFlags.Color;
        camera.backgroundColor     = windowBackgroundColor;
        editorRenderTexture        = Resources.Load("EditorRenderTexture") as RenderTexture;
        camera.targetTexture       = editorRenderTexture;

        levelEditorNode        = Resources.Load("LevelEditorNode") as GameObject;
        levelEditorPuzzlePivot = Resources.Load("levelEditorPuzzlePivot") as GameObject;

        nodeAssetDictionary = LevelAssetHelper.ConstructDictionary(myTarget.subPuzzleNodes);
        nodeDictionary      = new Dictionary <string, LevelEditorNode>();
        var rootNode = nodeAssetDictionary [""][0];

        SpawnNode(rootNode, new Vector2(0, 4));

        LevelEditorNode selectedNode;

        if (!string.IsNullOrEmpty(selectableNodeId))
        {
            nodeDictionary.TryGetValue(selectableNodeId, out selectedNode);
            if (selectedNode != null)
            {
                var pivot        = selectedNode.puzzlePivots [selectablePuzzlePivotId];
                var renderer     = pivot.GetComponent <MeshRenderer> ();
                var tempMaterial = new Material(renderer.sharedMaterial);
                tempMaterial.color      = Color.green;
                renderer.sharedMaterial = tempMaterial;
            }
        }
    }
コード例 #19
0
        public void Load(object context, LevelAsset levelAsset, Func<IPlan, object, bool> filter)
        {
            var reader = _kernel.Get<ILevelReader>(_currentNode, levelAsset.LevelDataFormat.ToString());
            var levelBytes = Encoding.ASCII.GetBytes(levelAsset.LevelData);

            var node = _kernel.Hierarchy.Lookup(context);
            using (var stream = new MemoryStream(levelBytes))
            {
                foreach (var entity in reader.Read(stream, context, filter))
                {
                    var existingNode = _kernel.Hierarchy.Lookup(entity);
                    if (existingNode != null)
                    {
                        // Remove it from the hierarchy if it's already there.
                        _kernel.Hierarchy.RemoveNode(existingNode);
                    }
                    _kernel.Hierarchy.AddChildNode(node, existingNode);
                }
            }
        }
コード例 #20
0
    void OnGUI()
    {
        //string[] filePaths = Directory.GetFiles(@"\Assets\Levels", "*.asset");
        LevelAsset[] levels = AssetDatabase.LoadAllAssetsAtPath("Assets/Levels/*") as LevelAsset[];
        if (levels != null)
        {
            foreach (LevelAsset level in levels)
            {
                GUILayout.Label(level.name);
            }
        }

        //if(filePaths != null)
        //	foreach(string file in filePaths)
        //		GUILayout.Label(file);

        GUILayout.BeginHorizontal();

        GUILayout.BeginVertical();
        GUILayout.Label("Width:");
        GUILayout.Label("Height:");
        GUILayout.EndVertical();

        GUILayout.BeginVertical();
        width  = EditorGUILayout.IntField(width);
        height = EditorGUILayout.IntField(height);
        GUILayout.EndVertical();

        GUILayout.EndHorizontal();

        newLevelName = GUILayout.TextField(newLevelName);
        if (GUILayout.Button("New Level"))
        {
            LevelAsset newLevel = ScriptableObject.CreateInstance(typeof(LevelAsset)) as LevelAsset;
            AssetDatabase.CreateAsset(newLevel, "Assets/Levels/" + newLevelName + ".asset");

            //PrefabUtility.InstantiatePrefab(hexObject);
            //setUpGrid(width, height);
            //hexGrid.setUpGrid(width, height);
        }
    }
コード例 #21
0
ファイル: LevelAsset.cs プロジェクト: yatyricky/pixel-paint
 public LevelAsset(LevelAsset asset, bool toGray)
 {
     Name    = asset.Name;
     Width   = asset.Width;
     Height  = asset.Height;
     Palette = new Color[asset.Palette.Length];
     for (int i = 0; i < Palette.Length; i++)
     {
         Palette[i] = new Color(asset.Palette[i].r, asset.Palette[i].g, asset.Palette[i].b, asset.Palette[i].a);
     }
     Data = new Color[asset.Data.Length];
     for (int i = 0; i < Data.Length; i++)
     {
         if (toGray)
         {
             Data[i] = SmallTricks.Utils.ConvertGreyscale(asset.Data[i]);
         }
         else
         {
             Data[i] = new Color(asset.Data[i].r, asset.Data[i].g, asset.Data[i].b, asset.Data[i].a);
         }
     }
 }
コード例 #22
0
    void Start()
    {
        if (Director.Instance.IsAlternativeLevel)
        {
            additionalPieces = 1;
        }
        if (levelOverride == null)
        {
            level = Director.LevelDatabase.levels [Director.Instance.LevelIndex];
        }
        else
        {
            level = levelOverride;
        }

        numberOfPieces = level.numberOfPieces + new Vector2(additionalPieces, additionalPieces);

        ZoomScale = numberOfPieces.x;

        startScale          = transform.localScale;
        nodeAssetDictionary = LevelAssetHelper.ConstructDictionary(level.subPuzzleNodes);

        StartCoroutine(SpawnInitialSubPuzzle());
    }
コード例 #23
0
 private void OnLoadLevel(LevelAsset levelAsset)
 {
     bulletListAsset    = levelAsset.BulletList;
     currentBulletIndex = 0;
     remainingItemsSignal.Dispatch(bulletListAsset.Prefabs.Length);
 }
コード例 #24
0
    public override void OnInspectorGUI()
    {
        bool       reconstruct = false;
        LevelAsset myTarget    = (LevelAsset)target;

        var editorModeCached = editorMode;

        string[] editorModeOptions = { "Select", "Add" };
        editorMode = (EditorMode)EditorGUILayout.Popup("Mode", (int)editorMode, editorModeOptions);

        if (editorModeCached != editorMode)
        {
            reconstruct = true;
        }

        if (editorMode == EditorMode.Add)
        {
            string[] pieceOptions = Enum.GetNames(typeof(PieceType));
            pieceType = (PieceType)EditorGUILayout.Popup("Piece Type", (int)pieceType, pieceOptions);
        }

        if (cameraGameObject != null)
        {
            EditorGUI.DrawPreviewTexture(new Rect(0 + windowOffset.x, 0 + windowOffset.y, windowSize.x, windowSize.y), editorRenderTexture);
        }

        var tmpMousePos = Event.current.mousePosition;

        tmpMousePos -= windowOffset;
        tmpMousePos -= windowSize * 0.5f;
        var mousePosInGrid = new Vector3(Mathf.RoundToInt(tmpMousePos.x / windowGridSize), 0, -Mathf.RoundToInt(tmpMousePos.y / windowGridSize));

        if (Event.current.type == EventType.MouseDown && IsPositionWithinWindow(Event.current.mousePosition))
        {
            if (editorMode == EditorMode.Select)
            {
                selectPos      = mousePosInGrid;
                selectableTile = myTarget.Tiles.Find(x => { return(x.Pos == mousePosInGrid); });

                reconstruct = true;
            }
            else if (editorMode == EditorMode.Add)
            {
                if (pieceType == PieceType.Tile)
                {
                    if (Event.current.button == 0)
                    {
                        if (!myTarget.Tiles.Exists(x => { return(x.Pos == mousePosInGrid); }))
                        {
                            myTarget.Tiles.Add(new TileData(mousePosInGrid));
                            reconstruct = true;
                        }
                    }

                    if (Event.current.button == 1)
                    {
                        var posibleTile = myTarget.Tiles.Find(x => { return(x.Pos == mousePosInGrid); });
                        if (posibleTile != null)
                        {
                            myTarget.Tiles.Remove(posibleTile);
                            reconstruct = true;
                        }
                    }
                }
                else
                {
                    var posibleTile = myTarget.Tiles.Find(x => { return(x.Pos == mousePosInGrid); });
                    if (Event.current.button == 0)
                    {
                        if (posibleTile != null && posibleTile.Pieces.Count == 0)
                        {
                            posibleTile.Pieces.Add(new PieceData(pieceType));
                            reconstruct = true;
                        }
                    }
                    if (Event.current.button == 1)
                    {
                        if (posibleTile != null && posibleTile.Pieces.Count != 0)
                        {
                            posibleTile.Pieces = new List <PieceData>();
                            reconstruct        = true;
                        }
                    }
                }
            }
        }

        if (Event.current.button == 2)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                mousePos = Event.current.mousePosition;
            }
            if (Event.current.type == EventType.MouseDrag)
            {
                var mouseDir = (mousePos - Event.current.mousePosition) * 0.01f;
                cameraGameObject.transform.position += new Vector3(mouseDir.x, 0, -mouseDir.y);
                mousePos = Event.current.mousePosition;
            }
        }

        if (reconstruct)
        {
            DestroyLevel();
            ConstructLevel();
        }

        if (editorMode == EditorMode.Select && selectableTile != null)
        {
            EditorGUILayout.BeginVertical();
            GUILayout.Space(windowOffset.y + windowSize.y);


            ReorderableListGUI.Title("Selection");
            ReorderableListGUI.ListField <PieceData>(selectableTile.Pieces, SelectionOfPieceDrawer);
            EditorGUILayout.EndVertical();
        }

        EditorUtility.SetDirty(myTarget);
    }
コード例 #25
0
 private LevelAsset.SubPuzzleNode GetSubPuzzleNode(LevelAsset levelAsset)
 {
     return(levelAsset.subPuzzleNodes[0]);
 }
コード例 #26
0
 /// <summary>
 /// Loads a level entity into the game hierarchy, with the specified
 /// context as the place to load entities.  Normally you'll pass in the
 /// game world here, but you don't have to.  For example, if you wanted to
 /// load the level into an entity group, you would pass the entity group
 /// as the context instead.
 /// </summary>
 /// <param name="context">Usually the current game world, but can be any object in the hierarchy.</param>
 /// <param name="levelAsset">The level to load.</param>
 public void Load(object context, LevelAsset levelAsset)
 {
     Load(context, levelAsset, null);
 }
コード例 #27
0
 public void ClearSaveData(LevelAsset level)
 {
     SimpleSerializer.ClearKey(level.SaveKey);
 }
コード例 #28
0
 public void ResetData(LevelAsset level)
 {
     ClearSaveData(level);
     level.LevelData.SaveTime = 0f;
     level.LevelData.Offset   = Vector2.zero;
 }
コード例 #29
0
ファイル: LevelAssetEditor.cs プロジェクト: Matt343/hexdef
    //custom element to display the hex in the grid
    //provides more buttons for the selected cell
    bool hexDisplay(bool toggle, LevelAsset level, HexInfo hex, int hexSize, Rect hexRect)
    {
        //if not toggled, display empty hex with info
        if (!toggle)
        {
            Color tempColor = GUI.backgroundColor;
            Color color;
            if (level.colors != null && hex.color < level.colors.Length)
            {
                color = level.colors[hex.color];
            }
            else
            {
                color = Color.white;
            }
            color.a             = 1;
            GUI.backgroundColor = color;

            string content = "" + hex.pathId;

            toggle = GUILayout.Toggle(toggle, content, skin.customStyles[0], GUILayout.Height(hexSize), GUILayout.Width(hexSize));

            GUI.backgroundColor = tempColor;
        }
        //if it is toggled, display the more complex button
        else
        {
            GUILayout.Space(hexSize);
            //path gui contains the toggle in the center and toggles for next positions on each edge
            if (hex.path)
            {
                Color tempColor = GUI.color;
                Color color;
                if (level.colors != null && hex.color < level.colors.Length)
                {
                    color = level.colors[hex.color];
                }
                else
                {
                    color = Color.white;
                }
                color.a   = 1;
                GUI.color = color;

                GUI.DrawTexture(hexRect, hexBackTex);
                //bool result = GUI.Button(hexRect, hexBack, skin.customStyles[0]);
                if (alphaButton(hexRect, hexInnerTex))
                {
                    setBase(hex);
                }

                Vector2[] pathPoints = (((int)hex.position.y) % 2) == 0 ? HexInfo.pathPointsEven : HexInfo.pathPointsOdd;

                //draw each segment button
                for (int i = 0; i < 6; i++)
                {
                    bool active = ((hex.nextPositions & (1 << i)) != 0);
                    bool result = alphaToggle(active, hexRect, hexSegmentTexs[i]);
                    if (active && !result)
                    {
                        hex.nextPositions = (byte)(hex.nextPositions & (~(1 << i)));
                    }
                    else if (!active && result)
                    {
                        hex.nextPositions = (byte)(hex.nextPositions | (byte)(1 << i));
                        Vector2 next = hex.position + pathPoints[i];
                        if (next.x >= 0 && next.y >= 0 && next.x < level.gridWidth && next.y < level.gridHeight && !level.grid[(int)next.y][(int)next.x].path)
                        {
                            setPath(level.grid[(int)next.y][(int)next.x]);
                        }
                    }
                }


                GUI.color = tempColor;
                GUI.Label(hexRect, "" + hex.pathId, skin.label);
            }
            //base gui only contains the toggle in the center
            else
            {
                Color tempColor = GUI.color;
                Color color;
                if (level.colors != null && hex.color < level.colors.Length)
                {
                    color = level.colors[hex.color];
                }
                else
                {
                    color = Color.white;
                }
                color.a   = 1;
                GUI.color = color;

                GUI.DrawTexture(hexRect, hexBackTex);
                //bool result = GUI.Button(hexRect, hexBack, skin.customStyles[0]);
                if (alphaButton(hexRect, hexInnerTex))
                {
                    setPath(hex);
                }

                GUI.color = tempColor;
                GUI.Label(hexRect, "" + hex.pathId, skin.label);
            }
        }
        return(toggle);
    }
コード例 #30
0
    public override void OnInspectorGUI()
    {
        if (EditorApplication.isPlaying)
        {
            return;
        }
        bool       reconstruct = false;
        LevelAsset myTarget    = (LevelAsset)target;

        var editorModeCached = editorMode;

        string[] editorModeOptions = { "Select", "Add" };
        if (GUILayout.Button("Play Level"))
        {
            DestroyLevel();
            EditorApplication.isPlaying = false;
            EditorSceneManager.OpenScene("Assets/Scenes/LevelScene.unity");
            var gameBoard = GameObject.Find("GameBoard").GetComponent <GameBoard> ();
            gameBoard.levelOverride     = myTarget;
            EditorApplication.isPlaying = true;
        }
        myTarget.isMasterPuzzle = EditorGUILayout.Toggle("IsMasterPuzzle:", myTarget.isMasterPuzzle);
        editorMode       = (EditorMode)EditorGUILayout.Popup("Mode", (int)editorMode, editorModeOptions);
        myTarget.picture = EditorGUILayout.ObjectField("GoalTexture", myTarget.picture, typeof(Texture), false) as Texture;
        if (GUILayout.Button("Clear Nodes"))
        {
            myTarget.subPuzzleNodes.Clear();
            myTarget.subPuzzleNodes.Add(new LevelAsset.SubPuzzleNode("0"));
            reconstruct = true;
        }

        if (editorModeCached != editorMode)
        {
            reconstruct = true;
        }

        if (cameraGameObject != null)
        {
            EditorGUI.DrawPreviewTexture(new Rect(0 + windowOffset.x, 0 + windowOffset.y, windowSize.x, windowSize.y), editorRenderTexture);
        }

        var selectionId = "0";

        if (editorMode == EditorMode.Select && !string.IsNullOrEmpty(selectableNodeId))
        {
            selectionId = selectableNodeId;
        }
        if (!string.IsNullOrEmpty(selectableNodeId))
        {
            EditorGUILayout.BeginVertical();
            GUILayout.Space(windowOffset.y + windowSize.y);

            var selectedNodeAsset = LevelAssetHelper.GetNodeAsset(nodeAssetDictionary, selectableNodeId);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("SelectionId:");
            EditorGUILayout.LabelField(selectionId);
            EditorGUILayout.EndHorizontal();

            var puzzlePivotAsset = selectedNodeAsset.puzzlePivots [selectablePuzzlePivotId];
            puzzlePivotAsset.numberOfPieces        = EditorGUILayout.Vector2Field("Number of Pieces:", puzzlePivotAsset.numberOfPieces);
            puzzlePivotAsset.type                  = (PuzzlePivotType)EditorGUILayout.EnumPopup("Type:", puzzlePivotAsset.type);
            selectedNodeAsset.collectable.isActive = EditorGUILayout.Toggle("Has Collectable:", selectedNodeAsset.collectable.isActive);
            if (selectedNodeAsset.collectable.isActive)
            {
                selectedNodeAsset.collectable.position = EditorGUILayout.Vector2Field("Position of collectable:", selectedNodeAsset.collectable.position);
                selectedNodeAsset.collectable.scale    = EditorGUILayout.Vector2Field("Scale of collectable:", selectedNodeAsset.collectable.scale);
            }

            EditorGUILayout.EndVertical();
            if (GUILayout.Button("Add PuzzlePivot"))
            {
                selectedNodeAsset.puzzlePivots.Add(new LevelAsset.PuzzlePivot());
                reconstruct = true;
            }
            if (GUILayout.Button("Add Node"))
            {
                myTarget.subPuzzleNodes.Add(new LevelAsset.SubPuzzleNode(selectedNodeAsset.id + "-" + LevelAssetHelper.GetChildrenNodes(nodeAssetDictionary, selectedNodeAsset.id).Count));
                reconstruct = true;
            }
        }

        var tmpMousePos = Event.current.mousePosition;

        tmpMousePos -= windowOffset;
        tmpMousePos -= windowSize * 0.5f;
        if (Event.current.type == EventType.MouseDown && IsPositionWithinWindow(Event.current.mousePosition))
        {
            if (editorMode == EditorMode.Select)
            {
                var mousePosInWindow = new Vector3(tmpMousePos.x / 50, -tmpMousePos.y / 50, 0);
                var hits             = Physics.RaycastAll(cameraGameObject.transform.position + mousePosInWindow, Vector3.forward, 200);
                selectableNodeId = String.Empty;
                if (hits.Length > 0)
                {
                    if (hits [0].collider.gameObject.GetComponent <LevelEditorNode> () != null)
                    {
                        selectableNodeId = hits[0].collider.gameObject.GetComponent <LevelEditorNode>().nodeId;
                    }
                    if (hits [0].collider.gameObject.GetComponent <LevelEditorPuzzlePivot> () != null)
                    {
                        var levelEditorPuzzlePivot = hits [0].collider.gameObject.GetComponent <LevelEditorPuzzlePivot> ();
                        selectableNodeId        = levelEditorPuzzlePivot.parent.nodeId;
                        selectablePuzzlePivotId = levelEditorPuzzlePivot.parent.puzzlePivots.IndexOf(levelEditorPuzzlePivot);
                    }
                }
                reconstruct = true;
            }
        }

        if (Event.current.button == 2)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                mousePos = Event.current.mousePosition;
            }
            if (Event.current.type == EventType.MouseDrag)
            {
                var mouseDir = (mousePos - Event.current.mousePosition) * 0.02f;
                cameraGameObject.transform.position += new Vector3(mouseDir.x, -mouseDir.y, 0);
                mousePos = Event.current.mousePosition;
            }
        }

        if (reconstruct)
        {
            DestroyLevel();
            ConstructLevel();
        }

        EditorUtility.SetDirty(myTarget);
    }
コード例 #31
0
ファイル: LevelAssetEditor.cs プロジェクト: Matt343/hexdef
    public override void OnInspectorGUI()
    {
        if (skin == null)
        {
            skin = EditorGUIUtility.Load("LevelEditorSkin.guiskin") as GUISkin;
        }
        if (hexBackTex == null)
        {
            hexBackTex = EditorGUIUtility.Load("Textures/hexagon_back.png") as Texture2D;
        }
        if (hexInnerTex == null)
        {
            hexInnerTex = EditorGUIUtility.Load("Textures/hexagon_inner.png") as Texture2D;
        }

        for (int i = 0; i < 6; i++)
        {
            if (hexSegmentTexs[i] == null)
            {
                hexSegmentTexs[i] = EditorGUIUtility.Load("Textures/hexagon_" + i + ".png") as Texture2D;
            }
        }

        //let the default inspector handle the easy stuff
        DrawDefaultInspector();

        LevelAsset level = target as LevelAsset;

        //make sure that the grid is the correct size, also initiallizes any nulls
        if (level.grid == null || level.grid.Count != level.gridHeight || (level.grid.Count != 0 && level.grid[0].Count != level.gridWidth))
        {
            level.grid = createGrid(level.gridWidth, level.gridHeight, level.grid);
        }


        //grid editor
        showGrid = EditorGUILayout.Foldout(showGrid, "Grid");
        if (Event.current.type == EventType.Repaint)
        {
            gridShowRect = GUILayoutUtility.GetLastRect();
        }

        if (showGrid)
        {
            if (level.grid != null && level.grid.Count == level.gridHeight && level.grid.Count > 0 && level.grid[0].Count == level.gridWidth)
            {
                gridRect      = new Rect(gridShowRect.x, gridShowRect.yMax, hexSize * level.gridHeight, hexSize * level.gridWidth);
                gridSelection = hexGrid(gridSelection, level, hexSize, gridRect);
                //GUILayout.Space(level.gridHeight * hexSize);
            }
            else
            {
                GUILayout.Label("Grid size changed, recreate grid");
            }
        }

        //next path point
        GUILayout.BeginHorizontal();
        GUILayout.Label("Next Path ID");
        nextPathPoint = EditorGUILayout.IntField(nextPathPoint);
        GUILayout.EndHorizontal();

        //grid selection editor, changes HexInfo values for selected cell
        if (gridSelection.x != -1 && level.grid.Count != 0 && level.grid[0].Count != 0)
        {
            showHex = EditorGUILayout.Foldout(showHex, "Hex " + gridSelection.ToString());
            if (showHex && gridSelection.y < level.grid.Count && gridSelection.x < level.grid[0].Count)
            {
                hexEditor(level.grid[(int)gridSelection.y][(int)gridSelection.x]);
            }
        }

        //preset menu for base cells
        showBasePreset = EditorGUILayout.Foldout(showBasePreset, "Base Preset");
        if (showBasePreset)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            GUILayout.BeginVertical();
            GUILayout.Label("Color");
            GUILayout.Label("Height");
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            baseColor  = EditorGUILayout.IntField(baseColor);
            baseHeight = EditorGUILayout.FloatField(baseHeight);
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();
        }

        //preset menu for path cells
        showPathPreset = EditorGUILayout.Foldout(showPathPreset, "Path Preset");
        if (showPathPreset)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            GUILayout.BeginVertical();
            GUILayout.Label("Color");
            GUILayout.Label("Height");
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            pathColor  = EditorGUILayout.IntField(pathColor);
            pathHeight = EditorGUILayout.FloatField(pathHeight);
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();
        }

        //tells the editor to save the changes to disk
        EditorUtility.SetDirty(level);
    }
コード例 #32
0
 public Task LoadAsync(object context, LevelAsset levelAsset)
 {
     Load(context, levelAsset);
     return new Task(() => { });
 }
コード例 #33
0
 public Task LoadAsync(object context, LevelAsset levelAsset, Func<IPlan, object, bool> filter)
 {
     Load(context, levelAsset, filter);
     return new Task(() => { });
 }
コード例 #34
0
ファイル: HallScene.cs プロジェクト: yatyricky/pixel-paint
 public static void DispatchRenderLevels()
 {
     ReceivedActions.Enqueue(() =>
     {
         // fill saves
         foreach (KeyValuePair <string, LevelAsset> entry in DataManager.Instance.AllSaves)
         {
             LevelAsset levelData = null;
             if (DataManager.Instance.AllLevels.TryGetValue(entry.Key, out levelData))
             {
                 // love first
                 if (DataManager.Instance.LoveLevels.Contains(entry.Key))
                 {
                     if (!self.FavoriteViewObjects.HasLoad(entry.Key))
                     {
                         GameObject go    = Instantiate(self.LevelEntrancePrefab);
                         LevelEntrance le = go.GetComponent <LevelEntrance>();
                         le.SetData(levelData, entry.Value);
                         le.beloved = true;
                         self.FavoriteViewObjects.AddChild(go, entry.Key);
                     }
                 }
                 else
                 {
                     if (!self.TrendingViewObjects.HasLoad(entry.Key))
                     {
                         GameObject go    = Instantiate(self.LevelEntrancePrefab);
                         LevelEntrance le = go.GetComponent <LevelEntrance>();
                         le.SetData(levelData, entry.Value);
                         self.TrendingViewObjects.AddChild(go, entry.Key);
                     }
                 }
             }
             else
             {
                 Debug.LogWarning("Has save data without level data");
             }
         }
         // fill all levels
         foreach (KeyValuePair <string, LevelAsset> entry in DataManager.Instance.AllLevels)
         {
             if (!DataManager.Instance.AllSaves.ContainsKey(entry.Key))
             {
                 if (DataManager.Instance.LoveLevels.Contains(entry.Key))
                 {
                     if (!self.FavoriteViewObjects.HasLoad(entry.Key))
                     {
                         GameObject go    = Instantiate(self.LevelEntrancePrefab);
                         LevelEntrance le = go.GetComponent <LevelEntrance>();
                         le.SetData(entry.Value, null);
                         le.beloved = true;
                         self.FavoriteViewObjects.AddChild(go, entry.Key);
                     }
                 }
                 else
                 {
                     if (!self.TrendingViewObjects.HasLoad(entry.Key))
                     {
                         GameObject go    = Instantiate(self.LevelEntrancePrefab);
                         LevelEntrance le = go.GetComponent <LevelEntrance>();
                         le.SetData(entry.Value, null);
                         self.TrendingViewObjects.AddChild(go, entry.Key);
                     }
                 }
             }
         }
         if (DataManager.Instance.LoveLevels.Count == 0)
         {
             self.TrendingToggle.OnClicked();
             self.OnClickedTrending();
         }
         self.TrendingViewObjects.transform.parent.GetComponent <TrendingContents>().CompleteLoad();
     });
 }