Exemplo n.º 1
0
        virtual public void OnDrawGizmos(Color m_StartCol, Color m_EndCol)
        {
#if UNITY_EDITOR
            var tmp = Gizmos.color;

            Gizmos.color = m_StartCol;
            var prev = m_Points[0];
            UCL_DrawGizmos.DrawConstSizeSphere(prev, 1.5f);
            for (int i = 1; i < m_Points.Count; i++)
            {
                var cur = m_Points[i];
                //Gizmos.color = Color.Lerp(m_StartCol, m_EndCol, (i / (float)m_Points.Count));
                UCL_DrawGizmos.DrawLine(prev, cur);
                prev = cur;
            }
            Gizmos.color = m_EndCol;
            if (m_Points.Count > 1)
            {
                UCL_DrawGizmos.DrawConstSizeSphere(prev, 1.5f);
            }

            //m_Rnd.OnRect(width, height);

            Gizmos.color = tmp;
#endif
        }
Exemplo n.º 2
0
        private void OnDrawGizmos()
        {
#if UNITY_EDITOR
            var tmp = Gizmos.color;
            if (m_PathPoints == null)
            {
                m_PathPoints = new List <Vector3>();
            }
            if (m_PathPoints.Count == 0)
            {
                UpdatePath();
            }
            UCL_DrawGizmos.DrawConstSizeSphere(m_PathPoints[0], 1.5f);
            //m_Rnd.OnRect(width, height);

            Gizmos.color = tmp;
#endif
        }
Exemplo n.º 3
0
        private void OnDrawGizmos()
        {
            var prev_col = Gizmos.color;

            Gizmos.color = Color.green;
            Vector3 s    = m_S.position;
            Vector3 e    = m_E.position;
            Vector3 prev = Vector3.Lerp(s, e, m_Datas[0]);

            UCL_DrawGizmos.DrawConstSizeSphere(prev, 1f);
            for (int i = 1; i < m_Datas.Count; i++)
            {
                Vector3 cur = Vector3.Lerp(s, e, m_Datas[i]);
                Gizmos.DrawLine(prev, cur);
                UCL_DrawGizmos.DrawConstSizeSphere(cur, 1f);
                prev = cur;
            }
            //m_Datas.FirstElement
            Gizmos.color = Color.red;
            float seg = 1f / (m_Datas.Count - 1);
            float x   = 0;
            float y   = 0;

            for (int i = 0; i < m_Datas.Count; i++)
            {
                y = seg * i;
                x = MathLib.LinearMapping.GetX(m_Datas, y);
                Vector3 cur = Vector3.Lerp(s, e, CurveFunc(x));
                //Gizmos.DrawLine(prev, cur);
                UCL_DrawGizmos.DrawConstSizeSphere(cur, 1f);
                prev = cur;
            }

            /*
             * Gizmos.color = Color.red;
             * float seg = 1.0f / (m_Datas.Count - 1);
             * for(int i = 0; i < m_Datas.Count; i++) {
             *  Vector3 cur = Vector3.Lerp(s, e, MathLib.LinearMapping.get);
             *  UCL_DrawGizmos.DrawConstSizeSphere(cur, 1f);
             *  prev = cur;
             * }
             */
            Gizmos.color = prev_col;
        }
Exemplo n.º 4
0
#pragma warning restore 0414
        virtual protected void DrawGizmos()
        {
#if UNITY_EDITOR
            var tmp = Gizmos.color;
            {
                Vector3 prev = GetPos(0);
                Gizmos.color = m_PathCol;
                int m_SmoothAmount = 100;
                for (int i = 1; i <= m_SmoothAmount; i++)
                {
                    float   pm     = (float)i / m_SmoothAmount;
                    Vector3 currPt = GetPos(pm);
                    Gizmos.DrawLine(currPt, prev);
                    prev = currPt;
                }
            }

            if (m_DisPointCount > 0)
            {
                float seg = 1.0f / m_DisPointCount;
                for (int i = 0; i < m_DisPointCount; i++)
                {
                    var a = GetPos(i * seg);
                    //var a = m_GetPoint ? GetPoint(i * seg) : GetPos(i * seg);
                    UCL_DrawGizmos.DrawConstSizeSphere(a, 0.5f * m_PointSize);
                }

                /*
                 * for(int i = 0; i < m_WorldSpacePoints.Length - 1; i++) {
                 *  Gizmos.DrawLine(m_WorldSpacePoints[i], m_WorldSpacePoints[i + 1]);
                 * }
                 */
            }
            else
            {
                Gizmos.color = m_DemoPointColor;
                UCL_DrawGizmos.DrawConstSizeSphere(GetPos(m_DemoPoint), 0.75f * m_PointSize);
            }

            Gizmos.color = tmp;
#endif
        }
