public void ExportAsPolyline()
    {
        List <Vector3> points = new List <Vector3>();

        BezierLine current = start;

        do
        {
            for (int i = 0; i < exportResolution; i++)
            {
                float step = ((float)i / exportResolution);
                Debug.Log(step);
                Vector3 pointA = Vector3.Lerp(current.Start, current.StartHandle, step);
                Vector3 pointB = Vector3.Lerp(current.StartHandle, current.EndHandle, step);
                Vector3 pointC = Vector3.Lerp(current.EndHandle, current.End, step);

                Vector3 pointAB = Vector3.Lerp(pointA, pointB, step);
                Vector3 pointBC = Vector3.Lerp(pointB, pointC, step);

                points.Add(Vector3.Lerp(pointAB, pointBC, step));
                Debug.Log(Vector3.Lerp(pointAB, pointBC, step).ToString());
            }

            current = current.nextLine;
        }while (current != start);

        Polyline polyline = ScriptableObject.CreateInstance <Polyline>();

        polyline.nodes = points;

        AssetDatabase.CreateAsset(polyline, "Assets/MyPolyline.asset");
    }
    private void Draw()
    {
        //throw new NotImplementedException();

        BezierLine current = polylineCreator.start;

        do
        {
            Handles.DrawBezier(current.Start, current.End,
                               current.StartHandle, current.EndHandle, Color.blue, null, 5f);

            Handles.color = Color.red;
            current.Start = Handles.FreeMoveHandle(current.Start, Quaternion.identity, .1f, Vector2.zero, Handles.SphereHandleCap);

            if (!polylineCreator.closed && current.nextLine == null)
            {
                current.End = Handles.FreeMoveHandle(current.End, Quaternion.identity, .1f, Vector2.zero, Handles.SphereHandleCap);
            }

            Handles.color       = Color.green;
            current.StartHandle = Handles.FreeMoveHandle(current.StartHandle, Quaternion.identity, .1f, Vector2.zero, Handles.CubeHandleCap);
            current.EndHandle   = Handles.FreeMoveHandle(current.EndHandle, Quaternion.identity, .1f, Vector2.zero, Handles.CubeHandleCap);
            Handles.color       = Color.white;
            Handles.DrawDottedLine(current.Start, current.StartHandle, .5f);
            Handles.DrawDottedLine(current.End, current.EndHandle, .5f);

            current = current.nextLine;
        } while (current != polylineCreator.start && current != null);
    }
Exemplo n.º 3
0
 void Start()
 {
     name         = Type.ToString();
     _attackLine  = transform.GetComponentInChildren <BezierLine>();
     _propertie   = gameObject.GetComponent <PlayerPropertie>();
     _attackRange = _propertie.GetAttackRange();
 }
Exemplo n.º 4
0
    private void Start()
    {
        AIString = GameObject.FindGameObjectWithTag("UpString").GetComponent <BezierLine>();
        game     = GameObject.FindGameObjectWithTag("Game").GetComponent <Game>();
        gate     = game.gate.GetComponent <Gate>();

        active = false;

        Difficulty diff = new Difficulty();

        /*if (!XMLManager.LoadData<Difficulty>(ref diff, "settings"))
         * {
         *    XMLManager.LoadDifficulty(ref diff, "begginer");
         *    XMLManager.SaveData<Difficulty>(diff, "settings");
         * }*/

        XMLManager.LoadDifficulty(ref diff, (GameRule.globalDiff ? GameRule.difficulties + 2 : GameRule.difficulties).ToString());

        speedAI    = diff.speedAI;
        accuracyAI = diff.accuracyAI;
        timeRest   = diff.timeRest;

        accuracyAI /= 2;
        upBorder    = ScreenOptimization.GetWorldCoord2D(gameObject).first.y;
        dispersion  = Camera.main.ScreenToWorldPoint(new Vector2(accuracyAI * Screen.width, 0)).x + Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, 0)).x;
    }
    public void AddLine(Vector3 endPoint)
    {
        if (closed)
        {
            BezierLine current         = start;
            float      lowestMangitude = float.MaxValue;
            BezierLine currentClosest  = current;

            do
            {
                float magnitude = ((endPoint - current.Start) + (endPoint - current.End)).magnitude;

                if (magnitude < lowestMangitude)
                {
                    lowestMangitude = magnitude;
                    currentClosest  = current;
                }
                current = current.nextLine;
            }while (current.nextLine != start);

            BezierLine currentClosestNext = currentClosest.nextLine;
            BezierLine newLine            = new BezierLine(currentClosest, endPoint);
            currentClosestNext.SetPreviousLine(newLine);
        }
        else
        {
            BezierLine currentLast = GetLastLine();
            BezierLine newLine     = new BezierLine(currentLast, endPoint);
            newLine.SetPreviousLine(currentLast);
        }
    }
