public void ConvertDeprecatedTreeFunctions() { treeFunctionsAssets = new List <TreeFunctionAsset>(); if (treeFunctions == null) { return; } List <int> functionIds = new List <int>(); foreach (TreeFunction function in treeFunctions) { TreeFunctionAsset parent = null; if (function.type != FunctionType.Trunk && function.id != -1) { int parentIndex = functionIds.IndexOf(function.parentId); if (parentIndex != -1) { parent = treeFunctionsAssets[parentIndex]; } } TreeFunctionAsset convertedFunction = function.ToFunctionAsset(parent); treeFunctionsAssets.Add(convertedFunction); functionIds.Add(function.id); } GenerateTree(); }
private void AddTreeFunction(TreeFunctionAsset function) { Undo.RecordObjects(treeFunctionsAssets.ToArray(), "Added function"); Undo.RecordObject(this, "Added function"); Undo.RegisterCreatedObjectUndo(function, "Added function"); TreeFunctionAsset parent = treeFunctionsAssets.Count == 0 ? null : treeFunctionsAssets[selectedFunctionIndex]; function.Init(parent); selectedFunctionIndex = treeFunctionsAssets.Count; treeFunctionsAssets.Add(function); }
public void RemoveFunction(TreeFunctionAsset function) { Undo.RecordObjects(treeFunctionsAssets.ToArray(), "Removed function"); Undo.RecordObject(this, "Removed function"); treeFunctionsAssets.Remove(function); function.parent.chiildren.Remove(function); foreach (TreeFunctionAsset child in function.chiildren) { child.parent = function.parent; child.parent.chiildren.Add(child); } selectedFunctionIndex = function.parent == null ? 0 : treeFunctionsAssets.IndexOf(function.parent); Undo.DestroyObjectImmediate(function); }
public void FromTemplate() { if (template == null) { return; } treeFunctionsAssets.Clear(); for (int i = 0; i < template.treeFunctions.Count; i++) { TreeFunctionAsset function = Instantiate(template.treeFunctions[i]); treeFunctionsAssets.Add(function); } for (int i = 0; i < template.treeFunctions.Count; i++) { int parentIndex = template.treeFunctions.IndexOf(template.treeFunctions[i].parent); TreeFunctionAsset parent = parentIndex == -1 ? null : treeFunctionsAssets[parentIndex]; treeFunctionsAssets[i].Init(parent, true); } }