Example #1
0
 private static void ChangeShaderOnMaterials(TreeData treeData, Shader shader, TreeGroup group, TreeEditorHelper.NodeType nodeType)
 {
     if (group is TreeGroupBranch && nodeType == TreeEditorHelper.NodeType.BarkNode)
     {
         TreeGroupBranch treeGroupBranch = group as TreeGroupBranch;
         TreeEditorHelper.ChangeShaderOnMaterial(treeGroupBranch.materialBranch, shader);
         TreeEditorHelper.ChangeShaderOnMaterial(treeGroupBranch.materialBreak, shader);
         TreeEditorHelper.ChangeShaderOnMaterial(treeGroupBranch.materialFrond, shader);
     }
     else
     {
         if (group is TreeGroupLeaf && nodeType == TreeEditorHelper.NodeType.LeafNode)
         {
             TreeGroupLeaf treeGroupLeaf = group as TreeGroupLeaf;
             TreeEditorHelper.ChangeShaderOnMaterial(treeGroupLeaf.materialLeaf, shader);
         }
     }
     int[] childGroupIDs = group.childGroupIDs;
     for (int i = 0; i < childGroupIDs.Length; i++)
     {
         int       id     = childGroupIDs[i];
         TreeGroup group2 = treeData.GetGroup(id);
         TreeEditorHelper.ChangeShaderOnMaterials(treeData, shader, group2, nodeType);
     }
 }
Example #2
0
        public bool GUIWrongShader(string uniqueID, Material value, TreeEditorHelper.NodeType nodeType)
        {
            GUIContent gUIContent  = TreeEditorHelper.GetGUIContent("TreeEditor.TreeGroup.NotATreeShader");
            GUIContent gUIContent2 = TreeEditorHelper.GetGUIContent("TreeEditor.TreeGroup.ChangeShaderButton");

            if (TreeEditorHelper.IsMaterialCorrect(value))
            {
                return(false);
            }
            List <string> recommendedShaders = this.GetRecommendedShaders(nodeType);

            this.m_WrongShaders.Add(uniqueID);
            this.SetAnimBool(uniqueID, true, true);
            int num = this.GUIShowError(uniqueID, recommendedShaders, gUIContent, gUIContent2, ConsoleWindow.iconError);

            if (num >= 0)
            {
                value.shader = Shader.Find(recommendedShaders[num]);
                this.m_WrongShaders.Remove(uniqueID);
                this.DisableAnimBool(uniqueID);
                this.RemoveSelectedIndex(uniqueID);
                return(true);
            }
            return(false);
        }
Example #3
0
 private static void GetAllTreeShaders(TreeData treeData, List <string> barkShaders, List <string> leafShaders, TreeGroup group)
 {
     if (group is TreeGroupBranch)
     {
         TreeGroupBranch treeGroupBranch = group as TreeGroupBranch;
         TreeEditorHelper.AddShaderFromMaterial(treeGroupBranch.materialBranch, barkShaders, leafShaders);
         TreeEditorHelper.AddShaderFromMaterial(treeGroupBranch.materialBreak, barkShaders, leafShaders);
         TreeEditorHelper.AddShaderFromMaterial(treeGroupBranch.materialFrond, barkShaders, leafShaders);
     }
     else
     {
         if (group is TreeGroupLeaf)
         {
             TreeGroupLeaf treeGroupLeaf = group as TreeGroupLeaf;
             TreeEditorHelper.AddShaderFromMaterial(treeGroupLeaf.materialLeaf, barkShaders, leafShaders);
         }
     }
     int[] childGroupIDs = group.childGroupIDs;
     for (int i = 0; i < childGroupIDs.Length; i++)
     {
         int       id     = childGroupIDs[i];
         TreeGroup group2 = treeData.GetGroup(id);
         TreeEditorHelper.GetAllTreeShaders(treeData, barkShaders, leafShaders, group2);
     }
 }
Example #4
0
        public static GUIContent GetGUIContent(string id)
        {
            if (TreeEditorHelper.s_Dictionary.ContainsKey(id))
            {
                return(TreeEditorHelper.s_Dictionary[id]);
            }
            string uIString = TreeEditorHelper.GetUIString(id);

            if (uIString == null)
            {
                return(new GUIContent(id, string.Empty));
            }
            GUIContent gUIContent = new GUIContent(TreeEditorHelper.ExtractLabel(uIString), TreeEditorHelper.ExtractTooltip(uIString));

            TreeEditorHelper.s_Dictionary.Add(id, gUIContent);
            return(gUIContent);
        }
