//
        // Updates the seed
        //
        public void UpdateSeed()
        {
            // Fetch root seed
            TreeGroup gg = this;

            while (gg.parentGroup != null)
            {
                gg = gg.parentGroup;
            }
            int rootSeed = gg.seed;


            _internalSeed = rootSeed + (int)(seed * 1.21f);

            // update kids
            for (int i = 0; i < nodes.Count; i++)
            {
                // magic formula!
                nodes[i].seed = rootSeed + _internalSeed + (int)(i * 3.7482f);
            }

            // update sub-groups
            for (int i = 0; i < childGroups.Count; i++)
            {
                childGroups[i].UpdateSeed();
            }
        }
Esempio n. 2
0
 public TreeGroup()
 {
     Keyframe[] keys = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) };
     this.distributionCurve = new AnimationCurve(keys);
     this.distributionNodes = 5;
     this.distributionTwirl = 0f;
     this.distributionPitch = 0f;
     Keyframe[] keyframeArray2 = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) };
     this.distributionPitchCurve = new AnimationCurve(keyframeArray2);
     this.distributionScale      = 1f;
     Keyframe[] keyframeArray3 = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 0.3f) };
     this.distributionScaleCurve = new AnimationCurve(keyframeArray3);
     this.showAnimationProps     = true;
     this.animationPrimary       = 0.5f;
     this.animationSecondary     = 0.5f;
     this.animationEdge          = 1f;
     this.visible       = true;
     this.lockFlags     = 0;
     this.nodeIDs       = new int[0];
     this.parentGroupID = -1;
     this.childGroupIDs = new int[0];
     this.nodes         = new List <TreeNode>();
     this.parentGroup   = null;
     this.childGroups   = new List <TreeGroup>();
 }
Esempio n. 3
0
 public TreeGroup()
 {
     Keyframe[] keys = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) };
     this.distributionCurve = new AnimationCurve(keys);
     this.distributionNodes = 5;
     this.distributionTwirl = 0f;
     this.distributionPitch = 0f;
     Keyframe[] keyframeArray2 = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) };
     this.distributionPitchCurve = new AnimationCurve(keyframeArray2);
     this.distributionScale = 1f;
     Keyframe[] keyframeArray3 = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 0.3f) };
     this.distributionScaleCurve = new AnimationCurve(keyframeArray3);
     this.showAnimationProps = true;
     this.animationPrimary = 0.5f;
     this.animationSecondary = 0.5f;
     this.animationEdge = 1f;
     this.visible = true;
     this.lockFlags = 0;
     this.nodeIDs = new int[0];
     this.parentGroupID = -1;
     this.childGroupIDs = new int[0];
     this.nodes = new List<TreeNode>();
     this.parentGroup = null;
     this.childGroups = new List<TreeGroup>();
 }
Esempio n. 4
0
        public void DeleteNode(TreeNode n, bool validate)
        {
            TreeGroup group = this.GetGroup(n.groupID);

            if (group != null)
            {
                group.nodeIDs = this.ArrayRemove(group.nodeIDs, n.uniqueID);
                group.nodes.Remove(n);
                for (int i = 0; i < group.childGroups.Count; i++)
                {
                    TreeGroup treeGroup = group.childGroups[i];
                    for (int j = treeGroup.nodes.Count - 1; j >= 0; j--)
                    {
                        if (treeGroup.nodes[j] != null && treeGroup.nodes[j].parentID == n.uniqueID)
                        {
                            this.DeleteNode(treeGroup.nodes[j], false);
                        }
                    }
                }
            }
            n.group    = null;
            n.groupID  = 0;
            n.parent   = null;
            n.parentID = 0;
            this.nodes = this.ArrayRemove(this.nodes, n);
            if (validate)
            {
                this.ValidateReferences();
            }
        }
Esempio n. 5
0
        private TreeGroup[] ArrayRemove(TreeGroup[] array, TreeGroup value)
        {
            List <TreeGroup> list = new List <TreeGroup>(array);

            list.Remove(value);
            return(list.ToArray());
        }
Esempio n. 6
0
        public TreeGroup AddGroup(TreeGroup parent, Type type)
        {
            TreeGroup treeGroup;

            if (type == typeof(TreeGroupBranch))
            {
                treeGroup         = new TreeGroupBranch();
                this.branchGroups = this.ArrayAdd(this.branchGroups, treeGroup as TreeGroupBranch);
            }
            else
            {
                if (type != typeof(TreeGroupLeaf))
                {
                    return(null);
                }
                treeGroup       = new TreeGroupLeaf();
                this.leafGroups = this.ArrayAdd(this.leafGroups, treeGroup as TreeGroupLeaf);
            }
            treeGroup.uniqueID = this._uniqueID;
            this._uniqueID++;
            treeGroup.parentGroupID         = 0;
            treeGroup.distributionFrequency = 1;
            this.SetGroupParent(treeGroup, parent);
            return(treeGroup);
        }
Esempio n. 7
0
 private TreeGroup[] ArrayAdd(TreeGroup[] array, TreeGroup value)
 {
     return(new List <TreeGroup>(array)
     {
         value
     }.ToArray());
 }
Esempio n. 8
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);
     }
 }
Esempio n. 9
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);
     }
 }
Esempio n. 10
0
        public void ValidateReferences()
        {
            Profiler.BeginSample("ValidateReferences");
            int groupCount = this.GetGroupCount();

            for (int i = 0; i < groupCount; i++)
            {
                TreeGroup groupAt = this.GetGroupAt(i);
                groupAt.parentGroup = this.GetGroup(groupAt.parentGroupID);
                groupAt.childGroups.Clear();
                groupAt.nodes.Clear();
                for (int j = 0; j < groupAt.childGroupIDs.Length; j++)
                {
                    TreeGroup group = this.GetGroup(groupAt.childGroupIDs[j]);
                    groupAt.childGroups.Add(group);
                }
                for (int k = 0; k < groupAt.nodeIDs.Length; k++)
                {
                    TreeNode node = this.GetNode(groupAt.nodeIDs[k]);
                    groupAt.nodes.Add(node);
                }
            }
            int nodeCount = this.GetNodeCount();

            for (int l = 0; l < nodeCount; l++)
            {
                TreeNode nodeAt = this.GetNodeAt(l);
                nodeAt.parent = this.GetNode(nodeAt.parentID);
                nodeAt.group  = this.GetGroup(nodeAt.groupID);
            }
            Profiler.EndSample();
        }
