public Mapper_Node PlaceObjAsMain(Mapper_Node_Main mainNode)
    {
        Mapper_NodeConnector outputConnector = null;
        Mapper_Node          childNode       = null;

        foreach (Mapper_NodeConnector con in mainNode.connectors)
        {
            if (con.conType == ConType.cParent)
            {
                outputConnector = con;
            }
        }

        childNode = outputConnector.childLines[0].childNode.node;

        Object     prefab = Resources.Load(objPath + childNode.nodeName);
        Vector3    pos    = new Vector3((float)mainNode.mainInfo.posInWorldX, (float)mainNode.mainInfo.posInWorldY, (float)mainNode.mainInfo.posInWorldZ);
        GameObject go     = (GameObject)Instantiate(prefab, pos, Quaternion.identity, folder.transform);

        go.name = childNode.nodeName;
        go.transform.Rotate(0, Random.Range(0.0f, 360.0f), 0, Space.World);

        childNode.seInfo.isPlaced = true;
        childNode.seInfo.nodeGO   = go;

        return(childNode);
    }
Exemple #2
0
 public Mapper_NodeConnector Initialize(Mapper_Node node, ConType conType)
 {
     childLines   = new List <Mapper_NodeConnectionLine>();
     parentLines  = new List <Mapper_NodeConnectionLine>();
     this.node    = node;
     this.conType = conType;
     return(this);
 }
 public void Select(Mapper_Node node)
 {
     // Debug.Log("Node selected!");
     Deselect();
     if (node is Mapper_Node_Main)
     {
         mainNode = node as Mapper_Node_Main;
     }
     else
     {
         objectNode = node as Mapper_Node_Object;
     }
 }
    public void ToPlaceObj(Mapper_Node objNode)
    {
        Mapper_NodeConnector outputConnector = null;
        Mapper_NodeConnector inputConnector  = null;
        Mapper_Node          childNode       = null;

        foreach (Mapper_NodeConnector con in objNode.connectors)
        {
            if (con.conType == ConType.cParent)
            {
                outputConnector = con;
            }
            if (con.conType == ConType.cChild)
            {
                inputConnector = con;
            }
        }

        for (int i = 0; i < outputConnector.childLines.Count; i++)
        {
            childNode = outputConnector.childLines[i].childNode.node;
            if (objNode.seInfo.isPlaced == true && childNode.seInfo.isPlaced == false)
            {
                PlaceObj(objNode, childNode, outputConnector.childLines[i]);
                ToPlaceObj(childNode);
            }
        }

        if (objNode is Mapper_Node_Object)
        {
            for (int i = 0; i < inputConnector.parentLines.Count; i++)
            {
                childNode = inputConnector.parentLines[i].parentNode.node;
                if (objNode.seInfo.isPlaced == true && childNode.seInfo.isPlaced == false)
                {
                    PlaceObj(objNode, childNode, inputConnector.parentLines[i], true);
                    ToPlaceObj(childNode);
                }
            }
        }
    }
    void OnGUI()
    {
        if (position != previousPosition)
        {
            previousPosition = position;
        }

        if (nodes != null)
        {
            for (int i = 0; i < nodes.Count; i++)
            {
                Mapper_Node n = nodes[i];
                n.DrawConnections();
            }
        }

        Rect pRect = new Rect(0, 0, Screen.width, Screen.height);

        pRect.width = separatorLeft.rect.x;
        DrawPreviewPanel(pRect);

        separatorLeft.MinX = 320;
        separatorLeft.MaxX = (int)(Screen.width / 2f - separatorLeft.rect.width);
        separatorLeft.Draw((int)pRect.y, (int)pRect.height);

        pRect.x     = separatorLeft.rect.x + separatorLeft.rect.width;
        pRect.width = separatorRight.rect.x - separatorLeft.rect.x - separatorLeft.rect.width;
        pRect.yMin += 19;

        nodeView.OnLocalGUI(pRect);

        separatorRight.MinX = (int)(Screen.width / EditorGUIUtility.pixelsPerPoint) - 150;
        separatorRight.MaxX = (int)(Screen.width / EditorGUIUtility.pixelsPerPoint) - 32;
        separatorRight.Draw((int)pRect.y, (int)pRect.height);

        pRect.x    += pRect.width + separatorRight.rect.width;
        pRect.width = (Screen.width / EditorGUIUtility.pixelsPerPoint) - separatorRight.rect.x - separatorRight.rect.width;

        nodeBrowser.OnLocalGUI(pRect);
    }