Exemplo n.º 6
0
        public BezierControl(BezierLine figure, bool isRight)
        {
            InitializeComponent();

            var leftPoint  = figure.LeftLineConnector.PosPoint;
            var rightPoint = figure.RightLineConnector.PosPoint;

            Figure  = figure;
            IsRight = isRight;

            if (IsRight)
            {
                figure.RightBezierControl = this;
            }
            else
            {
                figure.LeftBezierControl = this;
            }

            var mult = IsRight ? 2 : 1;

            PosPoint = new Point(leftPoint.X + (rightPoint.X - leftPoint.X) / 3 * mult,
                                 leftPoint.Y + (rightPoint.Y - leftPoint.Y) / 3 * mult);
            UpdatePos();

            MouseMove           += OnMouseMove;
            MouseLeftButtonDown += OnMouseLeftButtonDown;
            MouseLeftButtonUp   += OnMouseLeftButtonUp;
        }
Exemplo n.º 7
0
    public BezierLine Decode()
    {
        BezierLine Bez = BezierLine.Instance;

        Bez.LineId = 0;
        Bez.Path.Clear();
        Bez.CtrlPts.Clear();
        if (Path != null)   //in case we are loading a blank track
        {
            foreach (BezCtrlPtSerial BCPS in CtrlPts)
            {
                BezCtrlPt BCP = BCPS.Decode();
                Bez.CtrlPts.Add(BCP);
            }


            foreach (Vector3Serial PS in Path)
            {
                Bez.Path.Add(PS.V3);
            }
        }
        else
        {
            Bez.Init();
        }                       //blank track - put in the 2 dummies
        return(Bez);
    }
Exemplo n.º 8
0
    void OnWizardCreate()
    {
        GameObject pParentObj = new GameObject {
            name = LineName
        };

        pParentObj.transform.position = new Vector3(0.0f, 0.0f, 0.0f);

        for (int i = 0; i < InterplateNumber; ++i)
        {
            GameObject pInterplateObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            pInterplateObj.name = "interplate" + i;
            pInterplateObj.transform.position = new Vector3(10.0f * i, 0.0f, 0.0f);
            pInterplateObj.transform.parent   = pParentObj.transform;

            GameObject pControlObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            pControlObj.name = "control";
            pControlObj.transform.position = new Vector3(10.0f * i, 0.0f, 10.0f);
            pControlObj.transform.parent   = pInterplateObj.transform;
        }

        BezierLine pLine = pParentObj.AddComponent <BezierLine>();

        pLine.FixPoints(InterplateNumber);
    }