Esempio n. 11
0
 public override void UpdateMesh(List <TreeMaterial> materials, List <TreeVertex> verts, List <TreeTriangle> tris, List <TreeAOSphere> aoSpheres, int buildFlags, float adaptiveQuality, float aoDensity)
 {
     if (this.geometryMode == 4)
     {
         if (this.instanceMesh != null)
         {
             TreeGroupLeaf.cloneMeshFilter = this.instanceMesh.GetComponent <MeshFilter>();
             if (TreeGroupLeaf.cloneMeshFilter != null)
             {
                 TreeGroupLeaf.cloneMesh = TreeGroupLeaf.cloneMeshFilter.sharedMesh;
                 if (TreeGroupLeaf.cloneMesh != null)
                 {
                     Vector3 extents = TreeGroupLeaf.cloneMesh.bounds.extents;
                     float   num     = Mathf.Max(extents.x, extents.z) * 0.5f;
                     TreeGroupLeaf.cloneVerts    = TreeGroupLeaf.cloneMesh.vertices;
                     TreeGroupLeaf.cloneNormals  = TreeGroupLeaf.cloneMesh.normals;
                     TreeGroupLeaf.cloneUVs      = TreeGroupLeaf.cloneMesh.uv;
                     TreeGroupLeaf.cloneTangents = TreeGroupLeaf.cloneMesh.tangents;
                     for (int i = 0; i < TreeGroupLeaf.cloneVerts.Length; i++)
                     {
                         Vector3[] expr_D8_cp_0 = TreeGroupLeaf.cloneVerts;
                         int       expr_D8_cp_1 = i;
                         expr_D8_cp_0[expr_D8_cp_1].x = expr_D8_cp_0[expr_D8_cp_1].x / num;
                         Vector3[] expr_F0_cp_0 = TreeGroupLeaf.cloneVerts;
                         int       expr_F0_cp_1 = i;
                         expr_F0_cp_0[expr_F0_cp_1].y = expr_F0_cp_0[expr_F0_cp_1].y / num;
                         Vector3[] expr_108_cp_0 = TreeGroupLeaf.cloneVerts;
                         int       expr_108_cp_1 = i;
                         expr_108_cp_0[expr_108_cp_1].z = expr_108_cp_0[expr_108_cp_1].z / num;
                     }
                 }
             }
             if (this.instanceMesh.GetComponent <Renderer>() != null)
             {
                 Material[] sharedMaterials = this.instanceMesh.GetComponent <Renderer>().sharedMaterials;
                 for (int j = 0; j < sharedMaterials.Length; j++)
                 {
                     TreeGroup.GetMaterialIndex(sharedMaterials[j], materials, false);
                 }
             }
         }
     }
     else
     {
         TreeGroup.GetMaterialIndex(this.materialLeaf, materials, false);
     }
     for (int k = 0; k < this.nodes.Count; k++)
     {
         this.UpdateNodeMesh(this.nodes[k], materials, verts, tris, aoSpheres, buildFlags, adaptiveQuality, aoDensity);
     }
     TreeGroupLeaf.cloneMesh       = null;
     TreeGroupLeaf.cloneMeshFilter = null;
     TreeGroupLeaf.cloneVerts      = null;
     TreeGroupLeaf.cloneNormals    = null;
     TreeGroupLeaf.cloneUVs        = null;
     TreeGroupLeaf.cloneTangents   = null;
     base.UpdateMesh(materials, verts, tris, aoSpheres, buildFlags, adaptiveQuality, aoDensity);
 }
Esempio n. 12
0
        public float GetRootSpread()
        {
            TreeGroup root = this;

            while (root.parentGroup != null)
            {
                root = root.parentGroup;
            }
            return(root.nodes[0].size);
        }
Esempio n. 13
0
        public Matrix4x4 GetRootMatrix()
        {
            TreeGroup treeGroup = this;

            while (treeGroup.parentGroup != null)
            {
                treeGroup = treeGroup.parentGroup;
            }
            return(treeGroup.nodes[0].matrix);
        }
Esempio n. 14
0
        public float GetRootSpread()
        {
            TreeGroup treeGroup = this;

            while (treeGroup.parentGroup != null)
            {
                treeGroup = treeGroup.parentGroup;
            }
            return(treeGroup.nodes[0].size);
        }
Esempio n. 15
0
        public Matrix4x4 GetRootMatrix()
        {
            TreeGroup root = this;

            while (root.parentGroup != null)
            {
                root = root.parentGroup;
            }
            return(root.nodes[0].matrix);
        }
Esempio n. 16
0
        public TreeNode DuplicateNode(TreeNode n)
        {
            TreeGroup group = this.GetGroup(n.groupID);

            if (group == null)
            {
                return(null);
            }
            TreeNode treeNode = this.AddNode(group, this.GetNode(n.parentID));

            this.CopyFields(n, treeNode);
            return(treeNode);
        }