Example #5
0
 private static void AddShaderFromMaterial(Material material, List <string> barkShaders, List <string> leafShaders)
 {
     if (material && material.shader)
     {
         Shader shader = material.shader;
         if (TreeEditorHelper.IsTreeBarkShader(shader) && !barkShaders.Contains(shader.name))
         {
             barkShaders.Add(shader.name);
         }
         else
         {
             if (TreeEditorHelper.IsTreeLeafShader(material.shader) && !leafShaders.Contains(shader.name))
             {
                 leafShaders.Add(shader.name);
             }
         }
     }
 }
Example #6
0
        private List <string> GetRecommendedShaders(TreeEditorHelper.NodeType nodeType)
        {
            List <string> list = new List <string>(3);
            List <string> shadersListForNodeType        = this.GetShadersListForNodeType(nodeType);
            List <string> shadersListOppositeToNodeType = this.GetShadersListOppositeToNodeType(nodeType);

            if (shadersListForNodeType.Count == 1 || (shadersListForNodeType.Count == 2 && shadersListOppositeToNodeType.Count == 0))
            {
                foreach (string current in shadersListForNodeType)
                {
                    list.Add(current);
                }
            }
            if (shadersListForNodeType.Count == 0)
            {
                list.Add(TreeEditorHelper.GetDefaultShader(nodeType));
            }
            return(list);
        }
Example #7
0
        private static void ExtractOptimizedShaders(List <TreeMaterial> materials, out Shader optimizedSolidShader, out Shader optimizedCutoutShader)
        {
            List <Shader> list  = new List <Shader>();
            List <Shader> list2 = new List <Shader>();

            foreach (TreeMaterial current in materials)
            {
                Material material = current.material;
                if (material && material.shader)
                {
                    if (TreeEditorHelper.IsTreeBarkShader(material.shader))
                    {
                        list.Add(material.shader);
                    }
                    else
                    {
                        if (TreeEditorHelper.IsTreeLeafShader(material.shader))
                        {
                            list2.Add(material.shader);
                        }
                    }
                }
            }
            optimizedSolidShader  = null;
            optimizedCutoutShader = null;
            if (list.Count > 0)
            {
                optimizedSolidShader = Shader.Find(TreeEditorHelper.GetOptimizedShaderName(list[0]));
            }
            if (list2.Count > 0)
            {
                optimizedCutoutShader = Shader.Find(TreeEditorHelper.GetOptimizedShaderName(list2[0]));
            }
            if (!optimizedSolidShader)
            {
                optimizedSolidShader = TreeEditorHelper.DefaultOptimizedBarkShader;
            }
            if (!optimizedCutoutShader)
            {
                optimizedCutoutShader = TreeEditorHelper.DefaultOptimizedLeafShader;
            }
        }
Example #8
0
        public bool NodeHasWrongMaterial(TreeGroup group)
        {
            bool flag = false;

            if (group is TreeGroupBranch)
            {
                TreeGroupBranch treeGroupBranch = group as TreeGroupBranch;
                flag |= !TreeEditorHelper.IsMaterialCorrect(treeGroupBranch.materialBranch);
                flag |= !TreeEditorHelper.IsMaterialCorrect(treeGroupBranch.materialBreak);
                flag |= !TreeEditorHelper.IsMaterialCorrect(treeGroupBranch.materialFrond);
            }
            else
            {
                if (group is TreeGroupLeaf)
                {
                    TreeGroupLeaf treeGroupLeaf = group as TreeGroupLeaf;
                    flag |= !TreeEditorHelper.IsMaterialCorrect(treeGroupLeaf.materialLeaf);
                }
            }
            return(flag);
        }
