//public List<TreeData> GetListTreeService(bool selectable, int ParentsID, List<Service> roots) //{ // var tmp = new List<TreeData>(); // var levesub = roots.FindAll(c => c.ParentsID == ParentsID); // levesub.Sort((f1, f2) => f1.ServiceID.CompareTo(f2.ServiceID)); // if (levesub.Count <= 0) return null; // foreach (var t in levesub) // { // roots.Remove(t); // var data = new TreeData // { // serviceId = t.ServiceID, // parentServiceId = t.ParentsID, // groupService = t.GroupService, // text = t.ServiceName, // status = t.Status, // selectable = selectable // }; // if (data.serviceId <= 0) // { // data.selectable = false; // } // tmp.Add(data); // var childrens = GetListTreeService(selectable, t.ServiceID, roots); // data.nodes = childrens; // } // return tmp; //} //public List<TreeData> GetListTreeSelected(int ServiceSelect, int ParentsID, List<Service> roots) //{ // var tmp = new List<TreeData>(); // var levesub = roots.FindAll(c => c.ParentsID == ParentsID); // levesub.Sort((f1, f2) => f1.ServiceID.CompareTo(f2.ServiceID)); // if (levesub.Count <= 0) return null; // foreach (var t in levesub) // { // roots.Remove(t); // var data = new TreeData // { // serviceId = t.ServiceID, // parentServiceId = t.ParentsID, // groupService = t.GroupService, // text = "[" + t.ServiceID + "]" + " - " + t.ServiceName, // status = t.Status, // selectable = true, // state = new state() // }; // if (t.ServiceID <= 0) // { // data.selectable = false; // } // if (ServiceSelect == t.ServiceID) // { // data.state.selected = true; // } // var childrens = GetListTreeSelected(ServiceSelect, t.ServiceID, roots); // data.nodes = childrens; // tmp.Add(data); // } // return tmp; //} public List <TreeFunction> GetListTreeFunction(int ParentsID, List <Functions> roots) { var tmp = new List <TreeFunction>(); var levesub = roots.FindAll(c => c.ParentID == ParentsID); levesub.Sort((f1, f2) => f1.FunctionID.CompareTo(f2.FunctionID)); if (levesub.Count <= 0) { return(null); } foreach (var t in levesub) { roots.Remove(t); var data = new TreeFunction { FuntionId = t.FunctionID, ParentId = t.ParentID, text = t.FunctionName, icon = t.CssIcon, IsBtnGrant = false }; if (!string.IsNullOrEmpty(t.Url)) { data.IsBtnGrant = true; } tmp.Add(data); var childrens = GetListTreeFunction(t.FunctionID, roots); data.nodes = childrens; } return(tmp); }
public void RemoveFunction(int index) { #if UNITY_EDITOR Undo.RecordObject(this, "Removed function"); #endif Mtree.TreeFunction functionToRemove = treeFunctions[index]; TreeFunction newParent = functionToRemove.parent; foreach (TreeFunction tf in treeFunctions) { if (tf.parent != null && tf.parent.id == functionToRemove.id) { tf.parent = newParent; } } treeFunctions.RemoveAt(index); if (selectedFunctionIndex >= index) { selectedFunctionIndex--; } UpdateTreeFunctions(); }
I386Function TranslateFunction(TreeFunction function) { currentBody = new List <IMachineInstruction>(); currentParamCount = function.NumberOfParameters - 1; Emit(new InstrUnary(InstrUnary.Kind.PUSH, new Operand.Reg(EBP))); Emit(new InstrBinary(InstrBinary.Kind.MOV, new Operand.Reg(EBP), new Operand.Reg(ESP))); Emit(new InstrBinary(InstrBinary.Kind.SUB, new Operand.Reg(ESP), new Operand.Imm(0))); Temp ebxTemp = new Temp(), esiTemp = new Temp(), ediTemp = new Temp(); Emit(new InstrBinary(InstrBinary.Kind.MOV, new Operand.Reg(ebxTemp), new Operand.Reg(EBX))); Emit(new InstrBinary(InstrBinary.Kind.MOV, new Operand.Reg(esiTemp), new Operand.Reg(ESI))); Emit(new InstrBinary(InstrBinary.Kind.MOV, new Operand.Reg(ediTemp), new Operand.Reg(EDI))); foreach (var stm in function.Body) { MunchStm(stm); } Emit(new InstrBinary(InstrBinary.Kind.MOV, new Operand.Reg(EAX), new Operand.Reg(function.ReturnTemp))); Emit(new InstrBinary(InstrBinary.Kind.MOV, new Operand.Reg(EBX), new Operand.Reg(ebxTemp))); Emit(new InstrBinary(InstrBinary.Kind.MOV, new Operand.Reg(ESI), new Operand.Reg(esiTemp))); Emit(new InstrBinary(InstrBinary.Kind.MOV, new Operand.Reg(EDI), new Operand.Reg(ediTemp))); Emit(new InstrBinary(InstrBinary.Kind.MOV, new Operand.Reg(ESP), new Operand.Reg(EBP))); Emit(new InstrUnary(InstrUnary.Kind.POP, new Operand.Reg(EBP))); Emit(new InstrNullary(InstrNullary.Kind.RET)); return(new I386Function(function.Name, currentBody)); }
public void AddTrunkFunction() { TreeFunction f = new TreeFunction(treeFunctionId, FunctionType.Trunk, null); treeFunctions.Add(f); treeFunctionId++; GenerateTree(); }
private TreeFunction CanonFunction(TreeFunction function) { List <TreeStm> canonBody = new List <TreeStm>(); foreach (var s in function) { canonBody.AddRange(CanonStm(s)); } return(new TreeFunction(function.Name, function.NumberOfParameters, canonBody, function.ReturnTemp)); }
public void AddTreeFunction(FunctionType type) { #if UNITY_EDITOR Undo.RecordObject(this, "Added function"); #endif int functionIndex = selectedFunctionIndex + 1; int parentPos = treeFunctions[selectedFunctionIndex].position; while (functionIndex < treeFunctions.Count && treeFunctions[functionIndex].position > parentPos) { functionIndex++; } TreeFunction f = new TreeFunction(treeFunctionId, type, treeFunctions[selectedFunctionIndex]); treeFunctions.Insert(functionIndex, f); selectedFunctionIndex = functionIndex; treeFunctionId++; UpdateTreeFunctions(); }
public void UpdateTreeFunctions() { if (treeFunctions == null) { treeFunctions = new List <Mtree.TreeFunction>(); AddTrunkFunction(); } int n = treeFunctions.Count; bool styleFlushed = false; // true when unity serialization has failed for (int i = 0; i < n; i++) { TreeFunction tf = treeFunctions[i]; if (tf.type != FunctionType.Trunk && tf.parent == null) // Reassigning parent when unity serialization fails to keep it { styleFlushed = true; tf.UpdateStyle(); int functionId = tf.parentId; foreach (TreeFunction f in treeFunctions) { if (f.id == functionId) { tf.parent = f; break; } } } } if (styleFlushed) { treeFunctions[0].UpdateStyle(); } for (int i = 0; i < n; i++) { treeFunctions[i].UpdateRect(i); } }
void Setup() { if (reflectionValue == null) { reflectionValue = MemberData.none; } if (filter == null) { filter = new FilterAttribute() { UnityReference = false, OnlyGetType = onlyGetType }; } if (onlyGetType) { filter = new FilterAttribute(filter) { OnlyGetType = onlyGetType } } ; if (filter.OnlyGetType) { filter.ValidTargetType = MemberData.TargetType.Type | MemberData.TargetType.Null; } if (targetObject) { uNodeRoot UNR = null; if (targetObject is uNodeRoot) { UNR = targetObject as uNodeRoot; } else if (targetObject is RootObject) { UNR = (targetObject as RootObject).owner; } else if (targetObject is NodeComponent) { UNR = (targetObject as NodeComponent).owner; } else if (targetObject is TransitionEvent) { UNR = (targetObject as TransitionEvent).owner; } if (UNR) { uNodeData data = UNR.GetComponent <uNodeData>(); if (data) { //Clear the default namespace usingNamespaces.Clear(); //Add graph namespaces foreach (var n in data.GetNamespaces()) { usingNamespaces.Add(n); } } if (UNR is IIndependentGraph graph) { if (data == null) { //Clear the default namespace usingNamespaces.Clear(); } foreach (var n in graph.UsingNamespaces) { usingNamespaces.Add(n); } } } } editorData.manager = new Manager(new TreeViewState()); editorData.manager.window = this; editorData.searchField = new SearchField(); editorData.searchField.downOrUpArrowKeyPressed += editorData.manager.SetFocusAndEnsureSelectedItem; editorData.searchField.autoSetFocusOnFindCommand = true; window = this; uNodeThreadUtility.Queue(DoSetup); } void DoSetup() { editorData.setup.Setup((progress) => { if (progress == 1) { uNodeThreadUtility.Queue(() => { var categories = new List <TreeViewItem>(); if (displayDefaultItem) { var categoryTree = new SelectorCategoryTreeView("#", "", uNodeEditorUtility.GetUIDFromString("[CATEG]#"), -1); categories.Add(categoryTree); var recentTree = new SelectorCategoryTreeView("Recently", "", uNodeEditorUtility.GetUIDFromString("[CATEG]#Recently"), -1); categories.Add(recentTree); if (displayNoneOption && filter.IsValidTarget(MemberData.TargetType.None)) { categoryTree.AddChild(new SelectorMemberTreeView(MemberData.none, "None", uNodeEditorUtility.GetUIDFromString("#None")) { icon = uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.NullTypeIcon)) as Texture2D }); } if (!filter.SetMember) { if (!filter.IsValueTypes() && filter.IsValidTarget(MemberData.TargetType.Null) && !filter.OnlyGetType) { categoryTree.AddChild(new SelectorMemberTreeView(MemberData.Null, "Null", uNodeEditorUtility.GetUIDFromString("#Null")) { icon = uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.NullTypeIcon)) as Texture2D }); } //if(!filter.OnlyGetType && filter.IsValidTarget(MemberData.TargetType.Values) && // (filter.Types == null || filter.Types.Count != 1 || filter.Types[0] != typeof(Type))) { // categoryTree.AddChild(new SelectorCallbackTreeView((cRect) => { // var screenRect = cRect.ToScreenRect(); // FilterAttribute F = new FilterAttribute(filter); // F.OnlyGetType = true; // ItemSelector w = null; // Action<MemberData> action = delegate (MemberData m) { // if(w != null) { // w.Close(); // //EditorGUIUtility.ExitGUI(); // } // if(filter.CanManipulateArray()) { // if(Event.current.button == 0) { // TypeSelectorWindow.ShowAsNew(Rect.zero, F, delegate (MemberData[] members) { // Type t = members[0].Get<Type>(); // SelectValues(t); // }, m).ChangePosition(screenRect); // } else { // CommandWindow.CreateWindow(screenRect, (items) => { // var member = CompletionEvaluator.CompletionsToMemberData(items); // if(member != null) { // Type t = member.Get<Type>(); // SelectValues(t); // return true; // } // return false; // }, new CompletionEvaluator.CompletionSetting() { // validCompletionKind = CompletionKind.Type | CompletionKind.Namespace | CompletionKind.Keyword, // }); // } // } else { // Type t = m.Get<Type>(); // SelectValues(t); // } // }; // w = ShowAsNew(targetObject, F, action, true).ChangePosition(screenRect); // }, "Values", uNodeEditorUtility.GetUIDFromString("#Values"), -1) { // icon = uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.ValueIcon)) as Texture2D // }); //} } if (displayRecentItem) { var listRecentItems = new List <TreeViewItem>(); if (uNodeEditor.SavedData.recentItems != null) { foreach (var recent in uNodeEditor.SavedData.recentItems) { if (recent != null && recent.info != null) { if (recent.info is Type) { listRecentItems.Add(new TypeTreeView(recent.info as Type, recent.GetHashCode(), -1)); } else if (!filter.OnlyGetType && (recent.isStatic || filter.DisplayInstanceOnStatic)) { listRecentItems.Add(new MemberTreeView(recent.info, recent.GetHashCode(), -1)); } } } } while (listRecentItems.Count > 10) { listRecentItems.RemoveAt(listRecentItems.Count - 1); } if (listRecentItems.Count > 0) { foreach (var item in listRecentItems) { if (item is MemberTreeView) { var tree = item as MemberTreeView; if (!(tree.member is Type)) { tree.displayName = tree.member.DeclaringType.Name + "." + tree.displayName; } } recentTree.AddChild(item); } recentTree.expanded = false; } } if (!filter.OnlyGetType && filter.UnityReference) { if (reflectionValue != null && reflectionValue.GetInstance() != null && !(reflectionValue.GetInstance() is IGraphSystem) && !(reflectionValue.GetInstance() is INode)) { categories.Add(TreeFunction.CreateTargetItem(reflectionValue.GetInstance(), "Target Reference", filter)); } categories.AddRange(TreeFunction.CreateGraphItem(targetObject, reflectionValue, filter)); } if (filter.UnityReference) { categories.AddRange(TreeFunction.CreateRootItem(targetObject, filter)); } categories.AddRange(TreeFunction.CreateCustomItem(customItems)); if (filter.DisplayDefaultStaticType) { categoryTree.AddChild(new SelectorGroupedTreeView(() => { var result = new List <TreeViewItem>(); result.Add(new SelectorSearchTreeView((prog) => { var treeResult = new List <TreeViewItem>(); var sp = new SearchProgress(); prog?.Invoke(sp); var allTypes = GetAllTypes((currProgress) => { prog?.Invoke(currProgress); }, true, true); sp.info = "Setup Items"; for (int i = 0; i < allTypes.Count; i++) { var pair = allTypes[i]; var nsTree = new SelectorCategoryTreeView(pair.Key, "", uNodeEditorUtility.GetUIDFromString("[CATEG-SEARCH]" + pair.Key), -1); foreach (var type in pair.Value) { nsTree.AddChild(new TypeTreeView(type, type.GetHashCode(), -1)); } treeResult.Add(nsTree); sp.progress = (float)i / (float)allTypes.Count; prog?.Invoke(sp); } return(treeResult); }, "Search All Types", uNodeEditorUtility.GetUIDFromString("[SAT]"), -1)); var nestedNS = new HashSet <string>(); //var excludedNs = uNodePreference.GetExcludedNamespace(); var namespaces = new List <string>(EditorReflectionUtility.GetNamespaces()); namespaces.Sort(); namespaces.RemoveAll(i => /*excludedNs.Contains(i) ||*/ i == null || i.Contains(".")); foreach (var ns in namespaces) { result.Add(new NamespaceTreeView(ns, uNodeEditorUtility.GetUIDFromString("[N]" + ns), -1)); } //var nsTypes = GetNamespaceTypes(namespaces); //foreach(var pair in nsTypes) { // var nsTree = new SelectorCategoryTreeView(pair.Key, "", uNodeEditorUtility.GetUIDFromString("[Nested-NS]" + pair.Key), -1); // foreach(var ns in nestedNS) { // if(ns.StartsWith(pair.Key)) { // nsTree.AddChild(new NamespaceTreeView(ns, uNodeEditorUtility.GetUIDFromString("[N]" + ns), -1)); // } // } // foreach(var type in pair.Value) { // nsTree.AddChild(new TypeTreeView(type, type.GetHashCode(), -1)); // } // //nsTree.children.Sort((x, y) => string.Compare(x.displayName, y.displayName)); // nsTree.expanded = false; // result.Add(nsTree); //} return(result); }, "All Namespaces", uNodeEditorUtility.GetUIDFromString("[ALL-NS]"), -1) { icon = uNodeEditorUtility.GetTypeIcon(typeof(TypeIcons.NamespaceIcon)) as Texture2D }); categoryTree.AddChild(new SelectorGroupedTreeView(() => { var result = new List <TreeViewItem>(); var favorites = uNodeEditor.SavedData.favoriteItems; if (favorites != null) //Favorite Type and Members { var typeTrees = new List <TypeTreeView>(); var memberTrees = new List <MemberTreeView>(); foreach (var fav in favorites) { if (fav.info != null && window.filter.IsValidMember(fav.info)) { if (fav.info is Type type) { typeTrees.Add(new TypeTreeView(type)); } else { var tree = new MemberTreeView(fav.info); tree.displayName = tree.member.DeclaringType.Name + "." + tree.displayName; memberTrees.Add(tree); } } } typeTrees.Sort((x, y) => string.Compare(x.displayName, y.displayName)); memberTrees.Sort((x, y) => string.Compare(x.displayName, y.displayName)); var typeCategory = new SelectorCategoryTreeView("Types", "", uNodeEditorUtility.GetUIDFromString("[TYPES]"), -1); foreach (var tree in typeTrees) { typeCategory.AddChild(tree); } var memberCategory = new SelectorCategoryTreeView("Members", "", uNodeEditorUtility.GetUIDFromString("[MEMBERS]"), -1); foreach (var tree in memberTrees) { memberCategory.AddChild(tree); } if (typeCategory.hasChildren) { result.Add(typeCategory); } if (memberCategory.hasChildren) { result.Add(memberCategory); } } { //Favorite Namespaces var nsTrees = new List <NamespaceTreeView>(); foreach (var fav in uNodeEditor.SavedData.favoriteNamespaces) { nsTrees.Add(new NamespaceTreeView(fav, uNodeEditorUtility.GetUIDFromString("[NS-FAV]" + fav), -1)); } nsTrees.Sort((x, y) => string.Compare(x.displayName, y.displayName)); var nsCategory = new SelectorCategoryTreeView("Namespaces", "", uNodeEditorUtility.GetUIDFromString("[NS]"), -1); foreach (var tree in nsTrees) { nsCategory.AddChild(tree); } if (nsCategory.hasChildren) { result.Add(nsCategory); } } return(result); }, "Favorites", uNodeEditorUtility.GetUIDFromString("[fav]"), -1) { icon = uNodeGUIUtility.Styles.favoriteIconOn }); var namespaceTrees = new SelectorCategoryTreeView("Types", "", uNodeEditorUtility.GetUIDFromString("[NS]"), -1); if (displayGeneralType) { var categTree = new SelectorCategoryTreeView("General", "", uNodeEditorUtility.GetUIDFromString("[GENERAL]"), -1); var items = TreeFunction.GetGeneralTrees(); items.ForEach(tree => categTree.AddChild(tree)); namespaceTrees.AddChild(categTree); } if (filter.DisplayRuntimeType) { var runtimeItems = TreeFunction.GetRuntimeItems(); var runtimeTypes = new Dictionary <string, List <TypeTreeView> >(); foreach (var item in runtimeItems) { var ns = item.type.Namespace; if (string.IsNullOrEmpty(ns) || ns == RuntimeType.RuntimeNamespace) { ns = "Generated Type"; } List <TypeTreeView> list; if (!runtimeTypes.TryGetValue(ns, out list)) { list = new List <TypeTreeView>(); runtimeTypes[ns] = list; } list.Add(item); } foreach (var pair in runtimeTypes) { var categTree = new SelectorCategoryTreeView(pair.Key, "", uNodeEditorUtility.GetUIDFromString("[RT]" + pair.Key), -1); var items = pair.Value; items.ForEach(tree => categTree.AddChild(tree)); namespaceTrees.AddChild(categTree); } } var typeList = editorData.setup.typeList; foreach (var pair in typeList) { var nsTree = new SelectorCategoryTreeView(pair.Key, "", uNodeEditorUtility.GetUIDFromString("[CATEG]" + pair.Key), -1); foreach (var type in pair.Value) { nsTree.AddChild(new TypeTreeView(type, type.GetHashCode(), -1)); } namespaceTrees.AddChild(nsTree); } categories.Add(namespaceTrees); } }
private void DisplayFunctionsTab() { EditorGUIUtility.labelWidth = 135; int functionCount = tree.treeFunctions.Count; // Used in multiple for loops if (GUILayout.Button("Add function")) { GenericMenu addFunctionMenu = new GenericMenu(); addFunctionMenu.AddItem(new GUIContent("Add branch"), false, tree.AddBranchFunction); addFunctionMenu.AddItem(new GUIContent("Add Leafs"), false, tree.AddLeafFunction); addFunctionMenu.AddItem(new GUIContent("Split"), false, tree.AddSplitFunction); addFunctionMenu.AddItem(new GUIContent("Grow"), false, tree.AddGrowFunction); addFunctionMenu.ShowAsContext(); } int rectHeight = functionCount * rectHeightMultiplier; // get the height of the drawing window inside inspector Rect rect = GUILayoutUtility.GetRect(10, 1000, rectHeight, rectHeight); // Create drawing window Event e = Event.current; // Get current event if (e.type == EventType.MouseDown && e.button == 0) // If mouse button is pressed, get button pressed and act accordingly { for (int i = 0; i < functionCount; i++) { TreeFunction tf = tree.treeFunctions[i]; if (tf.rect.Contains(e.mousePosition - rect.position)) { if (tf.type != FunctionType.Trunk && tf.deleteRect.Contains(e.mousePosition - rect.position)) { tree.RemoveFunction(i); UpdateTree(); } else { Undo.RecordObject(target, "Selected function"); tree.selectedFunctionIndex = i; } GUIUtility.ExitGUI(); break; } } } GUI.BeginClip(rect); // Set origin of coordinates to origin of drawing window for (int i = 0; i < functionCount; i++) // Draw each node { TreeFunction tf = tree.treeFunctions[i]; if (tf.type != FunctionType.Trunk && tf.parent == null) { tree.UpdateTreeFunctions(); } tf.Draw(i == tree.selectedFunctionIndex); } GUI.EndClip(); EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginVertical(EditorStyles.helpBox); TreeFunction f = tree.treeFunctions[tree.selectedFunctionIndex]; if (GUILayout.Button("Randomize tree")) { tree.RandomizeTree(); } if (f.type == FunctionType.Trunk) { f.seed = EditorGUILayout.IntField("Seed", f.seed); f.Tlength = EditorGUILayout.FloatField("Length", f.Tlength); f.Tlength = Mathf.Max(0.01f, f.Tlength); f.TradiusMultiplier = EditorGUILayout.FloatField("Radius", f.TradiusMultiplier); f.Tresolution = EditorGUILayout.FloatField("Resolution", f.Tresolution); f.Tresolution = Mathf.Max(.01f, f.Tresolution); f.ToriginAttraction = EditorGUILayout.Slider("Axis attraction", f.ToriginAttraction, 0, 1); f.Tradius = EditorGUILayout.CurveField("Shape", f.Tradius); f.TradiusMultiplier = Mathf.Max(0.0001f, f.TradiusMultiplier); f.Trandomness = EditorGUILayout.Slider("Randomness", f.Trandomness, 0f, 0.5f); f.TdisplacementStrength = EditorGUILayout.FloatField("Displacement strength", f.TdisplacementStrength); f.TdisplacementSize = EditorGUILayout.FloatField("Displacement size", f.TdisplacementSize); f.TspinAmount = EditorGUILayout.FloatField("Spin amount", f.TspinAmount); f.TheightOffset = EditorGUILayout.FloatField("Height Offset", f.TheightOffset); EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.LabelField("Root"); f.TrootShape = EditorGUILayout.CurveField("Root shape", f.TrootShape); f.TrootHeight = EditorGUILayout.FloatField("Height", f.TrootHeight); f.TrootHeight = Mathf.Max(.01f, f.TrootHeight); f.TrootRadius = EditorGUILayout.Slider("Root Radius", f.TrootRadius, 0, 2); f.TrootResolution = EditorGUILayout.FloatField("Additional Resolution", f.TrootResolution); f.TrootResolution = Mathf.Max(1, f.TrootResolution); f.TflareNumber = EditorGUILayout.IntSlider("Flare Number", f.TflareNumber, 0, 10); EditorGUILayout.EndVertical(); } else if (f.type == FunctionType.Grow) { f.seed = EditorGUILayout.IntField("Seed", f.seed); EditorGUILayout.BeginHorizontal(); f.Glength = EditorGUILayout.FloatField("Length", f.Glength); f.GlengthCurve = EditorGUILayout.CurveField(f.GlengthCurve); EditorGUILayout.EndHorizontal(); f.Glength = Mathf.Max(.001f, f.Glength); f.Gresolution = EditorGUILayout.FloatField("Resolution", f.Gresolution); f.Gresolution = Mathf.Max(f.Gresolution, .01f); EditorGUILayout.BeginHorizontal(); f.GsplitProba = EditorGUILayout.Slider("Split proba", f.GsplitProba, 0, 1); f.GsplitProbaCurve = EditorGUILayout.CurveField(f.GsplitProbaCurve); EditorGUILayout.EndHorizontal(); f.GsplitAngle = EditorGUILayout.Slider("Split angle", f.GsplitAngle, 0, 2); f.Gradius = EditorGUILayout.CurveField("Shape", f.Gradius); f.GsplitRadius = EditorGUILayout.Slider("Split radius", f.GsplitRadius, .5f, .999f); f.GmaxSplits = EditorGUILayout.IntSlider("Max splits at a time", f.GmaxSplits, 2, 4); f.Grandomness = EditorGUILayout.Slider("Randomness", f.Grandomness, 0, 1); f.GupAttraction = EditorGUILayout.Slider("Up attraction", f.GupAttraction, 0, 1f); f.GgravityStrength = EditorGUILayout.FloatField("Gravity strength", f.GgravityStrength); } else if (f.type == FunctionType.Split) { f.seed = EditorGUILayout.IntField("Seed", f.seed); f.Snumber = EditorGUILayout.IntField("Number", f.Snumber); f.Snumber = Mathf.Max(0, f.Snumber); f.SsplitAngle = EditorGUILayout.Slider("Split angle", f.SsplitAngle, 0, 2); f.SmaxSplits = EditorGUILayout.IntSlider("Max splits at a time", f.SmaxSplits, 1, 10); f.SsplitRadius = EditorGUILayout.Slider("split radius", f.SsplitRadius, 0.001f, 1); f.Sstart = EditorGUILayout.Slider("Start", f.Sstart, 0f, 1f); f.Sspread = EditorGUILayout.Slider("Height spread", f.Sspread, 0, 1); } else if (f.type == FunctionType.Branch) { f.seed = EditorGUILayout.IntField("Seed", f.seed); f.Bnumber = EditorGUILayout.IntField("Number", f.Bnumber); f.Bnumber = Mathf.Max(0, f.Bnumber); EditorGUILayout.BeginHorizontal(); f.Blength = EditorGUILayout.FloatField("Length", f.Blength); f.Blength = Mathf.Max(f.Blength, .001f); f.BlengthCurve = EditorGUILayout.CurveField(f.BlengthCurve); EditorGUILayout.EndHorizontal(); f.Bresolution = EditorGUILayout.FloatField("Resolution", f.Bresolution); f.Bresolution = Mathf.Max(f.Bresolution, .01f); f.Brandomness = EditorGUILayout.Slider("Randomness", f.Brandomness, 0, 1); f.Bradius = EditorGUILayout.Slider("Radius", f.Bradius, 0.001f, 1); EditorGUILayout.BeginHorizontal(); f.BsplitProba = EditorGUILayout.Slider("Split proba", f.BsplitProba, 0, 1); f.BsplitProbaCurve = EditorGUILayout.CurveField(f.BsplitProbaCurve); EditorGUILayout.EndHorizontal(); f.BmaxSplits = EditorGUILayout.IntSlider("Max splits number", f.BmaxSplits, 1, 5); f.Bangle = EditorGUILayout.Slider("Angle", f.Bangle, 0, 2); f.BupAttraction = EditorGUILayout.Slider("Up attraction", f.BupAttraction, 0, 1); f.BgravityStrength = EditorGUILayout.FloatField("Gravity strength", f.BgravityStrength); f.Bstart = EditorGUILayout.Slider("Start", f.Bstart, 0f, 1f); } else if (f.type == FunctionType.Leaf) { if (f.LleafTypesNames == null || f.LleafTypesNames.Length == 5) { f.LleafTypesNames = new string[6] { "cross", "diamond cross", "diamond", "long", "plane", "custom" } } ; f.LleafType = EditorGUILayout.Popup(f.LleafType, f.LleafTypesNames); Mesh[] leafMesh = null; switch (f.LleafType) { case 0: leafMesh = new Mesh[] { Resources.LoadAll <Mesh>("Mtree/branches")[0] }; break; case 1: leafMesh = new Mesh[] { Resources.LoadAll <Mesh>("Mtree/branches")[1] }; break; case 2: leafMesh = new Mesh[] { Resources.LoadAll <Mesh>("Mtree/branches")[2], Resources.LoadAll <Mesh>("Mtree/branches")[3] }; break; case 3: leafMesh = new Mesh[] { Resources.LoadAll <Mesh>("Mtree/branches")[4], Resources.LoadAll <Mesh>("Mtree/branches")[5] }; break; case 4: leafMesh = new Mesh[] { Resources.LoadAll <Mesh>("Mtree/branches")[6] }; break; case 5: leafMesh = new Mesh[] { (Mesh)EditorGUILayout.ObjectField("Mesh: ", f.LleafMesh[0], typeof(Mesh), false) }; break; } f.LleafMesh = leafMesh; f.Lnumber = EditorGUILayout.IntField("number", f.Lnumber); f.Lnumber = Mathf.Max(f.Lnumber, 0); f.Lsize = EditorGUILayout.FloatField("Size", f.Lsize); f.Lsize = Mathf.Max(0, f.Lsize); f.LmaxRadius = EditorGUILayout.Slider("Max branch radius", f.LmaxRadius, 0, 1); f.LmaxRadius = Mathf.Max(0.001f, f.LmaxRadius); EditorGUILayout.MinMaxSlider("leafs weight", ref f.LminWeight, ref f.LmaxWeight, -1, 1); f.LoverrideNormals = EditorGUILayout.Toggle("Override Normals", f.LoverrideNormals); } EditorGUILayout.EndVertical(); if (EditorGUI.EndChangeCheck()) { UpdateTree(); } }
public void Register(string name, TreeFunction fun) { _treefun[name] = fun; }