Esempio n. 17
0
 public bool IsAncestor(TreeGroup ancestor, TreeGroup g)
 {
     if (g == null)
     {
         return(false);
     }
     for (TreeGroup group = this.GetGroup(g.parentGroupID); group != null; group = this.GetGroup(group.parentGroupID))
     {
         if (group == ancestor)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 18
0
 public TreeNode()
 {
     spline      = null;
     parentID    = 0;
     groupID     = 0;
     parent      = null;
     group       = null;
     seed        = 1234;
     breakOffset = 1.0f;
     visible     = true;
     animSeed    = 0.0f;
     scale       = 1.0f;
     rotation    = Quaternion.identity;
     matrix      = Matrix4x4.identity;
 }
Esempio n. 19
0
 public TreeNode()
 {
     this.spline      = null;
     this.parentID    = 0;
     this.groupID     = 0;
     this.parent      = null;
     this.group       = null;
     this.seed        = 1234;
     this.breakOffset = 1f;
     this.visible     = true;
     this.animSeed    = 0f;
     this.scale       = 1f;
     this.rotation    = Quaternion.identity;
     this.matrix      = Matrix4x4.identity;
 }
Esempio n. 20
0
		public TreeNode()
		{
			this.spline = null;
			this.parentID = 0;
			this.groupID = 0;
			this.parent = null;
			this.group = null;
			this.seed = 1234;
			this.breakOffset = 1f;
			this.visible = true;
			this.animSeed = 0f;
			this.scale = 1f;
			this.rotation = Quaternion.identity;
			this.matrix = Matrix4x4.identity;
		}
Esempio n. 21
0
        public void UpdateDistribution(int id)
        {
            TreeGroup group = this.GetGroup(id);

            if (group == null)
            {
                return;
            }
            int seed = UnityEngine.Random.seed;

            this.ClearReferences();
            this.ValidateReferences();
            group.UpdateDistribution(true, true);
            this.ClearReferences();
            UnityEngine.Random.seed = seed;
        }
Esempio n. 22
0
        public void UpdateFrequency(int id)
        {
            TreeGroup group = this.GetGroup(id);

            if (group == null)
            {
                return;
            }
            int seed = UnityEngine.Random.seed;

            this.ClearReferences();
            this.ValidateReferences();
            group.UpdateFrequency(this);
            this.ClearReferences();
            UnityEngine.Random.seed = seed;
        }
Esempio n. 23
0
        public TreeGroup DuplicateGroup(TreeGroup g)
        {
            TreeGroup treeGroup = this.AddGroup(this.GetGroup(g.parentGroupID), g.GetType());

            this.CopyFields(g, treeGroup);
            treeGroup.childGroupIDs = new int[0];
            treeGroup.nodeIDs       = new int[0];
            for (int i = 0; i < g.nodeIDs.Length; i++)
            {
                TreeNode node     = this.GetNode(g.nodeIDs[i]);
                TreeNode treeNode = this.AddNode(treeGroup, this.GetNode(node.parentID));
                this.CopyFields(node, treeNode);
                treeNode.groupID = treeGroup.uniqueID;
            }
            return(treeGroup);
        }
        public bool NodeHasWrongMaterial(TreeGroup group)
        {
            bool flag = false;

            if (group is TreeGroupBranch)
            {
                TreeGroupBranch branch = group as TreeGroupBranch;
                flag |= !IsMaterialCorrect(branch.materialBranch);
                flag |= !IsMaterialCorrect(branch.materialBreak);
                return(flag | !IsMaterialCorrect(branch.materialFrond));
            }
            if (group is TreeGroupLeaf)
            {
                TreeGroupLeaf leaf = group as TreeGroupLeaf;
                flag |= !IsMaterialCorrect(leaf.materialLeaf);
            }
            return(flag);
        }
Esempio n. 25
0
        public bool NodeHasWrongMaterial(TreeGroup group)
        {
            bool result = false;

            if (group is TreeGroupBranch)
            {
                TreeGroupBranch tgb = group as TreeGroupBranch;
                result |= !IsMaterialCorrect(tgb.materialBranch);
                result |= !IsMaterialCorrect(tgb.materialBreak);
                result |= !IsMaterialCorrect(tgb.materialFrond);
            }
            else if (group is TreeGroupLeaf)
            {
                TreeGroupLeaf tgl = group as TreeGroupLeaf;
                result |= !IsMaterialCorrect(tgl.materialLeaf);
            }

            return(result);
        }
Esempio n. 26
0
 public void DeleteGroup(TreeGroup g)
 {
     for (int i = g.nodes.Count - 1; i >= 0; i--)
     {
         this.DeleteNode(g.nodes[i], false);
     }
     if (g.GetType() == typeof(TreeGroupBranch))
     {
         this.branchGroups = this.ArrayRemove(this.branchGroups, g as TreeGroupBranch);
     }
     else
     {
         if (g.GetType() == typeof(TreeGroupLeaf))
         {
             this.leafGroups = this.ArrayRemove(this.leafGroups, g as TreeGroupLeaf);
         }
     }
     this.SetGroupParent(g, null);
 }
 private static void ChangeShaderOnMaterials(TreeData treeData, Shader shader, TreeGroup group, NodeType nodeType)
 {
     if ((group is TreeGroupBranch) && (nodeType == NodeType.BarkNode))
     {
         TreeGroupBranch branch = group as TreeGroupBranch;
         ChangeShaderOnMaterial(branch.materialBranch, shader);
         ChangeShaderOnMaterial(branch.materialBreak, shader);
         ChangeShaderOnMaterial(branch.materialFrond, shader);
     }
     else if ((group is TreeGroupLeaf) && (nodeType == NodeType.LeafNode))
     {
         TreeGroupLeaf leaf = group as TreeGroupLeaf;
         ChangeShaderOnMaterial(leaf.materialLeaf, shader);
     }
     foreach (int num in group.childGroupIDs)
     {
         TreeGroup group2 = treeData.GetGroup(num);
         ChangeShaderOnMaterials(treeData, shader, group2, nodeType);
     }
 }
Esempio n. 28
0
        public void UpdateSeed()
        {
            TreeGroup treeGroup = this;

            while (treeGroup.parentGroup != null)
            {
                treeGroup = treeGroup.parentGroup;
            }
            int num = treeGroup.seed;

            this._internalSeed = num + (int)((float)this.seed * 1.21f);
            for (int i = 0; i < this.nodes.Count; i++)
            {
                this.nodes[i].seed = num + this._internalSeed + (int)((float)i * 3.7482f);
            }
            for (int j = 0; j < this.childGroups.Count; j++)
            {
                this.childGroups[j].UpdateSeed();
            }
        }
 private static void GetAllTreeShaders(TreeData treeData, List <string> barkShaders, List <string> leafShaders, TreeGroup group)
 {
     if (group is TreeGroupBranch)
     {
         TreeGroupBranch branch = group as TreeGroupBranch;
         AddShaderFromMaterial(branch.materialBranch, barkShaders, leafShaders);
         AddShaderFromMaterial(branch.materialBreak, barkShaders, leafShaders);
         AddShaderFromMaterial(branch.materialFrond, barkShaders, leafShaders);
     }
     else if (group is TreeGroupLeaf)
     {
         TreeGroupLeaf leaf = group as TreeGroupLeaf;
         AddShaderFromMaterial(leaf.materialLeaf, barkShaders, leafShaders);
     }
     foreach (int num in group.childGroupIDs)
     {
         TreeGroup group2 = treeData.GetGroup(num);
         GetAllTreeShaders(treeData, barkShaders, leafShaders, group2);
     }
 }
Esempio n. 30
0
 public override void UpdateMesh(List <TreeMaterial> materials, List <TreeVertex> verts, List <TreeTriangle> tris, List <TreeAOSphere> aoSpheres, int buildFlags, float adaptiveQuality, float aoDensity)
 {
     if ((this.geometryMode == GeometryMode.Branch) || (this.geometryMode == GeometryMode.BranchFrond))
     {
         TreeGroup.GetMaterialIndex(this.materialBranch, materials, true);
         if (this.breakingChance > 0f)
         {
             TreeGroup.GetMaterialIndex(this.materialBreak, materials, false);
         }
     }
     if ((this.geometryMode == GeometryMode.Frond) || (this.geometryMode == GeometryMode.BranchFrond))
     {
         TreeGroup.GetMaterialIndex(this.materialFrond, materials, false);
     }
     for (int i = 0; i < base.nodes.Count; i++)
     {
         this.UpdateNodeMesh(base.nodes[i], materials, verts, tris, aoSpheres, buildFlags, adaptiveQuality, aoDensity);
     }
     base.UpdateMesh(materials, verts, tris, aoSpheres, buildFlags, adaptiveQuality, aoDensity);
 }
 private static void ChangeShaderOnMaterials(TreeData treeData, Shader shader, TreeGroup group, NodeType nodeType)
 {
     if ((group is TreeGroupBranch) && (nodeType == NodeType.BarkNode))
     {
         TreeGroupBranch branch = group as TreeGroupBranch;
         ChangeShaderOnMaterial(branch.materialBranch, shader);
         ChangeShaderOnMaterial(branch.materialBreak, shader);
         ChangeShaderOnMaterial(branch.materialFrond, shader);
     }
     else if ((group is TreeGroupLeaf) && (nodeType == NodeType.LeafNode))
     {
         TreeGroupLeaf leaf = group as TreeGroupLeaf;
         ChangeShaderOnMaterial(leaf.materialLeaf, shader);
     }
     foreach (int num in group.childGroupIDs)
     {
         TreeGroup group2 = treeData.GetGroup(num);
         ChangeShaderOnMaterials(treeData, shader, group2, nodeType);
     }
 }
Esempio n. 32
0
        public void UpdateSeed()
        {
            TreeGroup parentGroup = this;

            while (parentGroup.parentGroup != null)
            {
                parentGroup = parentGroup.parentGroup;
            }
            int seed = parentGroup.seed;

            this._internalSeed = seed + ((int)(this.seed * 1.21f));
            for (int i = 0; i < this.nodes.Count; i++)
            {
                this.nodes[i].seed = (seed + this._internalSeed) + ((int)(i * 3.7482f));
            }
            for (int j = 0; j < this.childGroups.Count; j++)
            {
                this.childGroups[j].UpdateSeed();
            }
        }
Esempio n. 33
0
        private static void ChangeShaderOnMaterials(TreeData treeData, Shader shader, TreeGroup group, NodeType nodeType)
        {
            if (group is TreeGroupBranch && nodeType == NodeType.BarkNode)
            {
                TreeGroupBranch tgb = group as TreeGroupBranch;
                ChangeShaderOnMaterial(tgb.materialBranch, shader);
                ChangeShaderOnMaterial(tgb.materialBreak, shader);
                ChangeShaderOnMaterial(tgb.materialFrond, shader);
            }
            else if (group is TreeGroupLeaf && nodeType == NodeType.LeafNode)
            {
                TreeGroupLeaf tgl = group as TreeGroupLeaf;
                ChangeShaderOnMaterial(tgl.materialLeaf, shader);
            }

            foreach (int id in group.childGroupIDs)
            {
                TreeGroup childGroup = treeData.GetGroup(id);
                ChangeShaderOnMaterials(treeData, shader, childGroup, nodeType);
            }
        }
Esempio n. 34
0
 public TreeNode AddNode(TreeGroup g, TreeNode parent, bool validate)
 {
     if (g == null)
     {
         return null;
     }
     TreeNode n = new TreeNode {
         uniqueID = this._uniqueID
     };
     this._uniqueID++;
     this.SetNodeParent(n, parent);
     n.groupID = g.uniqueID;
     n.group = g;
     g.nodeIDs = this.ArrayAdd(g.nodeIDs, n.uniqueID);
     g.nodes.Add(n);
     this.nodes = this.ArrayAdd(this.nodes, n);
     if (validate)
     {
         this.ValidateReferences();
     }
     return n;
 }
Esempio n. 35
0
 public TreeGroup AddGroup(TreeGroup parent, System.Type type)
 {
     TreeGroup g = null;
     if (type == typeof(TreeGroupBranch))
     {
         g = new TreeGroupBranch();
         this.branchGroups = this.ArrayAdd(this.branchGroups, g as TreeGroupBranch);
     }
     else if (type == typeof(TreeGroupLeaf))
     {
         g = new TreeGroupLeaf();
         this.leafGroups = this.ArrayAdd(this.leafGroups, g as TreeGroupLeaf);
     }
     else
     {
         return null;
     }
     g.uniqueID = this._uniqueID;
     this._uniqueID++;
     g.parentGroupID = 0;
     g.distributionFrequency = 1;
     this.SetGroupParent(g, parent);
     return g;
 }
Esempio n. 36
0
 public float GetRootSpread()
 {
     TreeGroup parentGroup = this;
     while (parentGroup.parentGroup != null)
     {
         parentGroup = parentGroup.parentGroup;
     }
     return parentGroup.nodes[0].size;
 }
Esempio n. 37
0
 public void UpdateSeed()
 {
     TreeGroup parentGroup = this;
     while (parentGroup.parentGroup != null)
     {
         parentGroup = parentGroup.parentGroup;
     }
     int seed = parentGroup.seed;
     this._internalSeed = seed + ((int) (this.seed * 1.21f));
     for (int i = 0; i < this.nodes.Count; i++)
     {
         this.nodes[i].seed = (seed + this._internalSeed) + ((int) (i * 3.7482f));
     }
     for (int j = 0; j < this.childGroups.Count; j++)
     {
         this.childGroups[j].UpdateSeed();
     }
 }
 private static void GetAllTreeShaders(TreeData treeData, List<string> barkShaders, List<string> leafShaders, TreeGroup group)
 {
     if (group is TreeGroupBranch)
     {
         TreeGroupBranch branch = group as TreeGroupBranch;
         AddShaderFromMaterial(branch.materialBranch, barkShaders, leafShaders);
         AddShaderFromMaterial(branch.materialBreak, barkShaders, leafShaders);
         AddShaderFromMaterial(branch.materialFrond, barkShaders, leafShaders);
     }
     else if (group is TreeGroupLeaf)
     {
         TreeGroupLeaf leaf = group as TreeGroupLeaf;
         AddShaderFromMaterial(leaf.materialLeaf, barkShaders, leafShaders);
     }
     foreach (int num in group.childGroupIDs)
     {
         TreeGroup group2 = treeData.GetGroup(num);
         GetAllTreeShaders(treeData, barkShaders, leafShaders, group2);
     }
 }
 public bool NodeHasWrongMaterial(TreeGroup group)
 {
     bool flag = false;
     if (group is TreeGroupBranch)
     {
         TreeGroupBranch branch = group as TreeGroupBranch;
         flag |= !IsMaterialCorrect(branch.materialBranch);
         flag |= !IsMaterialCorrect(branch.materialBreak);
         return (flag | !IsMaterialCorrect(branch.materialFrond));
     }
     if (group is TreeGroupLeaf)
     {
         TreeGroupLeaf leaf = group as TreeGroupLeaf;
         flag |= !IsMaterialCorrect(leaf.materialLeaf);
     }
     return flag;
 }
Esempio n. 40
0
		public static List<float> GetAdaptiveSamples(TreeGroup group, TreeNode node, float adaptiveQuality)
		{
			List<float> list = new List<float>();
			if (node.spline == null)
			{
				return list;
			}
			float num = 1f - node.capRange;
			SplineNode[] array = node.spline.GetNodes();
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i].time >= node.breakOffset)
				{
					list.Add(node.breakOffset);
					break;
				}
				if (array[i].time > num)
				{
					list.Add(num);
					break;
				}
				list.Add(array[i].time);
			}
			list.Sort();
			if (list.Count < 2)
			{
				return list;
			}
			float num2 = 1f;
			if (group.GetType() == typeof(TreeGroupBranch))
			{
				num2 = ((TreeGroupBranch)group).radius;
			}
			float num3 = Mathf.Lerp(0.999f, 0.99999f, adaptiveQuality);
			float num4 = Mathf.Lerp(0.5f, 0.985f, adaptiveQuality);
			float num5 = Mathf.Lerp(0.3f * num2, 0.1f * num2, adaptiveQuality);
			int num6 = 200;
			int j = 0;
			while (j < list.Count - 1)
			{
				for (int k = j; k < list.Count - 1; k++)
				{
					Quaternion rotationAtTime = node.spline.GetRotationAtTime(list[k]);
					Quaternion rotationAtTime2 = node.spline.GetRotationAtTime(list[k + 1]);
					Vector3 lhs = rotationAtTime * Vector3.up;
					Vector3 rhs = rotationAtTime2 * Vector3.up;
					Vector3 lhs2 = rotationAtTime * Vector3.right;
					Vector3 rhs2 = rotationAtTime2 * Vector3.right;
					Vector3 lhs3 = rotationAtTime * Vector3.forward;
					Vector3 rhs3 = rotationAtTime2 * Vector3.forward;
					float radiusAtTime = group.GetRadiusAtTime(node, list[k], true);
					float radiusAtTime2 = group.GetRadiusAtTime(node, list[k + 1], true);
					bool flag = false;
					if (Vector3.Dot(lhs, rhs) < num4)
					{
						flag = true;
					}
					if (Vector3.Dot(lhs2, rhs2) < num4)
					{
						flag = true;
					}
					if (Vector3.Dot(lhs3, rhs3) < num4)
					{
						flag = true;
					}
					if (Mathf.Abs(radiusAtTime - radiusAtTime2) > num5)
					{
						flag = true;
					}
					if (flag)
					{
						num6--;
						if (num6 > 0)
						{
							float item = (list[k] + list[k + 1]) * 0.5f;
							list.Insert(k + 1, item);
							break;
						}
					}
					j = k + 1;
				}
			}
			for (int l = 0; l < list.Count - 2; l++)
			{
				Vector3 positionAtTime = node.spline.GetPositionAtTime(list[l]);
				Vector3 positionAtTime2 = node.spline.GetPositionAtTime(list[l + 1]);
				Vector3 positionAtTime3 = node.spline.GetPositionAtTime(list[l + 2]);
				float radiusAtTime3 = group.GetRadiusAtTime(node, list[l], true);
				float radiusAtTime4 = group.GetRadiusAtTime(node, list[l + 1], true);
				float radiusAtTime5 = group.GetRadiusAtTime(node, list[l + 2], true);
				Vector3 normalized = (positionAtTime2 - positionAtTime).normalized;
				Vector3 normalized2 = (positionAtTime3 - positionAtTime).normalized;
				bool flag2 = false;
				if (Vector3.Dot(normalized, normalized2) >= num3)
				{
					flag2 = true;
				}
				if (Mathf.Abs(radiusAtTime3 - radiusAtTime4) > num5)
				{
					flag2 = false;
				}
				if (Mathf.Abs(radiusAtTime4 - radiusAtTime5) > num5)
				{
					flag2 = false;
				}
				if (flag2)
				{
					list.RemoveAt(l + 1);
					l--;
				}
			}
			if (node.capRange > 0f)
			{
				int num7 = 1 + Mathf.CeilToInt(node.capRange * 16f * adaptiveQuality);
				for (int m = 0; m < num7; m++)
				{
					float f = (float)(m + 1) / (float)num7 * 3.14159274f * 0.5f;
					float num8 = Mathf.Sin(f);
					float num9 = num + node.capRange * num8;
					if (num9 < node.breakOffset)
					{
						list.Add(num9);
					}
				}
				list.Sort();
			}
			if (1f <= node.breakOffset)
			{
				if (list[list.Count - 1] < 1f)
				{
					list.Add(1f);
				}
				else
				{
					list[list.Count - 1] = 1f;
				}
			}
			return list;
		}
