Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
MaterialBaseVisitor.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Linq;
5 
6 namespace SiliconStudio.Paradox.Assets.Materials.Processor.Visitors
7 {
8  public class MaterialBaseVisitor
9  {
10  /// <summary>
11  /// The material to process.
12  /// </summary>
13  protected MaterialDescription Material { get; private set; }
14 
16  {
17  if (mat == null)
18  throw new ArgumentNullException();
19  Material = mat;
20  }
21  }
22 
23  public static class MaterialExtensions
24  {
25  public static void VisitNodes(this MaterialDescription material, Action<object, MaterialNodeEntry> callback, object context = null)
26  {
27  if (callback == null) throw new ArgumentNullException("callback");
28  var nodes = material.Nodes.ToList();
29  foreach (var nodeIt in nodes)
30  {
31  var key = nodeIt.Key;
32  VisitNode(new MaterialNodeEntry(nodeIt.Value, node => material.Nodes[key] = node), callback, context);
33  }
34  }
35 
36  public static void VisitNodes(this IMaterialNode node, Action<object, MaterialNodeEntry> callback, object context = null)
37  {
38  if (callback == null) throw new ArgumentNullException("callback");
39  VisitNode(new MaterialNodeEntry(node, DoNothing), callback, context);
40  }
41 
42  public static void VisitNode(this MaterialNodeEntry nodeEntry, Action<object, MaterialNodeEntry> callback, object context = null)
43  {
44  if (callback == null) throw new ArgumentNullException("callback");
45  callback(context, nodeEntry);
46  if (nodeEntry.Node != null)
47  {
48  foreach (var entry in nodeEntry.Node.GetChildren(context))
49  {
50  VisitNode(entry, callback, context);
51  }
52  }
53  }
54 
55  private static void DoNothing(IMaterialNode node)
56  {
57  }
58  }
59 }
IEnumerable< MaterialNodeEntry > GetChildren(object context=null)
Gets the children.
An entry to a nested IMaterialNode
static void VisitNodes(this MaterialDescription material, Action< object, MaterialNodeEntry > callback, object context=null)
static void VisitNodes(this IMaterialNode node, Action< object, MaterialNodeEntry > callback, object context=null)
Base interface for all nodes in the material tree
IMaterialNode Node
Gets or sets the node.
static void VisitNode(this MaterialNodeEntry nodeEntry, Action< object, MaterialNodeEntry > callback, object context=null)