Exemplo n.º 9
0
    public static XSec CalcXSecPerp(int PathId, int RoadWidth)
    {
        XSec       rtn = new XSec(PathId);
        BezierLine Bez = BezierLine.Instance;
        Vector3    Path3d;

        if (PathId == Bez.Path.Count)
        {
            Path3d = Bez.CtrlPts[Bez.CtrlPts.Count - 2].Pos;
        }
        else
        {
            Path3d = Bez.Path[PathId];
        }
        Vector2 Path2d  = Convert2d(Path3d);
        Vector2 Perp1   = Perpndclr(PathId);
        Vector2 KerbR2d = Path2d + Perp1 * RoadWidth;
        Vector2 KerbL2d = Path2d - Perp1 * RoadWidth;

        Vector3 KerbR = new Vector3(KerbR2d.x, Path3d.y, KerbR2d.y);
        Vector3 KerbL = new Vector3(KerbL2d.x, Path3d.y, KerbL2d.y);


        rtn.TerrainL = (KerbL - Path3d) * 1.3f + Path3d;         //Here's where ther terrain is slightly wider than the road
        rtn.TerrainR = (KerbR - Path3d) * 1.3f + Path3d;         //Here's where ther terrain is slightly wider than the road
        rtn.KerbL    = KerbL;
        rtn.KerbR    = KerbR;
        rtn.MidPt    = Path3d;
        return(rtn);
    }
        /// <summary>
        /// 初始化基本信息
        /// </summary>
        protected override void InitBaseInfo()
        {
            base.InitBaseInfo();
            ///创建函数入口代码块
            FunctionEnterBox            = CreateXCodeBox("方法入口", CenterPoint, CodeBox.XAType.XFunctionEnter);
            FunctionEnterBox.OpenButton = 2;
            FunctionEnterBox.AddXExcXAribute();
            FunctionEnterBox.XAributeChangeMessage = () => { XAributeChangeMessage(this); };///属性消息变更通知
            ///创建函数出口代码块
            CodeBox functionExc = CreateXCodeBox("方法出口", new Point(CenterPoint.X + 250, CenterPoint.Y), CodeBox.XAType.XFunctionExc);

            functionExc.OpenButton = 1;
            functionExc.AddXEnterXAribute();
            functionExc.XAributeChangeMessage = () => { XAributeChangeMessage(this); };///属性消息变更通知
            ///保存函数出口代码块的地址
            FunctionExcBox = functionExc;

            ///添加初始连线
            XAribute   FirstXa      = FunctionEnterBox.GetRightExc()[0];
            XAribute   SecondXa     = functionExc.GetLeftEnter();
            BezierLine MyBezierLine = new BezierLine(CreateBezierID(), FirstXa.BorderColor, FirstXa.GetWorldPosition(), FirstXa.SelectPositionStyle);

            AddBezierLine(MyBezierLine);
            FirstXa.AddBezierLine(MyBezierLine);
            MyBezierLine.StartPoint.LinkAribute = FirstXa;
            SecondXa.AddBezierLine(MyBezierLine);
            MyBezierLine.EndPoint.LinkAribute = SecondXa;
            MyBezierLine.SetBezierLine(SecondXa.GetWorldPosition(), SecondXa.SelectPositionStyle);
        }
Exemplo n.º 11
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            bezier = new BezierLine(pictureBox1);

            //If you need snapping to grid!
            //bezier.isSnap = true;
            //bezier.snapRes = 20;

            //If you need to change colors
            //bezier.pathPenColor = Color.Black;
            //bezier.anchorBrushColor = Color.Gold;
            //bezier.ctrlBrushColor = Color.Blue;
            //bezier.ctrlPenColor = Color.Green;

            //If you need to change sizes
            //bezier.AnchorSize = 20;
            //bezier.ControlSize = 10;
            //bezier.pathPenWidth = 20;
            //bezier.ctrlPen.Width = 10;

            //Wanna get fast draw?
            //bezier.Smoothing = false;

            bezier.Spawn(40, 40);
        }
Exemplo n.º 12
0
    void OnEnable()
    {
        m_Self = target as BezierLine;
        m_Root = m_Self.transform;

        InitAnchor();
    }
Exemplo n.º 13
0
 public BuilderTests()
 {
     goPlayer = GameObject.Find("BuilderPlayer(Clone)");
     RB       = goPlayer.GetComponent <RoadBuilder>();
     Rd       = Road.Instance;
     Bez      = BezierLine.Instance;
 }
Exemplo n.º 14
0
 void Start()
 {
     FPCam             = GameObject.Find("BuilderCamera").GetComponent <Camera>();
     _rb               = GameObject.Find("BuilderPlayer(Clone)").GetComponent <RoadBuilder>();
     AttachedTransform = transform.parent;
     Bez               = BezierLine.Instance;
     Mrkr              = AttachedTransform.GetComponent <RoadMarker>();
 }
Exemplo n.º 15
0
 /// <summary>
 /// 删除一条贝塞尔曲线
 /// </summary>
 /// <param name="bz"></param>
 private void DelBezierLine(BezierLine bz)
 {
     if (GetBezierLines.ContainsValue(bz))
     {
         GetBezierLines.Remove(bz.Id);
         this.Children.Remove(bz.Bezier);
     }
 }
