Exemplo n.º 1
0
 public void Interesect(IPaintingTool tool, bool erase)
 {
     if (m_Root != null)
     {
         m_Root.Interesect(tool, erase, Vector2.zero, Vector2.right, Vector2.up, vertex0, vertex1, vertex2, 0, m_MaxDepth);
     }
 }
Exemplo n.º 2
0
 public void Erase(IPaintingTool tool)
 {
     if (m_Tree != null)
     {
         m_Tree.Interesect(tool, true);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// 相交测试
 /// </summary>
 /// <param name="tool">绘画工具</param>
 /// <param name="erase">是否擦除</param>
 public void Interesect(IPaintingTool tool, bool erase = false)
 {
     if (m_Root != null)
     {
         m_Root.Interesect(tool, erase);
     }
 }
Exemplo n.º 4
0
 public void Draw(IPaintingTool tool)
 {
     if (m_Tree != null)
     {
         m_Tree.Interesect(tool);
     }
 }
Exemplo n.º 5
0
 private void ApplyPaint(IPaintingTool tool)
 {
     if (tool != null)
     {
         m_IsPainterChanged = true;
         if (m_ToolType == ToolType.Paint)
         {
             m_Target.Draw(tool);
         }
         else if (m_ToolType == ToolType.Erase)
         {
             m_Target.Erase(tool);
         }
     }
 }
Exemplo n.º 6
0
    private void DrawPaintingToolSceneGUI()
    {
        IPaintingTool tool = m_Target.GetPaintingTool();

        if (tool == null)
        {
            return;
        }
        HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));


        if (m_Target.data != null && m_Target.renderMeshs != null && m_Target.renderMeshs.Length > 0)
        {
            var tooleditor = GetPaintingToolEditor(tool);
            tooleditor.DrawSceneGUI(m_Target);
        }
    }
Exemplo n.º 7
0
        public void Interesect(IPaintingTool tool, bool erase)
        {
            for (int i = 0; i < m_ChildNodes.Length; i++)
            {
                if (m_ChildNodes[i] != null)
                {
                    m_ChildNodes[i].Interesect(tool, erase);
                }
            }

            if (tool.IntersectsBounds(this.bounds))
            {
                for (int i = 0; i < m_ItemList.Count; i++)
                {
                    if (tool.IntersectsBounds(m_ItemList[i].bounds))
                    {
                        m_ItemList[i].Interesect(tool, erase);
                    }
                }
            }
        }
Exemplo n.º 8
0
    private NavMeshToolEditor GetPaintingToolEditor(IPaintingTool tool)
    {
        System.Type       tooltype = tool.GetType();
        NavMeshToolEditor editor   = null;

        if (m_ToolEditors == null)
        {
            m_ToolEditors = new Dictionary <System.Type, NavMeshToolEditor>();
            System.Reflection.Assembly assembly = this.GetType().Assembly;
            var types = assembly.GetTypes();
            foreach (var type in types)
            {
                if (type.IsSubclassOf(typeof(NavMeshToolEditor)))
                {
                    var attributes = type.GetCustomAttributes(typeof(CustomNavMeshToolEditorAttribute), false);
                    foreach (var att in attributes)
                    {
                        CustomNavMeshToolEditorAttribute a = att as CustomNavMeshToolEditorAttribute;
                        if (a == null)
                        {
                            continue;
                        }
                        if (!m_ToolEditors.ContainsKey(a.navMeshToolType))
                        {
                            m_ToolEditors[a.navMeshToolType] = (NavMeshToolEditor)System.Activator.CreateInstance(type);
                            m_ToolEditors[a.navMeshToolType].SetApplyAction(new System.Action <IPaintingTool>(ApplyPaint));
                        }
                    }
                }
            }
        }
        if (m_ToolEditors.ContainsKey(tooltype))
        {
            editor = m_ToolEditors[tooltype];
            editor.SetTool(tool);
        }
        return(editor);
    }
        public void Interesect(IPaintingTool tool, bool erase, Vector2 weight0, Vector2 weight1, Vector2 weight2, Vector3 v0, Vector3 v1, Vector3 v2, int depth, int maxDepth)
        {
            Vector3 vertex0 = (1 - weight0.x - weight0.y) * v0 + weight0.x * v1 + weight0.y * v2;
            Vector3 vertex1 = (1 - weight1.x - weight1.y) * v0 + weight1.x * v1 + weight1.y * v2;
            Vector3 vertex2 = (1 - weight2.x - weight2.y) * v0 + weight2.x * v1 + weight2.y * v2;

            if (tool.IntersectsTriangle(vertex0, vertex1, vertex2))
            {
                bool continuePaint = m_PaintedType == PaintedType.Mix;
                if (m_PaintedType == PaintedType.Painted && erase)
                {
                    continuePaint = true;
                }
                if (m_PaintedType == PaintedType.None && !erase)
                {
                    continuePaint = true;
                }
                if (!continuePaint)
                {
                    return;
                }

                if (depth <= maxDepth)
                {
                    if (m_CenterNode == null)
                    {
                        m_CenterNode = new NavMeshTriangleNode(m_PaintedType);
                    }
                    if (m_TopNode == null)
                    {
                        m_TopNode = new NavMeshTriangleNode(m_PaintedType);
                    }
                    if (m_LeftNode == null)
                    {
                        m_LeftNode = new NavMeshTriangleNode(m_PaintedType);
                    }
                    if (m_RightNode == null)
                    {
                        m_RightNode = new NavMeshTriangleNode(m_PaintedType);
                    }
                }

                Vector2 halfw01 = weight0 + (weight1 - weight0) * 0.5f;
                Vector2 halfw02 = weight0 + (weight2 - weight0) * 0.5f;
                Vector2 halfw12 = weight1 + (weight2 - weight1) * 0.5f;

                if (m_CenterNode != null)
                {
                    m_CenterNode.Interesect(tool, erase, halfw01, halfw12, halfw02, v0, v1, v2, depth + 1, maxDepth);
                }

                if (m_TopNode != null)
                {
                    m_TopNode.Interesect(tool, erase, halfw01, weight1, halfw12, v0, v1, v2, depth + 1, maxDepth);
                }

                if (m_LeftNode != null)
                {
                    m_LeftNode.Interesect(tool, erase, weight0, halfw01, halfw02, v0, v1, v2, depth + 1, maxDepth);
                }

                if (m_RightNode != null)
                {
                    m_RightNode.Interesect(tool, erase, halfw02, halfw12, weight2, v0, v1, v2, depth + 1, maxDepth);
                }

                ResetPaintMark(!erase);
            }
        }
Exemplo n.º 10
0
 public void SetTool(IPaintingTool tool)
 {
     target = tool;
 }