예제 #1
0
    public override void Init(BlockSaveData saveData)
    {
        base.Init(saveData);

        sortingOrder = (int)Block.SortingOrder.Idle;
        mapTiles     = new List <MapTile>();

        transform.SetParent(Map.Instance.blocks, false);
        transform.localPosition = saveData.tilePositions [0];

        slot = GameObject.Instantiate <SlotBlock>(Map.Instance.slotBlockPrefab);
        slot.Init(saveData);

        if (saveData.hintPosition != saveData.slotPosition)
        {
            hint = GameObject.Instantiate <HintBlock> (Map.Instance.hintBlockPrefab);
            hint.Init(saveData);
        }

        transform.position = slot.transform.position;
        float minY = float.MaxValue;

        foreach (BlockTile blockTile in blockTiles)
        {
            minY = Mathf.Min(minY, blockTile.transform.position.y);
        }
        clickDeltaPosition   = transform.position;
        clickDeltaPosition.y = Mathf.Abs(transform.position.y - minY);
        if (false == Map.Instance.enabled)
        {
            colliderSize = new Vector3(2.0f, 2.0f, 1.0f);
        }
        transform.localScale = slot.transform.localScale;
        initPosition         = transform.position;
        mapTileCount         = 0;
        if (true == Map.Instance.editMode && null != hint)
        {
            transform.position   = hint.transform.position;
            transform.localScale = Vector3.one;
            initPosition         = hint.transform.position;
        }
    }
예제 #2
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        if (false == Application.isPlaying)
        {
            return;
        }
        Editor editor = (Editor)target;

        if (GUILayout.Button("Init"))
        {
            MapSaveData mapSaveData = ScriptableObject.CreateInstance <MapSaveData>();
            mapSaveData.stage          = editor.stage;
            mapSaveData.level          = editor.level;
            mapSaveData.width          = editor.width;
            mapSaveData.height         = editor.height;
            mapSaveData.tiles          = new int[mapSaveData.width * mapSaveData.height];
            mapSaveData.blockSlotScale = 1.0f;
            Map.Instance.Init(mapSaveData);
        }

        if (GUILayout.Button("Save"))
        {
            Map.Instance.stage = editor.stage;
            Map.Instance.level = editor.level;

            MapSaveData saveData = Map.Instance.GetSaveData();
            AssetDatabase.CreateAsset(saveData, "Assets/Resources/" + saveData.stage + "_" + saveData.level + ".asset");
            for (int i = 0; i < saveData.blocks.Length; i++)
            {
                AssetDatabase.AddObjectToAsset(saveData.blocks[i], saveData);
            }
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            Debug.Log("success to save map file to " + "\'Assets/Resources/" + saveData.stage + "_" + saveData.level + ".asset" + "\'");
        }

        if (GUILayout.Button("Load"))
        {
            editor.Init();
            MapSaveData data = Resources.Load <MapSaveData>(editor.stage + "_" + editor.level);
            Map.Instance.Init(data);

            editor.blockSlotScale = Map.Instance.blockSlotScale;
            for (int i = 0; i < Map.Instance.blocks.childCount; i++)
            {
                MapBlock block = Map.Instance.blocks.GetChild(i).GetComponent <MapBlock>();
                editor.blocks.Add(block.id, block);
                editor.blockID = Mathf.Max(editor.blockID, block.id + 1);
            }
            Debug.Log("success to load map file from " + "\'Assets/Resources/" + data.stage + "_" + data.level + ".asset" + "\'");
        }

        if (GUILayout.Button("Check Map Validation"))
        {
            for (int stage = 1; stage <= 72; stage++)
            {
                for (int level = 1; level <= 24; level++)
                {
                    MapSaveData data = Resources.Load <MapSaveData> (stage + "_" + level);
                    if (null == data)
                    {
                        Debug.Log(stage + "-" + level + " is null");
                        return;
                    }
                    Map.Instance.Init(data);

                    int count = 0;
                    foreach (MapTile mapTile in Map.Instance.mapTiles)
                    {
                        if (0 != mapTile.id)
                        {
                            count++;
                        }
                    }
                    if (0 != count % 5)
                    {
                        Debug.Log(stage + "-" + level + " is wrong");
                    }
                }
            }
            Debug.Log("complete vaidation check");
        }
        Map.Instance.blockSlotScale = editor.blockSlotScale;

        for (int i = 0; i < Map.Instance.slots.childCount; i++)
        {
            SlotBlock block = Map.Instance.slots.GetChild(i).GetComponent <SlotBlock>();
            block.transform.localScale = new Vector3(Map.Instance.blockSlotScale, Map.Instance.blockSlotScale, 1.0f);
        }
    }