public Mapper_SelectionInfo Initialize(Mapper_Editor editor)
    {
        this.editor    = editor;
        mainNode       = null;
        objectNode     = null;
        connectionLine = null;

        return(this);
    }
Ejemplo n.º 2
0
    public void LinkTo(Mapper_NodeConnector otherNode, ConnectionInfo connectionInfo = null)
    {
        if (conType == ConType.cChild)
        {
            otherNode.LinkTo(this);
            return;
        }

        Mapper_NodeConnectionLine temp = ScriptableObject.CreateInstance <Mapper_NodeConnectionLine>().Initialize(this, otherNode, node.editor, connectionInfo);

        childLines.Add(temp);
        otherNode.parentLines.Add(temp);
    }
    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;
    }
 public void Select(Mapper_NodeConnectionLine connectionLine)
 {
     Deselect();
     this.connectionLine = connectionLine;
 }
 public void Deselect()
 {
     mainNode       = null;
     objectNode     = null;
     connectionLine = null;
 }