Exemplo n.º 16
0
    private void AddLine()
    {
        GameObject line = Instantiate(Resources.Load("Prefab/BZLine", typeof(GameObject)) as GameObject);

        line.transform.SetParent(GameObject.Find("uComponet/BZLine").transform);
        line.name  = name + "BZLine";
        BezierLine = line.GetComponent <BezierLine>();
    }
Exemplo n.º 17
0
    public void SetPreviousLine(BezierLine previousLine)
    {
        this.previousLine     = previousLine;
        previousLine.nextLine = this;

        start       = previousLine.end;
        startHandle = start - (previousLine.endHandle - start);
    }
Exemplo n.º 18
0
 void CalcBezier()
 {
     m_Self.m_BezierPoints.Clear();
     m_Self.m_BezierPoints = BezierLine.GetEqualSpaceBezier(m_Root.position,
                                                            m_Self.m_AnchorPos[BezierLine.FirstAnchor],
                                                            m_Self.m_AnchorPos[BezierLine.SecondAnchor],
                                                            m_Self.m_AnchorPos[BezierLine.ThirdAnchor], m_Self.m_PointNumber);
 }
Exemplo n.º 19
0
 void Start()
 {
     name         = Type.ToString();
     _attackLine  = GetComponentInChildren <BezierLine>();
     _propertie   = GetComponent <EnemyPropertie>();
     _animator    = GetComponent <Animator>();
     _attackRange = _propertie.GetAttackRange();
 }
    public void CloseLine()
    {
        BezierLine lastLine   = GetLastLine();
        BezierLine fillerLine = new BezierLine(lastLine.End, start.Start);

        fillerLine.SetPreviousLine(lastLine);
        start.SetPreviousLine(fillerLine);
        closed = true;
    }
Exemplo n.º 21
0
 public void Init()
 {
     FPCam             = GameObject.Find("BuilderCamera").GetComponent <Camera>();
     _rb               = GameObject.Find("BuilderPlayer(Clone)").GetComponent <RoadBuilder>();
     AttachedTransform = transform.parent;
     Bez               = BezierLine.Instance;
     Mrkr              = AttachedTransform.GetComponent <RoadMarker>();
     int XSecId = Bez.CtrlPts[Mrkr.Index].SegStartIdx;
     //transform.LookAt(Road.Instance.XSecs[XSecId+1].MidPt);
     //transform.Rotate(Vector3.forward, Bez.CtrlPts[Mrkr.Index].BankAngle);
 }
    public BezierLine GetLastLine()
    {
        BezierLine current = start;

        while (current.nextLine != null)
        {
            current = current.nextLine;
        }

        return(current);
    }
Exemplo n.º 23
0
    public static Vector2 Perpndclr(int Idx)
    //Returns the vector2 that is perpendiclr to the path
    {
        BezierLine Bez = BezierLine.Instance;
        Vector2    p0;
        Vector2    p1;
        Vector2    p2;

        if (Idx == Bez.Path.Count)
        {
            p1 = new Vector2(Bez.CtrlPts[Bez.CtrlPts.Count - 2].Pos.x, Bez.CtrlPts[Bez.CtrlPts.Count - 2].Pos.z);
        }
        else
        {
            p1 = new Vector2(Bez.Path[Idx].x, Bez.Path[Idx].z);
        }

        if (Idx > 0)
        {
            p0 = new Vector2(Bez.Path[Idx - 1].x, Bez.Path[Idx - 1].z);
        }
        else
        {
            p0 = p1;
        }
        if (Idx < Bez.Path.Count - 1)
        {
            p2 = new Vector2(Bez.Path[Idx + 1].x, Bez.Path[Idx + 1].z);
        }
        else
        {
            p2 = p1;
        }
        if (Road.Instance.IsCircular && Idx == Road.Instance.XSecs.Count)
        {
            p2 = new Vector2(Bez.Path[1].x, Bez.Path[1].z);
        }
        //p0.Normalize();
        //p1.Normalize();
        //p2.Normalize();

        Vector2 Dir1      = p1 - p0;
        Vector2 Dir2      = p2 - p1;
        Vector2 Tangent   = (Dir1 + Dir2) / 2;
        Vector2 Perpndclr = new Vector2(Tangent.y, -Tangent.x);

        Perpndclr.Normalize();
        return(Perpndclr);
    }