Esempio n. 41
0
 public static List<float> GetAdaptiveSamples(TreeGroup group, TreeNode node, float adaptiveQuality)
 {
     List<float> list = new List<float>();
     if (node.spline != null)
     {
         float item = 1f - node.capRange;
         SplineNode[] nodes = node.spline.GetNodes();
         for (int i = 0; i < nodes.Length; i++)
         {
             if (nodes[i].time >= node.breakOffset)
             {
                 list.Add(node.breakOffset);
                 break;
             }
             if (nodes[i].time > item)
             {
                 list.Add(item);
                 break;
             }
             list.Add(nodes[i].time);
         }
         list.Sort();
         if (list.Count < 2)
         {
             return list;
         }
         float radius = 1f;
         if (group.GetType() == typeof(TreeGroupBranch))
         {
             radius = ((TreeGroupBranch) group).radius;
         }
         float num4 = Mathf.Lerp(0.999f, 0.99999f, adaptiveQuality);
         float num5 = Mathf.Lerp(0.5f, 0.985f, adaptiveQuality);
         float num6 = Mathf.Lerp(0.3f * radius, 0.1f * radius, adaptiveQuality);
         int num7 = 200;
         int num8 = 0;
         while (num8 < (list.Count - 1))
         {
             for (int k = num8; k < (list.Count - 1); k++)
             {
                 Quaternion rotationAtTime = node.spline.GetRotationAtTime(list[k]);
                 Quaternion quaternion2 = node.spline.GetRotationAtTime(list[k + 1]);
                 Vector3 lhs = (Vector3) (rotationAtTime * Vector3.up);
                 Vector3 rhs = (Vector3) (quaternion2 * Vector3.up);
                 Vector3 vector3 = (Vector3) (rotationAtTime * Vector3.right);
                 Vector3 vector4 = (Vector3) (quaternion2 * Vector3.right);
                 Vector3 vector5 = (Vector3) (rotationAtTime * Vector3.forward);
                 Vector3 vector6 = (Vector3) (quaternion2 * Vector3.forward);
                 float num10 = group.GetRadiusAtTime(node, list[k], true);
                 float num11 = group.GetRadiusAtTime(node, list[k + 1], true);
                 bool flag = false;
                 if (Vector3.Dot(lhs, rhs) < num5)
                 {
                     flag = true;
                 }
                 if (Vector3.Dot(vector3, vector4) < num5)
                 {
                     flag = true;
                 }
                 if (Vector3.Dot(vector5, vector6) < num5)
                 {
                     flag = true;
                 }
                 if (Mathf.Abs((float) (num10 - num11)) > num6)
                 {
                     flag = true;
                 }
                 if (flag)
                 {
                     num7--;
                     if (num7 > 0)
                     {
                         float num12 = (list[k] + list[k + 1]) * 0.5f;
                         list.Insert(k + 1, num12);
                         continue;
                     }
                 }
                 num8 = k + 1;
             }
         }
         for (int j = 0; j < (list.Count - 2); j++)
         {
             Vector3 positionAtTime = node.spline.GetPositionAtTime(list[j]);
             Vector3 vector8 = node.spline.GetPositionAtTime(list[j + 1]);
             Vector3 vector9 = node.spline.GetPositionAtTime(list[j + 2]);
             float num14 = group.GetRadiusAtTime(node, list[j], true);
             float num15 = group.GetRadiusAtTime(node, list[j + 1], true);
             float num16 = group.GetRadiusAtTime(node, list[j + 2], true);
             Vector3 vector12 = vector8 - positionAtTime;
             Vector3 normalized = vector12.normalized;
             Vector3 vector13 = vector9 - positionAtTime;
             Vector3 vector11 = vector13.normalized;
             bool flag2 = false;
             if (Vector3.Dot(normalized, vector11) >= num4)
             {
                 flag2 = true;
             }
             if (Mathf.Abs((float) (num14 - num15)) > num6)
             {
                 flag2 = false;
             }
             if (Mathf.Abs((float) (num15 - num16)) > num6)
             {
                 flag2 = false;
             }
             if (flag2)
             {
                 list.RemoveAt(j + 1);
                 j--;
             }
         }
         if (node.capRange > 0f)
         {
             int num17 = 1 + Mathf.CeilToInt((node.capRange * 16f) * adaptiveQuality);
             for (int m = 0; m < num17; m++)
             {
                 float f = ((((float) (m + 1)) / ((float) num17)) * 3.141593f) * 0.5f;
                 float num20 = Mathf.Sin(f);
                 float num21 = item + (node.capRange * num20);
                 if (num21 < node.breakOffset)
                 {
                     list.Add(num21);
                 }
             }
             list.Sort();
         }
         if (1f <= node.breakOffset)
         {
             if (list[list.Count - 1] < 1f)
             {
                 list.Add(1f);
                 return list;
             }
             list[list.Count - 1] = 1f;
         }
     }
     return list;
 }