Exemplo n.º 5
0
#pragma warning restore 0414
        //[SerializeField] bool m_GetPoint = false;
        //#endif
        protected void DrawGizmos()
        {
#if UNITY_EDITOR
            if (m_PathPoints == null || m_PathPoints.Length < 4)
            {
                return;
            }
            if (m_GenStartPos != transform.position ||
                m_GenStartRot != transform.rotation ||
                m_GenStartScale != transform.lossyScale)
            {
                UpdatePathPoint();
            }
            var tmp = Gizmos.color;
            {
                Vector3 prev = GetPoint(m_PathPoints, 0);
                Gizmos.color = m_PathCol;
                int SmoothAmount = m_WorldSpacePoints.Length * m_SmoothSeg;
                for (int i = 1; i <= SmoothAmount; i++)
                {
                    float   pm     = (float)i / SmoothAmount;
                    Vector3 currPt = GetPoint(pm);
                    Gizmos.DrawLine(currPt, prev);
                    prev = currPt;
                }
            }

            if (m_DisPointCount > 0)
            {
                float seg = 1.0f / m_DisPointCount;
                for (int i = 0; i < m_DisPointCount; i++)
                {
                    var a = GetPos(i * seg);
                    //var a = m_GetPoint ? GetPoint(i * seg) : GetPos(i * seg);
                    UCL_DrawGizmos.DrawConstSizeSphere(a, 0.5f * m_PointSize);

                    /*
                     * var b = GetPosLinear(i * seg);
                     * UCL_DrawGizmos.DrawConstSizeSphere(b, 0.5f * m_PointSize);
                     * Gizmos.DrawLine(a, b);
                     */
                }

                /*
                 * for(int i = 0; i < m_WorldSpacePoints.Length - 1; i++) {
                 *  Gizmos.DrawLine(m_WorldSpacePoints[i], m_WorldSpacePoints[i + 1]);
                 * }
                 */
            }
            else
            {
                Gizmos.color = m_DemoPointColor;
                UCL_DrawGizmos.DrawConstSizeSphere(GetPos(m_DemoPoint), 0.75f * m_PointSize);
            }
            Gizmos.color = m_PointCol;
            //UnityEditor.Handles.color = m_PointCol;


            for (int i = 0; i < m_WorldSpacePoints.Length; i++)
            {
                UCL_DrawGizmos.DrawConstSizeSphere(m_WorldSpacePoints[i], m_PointSize);
                //Gizmos.DrawSphere(m_WorldSpacePoints[i], 1f * GetGizmoSize(m_WorldSpacePoints[i]));
                //UnityEditor.Handles.dra(m_WorldSpacePoints[i], Vector3.one);
            }

            Gizmos.color = tmp;
#endif
        }
Exemplo n.º 6
0
        /*
         * GUIStyle m_Style = new GUIStyle();
         * GUIStyle m_OutlineStyle = new GUIStyle();
         * void OnEnable() {
         *  m_OutlineStyle.fontStyle = m_Style.fontStyle = FontStyle.Bold;
         *
         *  m_Style.normal.textColor = Color.black;
         *  m_OutlineStyle.normal.textColor = Color.white;
         *  m_Style.fontSize = 28;
         *  m_OutlineStyle.fontSize = 29;
         *  //style.border.top = style.border.bottom = style.border.left = style.border.right = 2;
         *
         * }
         */
        void OnSceneGUI()
        {
            m_Path = target as UCL_Curve;
            int new_node_at    = -1;
            int delete_node_at = -1;

            if (m_Path.enabled && m_Path.gameObject.activeInHierarchy)
            {
                if (m_Path.m_Points != null && m_Path.m_Points.Count > 0)
                {
                    //allow path adjustment undo
                    Undo.RecordObject(m_Path, "Alter Path");
                    //node handle display:
                    Color   but_col    = new Color(1, 1, 1, 0.8f);
                    Vector2 but_offset = new Vector2(0, 30);
                    int     draw_count = m_Path.m_Points.Count;
                    //if(path.m_Loop) --draw_count;
                    for (int i = 0; i < draw_count; i++)
                    {
                        var p = m_Path.m_Points[i];

                        if (!m_Path.m_Loop || i < draw_count - 1)
                        {
                            Vector3 pos     = m_Path.transform.TransformPoint(p);
                            var     new_pos = m_Path.transform.InverseTransformPoint(Handles.PositionHandle(pos, Quaternion.identity));
                            if ((new_pos - p).magnitude > 0.001f)
                            {
                                //Debug.LogWarning("(new_pos - p).magnitude:" + (new_pos - p).magnitude);
                                m_Path.SetPoint(i, new_pos);
                            }

                            string str = "node " + i;
                            UCL_DrawGizmos.DrawStringGUI(str, pos, 28, Color.black, Color.white);
                            if (UCL_DrawGizmos.DrawButtonGUI("delete", pos, 28, new Vector2(50, 22), Color.red, but_col, but_offset))
                            {
                                delete_node_at = i;
                            }
                        }


                        if (i > 0 && m_Path.m_Points.Count >= 2)
                        {
                            var     at    = ((float)(i - 0.5f) / (m_Path.m_Points.Count - 1));
                            Vector3 m_pos = m_Path.GetPoint(at);//0.5f*(prev_pos + pos);

                            if (UCL_DrawGizmos.DrawButtonGUI("Insert node", m_pos, 28, new Vector2(80, 22), Color.black, but_col))
                            {
                                new_node_at = i;
                                //Debug.LogWarning("Pressed:" + str);
                            }
                        }
                        //Handles.Label(pos, str, outline_style);// - Vector3.one
                        //Handles.Label(pos, str, style);

                        /*
                         * if(Handles.Button(pos, Quaternion.LookRotation(Camera.current.transform.forward, Camera.current.transform.up),
                         *  20.0f, 20.0f, Handles.RectangleHandleCap)) {
                         *  Debug.LogWarning("Add Button:" + i);
                         * }
                         */
                    }
                }
            }
            if (new_node_at >= 0)
            {
                m_Path.InsertPoint(new_node_at);
            }
            if (delete_node_at >= 0)
            {
                m_Path.RemoveAt(delete_node_at);
            }
        }