Exemplo n.º 1
0
    private void RemoveChild(ENodePosition _ePosition)
    {
        switch (_ePosition)
        {
        case ENodePosition.EAbove:
            Destroy(childAbove.gameObject);
            childAbove = null;
            break;

        case ENodePosition.ELeft:
            Destroy(childLeft.gameObject);
            childLeft = null;
            break;

        case ENodePosition.EBelow:
            Destroy(childBelow.gameObject);
            childBelow = null;
            break;

        case ENodePosition.ERight:
            Destroy(childRight.gameObject);
            childRight = null;
            break;
        }
        if (eType == ENodeType.EBase)
        {
            UpdateNodeType();
        }
        else
        {
            parentNode.UpdateNodeType();
        }
    }
Exemplo n.º 2
0
    private void InstantiateNew()
    {
        GameObject baseNodeObject = Instantiate(NODE_TEMPLATE, Vector3.zero, Quaternion.identity);

        baseNode = baseNodeObject.GetComponent <Node_CellEditor>();
        baseNodeObject.transform.parent = transform;
        baseNode.PostConstructor(ENodeType.EBase, ENodePosition.EBase, null);
    }
Exemplo n.º 3
0
    public static void AddSelectedNode(Node_CellEditor _node)
    {
        if (_node != null)
        {
            if (selectedNodes == null)
            {
                selectedNodes = new List <Node_CellEditor>();
            }

            selectedNodes.Add(_node);
        }
    }
Exemplo n.º 4
0
    //-------------------------------------------------------------------------------------------//

    /** Call this after creating a new node
     * Will set all necessary member variables and assign a material
     *
     * @param _eNewType The type of node you created; Most likely normal
     * @param _eNewPositionToParent Where this node is relative to its parent
     * @param _parent The parentNode for this node
     */
    public void PostConstructor(ENodeType _eNewType, ENodePosition _eNewPositionToParent, Node_CellEditor _parent)
    {
        eType             = _eNewType;
        ePositionToParent = _eNewPositionToParent;
        parentNode        = _parent;
        InstantiateArrows();
        if (eType == ENodeType.EBase)
        {
            GetComponent <Rigidbody>().isKinematic = true;
        }
        else
        {
            connectionToParent = GetComponent <SpringJoint>();
            connectionToParent.connectedBody = parentNode.gameObject.GetComponent <Rigidbody>();
        }
        if (eType != ENodeType.EBase)
        {
            GetComponent <GB_Dragable>().allowDragging = true;
            GetComponent <GB_Dragable>().NodeDrag(_parent.gameObject);
        }
    }
Exemplo n.º 5
0
 public static void RemoveSelectedNode(Node_CellEditor _node)
 {
     selectedNodes.Remove(_node);
 }
Exemplo n.º 6
0
    private List <Node_CellEditor> GetSymmetryNodes(ESymmetry _eSymmetry)
    {
        List <Node_CellEditor> ret       = new List <Node_CellEditor>();
        Stack <ENodePosition>  positions = new Stack <ENodePosition>();

        positions.Push(ePositionToParent);
        Node_CellEditor center   = parentNode;
        int             children = center.GetChildCount();

        //find the center of symmetry
        if (Designer_CellEditor.HasSymmetryNode())
        {
            while (center.eType != ENodeType.EBase && !center.symmetryNode)
            {
                positions.Push(center.ePositionToParent);
                center   = center.parentNode;
                children = center.GetChildCount();
            }

            //if the base is reached withou finding the symmetry node, stop
            if (!center.symmetryNode)
            {
                return(ret);
            }
        }
        else
        {
            while (center.eType != ENodeType.EBase)
            {
                positions.Push(center.ePositionToParent);
                center   = center.parentNode;
                children = center.GetChildCount();
            }
        }
        //if the symmetry node has only one child, stop
        if (children == 1)
        {
            return(ret);
        }


        //now we have the center of symmetry
        //iterater over all the steps it took to get here, but backwards

        if (_eSymmetry == ESymmetry.EMirror || _eSymmetry == ESymmetry.EPointMirror)
        {
            ENodePosition curPos;
            curPos = positions.Pop();
            while (positions.Count != 0 && center != null)
            {
                curPos = UTIL_CellEditor.GetOppositePosition(curPos);
                center = center.GetChild(curPos);
            }

            if (center != null)
            {
                ret.Add(center);
            }
        }
        else if (_eSymmetry == ESymmetry.EPoint)
        {
            //F**K!
        }



        return(ret);
    }