Esempio n. 42
0
		public TreeGroup DuplicateGroup(TreeGroup g)
		{
			TreeGroup treeGroup = this.AddGroup(this.GetGroup(g.parentGroupID), g.GetType());
			this.CopyFields(g, treeGroup);
			treeGroup.childGroupIDs = new int[0];
			treeGroup.nodeIDs = new int[0];
			for (int i = 0; i < g.nodeIDs.Length; i++)
			{
				TreeNode node = this.GetNode(g.nodeIDs[i]);
				TreeNode treeNode = this.AddNode(treeGroup, this.GetNode(node.parentID));
				this.CopyFields(node, treeNode);
				treeNode.groupID = treeGroup.uniqueID;
			}
			return treeGroup;
		}
Esempio n. 43
0
 private void SelectGroup(TreeGroup group)
 {
     if (group == null)
     {
         Debug.Log("GROUP SELECTION IS NULL!");
     }
     if (this.m_TreeEditorHelper.NodeHasWrongMaterial(group))
     {
         s_ShowCategory = 1;
     }
     s_SelectedGroup = group;
     s_SelectedNode = null;
     s_SelectedPoint = -1;
     EditorUtility.SetDirty(this.target);
     Tree target = this.target as Tree;
     if (target != null)
     {
         EditorUtility.SetSelectedWireframeHidden(target.GetComponent<Renderer>(), !(s_SelectedGroup is TreeGroupRoot));
     }
 }
