示例#1
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.");
    }