Exemple #6
0
    public static void LinkNodes(Mapper_Node parentNode, Mapper_Node childNode, ConnectionInfo conInfo = null)
    {
        Mapper_NodeConnector parentOutputNode = null;
        Mapper_NodeConnector childInputNode   = null;

        foreach (Mapper_NodeConnector nodeCon in parentNode.connectors)
        {
            if (nodeCon.conType == ConType.cParent)
            {
                parentOutputNode = nodeCon;
            }
        }

        foreach (Mapper_NodeConnector nodeCon in childNode.connectors)
        {
            if (nodeCon.conType == ConType.cChild)
            {
                childInputNode = nodeCon;
            }
        }

        parentOutputNode.LinkTo(childInputNode, conInfo);
    }
    public void BuildScene()
    {
        GameObject find = GameObject.Find("folder");

        if (find != null)
        {
            DestroyImmediate(find);
        }

        folder = new GameObject("folder");

        Mapper_Node_Main mainNode = null;

        foreach (Mapper_Node node in editor.nodes)
        {
            node.seInfo.ToPlaceOnScene();

            if (node is Mapper_Node_Main)
            {
                mainNode = node as Mapper_Node_Main;
            }
        }

        Mapper_Node objNode = null;

        if (mainNode != null)
        {
            objNode = PlaceObjAsMain(mainNode);
        }
        else
        {
            return;
        }

        ToPlaceObj(objNode);
    }
