public void Write(object result) { TransitionsList trns = (TransitionsList)result; int childCount = parent.childCount; int c = 0; for (int t = 0; t < trns.count; t++) { Transform tfm; if (c >= childCount) { if (objPrefab == null) { tfm = GameObject.CreatePrimitive(PrimitiveType.Sphere).transform; } else { tfm = GameObject.Instantiate(objPrefab); } } else { tfm = parent.GetChild(c); } tfm.position = trns.arr[t].pos; tfm.localScale = trns.arr[t].scale; tfm.rotation = trns.arr[t].rotation; tfm.parent = parent; c++; } }
public override void Generate(TileData data, StopToken stop) { if (!enabled) { return; } MatrixWorld probMatrix = data.ReadInletProduct(this); if (factor < float.Epsilon) { factor = 1; } Noise random = new Noise(data.random, seed); float square = data.area.active.worldSize.x * data.area.active.worldSize.z; //note using the real size, density should not depend on margins float count = square * (density / 1000000); //number of items per terrain PosTab posTab = new PosTab((Vector3)data.area.full.worldPos, (Vector3)data.area.full.worldSize * factor, 16); RandomScatter((int)count, uniformity, (Vector3)data.area.full.worldPos, (Vector3)data.area.full.worldSize * factor, posTab, random, probMatrix, stop: null); TransitionsList transitions = posTab.ToTransitionsList(); data.StoreProduct(this, transitions); }
public override void Generate(TileData data, StopToken stop) { SplineSys splineSys = data.ReadInletProduct(this); if (splineSys == null || !enabled) { return; } if (stop != null && stop.stop) { return; } SplineSys bend = new SplineSys(splineSys); var objs = new TransitionsList(); foreach (var item in bend.GetAllPoints(resPerUnit: 1).SelectMany(list => list)) { objs.Add(new Transition { pos = item }); } if (stop != null && stop.stop) { return; } data.StoreProduct(this, objs); }
public void SetObject(TransitionsList posTab, MatrixWorld heights, Area area) { this.trns = posTab; this.heights = heights; this.worldPos = (Vector3)area.active.worldPos; this.worldSize = (Vector3)area.active.worldSize; Stage = PreviewStage.Generating; ThreadManager.Enqueue(ExecuteInThread, priority: -1000); }
public void Write(object result) { trns = (TransitionsList)result; #if UNITY_EDITOR #if UNITY_2019_1_OR_NEWER UnityEditor.SceneView.duringSceneGui -= DrawGizmos; UnityEditor.SceneView.duringSceneGui += DrawGizmos; #else UnityEditor.SceneView.onSceneGUIDelegate -= DrawGizmos; UnityEditor.SceneView.onSceneGUIDelegate += DrawGizmos; #endif #endif }
//[Val("Starting Id")] public int startId = 0; public object Read(CoordRect worldRect, float worldHeight, CoordRect pixelRect) { int childCount = parent.childCount; TransitionsList trns = new TransitionsList(); for (int c = 0; c < childCount; c++) { Transform child = parent.GetChild(c); Transition trs = new Transition(child); trns.Add(trs); } return(trns); }
public static ITestInput CreateTestInput(GameObject go, IInlet <TransitionsList> inlet, TransitionsList trsList) { Mesh mesh = new Mesh(); mesh.vertices = new Vector3[] { new Vector3(-.5f, -.5f, -.5f), new Vector3(.5f, -.5f, -.5f), new Vector3(.5f, .5f, -.5f), new Vector3(-.5f, .5f, -.5f), new Vector3(-.5f, .5f, .5f), new Vector3(.5f, .5f, .5f), new Vector3(.5f, -.5f, .5f), new Vector3(-.5f, -.5f, .5f) }; mesh.triangles = new int[] { 0, 2, 1, 0, 3, 2, 2, 3, 4, 2, 4, 5, 1, 2, 5, 1, 5, 6, 0, 7, 4, 0, 4, 3, 5, 4, 7, 5, 7, 6, 0, 6, 7, 0, 1, 6 }; for (int t = 0; t < trsList.count; t++) { GameObject trsGo = new GameObject(); MeshRenderer renderer = trsGo.AddComponent <MeshRenderer>(); MeshFilter filter = trsGo.AddComponent <MeshFilter>(); filter.mesh = mesh; trsGo.transform.localScale = new Vector3(5, 5, 5); trsGo.name = "Object" + t; trsGo.transform.position = trsList.arr[t].pos; trsGo.transform.parent = go.transform; } ObjectsIn objsIn = new ObjectsIn() { parent = go.transform }; return(objsIn); }
private void RenderOutlet(TileData data, AOTABundle bundle, Dictionary <string, ulong> OutletFullList) { ulong matchingId; foreach (var splineSys in bundle.SplineSysBundle) { // Check the list is properly formatted. Could be removed... if you are confident. if (!OutletFullList.ContainsKey(splineSys.outletName)) { Debug.LogFormat("{0} {1} not found initialised in the {2}", nameof(matchingId), splineSys.outletName, nameof(OutletFullList)); continue; } else { // item.outletName // should match the entry in OutletFullList matchingId = OutletFullList[splineSys.outletName]; } if (splineSys.splineSys.lines.Length > 0) { //Debug.LogFormat("{6} has {7} lines at tile {8}, first line goes from {0},{1},{2} to {3},{4},{5} ", // splineSys.splineSys.lines[0].segments[0].start.pos.x, // splineSys.splineSys.lines[0].segments[0].start.pos.y, // splineSys.splineSys.lines[0].segments[0].start.pos.z, // splineSys.splineSys.lines[0].segments[0].end.pos.x, // splineSys.splineSys.lines[0].segments[0].end.pos.y, // splineSys.splineSys.lines[0].segments[0].end.pos.z, // splineSys.outletName, // splineSys.splineSys.lines.Length, // data.area.Coord // ); // now we know the Id. go populate it. foreach (var outlet in Outlets()) { if (outlet.Id == matchingId) { // splineSys.splineSys.Clamp((Vector3)data.area.full.worldPos, (Vector3)data.area.full.worldSize); data.StoreProduct(outlet, splineSys.splineSys); } } } // else // Debug.LogFormat("Outlet {0} has {1} lines", splineSys.outletName, splineSys.splineSys.lines.Length); } // We only render the objects in the last gasp. (Main Pass) //if (data.isDraft) //{ // return; //} foreach (var objectList in bundle.TransitionsListBundle) { if (RoadOnly) { continue; } if (OutletFullList.ContainsKey(objectList.outletName)) { // item.outletName // should match the entry in OutletFullList matchingId = OutletFullList[objectList.outletName]; } else { Debug.LogFormat("{0} {1} not found initialised in the {2}", nameof(matchingId), objectList.outletName, nameof(OutletFullList)); continue; } if (objectList.transitionsList.count > 0) { // now we know the Id. go populate it. foreach (var outlet in Outlets()) { if (outlet.Id == matchingId) { // Bodge the city size into the object // 0,0 is shared between the corner of 4 tiles. so expect at least 4 if (objectList.outletName == "centerOut") { var hinum = (double)Mathf.Max((TownGlobalObjectService.PatchCap + 10), (TownGlobalObject.bundles[data.area.Coord].town.Options.Patches)); var magic = (float)(1 / (hinum / (double)TownGlobalObject.bundles[data.area.Coord].town.Options.Patches)); objectList.transitionsList.arr[0].scale = new Vector3(magic, magic, magic); // Store the single case. for the absolute town center if (data.area.Coord == TownGlobalObject.GetIndexAtCoord(data.area.Coord)) { var location = Outlets().Where(x => x.Id == singlecenterOut.Id).First(); objectList.transitionsList.arr = objectList.transitionsList.arr.Truncated(objectList.transitionsList.count); data.StoreProduct( location, objectList.transitionsList); } } objectList.transitionsList.arr.Truncated(objectList.transitionsList.count); // foreach (var item in objectList.transitionsList.arr) // { // if (!data.area.active.Contains(item.pos)) continue; // } TransitionsList cleaner = new TransitionsList(); if (objectList.outletName == "gatehouseSplineOut") { Debug.Log(objectList.transitionsList.arr.Length + " gatehouseSplines on this tile"); } //for (int i = 0; i < objectList.transitionsList.arr.Length; i++) // { // if (data.area.active.Contains(objectList.transitionsList.arr[i].pos)) // { // cleaner.Add( objectList.transitionsList.arr[i]); // } // } data.StoreProduct(outlet, objectList.transitionsList); // data.StoreProduct(outlet, cleaner); } } } // else // Debug.LogFormat("Outlet {0} has {1} objects", objectList.outletName, objectList.transitionsList.count); } // Let's shove it all in the list. }
/// <summary> /// Create an unnamed wrapper. The outletName must match the declaration name of the outlet in the class calling Generate /// </summary> /// <param name="sys">The TransitionsList as used at runtime time</param> /// <param name="outlet">The outlet variable name as defined at declaration</param> public TransitionsListWrapper(TransitionsList sys, string outletname) { this.outletName = outletname; this.transitionsList = new TransitionsList(sys); }
//public TransitionsListWrapper(string name) //{ // this.transitionsList = new TransitionsList(); // this.name = name; // this.outletName = string.Empty; //} //public TransitionsListWrapper(TransitionsList list) //{ // this.transitionsList = new TransitionsList(list); //} ///// <summary> ///// remember to fully populate this... ///// </summary> ///// <param name="name">the name of the list as a variable</param> ///// <param name="list">the list to copy from</param> //public TransitionsListWrapper(string name, TransitionsList list) //{ // this.transitionsList = new TransitionsList(list); // this.name = name; //} //public TransitionsListWrapper(TransitionsList sys, MapMagic.Nodes.Outlet<TransitionsList> outlet) //{ // this.transitionsList = new TransitionsList(sys); // this.outlet = outlet; //} public TransitionsListWrapper(string name, TransitionsList sys, MapMagic.Nodes.Outlet <TransitionsList> outlet) { this.outlet = outlet; this.transitionsList = new TransitionsList(sys); this.name = name; }
public TransitionsListWrapper() { this.transitionsList = new TransitionsList(); this.name = string.Empty; this.outletName = string.Empty; }
private void GetUsedObjects(DrawingSheet sheet, VariableCollection variables) { if (sheet is ModelSheet model) { UsedModels.Add(model); } else { UsedSheets.Add(sheet); } foreach (DrawableObject obj in sheet.Sketch.Objects) { if (obj is Relation indir) { Variable input = VariableCollection.GetIndirectInput(sheet, indir.Trigger); Variable output = VariableCollection.GetIndirectOutput(sheet, indir.Output); if (input == null) { MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Relation trigger variable not found.", indir)); } if (output == null) { MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Relation output variable not found.", indir)); } if (input != null && output != null) { BasicRelation ibindir = RelationsList.FirstOrDefault(ind => ind.Input.Name == input.Name); BasicRelation obindir = RelationsList.FirstOrDefault(ind => ind.Action.Output.Name == input.Name); if (ibindir != null) { MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Relation has same input than other one.", indir, ibindir.Relation)); } if (obindir != null) { MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Relation has same output than other one.", indir, obindir.Relation)); } if (ibindir == null && obindir == null) { BasicOutput action = indir.Action == null ? null : new BasicOutput((OperationType)Enum.Parse(typeof(OperationType), indir.Action), output); BasicRelation bindir = new BasicRelation(indir, input, action); RelationsList.Add(bindir); } } } else if (obj is Equation eq) { IInternalOutput output = variables.IndirectOutputs.FirstOrDefault(io => io.Name == eq.AssignTo); if (output == null) { MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Relation trigger variable not found.", eq)); } if (eq.Operation == "") { MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Equation does not have operation.", eq)); } LexicalAnalyzer lexAnalyzer = new LexicalAnalyzer(); SyntaxAnalyzer syntaxAnalyzer; lexAnalyzer.Source = eq.Operation; syntaxAnalyzer = new SyntaxAnalyzer(lexAnalyzer, VariableCollection.GetConditionDictionary(eq.OwnerDraw.OwnerSheet).Keys.ToList()); foreach (SyntaxToken token in syntaxAnalyzer.Tokens) { if (token.Qualifier != SyntaxToken.Qualifiers.Correct) { MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, string.Format("{0}: {1}.", eq.Name, token.ToString()), eq)); } } EquationsList.Add(new BasicEquation(eq)); } else if (obj is Transition trans) { TransitionsList.Add(trans); if (trans.StartObject == null) { MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Transition without start connection.", trans)); } if (trans.EndObject == null) { MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Transition without end connection.", trans)); } if (trans is SimpleTransition strans && strans.Condition == "" && strans.Timeout == 0) { if (strans.StartObject is Origin origin) { if (strans.EndObject is End || strans.EndObject is Abort) { MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "One shot machine Transition should have a condition.", trans)); } } else if (!strans.DefaultTransition) { MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Transition does not have condition or timeout value.", trans)); } } else if (trans is SuperTransition sptrans && sptrans.Links == "") { MessagesList.Add(new CheckMessage(CheckMessage.MessageTypes.Error, "Transition is not linking any object.", trans)); } }