Example #1
0
    public void AddNewPoint(SPData SPData, Vector3 position, addPathPointPos addPathPointPos, int targetIndex)
    {
        Undo.RecordObject(SPData.SplinePlus, "Node added");


        var branch = SPData.DictBranches[SPData.Selections._BranchKey];

        SPData.EditSpline = false;
        var node = new Node();

        node._Type = SPData.NodeType;

        node.Point = CreatePoint(SPData, "p" + SPData.PathPointCount, position, Quaternion.identity, SPData.DataParent.transform);

        if (addPathPointPos == addPathPointPos.Beginning)
        {
            branch.Nodes.Insert(0, node);

            node.Point1 = CreatePoint(SPData, "p1", branch.Nodes[targetIndex].Point.position, Quaternion.identity, node.Point);
            node.Point2 = CreatePoint(SPData, "p2", branch.Nodes[targetIndex].Point.position, Quaternion.identity, node.Point);

            if (branch.Nodes.Count > 1)
            {
                node.Point2.position      = Vector3.Lerp(branch.Nodes[targetIndex + 1].Point.position, node.Point.position, 0.5f);
                node.Point1.localPosition = -node.Point2.localPosition;
            }
            else
            {
                node.Point1.localPosition = new Vector3(5, 0, 0);
                node.Point2.localPosition = -node.Point1.localPosition;
            }
        }
        else if (addPathPointPos == addPathPointPos.End)//end
        {
            branch.Nodes.Add(node);
            targetIndex               = branch.Nodes.Count - 1;
            node.Point1               = CreatePoint(SPData, "p1", branch.Nodes[targetIndex].Point.position, Quaternion.identity, node.Point);
            node.Point2               = CreatePoint(SPData, "p2", branch.Nodes[targetIndex].Point.position, Quaternion.identity, node.Point);
            node.Point1.position      = Vector3.Lerp(branch.Nodes[targetIndex - 1].Point.position, node.Point.position, 0.5f);
            node.Point2.localPosition = -node.Point1.localPosition;
        }
        else if (addPathPointPos == addPathPointPos.Middle)//middle
        {
            var a = (targetIndex - 1) < 0 ? branch.Nodes.Count - 1 : targetIndex - 1;
            var b = (targetIndex + 1) >= branch.Nodes.Count ? 0 : (targetIndex + 1);

            branch.Nodes.Insert(targetIndex, node);
            node.Point1 = CreatePoint(SPData, "p1", branch.Nodes[targetIndex].Point.position, Quaternion.identity, node.Point);
            node.Point2 = CreatePoint(SPData, "p2", branch.Nodes[targetIndex].Point.position, Quaternion.identity, node.Point);
            var dir = (branch.Nodes[a].Point.position - branch.Nodes[b].Point.position).normalized;
            node.Point1.localPosition = dir * Vector3.Distance(branch.Nodes[a].Point.position, branch.Nodes[b].Point.position) * 0.2f;
            node.Point2.localPosition = -node.Point1.localPosition;
        }

        BranchesClass.BranchWeldSt(SPData);
        EditorUtility.SetDirty(SPData.SplinePlus);
        SPData.SplinePlus.SplineCreationClass.UpdateAllBranches(SPData);

        SPData.PathPointCount++;
    }
Example #2
0
    public void WeldBranch(SPData SPData, Node node, int n)
    {
        var branch = SPData.DictBranches[SPData.Selections._BranchKey];

        Undo.RecordObject(SPData.SplinePlus, "branch welded");
        if (n == 0)
        {
            branch.Nodes.Insert(0, node);
        }
        else
        {
            branch.Nodes.Add(node);
        }

        if (SPData.NodeType == NodeType.Free)
        {
            node._Type = NodeType.Free;
        }
        else
        {
            node._Type = NodeType.Smooth;
        }

        BranchesClass.BreakBranch(SPData, node);
        BranchesClass.AddRefreshSharedNode(SPData, node);
        BranchesClass.BranchWeldSt(SPData);
        EditorUtility.SetDirty(SPData.SplinePlus);
        SPData.SplinePlus.SplineCreationClass.UpdateBranch(SPData, branch);
    }
Example #3
0
    void SelectBranch(SPData SPData)
    {
        int n = 0;

        foreach (var branch in SPData.DictBranches)
        {
            for (int i = 0; i < branch.Value.Vertices.Count - 1; i++)
            {
                var dist = Vector2.Distance(HandleUtility.WorldToGUIPoint(branch.Value.Vertices[i]), Event.current.mousePosition);
                if (dist < 20)
                {
                    Undo.RecordObject(SPData.SplinePlus, "Branch selected");

                    if (SPData.Selections._BranchKey == branch.Key)
                    {
                        return;
                    }
                    SPData.Selections._BranchKey   = branch.Key;
                    SPData.Selections._BranchIndex = n;
                    BranchesClass.BranchWeldSt(SPData);

                    //init mesh layer selection when branch selection is changed to avoid index out of range exception
                    if (SPData.ObjectType == SPType.MeshDeformer)
                    {
                        //Change branch selection delegete
                        if (BranchSelectionChangedDel != null)
                        {
                            BranchSelectionChangedDel();
                        }
                    }
                    //keep path point selection when changing branches selection
                    if (SPData.Selections._SharedPathPointIndex != -1)
                    {
                        if (!SPData.SharedNodes[SPData.Selections._SharedPathPointIndex].ConnectedBranches.Contains(branch.Key))
                        {
                            SPData.Selections._PathPoint = new Node();
                        }
                        else
                        {
                            SPData.Selections._LocalNodeIndex = SPData.SharedNodes[SPData.Selections._SharedPathPointIndex].Node.LocalIndex(SPData, SPData.Selections._BranchKey);
                            SPData.Selections._PathPoint      = SPData.DictBranches[SPData.Selections._BranchKey].Nodes[SPData.Selections._LocalNodeIndex];
                        }
                    }
                    else
                    {
                        SPData.Selections._PathPoint = new Node();
                    }
                    EditorUtility.SetDirty(SPData.SplinePlus);

                    return;
                }
            }
            n++;
        }
    }