Example #9
0
        private bool GUITooManyShaders(TreeEditorHelper.NodeType nodeType)
        {
            string text = nodeType.ToString();

            if (this.CheckForTooManyShaders(nodeType))
            {
                this.SetAnimBool(text, true, true);
            }
            List <string> shadersListForNodeType = this.GetShadersListForNodeType(nodeType);
            GUIContent    gUIContent             = TreeEditorHelper.GetGUIContent((nodeType != TreeEditorHelper.NodeType.BarkNode) ? "TreeEditor.TreeGroup.TooManyLeafShaders" : "TreeEditor.TreeGroup.TooManyBarkShaders");
            GUIContent    gUIContent2            = TreeEditorHelper.GetGUIContent("TreeEditor.TreeGroup.ChangeAllShadersOnNodesButton");
            int           num = this.GUIShowError(text, shadersListForNodeType, gUIContent, gUIContent2, ConsoleWindow.iconError);

            if (num >= 0)
            {
                Shader shader = Shader.Find(shadersListForNodeType[num]);
                TreeEditorHelper.ChangeShaderOnMaterials(this.m_TreeData, shader, this.m_TreeData.root, nodeType);
                this.DisableAnimBool(text);
                this.RemoveSelectedIndex(text);
                return(true);
            }
            return(false);
        }
Example #10
0
 public static bool IsTreeBarkShader(Shader shader)
 {
     return(TreeEditorHelper.HasOptimizedShaderAndNameContains(shader, "bark"));
 }
Example #11
0
 public static bool IsTreeLeafShader(Shader shader)
 {
     return(TreeEditorHelper.HasOptimizedShaderAndNameContains(shader, "leaves"));
 }
Example #12
0
 private static bool IsTreeShader(Shader shader)
 {
     return(TreeEditorHelper.IsTreeBarkShader(shader) || TreeEditorHelper.IsTreeLeafShader(shader));
 }
		private List<string> GetShadersListForNodeType(TreeEditorHelper.NodeType nodeType)
		{
			if (nodeType == TreeEditorHelper.NodeType.BarkNode)
			{
				return this.m_BarkShaders;
			}
			return this.m_LeafShaders;
		}
		private List<string> GetShadersListOppositeToNodeType(TreeEditorHelper.NodeType nodeType)
		{
			if (nodeType == TreeEditorHelper.NodeType.BarkNode)
			{
				return this.GetShadersListForNodeType(TreeEditorHelper.NodeType.LeafNode);
			}
			return this.GetShadersListForNodeType(TreeEditorHelper.NodeType.BarkNode);
		}
		private static string GetDefaultShader(TreeEditorHelper.NodeType nodeType)
		{
			if (nodeType == TreeEditorHelper.NodeType.BarkNode)
			{
				return "Nature/Tree Creator Bark";
			}
			return "Nature/Tree Creator Leaves Fast";
		}
Example #16
0
 private static bool HasOptimizedShaderAndNameContains(Shader shader, string name)
 {
     return(TreeEditorHelper.GetOptimizedShaderName(shader) != null && shader.name.ToLower().Contains(name));
 }
		private List<string> GetRecommendedShaders(TreeEditorHelper.NodeType nodeType)
		{
			List<string> list = new List<string>(3);
			List<string> shadersListForNodeType = this.GetShadersListForNodeType(nodeType);
			List<string> shadersListOppositeToNodeType = this.GetShadersListOppositeToNodeType(nodeType);
			if (shadersListForNodeType.Count == 1 || (shadersListForNodeType.Count == 2 && shadersListOppositeToNodeType.Count == 0))
			{
				foreach (string current in shadersListForNodeType)
				{
					list.Add(current);
				}
			}
			if (shadersListForNodeType.Count == 0)
			{
				list.Add(TreeEditorHelper.GetDefaultShader(nodeType));
			}
			return list;
		}
Example #18
0
 private static bool IsMaterialCorrect(Material material)
 {
     return(!material || TreeEditorHelper.IsTreeShader(material.shader));
 }
		public bool GUIWrongShader(string uniqueID, Material value, TreeEditorHelper.NodeType nodeType)
		{
			GUIContent gUIContent = TreeEditorHelper.GetGUIContent("TreeEditor.TreeGroup.NotATreeShader");
			GUIContent gUIContent2 = TreeEditorHelper.GetGUIContent("TreeEditor.TreeGroup.ChangeShaderButton");
			if (TreeEditorHelper.IsMaterialCorrect(value))
			{
				return false;
			}
			List<string> recommendedShaders = this.GetRecommendedShaders(nodeType);
			this.m_WrongShaders.Add(uniqueID);
			this.SetAnimBool(uniqueID, true, true);
			int num = this.GUIShowError(uniqueID, recommendedShaders, gUIContent, gUIContent2, ConsoleWindow.iconError);
			if (num >= 0)
			{
				value.shader = Shader.Find(recommendedShaders[num]);
				this.m_WrongShaders.Remove(uniqueID);
				this.DisableAnimBool(uniqueID);
				this.RemoveSelectedIndex(uniqueID);
				return true;
			}
			return false;
		}
		private bool CheckForTooManyShaders(TreeEditorHelper.NodeType nodeType)
		{
			List<string> shadersListForNodeType = this.GetShadersListForNodeType(nodeType);
			List<string> shadersListOppositeToNodeType = this.GetShadersListOppositeToNodeType(nodeType);
			return shadersListForNodeType.Count > 2 || (shadersListForNodeType.Count == 2 && shadersListOppositeToNodeType.Count > 0);
		}