Exemplo n.º 24
0
    public void Encode(BezierLine Bez)
    {
        Path = new Vector3Serial[Bez.Path.Count];
        for (int Idx = 0; Idx < Bez.Path.Count; Idx++)
        {
            Vector3Serial PS = new Vector3Serial(Bez.Path[Idx]);
            Path.SetValue(PS, Idx);
        }

        CtrlPts = new BezCtrlPtSerial[Bez.CtrlPts.Count];
        for (int Idx = 0; Idx < Bez.CtrlPts.Count; Idx++)
        {
            BezCtrlPtSerial BCPS = new BezCtrlPtSerial();
            BCPS.Encode(Bez.CtrlPts[Idx]);
            CtrlPts.SetValue(BCPS, Idx);
        }
    }
Exemplo n.º 25
0
        public void TransformToBezier(LineFigure figure)
        {
            _canvas.Children.Remove(figure);
            var bezierLine = new BezierLine();

            figure.LeftLineConnector.RightFigure = bezierLine;
            figure.LeftLineConnector.UpdateLinks();
            figure.RightLineConnector.LeftFigure = bezierLine;
            figure.RightLineConnector.UpdateLinks();

            var bezCont1 = new BezierControl(bezierLine, false);
            var bezCont2 = new BezierControl(bezierLine, true);

            _canvas.Children.Add(bezierLine);
            _canvas.Children.Add(bezCont1);
            _canvas.Children.Add(bezCont2);
        }
Exemplo n.º 26
0
        /// <summary>
        /// 从文件读取的时候添加一个贝塞尔曲线
        /// </summary>
        /// <param name="bz">贝塞尔曲线对象</param>
        public bool ReadCreateBezierLine(BezierLine bz, int startID, int endID, int startfatherID, int endfatherID)
        {
            XAribute startPoint = GetXAributeByID(startID, startfatherID);
            XAribute endPoint   = GetXAributeByID(endID, endfatherID);

            if (startPoint != null && endPoint != null)
            {
                startPoint.AddBezierLine(bz);
                endPoint.AddBezierLine(bz);
                ///设置贝塞尔曲线信息
                bz.DirectSetBezierLineTwoPoint(startPoint, endPoint);
                ///将贝塞尔曲线添加入显示
                AddBezierLine(bz);
                return(true);
            }
            else
            {
                return(false);
            }
        }
    public void Init()
    {
        FPCam             = GameObject.Find("BuilderCamera").GetComponent <Camera>();
        _rb               = GameObject.Find("BuilderPlayer(Clone)").GetComponent <RoadBuilder>();
        AttachedTransform = transform.parent;
        Bez               = BezierLine.Instance;
        Mrkr              = AttachedTransform.GetComponent <RoadMarker>();
        XSecId            = Bez.CtrlPts[Mrkr.Index].SegStartIdx;

        if (name == "LeftTiltArrow")
        {
            _hand = "L";
            //OtherHandGizmo = Mrkr.GizmoTiltRight.transform;
        }
        else
        {
            _hand = "R";
            //OtherHandGizmo = Mrkr.GizmoTiltLeft.transform;
        }
        _otherHandStartPos = OtherHandGizmo.position;
    }