Exemplo n.º 7
0
    public void CreateAndAttachChildNode(ENodePosition _ePosition)
    {
        Vector3    childPos   = Vector3.zero;
        Quaternion childRot   = Quaternion.Euler(Vector3.zero);
        ENodeType  eChildType = ENodeType.ENormal;

        if (eType != ENodeType.EBase)
        {
            List <Node_CellEditor> armNodes = GetAllNodesOfArm();
            //this node is also in there as the last node so we have to take the node at index lenth -2
            Node_CellEditor parentNode = armNodes[armNodes.Count - 2];

            if (parentNode != null)
            {
                Vector3 pos    = transform.position;
                Vector3 parPos = parentNode.transform.position;
                Vector3 dir    = (pos - parPos).normalized;
                childPos = dir * DISTANCE_AVERAGE;
                float rot = StaticMaths.FindLookAtAngle2D(pos, parPos); //maybe pos and childPos or parPos and childPos
                childRot = Quaternion.Euler(0f, rot, 0f);
                //childRot = gameObject.transform.rotation;

                if ((ePositionToParent == ENodePosition.ERight && _ePosition == ENodePosition.EAbove) ||
                    (ePositionToParent == ENodePosition.ELeft && _ePosition == ENodePosition.EBelow))
                {
                    childPos = new Vector3(-childPos.z, childPos.y, childPos.x);
                }
                else if ((ePositionToParent == ENodePosition.EAbove && _ePosition == ENodePosition.ELeft) ||
                         (ePositionToParent == ENodePosition.EBelow && _ePosition == ENodePosition.ERight))
                {
                    childPos = new Vector3(-childPos.z, childPos.y, childPos.x);
                }
                else if ((ePositionToParent == ENodePosition.ERight && _ePosition == ENodePosition.EBelow) ||
                         (ePositionToParent == ENodePosition.ELeft && _ePosition == ENodePosition.EAbove))
                {
                    childPos = new Vector3(childPos.z, childPos.y, -childPos.x);
                }
                else if ((ePositionToParent == ENodePosition.EAbove && _ePosition == ENodePosition.ERight) ||
                         (ePositionToParent == ENodePosition.EBelow && _ePosition == ENodePosition.ELeft))
                {
                    childPos = new Vector3(childPos.z, childPos.y, -childPos.x);
                }
            }
            else
            {
                Debug.Log("FATAL ERROR : non-base node doesn't have parent node. ");
            }
        }
        else
        {
            childPos   = transform.position;
            eChildType = ENodeType.ESingle;
            switch (_ePosition)
            {
            case ENodePosition.EAbove:
                childPos.z += DISTANCE_AVERAGE;
                break;

            case ENodePosition.EBelow:
                childPos.z -= DISTANCE_AVERAGE;
                break;

            case ENodePosition.ERight:
                childPos.x += DISTANCE_AVERAGE;
                break;

            case ENodePosition.ELeft:
                childPos.x -= DISTANCE_AVERAGE;
                break;
            }
        }

        childPos += transform.position;

        //These ifs make sure that you can't create a child node on the socket where a parent node is attached
        if (_ePosition == ENodePosition.EAbove && ePositionToParent != ENodePosition.EBelow)
        {
            GameObject chA = Instantiate(NODE_TEMPLATE, childPos, childRot);
            chA.transform.parent = transform;
            childAbove           = chA.GetComponent <Node_CellEditor>();
            childAbove.PostConstructor(eChildType, _ePosition, this);
            if (arrowUp != null)
            {
                Destroy(arrowUp.gameObject);
                arrowUp = null;
            }
        }
        else if (_ePosition == ENodePosition.ERight && ePositionToParent != ENodePosition.ELeft)
        {
            GameObject chR = Instantiate(NODE_TEMPLATE, childPos, childRot);
            chR.transform.parent = transform;
            childRight           = chR.GetComponent <Node_CellEditor>();
            childRight.PostConstructor(eChildType, _ePosition, this);

            if (arrowRight != null)
            {
                Destroy(arrowRight.gameObject);
                arrowRight = null;
            }
        }
        else if (_ePosition == ENodePosition.EBelow && ePositionToParent != ENodePosition.EAbove)
        {
            GameObject chB = Instantiate(NODE_TEMPLATE, childPos, childRot);
            chB.transform.parent = transform;
            childBelow           = chB.GetComponent <Node_CellEditor>();
            childBelow.PostConstructor(eChildType, _ePosition, this);

            if (arrowDown != null)
            {
                Destroy(arrowDown.gameObject);
                arrowDown = null;
            }
        }
        else if (_ePosition == ENodePosition.ELeft && ePositionToParent != ENodePosition.ERight)
        {
            GameObject chL = Instantiate(NODE_TEMPLATE, childPos, childRot);
            chL.transform.parent = transform;
            childLeft            = chL.GetComponent <Node_CellEditor>();
            childLeft.PostConstructor(eChildType, _ePosition, this);

            if (arrowLeft != null)
            {
                Destroy(arrowLeft.gameObject);
                arrowLeft = null;
            }
        }

        if (eType != ENodeType.EBase)
        {
            parentNode.UpdateNodeType();
        }
        else
        {
            UpdateNodeType();
        }
    }