Example #21
0
 public void RefreshAllTreeShaders()
 {
     this.m_BarkShaders.Clear();
     this.m_LeafShaders.Clear();
     TreeEditorHelper.GetAllTreeShaders(this.m_TreeData, this.m_BarkShaders, this.m_LeafShaders, this.m_TreeData.root);
 }
		private static void ChangeShaderOnMaterials(TreeData treeData, Shader shader, TreeGroup group, TreeEditorHelper.NodeType nodeType)
		{
			if (group is TreeGroupBranch && nodeType == TreeEditorHelper.NodeType.BarkNode)
			{
				TreeGroupBranch treeGroupBranch = group as TreeGroupBranch;
				TreeEditorHelper.ChangeShaderOnMaterial(treeGroupBranch.materialBranch, shader);
				TreeEditorHelper.ChangeShaderOnMaterial(treeGroupBranch.materialBreak, shader);
				TreeEditorHelper.ChangeShaderOnMaterial(treeGroupBranch.materialFrond, shader);
			}
			else
			{
				if (group is TreeGroupLeaf && nodeType == TreeEditorHelper.NodeType.LeafNode)
				{
					TreeGroupLeaf treeGroupLeaf = group as TreeGroupLeaf;
					TreeEditorHelper.ChangeShaderOnMaterial(treeGroupLeaf.materialLeaf, shader);
				}
			}
			int[] childGroupIDs = group.childGroupIDs;
			for (int i = 0; i < childGroupIDs.Length; i++)
			{
				int id = childGroupIDs[i];
				TreeGroup group2 = treeData.GetGroup(id);
				TreeEditorHelper.ChangeShaderOnMaterials(treeData, shader, group2, nodeType);
			}
		}
Example #23
0
 private Material GUIMaterialField(PropertyType prop, int uniqueNodeID, string contentID, Material value, TreeEditorHelper.NodeType nodeType)
 {
     string uniqueID = uniqueNodeID + "_" + contentID;
     this.GUIPropBegin();
     Material material = EditorGUILayout.ObjectField(TreeEditorHelper.GetGUIContent(contentID), value, typeof(Material), false, new GUILayoutOption[0]) as Material;
     this.GUIPropEnd();
     bool flag = this.m_TreeEditorHelper.GUIWrongShader(uniqueID, material, nodeType);
     if ((material != value) || flag)
     {
         this.GUIHandlePropertyChange(prop);
         this.m_WantCompleteUpdate = true;
     }
     return material;
 }
		private bool GUITooManyShaders(TreeEditorHelper.NodeType nodeType)
		{
			string text = nodeType.ToString();
			if (this.CheckForTooManyShaders(nodeType))
			{
				this.SetAnimBool(text, true, true);
			}
			List<string> shadersListForNodeType = this.GetShadersListForNodeType(nodeType);
			GUIContent gUIContent = TreeEditorHelper.GetGUIContent((nodeType != TreeEditorHelper.NodeType.BarkNode) ? "TreeEditor.TreeGroup.TooManyLeafShaders" : "TreeEditor.TreeGroup.TooManyBarkShaders");
			GUIContent gUIContent2 = TreeEditorHelper.GetGUIContent("TreeEditor.TreeGroup.ChangeAllShadersOnNodesButton");
			int num = this.GUIShowError(text, shadersListForNodeType, gUIContent, gUIContent2, ConsoleWindow.iconError);
			if (num >= 0)
			{
				Shader shader = Shader.Find(shadersListForNodeType[num]);
				TreeEditorHelper.ChangeShaderOnMaterials(this.m_TreeData, shader, this.m_TreeData.root, nodeType);
				this.DisableAnimBool(text);
				this.RemoveSelectedIndex(text);
				return true;
			}
			return false;
		}