Ejemplo n.º 1
0
    public static CubeGrid ToGrid(string path)
    {
        CubeGridXML XMLObject = LoadFromFile(path);
        CubeGrid    _grid     = ScriptableObject.CreateInstance <CubeGrid>();

        _grid.m_CubeLibrary = AssetDatabase.LoadAssetAtPath(XMLObject.CubeLibraryPath, typeof(CubeLibrary)) as CubeLibrary;
        _grid.gridSize      = XMLObject.CubeSize;

        CubeLibrary _lib = _grid.m_CubeLibrary;

        KeyValuePair <string, GameObject>[] LibraryList = _lib.GetObjectsAndGuids();
        List <StructNeedTarget>             NeedTarget  = new List <StructNeedTarget>();


        foreach (SerializableXMLElement iterator in XMLObject.Elements)
        {
            GameObject NewCube = null;
            string     NewGuid = "";
            int        index   = 0;
            foreach (KeyValuePair <string, GameObject> _pairiterator in LibraryList)
            {
                if (_pairiterator.Key == iterator._guid)
                {
                    NewCube = _lib.GetGameObjectByIndex(index);
                    NewGuid = iterator._guid;
                    break;
                }
                index++;
            }

            GameObject CreatedCube = null;
            if (NewCube == null)
            {
                continue;
            }

            _grid.currentPrefab     = NewCube;
            _grid.currentPrefabGuid = NewGuid;
            _grid.CreateCubeAt(iterator._position.V3, out CreatedCube);

            CreatedCube.transform.forward = iterator._forward.V3;
            CreatedCube.transform.up      = iterator._up.V3;
            CreatedCube.transform.right   = iterator._right.V3;

            if (iterator._usetarget)
            {
                StructNeedTarget CurrentTarget = new StructNeedTarget();
                CurrentTarget.SetArgs(CreatedCube, iterator._target.V3);
                NeedTarget.Add(CurrentTarget);
            }
        }

        // пройдемся и проставим таргет по позиции
        foreach (StructNeedTarget targetObj in NeedTarget.ToArray())
        {
            targetObj.comp.SetTarget(_grid.GetCubeAt(targetObj.targetPos));
        }

        return(_grid);
    }
Ejemplo n.º 2
0
    public void LoadByPath(string _path)
    {
        if (_sing == null)
        {
            _sing = FindObjectOfType <CubeGridSingletonObject>() as CubeGridSingletonObject;
        }

        CurrentLevel = _path;
        _sing.Grid.ClearDictionary();
        _sing.Grid = CubeGridXML.ToGrid(_path);
        GlobalOptions.Refresh();
    }
Ejemplo n.º 3
0
    public void LoadByIndex(int _index)
    {
        if (_sing == null)
        {
            _sing = FindObjectOfType <CubeGridSingletonObject>() as CubeGridSingletonObject;
        }

        CurrentLevel = LevelList[_index].path;

        _sing.Grid.ClearDictionary();
        _sing.Grid = CubeGridXML.ToGrid(CurrentLevel);
        GlobalOptions.Refresh();
    }
Ejemplo n.º 4
0
    void RefreshLevelList(string path)
    {
        if (path.Length == 0)
        {
            return;
        }

        LevelList.Clear();

                #if UNITY_EDITOR
        DirectoryInfo dir = new DirectoryInfo(path);
                #else
        DirectoryInfo dir = new DirectoryInfo(Path.Combine(Application.dataPath, "Levels"));
                #endif

        Debug.Log(path);

        if (!dir.Exists)
        {
            Debug.LogError("No Level direcory has being found");
        }

        Debug.Log("Reading level data...");
        FileInfo[] info  = dir.GetFiles("*.xml");
        int        count = 0;
        foreach (FileInfo f in info)
        {
            if (CubeGridXML.CanBeDeserialized(f.FullName))
            {
                LevelList.Add(new Level(f.FullName));
                Debug.Log("File " + f.FullName + "recognized as a level...");
                count++;
            }
        }

        Debug.Log("Total: " + count + " levels loaded.");
    }
Ejemplo n.º 5
0
    public static bool CanBeDeserialized(string path)
    {
        CubeGridXML XMLObject = LoadFromFile(path);

        return(XMLObject != null);
    }
Ejemplo n.º 6
0
    private bool processGUIMenus(SceneView _view)
    {
        Rect _rect = new Rect(10, 10, 100, 400);

        GUILayout.BeginArea(_rect);

        int selectedGridIndex = 0;

        switch (m_editMode)
        {
        case EditMode.addBlock: {
            selectedGridIndex = 0;
            break;
        }

        case EditMode.delBlock: {
            selectedGridIndex = 1;
            break;
        }
        }

        string[] _buttons = new string[] { "Add", "Delete", "Clear", "Destroy hiden", "Save", "Load", "Exit" };

        int oldButtonSelected = selectedGridIndex;

        selectedGridIndex = GUILayout.SelectionGrid(selectedGridIndex, _buttons, 1);

        GUILayout.EndArea();

        processSelectionGridMenu(_view);

        if (oldButtonSelected != selectedGridIndex)
        {
            switch (selectedGridIndex)
            {
            case 0: {
                m_editMode = EditMode.addBlock;
                break;
            }

            case 1: {
                m_editMode = EditMode.delBlock;
                break;
            }

            case 2: {
                m_Instance.ClearDictionary();
                break;
            }

            case 3: {
                DeleteHidenObjects();
                break;
            }

            case 4: {
                string path = EditorUtility.SaveFilePanelInProject("Select level path", "Level", "xml", "Select a file");
                if (path.Length != 0)
                {
                    m_Instance.SerializeMe(path);
                }
                break;
            }

            case 5: {
                string path = EditorUtility.OpenFilePanel("Select level path", Application.dataPath, "xml");
                if (path.Length != 0)
                {
                    m_Instance.ClearDictionary();
                    ScriptableObject.DestroyImmediate(m_Instance);
                    m_Instance = CubeGridXML.ToGrid(path);

                    CubeGridSingletonObject sing = GameObject.FindObjectOfType <CubeGridSingletonObject>();
                    if (sing != null)
                    {
                        sing.Grid = m_Instance;
                    }
                }
                break;
            }

            case 6: {
                DeselectThisGrid();
                break;
            }
            }

            return(true);
        }
        ;

        return(false);
    }