Exemplo n.º 28
0
 /// <summary>
 /// 贝塞尔曲线资源转换为文件
 /// </summary>
 /// <param name="writer">xml对象</param>
 /// <param name="line">贝塞尔曲线对象</param>
 public static void WriteBezierLine(XmlTextWriter writer, BezierLine line)
 {
     writer.WriteStartElement("BezierLine");
     writer.WriteAttributeString("ID", line.Id.ToString());
     writer.WriteAttributeString("StrokeThickness", line.StrokeThickness.ToString());
     ///起始点位置
     writer.WriteStartElement("StartPoint");
     writer.WriteElementString("PositionType", line.StartPoint.positionType.ToString());
     writer.WriteElementString("LinkAributeFatherID", line.StartPoint.LinkAribute.ParentControl.Id.ToString());
     writer.WriteElementString("LinkAributeID", line.StartPoint.LinkAribute.Id.ToString());
     ///结束起始点的属性
     writer.WriteEndElement();
     ///终止点的属性
     writer.WriteStartElement("EndPoint");
     writer.WriteElementString("PositionType", line.EndPoint.positionType.ToString());
     writer.WriteElementString("LinkAributeFatherID", line.EndPoint.LinkAribute.ParentControl.Id.ToString());
     writer.WriteElementString("LinkAributeID", line.EndPoint.LinkAribute.Id.ToString());
     writer.WriteEndElement();
     ///结束贝塞尔曲线的存储
     writer.WriteEndElement();
 }
Exemplo n.º 29
0
 /// <summary>
 /// 鼠标抬起的时候
 /// </summary>
 /// <param name="e"></param>
 protected override void OnMouseUp(MouseButtonEventArgs e)
 {
     base.OnMouseUp(e);
     ///释放鼠标焦点
     this.ReleaseMouseCapture();
     #region 取消框选
     MyPanel.IsToSelect = false;
     #endregion
     #region 对贝塞尔曲线的操作
     ///成功连接
     if (isDrawBezier && isOverAribute && SecondXa != null && SecondXa.IsCanLin(FirstXa))
     {
         #region 将属性和连线的关系赋值
         FirstXa.AddBezierLine(MyBezierLine);
         MyBezierLine.StartPoint.LinkAribute = FirstXa;
         SecondXa.AddBezierLine(MyBezierLine);
         MyBezierLine.EndPoint.LinkAribute = SecondXa;
         MyBezierLine.SetBezierLine(SecondXa.GetWorldPosition(), SecondXa.SelectPositionStyle);
         #endregion
     }
     ///失败连接
     else if (isDrawBezier)
     {
         ///删除失败的贝塞尔曲线
         DelBezierLine(MyBezierLine);
     }
     ///清空贝塞尔曲线对象,防止对此的再次操作
     if (MyBezierLine != null)
     {
         MyBezierLine = null;
         #region 初始化信息
         FirstXa       = null;
         SecondXa      = null;
         isOverAribute = false;
         isDrawBezier  = false;
         SecondXa      = null;
         #endregion
     }
     #endregion
 }
Exemplo n.º 30
0
    // Use this for initialization
    void Start()
    {
        _canvas    = GameObject.Find("BuilderGUICanvas(Clone)");
        BuilderCam = GameObject.Find("BuilderCamera").GetComponent <Camera>();
        Toolbox    = _canvas.GetComponent <ToolboxController>();
        Toolbox.ToolOptionChanged += ToolChange;
        Bez = BezierLine.Instance;
        Rd  = Road.Instance;
        if (Road.Instance.Segments.Count == 0 || Road.Instance.Segments[0].goSeg == null)    //Cos When they might already be built
        {
            if (Road.Instance.StartingLinePos != null)
            {
                PlaceStartingLine(Road.Instance.StartingLineSegIdx);
            }
        }
        Bez.CreateGameObject();
        Bez.DrawLine();
        if (GameData.current.MacId == SystemInfo.deviceUniqueIdentifier)
        {
            Bez.CreateRoadMarkers();
        }
        //Open the tutorial if building first track
        if (SaveLoadModel.savedGames.Count < 3)     //!!!!!change to 3
        {
            UnityEngine.Object objPnl1 = Resources.Load("Prefabs/pnlTutorialBuild1");
            GameObject         goVid   = (GameObject)(GameObject.Instantiate(objPnl1, _canvas.transform));
            goVid.transform.localScale = Vector3.one;
            goVid.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;
        }

        //Open the turorial panel so you can say how many cones left
        UnityEngine.Object objPnl = Resources.Load("Prefabs/pnlTutorialBuild2");
        GameObject         goTut  = (GameObject)(GameObject.Instantiate(objPnl, _canvas.transform));

        Tut = goTut.GetComponent <Tutorial>();
        Tut.transform.localScale = Vector3.one;
        Tut.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;
        Tut.gameObject.SetActive(false);
    }