Esempio n. 44
0
 public void InspectorAnimation(TreeData treeData, TreeGroup group)
 {
     if (group != null)
     {
         this.PrepareSpacing(false);
         group.animationPrimary = this.GUISlider(PropertyType.Normal, group.MainWindString, group.animationPrimary, 0f, 1f, false);
         if (treeData.GetGroup(group.parentGroupID) != treeData.root)
         {
             group.animationSecondary = this.GUISlider(PropertyType.Normal, group.MainTurbulenceString, group.animationSecondary, 0f, 1f, false);
         }
         GUI.enabled = true;
         if (!(group is TreeGroupBranch) || ((group as TreeGroupBranch).geometryMode != TreeGroupBranch.GeometryMode.Branch))
         {
             group.animationEdge = this.GUISlider(PropertyType.Normal, group.EdgeTurbulenceString, group.animationEdge, 0f, 1f, false);
         }
         this.GUIPropBegin();
         if (GUILayout.Button(TreeEditorHelper.GetGUIContent("Create Wind Zone|Creates a default wind zone, which is required for animating trees while playing the game."), new GUILayoutOption[0]))
         {
             CreateDefaultWindZone();
         }
         this.GUIPropEnd();
     }
 }
Esempio n. 45
0
 private void BuildHierachyNodes(TreeData treeData, List<HierachyNode> nodes, TreeGroup group, int depth)
 {
     HierachyNode item = new HierachyNode {
         group = group,
         pos = new Vector3(0f, depth * this.hierachySpread.y, 0f)
     };
     nodes.Add(item);
     for (int i = 0; i < group.childGroupIDs.Length; i++)
     {
         TreeGroup group2 = treeData.GetGroup(group.childGroupIDs[i]);
         this.BuildHierachyNodes(treeData, nodes, group2, depth - 1);
     }
 }
Esempio n. 46
0
		public bool IsAncestor(TreeGroup ancestor, TreeGroup g)
		{
			if (g == null)
			{
				return false;
			}
			for (TreeGroup group = this.GetGroup(g.parentGroupID); group != null; group = this.GetGroup(group.parentGroupID))
			{
				if (group == ancestor)
				{
					return true;
				}
			}
			return false;
		}
Esempio n. 47
0
		public TreeNode AddNode(TreeGroup g, TreeNode parent)
		{
			return this.AddNode(g, parent, true);
		}
Esempio n. 48
0
 public Matrix4x4 GetRootMatrix()
 {
     TreeGroup parentGroup = this;
     while (parentGroup.parentGroup != null)
     {
         parentGroup = parentGroup.parentGroup;
     }
     return parentGroup.nodes[0].matrix;
 }