Exemple #8
0
    public void BuildEditor(Vector2 startPoint)
    {
        foreach (Mapper_Node node in editor.nodes)
        {
            if (node is Mapper_Node_Main)
            {
                node.seInfo.depth = 0;
            }
        }
        Mapper_Utility utility = Mapper_Utility.Create();

        path       = utility.GetPath();
        jsonString = File.ReadAllText(path);
        List <Connection> connections = Connection.CreateFromJSON(jsonString);

        foreach (Connection con in connections)
        {
            if (!editor.nodes.Exists(x => x.nodeName == con.first_object))
            {
                editor.nodes.Add(ScriptableObject.CreateInstance <Mapper_Node_Object>().Initialize(editor, Vector2.zero, con.first_object));
            }
            if (!editor.nodes.Exists(x => x.nodeName == con.second_object))
            {
                editor.nodes.Add(ScriptableObject.CreateInstance <Mapper_Node_Object>().Initialize(editor, Vector2.zero, con.second_object));
            }
        }

        if (connections.Count > 0)
        {
            foreach (Mapper_Node node in editor.nodes)
            {
                if (node is Mapper_Node_Main)
                {
                    Mapper_Node objNode = editor.nodes.Find(x => x.nodeName == connections[0].first_object);
                    objNode.seInfo.depth = 1;
                    Mapper_Node.LinkNodes(node, objNode);
                    break;
                }
            }
        }

        List <Connection> temp = new List <Connection>(connections);

        //Set Depth
        while (temp.Count > 0)
        {
            List <Connection> removedCon = new List <Connection>();

            temp.RemoveAll(x =>
            {
                if ((editor.nodes.Find(n1 => n1.nodeName == x.first_object).seInfo.depth == -1 && editor.nodes.Find(n1 => n1.nodeName == x.second_object).seInfo.depth != -1) ||
                    (editor.nodes.Find(n1 => n1.nodeName == x.first_object).seInfo.depth != -1 && editor.nodes.Find(n1 => n1.nodeName == x.second_object).seInfo.depth == -1))
                {
                    removedCon.Add(x);
                    return(true);
                }

                return(false);
            });

            if (removedCon.Count == 0)
            {
                Mapper_Node node = editor.nodes.Find(x => x.nodeName == temp[0].first_object);
                node.seInfo.depth = 0;
            }

            foreach (Connection con in removedCon)
            {
                Mapper_Node first  = editor.nodes.Find(x => x.nodeName == con.first_object);
                Mapper_Node second = editor.nodes.Find(x => x.nodeName == con.second_object);

                if (first.seInfo.depth != -1)
                {
                    second.seInfo.depth = first.seInfo.depth + 1;
                }
                else
                {
                    first.seInfo.depth = second.seInfo.depth - 1;
                }
            }
        }

        //Set Connection
        foreach (Connection con in connections)
        {
            Mapper_Node first  = editor.nodes.Find(x => x.nodeName == con.first_object);
            Mapper_Node second = editor.nodes.Find(x => x.nodeName == con.second_object);

            ConnectionInfo conInfo = new ConnectionInfo(con.distance, -1, con.rotation_side, con.rotation_up);

            Mapper_Node.LinkNodes(first, second, conInfo);
        }

        //Set Position
        List <Mapper_Node> orderedNodes = editor.nodes.OrderBy(x => x.seInfo.depth).ToList();
        int column = orderedNodes[0].seInfo.depth;
        int row    = 0;

        foreach (Mapper_Node node in orderedNodes)
        {
            if (column < node.seInfo.depth)
            {
                column = node.seInfo.depth;
                row    = 0;
            }

            node.rect.x = startPoint.x + column * (node.node_width + 100);
            node.rect.y = startPoint.y + row * (node.node_height + 100);

            row++;
        }
    }
    public void PlaceObj(Mapper_Node pNode, Mapper_Node cNode, Mapper_NodeConnectionLine conLine, bool reverse = false)
    {
        GameObject parentGo = pNode.seInfo.nodeGO;

        Object prefab = Resources.Load(objPath + cNode.nodeName);

        if (prefab == null)
        {
            return;
        }

        GameObject childGO = (GameObject)Instantiate(prefab, new Vector3(0, 0, 0), Quaternion.identity, folder.transform);

        childGO.name = cNode.nodeName;
        childGO.transform.Rotate(0, Random.Range(0.0f, 360.0f), 0, Space.World);

        float distance;
        float exactDistance;
        float rotationSide;
        float rotationUp;

        ConnectionInfo conInfo = conLine.connectionInfo;

        if (conInfo.distance == -1)
        {
            distance = Random.Range(0.0f, 2f);
        }
        else
        {
            distance = Random.Range(conInfo.distance - 1f <= 0 ? 0 : conInfo.distance - 0.5f, conInfo.distance + 0.5f);
        }

        if (conInfo.exactDistance >= 0)
        {
            exactDistance = conInfo.exactDistance;
            distance      = -1;
        }
        else
        {
            exactDistance = -1;
        }

        if (conInfo.rotationSide == -1)
        {
            rotationSide = Random.Range(0.0f, 360.0f);
        }
        else
        {
            int reverseValue = reverse == false ? 0 : 180;
            rotationSide = Random.Range(conInfo.rotationSide - 25f - reverseValue, conInfo.rotationSide + 25f - reverseValue);
        }

        if (conInfo.rotationUp != -1)
        {
            int reverseValue = reverse == false ? 0 : 180;
            rotationUp = conInfo.rotationUp - reverseValue;
        }

        BoxCollider parentMesh = parentGo.GetComponent <BoxCollider>();
        BoxCollider childMesh  = childGO.GetComponent <BoxCollider>();

        float parentRad = (parentMesh.bounds.size.x > parentMesh.bounds.size.z ? 0.7f * parentMesh.bounds.size.x + 0.3f * parentMesh.bounds.size.z : parentMesh.bounds.size.z + 0.3f * parentMesh.bounds.size.x) / 2;
        float childRad  = (childMesh.bounds.size.x > childMesh.bounds.size.z ? 0.7f * childMesh.bounds.size.x + 0.3f * childMesh.bounds.size.z : childMesh.bounds.size.z + 0.3f * childMesh.bounds.size.x) / 2;

        if (conInfo.rotationUp == -1)
        {
            if (distance != -1)
            {
                childGO.transform.position = new Vector3(parentGo.transform.position.x + (parentRad + childRad) * (1 + distance * 2), parentGo.transform.position.y, parentGo.transform.position.z);
            }
            else
            {
                childGO.transform.position = new Vector3(parentGo.transform.position.x + (parentRad + childRad) + exactDistance, parentGo.transform.position.y, parentGo.transform.position.z);
            }

            childGO.transform.RotateAround(parentGo.transform.position, Vector3.up, rotationSide);
        }
        else
        {
            float   height = parentMesh.bounds.size.y;
            Vector3 vec    = new Vector3(parentGo.transform.position.x, parentGo.transform.position.y, parentGo.transform.position.z);

            if (conInfo.rotationUp == 0)
            {
                vec.y -= height;
                childGO.transform.position = vec;
            }
            else if (conInfo.rotationUp == 180)
            {
                vec.y += height;
                childGO.transform.position = vec;
            }
        }

        cNode.seInfo.isPlaced = true;
        cNode.seInfo.nodeGO   = childGO;
    }