Example #1
0
    private void OnClickNewMap()
    {
        AIcuñaMap asset = ScriptableObject.CreateInstance <AIcuñaMap>();

        string path = AssetDatabase.GetAssetPath(Selection.activeObject);

        if (path == "")
        {
            path = "Assets";
        }
        else if (Path.GetExtension(path) != "")
        {
            path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
        }

        string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/New " + typeof(AIcuñaMap).ToString() + ".asset");


        AssetDatabase.CreateAsset(asset, assetPathAndName);

        _mapName = AssetDatabase.GetImplicitAssetBundleName(assetPathAndName);

        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        EditorUtility.FocusProjectWindow();
        Selection.activeObject = asset;

        OnClickSaveMap(asset);

        OnClickOpenMap(asset);
    }
Example #2
0
    private void OnClickSaveMap(AIcuñaMap map)
    {
        if (map == null)
        {
            EditorUtility.DisplayDialog("Error", "Something go wrong.", "Ok. This is a stupid msg.");
            return;
        }

        if (_nodes == null)
        {
            _nodes = new List <Node>();
        }
        if (_connections == null)
        {
            _connections = new List <Connection>();
        }

        string assetPath = AssetDatabase.GetAssetPath(map.GetInstanceID());

        AssetDatabase.RenameAsset(assetPath, _mapName);
        AssetDatabase.SaveAssets();

        map.actions     = new List <ActionNode>();
        map.questions   = new List <QuestionNode>();
        map.connections = new List <Connection>(_connections);

        foreach (var item in _nodes)
        {
            if (item.GetType() == typeof(ActionNode))
            {
                map.actions.Add(item as ActionNode);
            }
            else if (item.GetType() == typeof(QuestionNode))
            {
                map.questions.Add(item as QuestionNode);
            }
        }

        EditorUtility.DisplayDialog("Success Save", "AIcuña map has been saved correctly.", "Ok. You're awesome.");
    }
Example #3
0
    private void OnClickOpenMap(object asset)
    {
        ActionNode   auxAction;
        QuestionNode auxQuestion;

        if (asset.GetType() != typeof(AIcuñaMap))
        {
            EditorUtility.DisplayDialog("Error", "You must select an AIcuña Map.", "Ok. I'm Sorry.");
            return;
        }

        _currentMap = (AIcuñaMap)asset;

        if (_currentMap.actions == null)
        {
            _currentMap.actions = new List <ActionNode>();
        }
        if (_currentMap.questions == null)
        {
            _currentMap.questions = new List <QuestionNode>();
        }
        if (_currentMap.connections == null)
        {
            _currentMap.connections = new List <Connection>();
        }

        _mapName = _currentMap.name;

        _nodes       = new List <Node>();
        _connections = new List <Connection>();

        foreach (var item in _currentMap.actions)
        {
            auxAction = new ActionNode(item.rect.position, item.rect.width, item.rect.height,
                                       _nodeStyle, _selectedNodeStyle, _inPointStyle, OnClickInPoint, OnClickRemoveNode,
                                       item.id, item.inPoint.id);
            auxAction.goName     = item.goName;
            auxAction.scriptName = item.scriptName;
            auxAction.methodName = item.methodName;
            auxAction.SelectScript();
            auxAction.SelectMethod();
            _nodes.Add(auxAction);
        }

        foreach (var item in _currentMap.questions)
        {
            auxQuestion = new QuestionNode(item.rect.position, item.rect.width, item.rect.height,
                                           _nodeStyle, _selectedNodeStyle, _inPointStyle, _truePointStyle, _falsePointStyle,
                                           OnClickInPoint, OnClickOutPoint, OnClickRemoveNode,
                                           item.id, item.inPoint.id, item.truePoint.id, item.falsePoint.id);

            auxQuestion.goName     = item.goName;
            auxQuestion.scriptName = item.scriptName;
            auxQuestion.methodName = item.methodName;
            auxQuestion.SelectScript();
            auxQuestion.SelectMethod();
            _nodes.Add(auxQuestion);
        }

        foreach (var item in _currentMap.connections)
        {
            ConnectionPoint inPoint  = null;
            ConnectionPoint outPoint = null;

            foreach (var node in _nodes)
            {
                if (node.GetType() == typeof(ActionNode))
                {
                    ActionNode n = node as ActionNode;
                    if (item.inPoint.id == n.inPoint.id)
                    {
                        inPoint = n.inPoint;
                    }
                }
                else if (node.GetType() == typeof(QuestionNode))
                {
                    QuestionNode n = node as QuestionNode;
                    if (item.inPoint.id == n.inPoint.id)
                    {
                        inPoint = n.inPoint;
                    }
                    if (item.outPoint.id == n.truePoint.id)
                    {
                        outPoint = n.truePoint;
                    }
                    else if (item.outPoint.id == n.falsePoint.id)
                    {
                        outPoint = n.falsePoint;
                    }
                }
                if (inPoint != null && outPoint != null)
                {
                    break;
                }
            }

            if (inPoint != null && outPoint != null)
            {
                _connections.Add(new Connection(inPoint, outPoint, OnClickRemoveConnection));
            }
            else
            {
                EditorUtility.DisplayDialog("Error", "Something go wrong.", "Ok. This is a stupid msg.");
            }
        }

        EditorUtility.DisplayDialog("Success Open", "AIcuña map has been opened correctly.", "Ok. Let me work.");
    }