Esempio n. 49
0
		public TreeGroup AddGroup(TreeGroup parent, Type type)
		{
			TreeGroup treeGroup;
			if (type == typeof(TreeGroupBranch))
			{
				treeGroup = new TreeGroupBranch();
				this.branchGroups = this.ArrayAdd(this.branchGroups, treeGroup as TreeGroupBranch);
			}
			else
			{
				if (type != typeof(TreeGroupLeaf))
				{
					return null;
				}
				treeGroup = new TreeGroupLeaf();
				this.leafGroups = this.ArrayAdd(this.leafGroups, treeGroup as TreeGroupLeaf);
			}
			treeGroup.uniqueID = this._uniqueID;
			this._uniqueID++;
			treeGroup.parentGroupID = 0;
			treeGroup.distributionFrequency = 1;
			this.SetGroupParent(treeGroup, parent);
			return treeGroup;
		}
Esempio n. 50
0
		private TreeGroup[] ArrayRemove(TreeGroup[] array, TreeGroup value)
		{
			List<TreeGroup> list = new List<TreeGroup>(array);
			list.Remove(value);
			return list.ToArray();
		}
Esempio n. 51
0
 public TreeGroup DuplicateGroup(TreeGroup g)
 {
     TreeGroup group = this.AddGroup(this.GetGroup(g.parentGroupID), g.GetType());
     this.CopyFields(g, group);
     group.childGroupIDs = new int[0];
     group.nodeIDs = new int[0];
     for (int i = 0; i < g.nodeIDs.Length; i++)
     {
         TreeNode n = this.GetNode(g.nodeIDs[i]);
         TreeNode node2 = this.AddNode(group, this.GetNode(n.parentID));
         this.CopyFields(n, node2);
         node2.groupID = group.uniqueID;
     }
     return group;
 }
Esempio n. 52
0
		private TreeGroup[] ArrayAdd(TreeGroup[] array, TreeGroup value)
		{
			return new List<TreeGroup>(array)
			{
				value
			}.ToArray();
		}
Esempio n. 53
0
		public void DeleteGroup(TreeGroup g)
		{
			for (int i = g.nodes.Count - 1; i >= 0; i--)
			{
				this.DeleteNode(g.nodes[i], false);
			}
			if (g.GetType() == typeof(TreeGroupBranch))
			{
				this.branchGroups = this.ArrayRemove(this.branchGroups, g as TreeGroupBranch);
			}
			else
			{
				if (g.GetType() == typeof(TreeGroupLeaf))
				{
					this.leafGroups = this.ArrayRemove(this.leafGroups, g as TreeGroupLeaf);
				}
			}
			this.SetGroupParent(g, null);
		}
Esempio n. 54
0
		public TreeNode AddNode(TreeGroup g, TreeNode parent, bool validate)
		{
			if (g == null)
			{
				return null;
			}
			TreeNode treeNode = new TreeNode();
			treeNode.uniqueID = this._uniqueID;
			this._uniqueID++;
			this.SetNodeParent(treeNode, parent);
			treeNode.groupID = g.uniqueID;
			treeNode.group = g;
			g.nodeIDs = this.ArrayAdd(g.nodeIDs, treeNode.uniqueID);
			g.nodes.Add(treeNode);
			this.nodes = this.ArrayAdd(this.nodes, treeNode);
			if (validate)
			{
				this.ValidateReferences();
			}
			return treeNode;
		}
Esempio n. 55
0
		public void SetGroupParent(TreeGroup g, TreeGroup parent)
		{
			TreeGroup group = this.GetGroup(g.parentGroupID);
			if (group != null)
			{
				group.childGroupIDs = this.ArrayRemove(group.childGroupIDs, g.uniqueID);
				group.childGroups.Remove(g);
			}
			if (parent != null)
			{
				g.parentGroup = parent;
				g.parentGroupID = parent.uniqueID;
				parent.childGroups.Add(g);
				parent.childGroupIDs = this.ArrayAdd(parent.childGroupIDs, g.uniqueID);
			}
			else
			{
				g.parentGroup = null;
				g.parentGroupID = 0;
			}
			this.ValidateReferences();
			this.UpdateFrequency(g.uniqueID);
		}
Esempio n. 56
0
		public void LockGroup(TreeGroup g)
		{
			g.Lock();
		}
Esempio n. 57
0
 public void InspectorDistribution(TreeData treeData, TreeGroup group)
 {
     if (group != null)
     {
         this.PrepareSpacing(true);
         bool flag = true;
         if (group.lockFlags != 0)
         {
             flag = false;
         }
         GUI.enabled = flag;
         int seed = group.seed;
         group.seed = this.GUIIntSlider(PropertyType.Normal, group.GroupSeedString, group.seed, 0, 0xf423f, false);
         if (group.seed != seed)
         {
             treeData.UpdateSeed(group.uniqueID);
         }
         seed = group.distributionFrequency;
         group.distributionFrequency = this.GUIIntSlider(PropertyType.FullUndo, group.FrequencyString, group.distributionFrequency, 1, 100, false);
         if (group.distributionFrequency != seed)
         {
             treeData.UpdateFrequency(group.uniqueID);
         }
         seed = (int) group.distributionMode;
         group.distributionMode = (TreeGroup.DistributionMode) this.GUIPopup(PropertyType.Normal, group.DistributionModeString, inspectorDistributionPopupOptions, (int) group.distributionMode, true);
         if (group.distributionMode != seed)
         {
             treeData.UpdateDistribution(group.uniqueID);
         }
         AnimationCurve distributionCurve = group.distributionCurve;
         if (this.GUICurve(PropertyType.Normal, distributionCurve, this.m_CurveRangesA))
         {
             group.distributionCurve = distributionCurve;
             treeData.UpdateDistribution(group.uniqueID);
         }
         if (group.distributionMode != TreeGroup.DistributionMode.Random)
         {
             float distributionTwirl = group.distributionTwirl;
             group.distributionTwirl = this.GUISlider(PropertyType.Normal, group.TwirlString, group.distributionTwirl, -1f, 1f, false);
             if (group.distributionTwirl != distributionTwirl)
             {
                 treeData.UpdateDistribution(group.uniqueID);
             }
         }
         if (group.distributionMode == TreeGroup.DistributionMode.Whorled)
         {
             seed = group.distributionNodes;
             group.distributionNodes = this.GUIIntSlider(PropertyType.Normal, group.WhorledStepString, group.distributionNodes, 1, 0x15, false);
             if (group.distributionNodes != seed)
             {
                 treeData.UpdateDistribution(group.uniqueID);
             }
         }
         group.distributionScale = this.GUISlider(PropertyType.Normal, group.GrowthScaleString, group.distributionScale, 0f, 1f, true);
         distributionCurve = group.distributionScaleCurve;
         if (this.GUICurve(PropertyType.Normal, distributionCurve, this.m_CurveRangesA))
         {
             group.distributionScaleCurve = distributionCurve;
         }
         group.distributionPitch = this.GUISlider(PropertyType.Normal, group.GrowthAngleString, group.distributionPitch, 0f, 1f, true);
         distributionCurve = group.distributionPitchCurve;
         if (this.GUICurve(PropertyType.Normal, distributionCurve, this.m_CurveRangesB))
         {
             group.distributionPitchCurve = distributionCurve;
         }
         GUI.enabled = true;
         EditorGUILayout.Space();
     }
 }
