public async void CloseEditor() { // Leave scene if it's a tutorial (and it's loaded) //if (SceneData.IsTutorial && SceneData.LoadedScene) //{ // SceneManager.LoadScene("Menu"); // return; //} UsingEditor = !UsingEditor; if (currentClonedObject != null) { ReleaseCodeBlock(Input.mousePosition); await Task.Delay(0); } currentScriptObject.SetParent(scripts, false); currentScriptObject = null; beginEvent = null; }
public void OpenScript(SelectableObject obj) { if (currentScriptObject) { CloseEditor(); } UsingEditor = true; if (obj.Script != null) { currentScriptObject = obj.Script.transform; beginEvent = obj.Script.beginEvent; currentScriptObject.SetParent(codeScrollContent, false); currentScriptObject.GetComponent <RectTransform>().anchoredPosition = new Vector2(8, -8); currentScriptObject.SetAsFirstSibling(); } else { var newScript = Instantiate(scriptPrefab, codeScrollContent); var r = newScript.GetComponent <RectTransform>(); r.anchoredPosition = new Vector2(8, -8); r.SetAsFirstSibling(); var script = newScript.GetComponent <SavedScript>(); script.obj = obj; obj.Script = script; currentScriptObject = newScript; beginEvent = script.beginEvent; } codeScrollContent.anchoredPosition = Vector2.zero; otherCodeTransform = (RectTransform)obj.Script.transform.Find("OtherCode"); // Todo: Check if size needs to be updated first ReconnectAll(); }
public HasEvents CreateCode(B_BeginEvent startEvent) { var currentEvent = startEvent.NextConnection; if (currentEvent == null) { return(new HasEvents()); } // Initialize Variables var variables = new List <CachedValue>(); Variables = new Dictionary <string, object>(); while (currentEvent != null) { if (currentEvent is B_VariableEvent variableEvent) { var name = variableEvent.variableName.text; Variables.Add(name, null); variables.Add(new CachedValue(0f)); } currentEvent = currentEvent.NextConnection; } // Initialize Events after (because some code requires variables) var start = new List <Program>(); var update = new List <Program>(); var collisionEnter = new List <Program>(); var collisionEnd = new List <Program>(); var fixedUpdate = new List <Program>(); var deleted = new List <Program>(); var broadcastPrograms = new Dictionary <string, List <Program> >(); var events = new HasEvents(); currentEvent = startEvent.NextConnection; while (currentEvent != null) { // Todo: Convert to hash map for O(1)? if (currentEvent is B_StartEvent) { start.Add(currentEvent.ConvertToCode()); events.Start = true; } else if (currentEvent is B_UpdateEvent) { update.Add(currentEvent.ConvertToCode()); events.Update = true; } else if (currentEvent is B_Received b) { var bp = currentEvent.ConvertToCode(); if (broadcastPrograms.TryGetValue(b.broadcastName.text, out var list)) { list.Add(bp); } else { var l = new List <Program>(); l.Add(bp); broadcastPrograms.Add(b.broadcastName.text, l); } } else if (currentEvent is B_TouchBeganEvent) { collisionEnter.Add(currentEvent.ConvertToCode()); } else if (currentEvent is B_TouchEndedEvent) { collisionEnd.Add(currentEvent.ConvertToCode()); } else if (currentEvent is B_PhysicsUpdateEvent) { fixedUpdate.Add(currentEvent.ConvertToCode()); events.FixedUpdate = true; } else if (currentEvent is B_Deleted) { deleted.Add(currentEvent.ConvertToCode()); } currentEvent = currentEvent.NextConnection; } //updateProgram = startEvent.NextConnection?.ConvertToCode(); startProgram = start.ToArray(); updateProgram = update.ToArray(); fixedUpdateProgram = fixedUpdate.ToArray(); collisionEnterPrograms = collisionEnter.ToArray(); collisionEndPrograms = collisionEnd.ToArray(); deletedPrograms = deleted.ToArray(); this.broadcastPrograms = new Dictionary <string, Program[]>(broadcastPrograms.Count); foreach (var bp in broadcastPrograms) { this.broadcastPrograms.Add(bp.Key, bp.Value.ToArray()); } foreach (var bps in this.broadcastPrograms) { SceneExecutor.Instance.AddBroadcast(bps.Key, new BroadcastProgram(this, bps.Value)); } return(events); }