public override void _Ready() { base._Ready(); particles = GetNode <SceneCPUParticles>($"SceneCPUParticles{ObjectID.y}"); particles.ParticleParams = $"{ObjectID.y}"; CurrentData = ID2Data[ObjectID.y]; startSpawnDelay(CurrentData.min_time / 2f, CurrentData.max_time / 2f); }
static Leaf() { ID2Data = new Dictionary <int, LeafData>(); ID2Data[1] = new LeafData(1f, 3f); ID2Data[6] = new LeafData(.5f, 5f); ID2Data[10] = new LeafData(1f, 8f); ID2Data[12] = new LeafData(1f, 3f); }
// Use this for initialization void Start() { LeafData root = new LeafData(); root.parent = null; root.Start(); insert(root); insert(root); insert(root); }
protected override void OnClick(NodeData node, LeafData nullableLeaf, bool isDoubleClick) { if (nullableLeaf == null) { Debug.Log("click node=" + node.GetName() + ", isDoubleClick=" + isDoubleClick); } else { Debug.Log("click leaf=" + nullableLeaf.GetName() + ", isDoubleClick=" + isDoubleClick); } }
/// <summary> /// Finds leaf objects (Shape, Wire and Cable instances) given parent /// game object. /// </summary> /// <param name="parent">Parent game object.</param> /// <param name="searchChildren">True to search in children, false to only collect data in <paramref name="parent"/>.</param> /// <returns>Collections of shapes, wires and cables.</returns> public static LeafData LeafObjects(GameObject parent, bool searchChildren) { var data = new LeafData(); if (parent == null) { return(data); } var rb = parent.GetComponent <RigidBody>(); var shape = rb != null ? null : parent.GetComponent <Collide.Shape>(); var wire = rb != null || shape != null ? null : parent.GetComponent <Wire>(); var cable = rb != null || shape != null || wire != null ? null : parent.GetComponent <Cable>(); bool allPredefinedAreNull = rb == null && shape == null && wire == null && cable == null; if (allPredefinedAreNull && searchChildren) { data.Shapes = parent.GetComponentsInChildren <Collide.Shape>(); data.Wires = parent.GetComponentsInChildren <Wire>(); data.Cables = parent.GetComponentsInChildren <Cable>(); } // A wire is by definition independent of PropagateToChildren, since // it's not defined to add children to a wire game object. else if (wire != null) { data.Wires = new Wire[] { wire }; } // Same logics for Cable. else if (cable != null) { data.Cables = new Cable[] { cable }; } // Bodies have shapes so if 'rb' != null we should collect all shape children // independent of 'propagate' flag. // If 'shape' != null and propagate is true we have the same condition as for bodies. else if (rb != null || shape != null || (rb == null && shape == null && searchChildren)) { data.Shapes = shape != null && !searchChildren?parent.GetComponents <Collide.Shape>() : shape != null || rb != null?parent.GetComponentsInChildren <Collide.Shape>() : // Both shape and rb == null and PropagateToChildren == true. parent.GetComponentsInChildren <Collide.Shape>(); } else { // These groups has no effect. Debug.LogWarning("No leaf objects found. Are you missing a searchChildren = true?", parent); } return(data); }
private float DistributeLeafPosition(int leafCount, int i, LeafData leafData) { if (leafData.isFixed) { return(leafData.FixedPosition); } else { Vector2 positionRange = leafData.PositionRange; float positionRandomPercentage = leafData.PositionRandomPercentage; float range = positionRange.y - positionRange.x; float interval = range / leafCount; float random = Util.RandomRange(positionRandomPercentage); return(positionRange.x + (interval * i) + (interval * random)); } }
public LBVH.Node[] Build(List <IEntity> ents) { if (ents.Count == 0 || ents[0] == null) { return(null); } bvh = new LBVH((uint)ents.Count); //nodes = new BVHNode[nodeCount]; leafData = new LeafData[bvh.LeafCount]; mortonCodes = new uint[bvh.LeafCount]; // compute global AABB AABB globalBounds = new AABB(); for (int i = 0; i < bvh.LeafCount; ++i) { AABB tb = AABB.Transform(ents[i].Bounds, ents[i].Transform); leafData[i] = new LeafData(ents[i], i, tb); if (i == 0) { globalBounds = tb; } else { globalBounds.AssignUnion(tb); } } // compute morton index for each leaf for (int i = 0; i < bvh.LeafCount; ++i) { mortonCodes[i] = getMortonCode( globalBounds.NormalizePoint(leafData[i].bounds.Mean)); } // sort leaf data by morton index Array.Sort(mortonCodes, leafData); processRange(mortonCodes, leafData, 0, bvh.LeafCount - 1); return(bvh.Nodes); }
void insert(LeafData node) { // LeafData leaf = Instantiate(); // Leaf leaf = Instantiate(L); treeDepth++; if(node.left != null) { print("ASEREJE"); insert(node.left); } else { node.left = new LeafData(); node.left.parent = node; node.left.Start(); print(node.left.ToString()); } if(node.right != null) { print("ASEREJE"); insert(node.right); } else { node.right = new LeafData(); node.right.parent = node; node.right.Start(); print(node.right.ToString()); } // if(ld.right ) }
protected override void OnClick(NodeData node, LeafData nullableLeaf, bool isDoubleClick) { if (nullableLeaf == null) { var sn = node as SimpleNode; if (sn != null) { var di = sn.attach as ABAssetinfos.AssetInfo; if (di != null) { var obj = AssetDatabase.LoadMainAssetAtPath(di.asset); if (isDoubleClick) { EditorGUIUtility.PingObject(obj); } else { Selection.activeObject = obj; } } } } }
/// <summary> /// /// </summary> /// <param name="xml"></param> /// <param name="update"></param> /// <returns></returns> private string UpdateXml(string xml, LeafData update) { try { TreeNode node = new TreeNode(); var xDoc = XDocument.Parse(xml); XElement table = xDoc.Elements().First(); int i = 0; foreach (var ele in table.Elements()) { if (ele.HasElements) { if (i == update.rowNum) { UpdateElement(ele, update); } i++; } else { if (ele.Name.LocalName.Equals(update.colName)) { ele.Value = update.newValue; break; } } } xml = xDoc.ToString(); return(xml); } catch { throw; } }
/// <summary> /// /// </summary> /// <param name="element"></param> /// <param name="update"></param> private void UpdateElement(XElement element, LeafData update) { try { if (element.HasElements) { foreach (var ele in element.Elements()) { UpdateElement(ele, update); } } else { if (element.Name.LocalName.Equals(update.colName)) { element.Value = update.newValue; } } } catch { throw; } }
/// <summary> /// Finds leaf objects (Shape, Wire and Cable instances) given parent /// game object. /// </summary> /// <param name="parent">Parent game object.</param> /// <param name="searchChildren">True to search in children, false to only collect data in <paramref name="parent"/>.</param> /// <returns>Collections of shapes, wires and cables.</returns> public static LeafData LeafObjects(GameObject parent, bool searchChildren) { var data = new LeafData(); if (parent == null) { return(data); } var rb = parent.GetComponent <RigidBody>(); var shape = rb != null ? null : parent.GetComponent <Collide.Shape>(); var wire = rb != null || shape != null ? null : parent.GetComponent <Wire>(); var cable = rb != null || shape != null || wire != null ? null : parent.GetComponent <Cable>(); // Possible to have multiple tracks per game object. var tracks = rb != null || shape != null || wire != null || cable != null ? null : parent.GetComponents <Model.Track>(); if (tracks != null && tracks.Length == 0) { tracks = null; } var terrain = rb != null || shape != null || wire != null || cable != null || tracks != null ? null : parent.GetComponent <Model.DeformableTerrain>(); bool allPredefinedAreNull = rb == null && shape == null && wire == null && cable == null && terrain == null; // If tracks != null && search children we collect all children // since track component may be "anywhere". if (allPredefinedAreNull && searchChildren) { data.Shapes = parent.GetComponentsInChildren <Collide.Shape>(); data.Wires = parent.GetComponentsInChildren <Wire>(); data.Cables = parent.GetComponentsInChildren <Cable>(); data.Tracks = parent.GetComponentsInChildren <Model.Track>(); data.Terrains = parent.GetComponentsInChildren <Model.DeformableTerrain>(); } // A wire is by definition independent of PropagateToChildren, since // it's not defined to add children to a wire game object. else if (wire != null) { data.Wires = new Wire[] { wire }; } // Same logics for Cable. else if (cable != null) { data.Cables = new Cable[] { cable }; } else if (tracks != null) { data.Shapes = CollectShapes(parent, rb, shape, searchChildren); data.Tracks = searchChildren ? parent.GetComponentsInChildren <Model.Track>() : tracks; } else if (terrain != null) { data.Terrains = searchChildren ? parent.GetComponentsInChildren <Model.DeformableTerrain>() : new Model.DeformableTerrain[] { terrain }; } // Bodies have shapes so if 'rb' != null we should collect all shape children // independent of 'propagate' flag. // If 'shape' != null and propagate is true we have the same condition as for bodies. else if (rb != null || shape != null || (rb == null && shape == null && searchChildren)) { data.Shapes = CollectShapes(parent, rb, shape, searchChildren); } else { // These groups has no effect. It's not possible to issue warning // where when CollisionGroups.Initialize searches both with // searchChildren = false and searchChildren = true regardless // of the collision group "Propagate to children" state. } return(data); }
private List <LeafLocalData> DistributeLeafLocalData(LeafGrowRelation leafGrowRelation, LeafData SproutLeafData, LeafData GrownLeafData, ColorData colorData) { List <LeafLocalData> dataList = new List <LeafLocalData>(); int TotalLeafCount = Util.RandomRange(GrownLeafData.CountRange); int TotalSproutLeafCount = Util.RandomRange(SproutLeafData.CountRange); for (int i = 0; i < TotalLeafCount; i++) { LeafLocalData data = new LeafLocalData(); data.LeafIndex = i; data.TotalLeafCount = TotalLeafCount; //TODO use DistributeLeafRotations data.Rotation = Util.RandomRange(180f); data.FinalPosition = DistributeLeafPosition(TotalLeafCount, i, GrownLeafData); data.SproutPosition = leafGrowRelation == LeafGrowRelation.Same ? data.FinalPosition : DistributeLeafPosition(TotalLeafCount, i, SproutLeafData); data.FinalScale = GrownLeafData.BaseScale + Util.RandomRange(GrownLeafData.ScaleRandomValue); data.SproutScale = SproutLeafData.BaseScale + Util.RandomRange(SproutLeafData.ScaleRandomValue); data.leafColor = !colorData.isRandom ? colorData.Color : Util.GetColorFromRange(colorData.ColorRange1, colorData.ColorRange2); data.isSprout = i < TotalSproutLeafCount ? true : false; dataList.Add(data); } return(dataList); }
protected void OnGUI() { if (data == null) { return; } //TAB EditorGUILayout.BeginHorizontal(); var tabnames = new List <string>(); for (int i = 0; i < data.GetTabCount(); i++) { tabnames.Add(data.GetTab(i).GetName()); } if (tabnames.Count == 0) { return; } if (selectedTabIndex >= tabnames.Count) { selectedTabIndex = 0; } selectedTabIndex = ToolUtils.Tabs(tabnames.ToArray(), selectedTabIndex, false, 50, false); searchKeyword = EditorGUILayout.TextField("", searchKeyword, GUILayout.MinWidth(100)); bool isCmd = searchKeyword.StartsWith("!"); if (isCmd) { var cmd = searchKeyword.Substring(1); if (cmd.Equals("+")) { var thisTab = data.GetTab(selectedTabIndex); for (int j = 0; j < thisTab.GetNodeCount(); j++) { var node = thisTab.GetNode(j); node.expand = true; } } else if (cmd.Equals("-")) { var thisTab = data.GetTab(selectedTabIndex); for (int j = 0; j < thisTab.GetNodeCount(); j++) { var node = thisTab.GetNode(j); node.expand = false; } } else { OnCmd(cmd); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos); EditorGUILayout.BeginVertical(); //每行占18像素,Tab行也占18像素高度 int firstIndex = (int)(scrollPos.y / 18); int excludeLastIndex = firstIndex + viewCount; GUILayout.Space(firstIndex * 18); int index = 0; var tab = data.GetTab(selectedTabIndex); for (int j = 0; j < tab.GetNodeCount(); j++) { var node = tab.GetNode(j); bool nodeHit = isCmd || node.Hit(searchKeyword); if (nodeHit || node.IsChildrenHit(searchKeyword)) { index++; if (index > firstIndex && index < excludeLastIndex) { var foldpos = GUILayoutUtility.GetRect(18, 18); foldpos.width = 18; var style = selectedNodeData == node ? EditorStyles.whiteLabel : EditorStyles.label; node.expand = EditorGUI.Foldout(foldpos, node.expand, ""); var btnpos = new Rect(foldpos.x + foldpos.width, foldpos.y, position.width - foldpos.width, foldpos.height); if (GUI.Button(btnpos, node.GetName(), style)) { OnClick(node, null, false); var delta = watcher.ElapsedMilliseconds; if (delta < 500 && selectedNodeData == node) { OnClick(node, null, true); } selectedNodeData = node; selectedLeafData = null; watcher.Reset(); watcher.Start(); } } if (node.expand) { for (int k = 0; k < node.GetLeafCount(); k++) { var leaf = node.GetLeaf(k); if (nodeHit || leaf.Hit(searchKeyword)) { index++; if (index > firstIndex && index < excludeLastIndex) { var estyle = selectedLeafData == leaf ? EditorStyles.whiteLabel : EditorStyles.label; if (GUILayout.Button(" " + leaf.GetName(), estyle, GUILayout.Height(18))) { OnClick(node, leaf, false); var delta = watcher.ElapsedMilliseconds; if (delta < 500 && selectedLeafData == leaf) { OnClick(node, leaf, true); } selectedNodeData = null; selectedLeafData = leaf; watcher.Reset(); watcher.Start(); } } } } } } } var space = (index - viewCount - firstIndex) * 18; if (space < 0) { space = 0; } GUILayout.Space(space); EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); if (Event.current.type == EventType.repaint) { var viewSize = GUILayoutUtility.GetLastRect(); int newViewcount = (int)(viewSize.height / 18) + 1; viewCount = newViewcount; } }
protected abstract void OnClick(NodeData node, LeafData nullableLeaf, bool isDoubleClick);