Esempio n. 58
0
		public void UnlockGroup(TreeGroup g)
		{
			g.Unlock();
			this.UpdateFrequency(g.uniqueID);
		}
Esempio n. 59
0
        private void DrawHierachyNodes(TreeData treeData, List<HierachyNode> nodes, TreeGroup group, Vector2 offset, float alpha, float fade)
        {
            if (((this.dragNode != null) && this.isDragging) && (this.dragNode.group == group))
            {
                alpha = 0.5f;
                fade = 0.75f;
            }
            Vector3 vector = new Vector3(0f, this.hierachyNodeSize.y * 0.5f, 0f);
            Vector3 vector2 = new Vector3(offset.x, offset.y);
            Handles.color = new Color(0f, 0f, 0f, 0.5f * alpha);
            if (EditorGUIUtility.isProSkin)
            {
                Handles.color = new Color(0.4f, 0.4f, 0.4f, 0.5f * alpha);
            }
            HierachyNode node = null;
            for (int i = 0; i < nodes.Count; i++)
            {
                if (group == nodes[i].group)
                {
                    node = nodes[i];
                    break;
                }
            }
            if (node != null)
            {
                for (int j = 0; j < group.childGroupIDs.Length; j++)
                {
                    TreeGroup group2 = treeData.GetGroup(group.childGroupIDs[j]);
                    for (int m = 0; m < nodes.Count; m++)
                    {
                        if (nodes[m].group == group2)
                        {
                            Handles.DrawLine((node.pos + vector2) - vector, (nodes[m].pos + vector2) + vector);
                        }
                    }
                }
                Rect position = node.rect;
                position.x += offset.x;
                position.y += offset.y;
                int index = 0;
                if (node == this.dropNode)
                {
                    index = 1;
                }
                else if (s_SelectedGroup == node.group)
                {
                    if (s_SelectedNode != null)
                    {
                        index = 1;
                    }
                    else
                    {
                        index = 1;
                    }
                }
                GUI.backgroundColor = new Color(1f, 1f, 1f, alpha);
                GUI.contentColor = new Color(1f, 1f, 1f, alpha);
                GUI.Label(position, GUIContent.none, styles.nodeBoxes[index]);
                Rect rect2 = new Rect((position.x + (position.width / 2f)) - 4f, position.y - 2f, 0f, 0f);
                Rect rect3 = new Rect((position.x + (position.width / 2f)) - 4f, (position.y + position.height) - 2f, 0f, 0f);
                Rect rect4 = new Rect(position.x + 1f, position.yMax - 36f, 32f, 32f);
                Rect rect5 = new Rect(position.xMax - 18f, position.yMax - 18f, 16f, 16f);
                Rect rect6 = new Rect(position.x, position.y, position.width - 2f, 16f);
                bool flag = true;
                int num5 = 0;
                GUIContent gUIContent = new GUIContent();
                System.Type type = group.GetType();
                if (type != typeof(TreeGroupBranch))
                {
                    if (type == typeof(TreeGroupLeaf))
                    {
                        gUIContent = TreeEditorHelper.GetGUIContent("|Leaf Group");
                        num5 = 3;
                    }
                    else if (type == typeof(TreeGroupRoot))
                    {
                        gUIContent = TreeEditorHelper.GetGUIContent("|Tree Root Node");
                        num5 = 4;
                        flag = false;
                    }
                }
                else
                {
                    gUIContent = TreeEditorHelper.GetGUIContent("|Branch Group");
                    TreeGroupBranch branch = (TreeGroupBranch) group;
                    switch (branch.geometryMode)
                    {
                        case TreeGroupBranch.GeometryMode.BranchFrond:
                            num5 = 0;
                            break;

                        case TreeGroupBranch.GeometryMode.Branch:
                            num5 = 1;
                            break;

                        case TreeGroupBranch.GeometryMode.Frond:
                            num5 = 2;
                            break;
                    }
                }
                if (flag)
                {
                    Rect hierachyNodeVisRect = this.GetHierachyNodeVisRect(position);
                    GUIContent content = TreeEditorHelper.GetGUIContent("|Show / Hide Group");
                    content.image = styles.visibilityIcons[!group.visible ? 1 : 0].image;
                    GUI.contentColor = new Color(1f, 1f, 1f, 0.7f);
                    if (GUI.Button(hierachyNodeVisRect, content, GUIStyle.none))
                    {
                        group.visible = !group.visible;
                        GUI.changed = true;
                    }
                    GUI.contentColor = Color.white;
                }
                gUIContent.image = styles.nodeIcons[num5].image;
                GUI.contentColor = new Color(1f, 1f, 1f, !group.visible ? 0.5f : 1f);
                if (GUI.Button(rect4, gUIContent, GUIStyle.none) || (this.dragNode == node))
                {
                    TreeGroup group3 = s_SelectedGroup;
                    this.SelectGroup(group);
                    if (group3 == s_SelectedGroup)
                    {
                        Tree target = base.target as Tree;
                        this.FrameSelected(target);
                    }
                }
                GUI.contentColor = Color.white;
                if (group.CanHaveSubGroups())
                {
                    GUI.Label(rect2, GUIContent.none, styles.pinLabel);
                }
                if (flag)
                {
                    GUIContent content3 = TreeEditorHelper.GetGUIContent("|Node Count");
                    content3.text = group.nodeIDs.Length.ToString();
                    GUI.Label(rect6, content3, styles.nodeLabelTop);
                    if (this.m_TreeEditorHelper.NodeHasWrongMaterial(group))
                    {
                        GUI.DrawTexture(rect5, ConsoleWindow.iconErrorSmall);
                    }
                    else if (group.lockFlags != 0)
                    {
                        GUI.DrawTexture(rect5, styles.warningIcon.image);
                    }
                    GUI.Label(rect3, GUIContent.none, styles.pinLabel);
                }
                for (int k = 0; k < group.childGroupIDs.Length; k++)
                {
                    TreeGroup group4 = treeData.GetGroup(group.childGroupIDs[k]);
                    this.DrawHierachyNodes(treeData, nodes, group4, offset, alpha * fade, fade);
                }
                GUI.backgroundColor = Color.white;
                GUI.contentColor = Color.white;
            }
        }
		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);
			}
		}