// Creates a new AsyncStreamReader for the given stream. The // character encoding is set by encoding and the buffer size, // in number of 16-bit characters, is set by bufferSize. // internal AsyncStreamReader(Process process, Stream stream, UserCallBack callback, Encoding encoding, int bufferSize) { Debug.Assert(process != null && stream != null && encoding != null && callback != null, "Invalid arguments!"); Debug.Assert(stream.CanRead, "Stream must be readable!"); Debug.Assert(bufferSize > 0, "Invalid buffer size!"); Init(process, stream, callback, encoding, bufferSize); messageQueue = new Queue(); }
// Creates a new AsyncStreamReader for the given stream. The // character encoding is set by encoding and the buffer size, // in number of 16-bit characters, is set by bufferSize. // internal AsyncStreamReader(Process process, Stream stream, UserCallBack callback, Encoding encoding, int bufferSize) { Debug.Assert(process != null && stream != null && encoding != null && callback != null, "Invalid arguments!"); Debug.Assert(stream.CanRead, "Stream must be readable!"); Debug.Assert(bufferSize > 0, "Invalid buffer size!"); Init(process, stream, callback, encoding, bufferSize); _messageQueue = new Queue<string>(); }
private void Init(Process process, Stream stream, UserCallBack callback, Encoding encoding, int bufferSize) { this.process = process; this.stream = stream; this.encoding = encoding; this.userCallBack = callback; decoder = encoding.GetDecoder(); if (bufferSize < MinBufferSize) bufferSize = MinBufferSize; byteBuffer = new byte[bufferSize]; _maxCharsPerBuffer = encoding.GetMaxCharCount(bufferSize); charBuffer = new char[_maxCharsPerBuffer]; cancelOperation = false; eofEvent = new ManualResetEvent(false); sb = null; this.bLastCarriageReturn = false; }
private void Init(Process process, Stream stream, UserCallBack callback, Encoding encoding, int bufferSize) { this.process = process; this.stream = stream; this.encoding = encoding; this.userCallBack = callback; this.decoder = encoding.GetDecoder(); if (bufferSize < MinBufferSize) { bufferSize = MinBufferSize; } this.byteBuffer = new byte[bufferSize]; this._maxCharsPerBuffer = encoding.GetMaxCharCount(bufferSize); this.charBuffer = new char[this._maxCharsPerBuffer]; this.cancelOperation = false; this.eofEvent = new ManualResetEvent(false); this.sb = null; }
private void Init(Process process, Stream stream, UserCallBack callback, Encoding encoding, int bufferSize) { this.process = process; this.stream = stream; this.encoding = encoding; userCallBack = callback; decoder = encoding.GetDecoder(); if (bufferSize < 128) { bufferSize = 128; } byteBuffer = new byte[bufferSize]; _maxCharsPerBuffer = encoding.GetMaxCharCount(bufferSize); charBuffer = new char[_maxCharsPerBuffer]; cancelOperation = false; eofEvent = new ManualResetEvent(false); sb = null; bLastCarriageReturn = false; }
private void Init(Process process, Stream stream, UserCallBack callback, Encoding encoding, int bufferSize) { _process = process; _stream = stream; _encoding = encoding; _userCallBack = callback; _decoder = encoding.GetDecoder(); if (bufferSize < MinBufferSize) { bufferSize = MinBufferSize; } _byteBuffer = new byte[bufferSize]; _maxCharsPerBuffer = encoding.GetMaxCharCount(bufferSize); _charBuffer = new char[_maxCharsPerBuffer]; _cancelOperation = false; _eofEvent = new ManualResetEvent(false); _sb = null; _bLastCarriageReturn = false; }
// This method is used for making thread-safe // calls on the Scintilla control. // // If the calling thread is different from the thread that // created the Scintilla control, this method creates a // SetTextCallback and calls itself asynchronously using the // Invoke method. // // If the calling thread is the same as the thread that created // the Scintilla control, the Text property is set directly. private void SetTextCallback(string text) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (this.InvokeRequired) { UserCallBack d = new UserCallBack(SetTextCallback); this.Invoke(d, new object[] { text }); } else { StringBuilder sb = new StringBuilder(text); //if (carryNewLine && sb[0] == '\n') //{ // carryNewLine = false; // sb.Remove(0, 1); //} SetText(sb.ToString()); } }
internal AsyncStreamReader(Process2 process, Stream stream, UserCallBack callback, Encoding encoding) : this(process, stream, callback, encoding, 1024) { }
internal AsyncStreamReader(Process2 process, Stream stream, UserCallBack callback, Encoding encoding, int bufferSize) { Init(process, stream, callback, encoding, bufferSize); messageQueue = new Queue(); }
internal AsyncStreamReader(Process process, Stream stream, UserCallBack callback, Encoding encoding) : this(process, stream, callback, encoding, DefaultBufferSize) { }
public bool TaskHandler(StoryTask task) { bool done = false; switch (task.Instruction) { case "makeinterface": // Create a controller Controller = new Controller(); // Create a layout (can hold multiple planes and interfaces) MainLayout = new Layout(); // Create an interface MainInterface = new InterFace(UserCanvas.gameObject, "demo"); // Create a mapping and add it to the interface MainMapping = new Mapping(); MainMapping.ux_tap_2d += Methods.tapButton2D; MainInterface.AddMapping(MainMapping); // Create an exit button and add it to the interface Button button; button = new Button("Exit"); button.AddConstraint(Constraint.LockInPlace(button)); button.AddCallback("startmenu"); MainInterface.addButton(button); // Just using single plane for demo, add the interface to it MainLayout.AddInterface(MainInterface); done = true; break; case "interface": // Update the interface(s) and get result. UserCallBack result = Controller.updateUi(MainLayout); if (result.trigger) { Log("User tapped " + result.sender + ", starting storyline " + result.label); Director.Instance.NewStoryLine(result.label); } break; case "startallsamples": SceneManager.LoadScene("AllSamples", LoadSceneMode.Single); done = true; break; case "pingpong": // Every device tries to switch the value every 5 seconds. if (Time.time > wait) { wait = Time.time + 4f; string pingpong; task.GetStringValue("debug", out pingpong); switch (pingpong) { case "ping": task.SetStringValue("debug", "pong"); Log("pong"); break; default: task.SetStringValue("debug", "ping"); Log("ping"); break; } } break; default: done = true; break; } return(done); }
internal AsyncStreamReader(Process process, Stream stream, UserCallBack callback, Encoding encoding, int bufferSize) { this.Init(process, stream, callback, encoding, bufferSize); this.messageQueue = new Queue(); }
// ------------------------------------ MAIN UPDATE METHOD ------------------------------------------------------------------- // Checks and applies user interaction. Keeps a stack of ui events to allow for inertia, springing. /*!\brief Main method to be called to run user interaction, returns callback. * * Keeps a stack of ui Event objects to allow for intertia and springing. * Always has 1 active ui Event that contains current user activity */ public UserCallBack updateUi(Layout _layout) { cycle = (cycle + 1) % 1000; UserCallBack callBack = new UserCallBack(); int stackSize = uiEventStack.Count; activeUiEvent.GetUserActivity(); // get (unscaled) mouse movement, touches, taps // If a user touch/click just began, set targets and remove any old event targeting the same objects. if (activeUiEvent.touch == TOUCH.BEGAN) { activeUiEvent.plane = _layout.FindPlaneByPoint(activeUiEvent.position); // get the plane the user is active in by screen coordinates if (activeUiEvent.plane != null && activeUiEvent.plane.interFace != null) { Verbose("targeting interface " + activeUiEvent.plane.interFace.name); } else { Verbose("not targeting any interface"); } activeUiEvent.SetTargets(); int e = uiEventStack.Count - 1; while (e >= 0) { Event oldEvent = uiEventStack[e]; if (oldEvent != activeUiEvent) { bool removeOld = false; if (activeUiEvent.targetButton != null) { // we check all the new events button targets against the actual single target of the check event. if (oldEvent.targetButton != null && activeUiEvent.targetButton.HasDragTarget(oldEvent.targetButton.GetDragTarget(oldEvent.direction))) { if (oldEvent.tapTimeOut > 0) { // the old event was in a tap when the new one started. // we flag this so the new event will perform a double tap rather than a tap activeUiEvent.targetJustTapped = true; } removeOld = true; } } else if (activeUiEvent.target2D != null) { // if same 2d target, remove old. if (oldEvent.target2D == activeUiEvent.target2D) { if (oldEvent.tapTimeOut > 0) { activeUiEvent.targetJustTapped = true; } removeOld = true; } } else if (activeUiEvent.target3D != null) { // if same 3d target, remove old. if (oldEvent.target3D == activeUiEvent.target3D) { if (oldEvent.tapTimeOut > 0) { activeUiEvent.targetJustTapped = true; } removeOld = true; } } else { // if both have no targets at all, remove old. if (oldEvent.targetButton == null && oldEvent.target2D == null && oldEvent.target3D == null) { removeOld = true; } } if (removeOld) { uiEventStack.RemoveAt(e); } } e--; } } // When we get user activity from mouse/touch we get screen coordinates. // Before we start applying drag etc to object, we need to scale the delta values. //float scale = (activeUiEvent.plane.interFace) //activeUiEvent.CorrectForCanvasScale(); // now handle the stack of ui events. this way, events can play out (inertia, springing) while the user starts new interaction. // create empty callback object int i = 0; //Log("events "+uiEventStack.Count); while (i < uiEventStack.Count) { Event uiEvent = uiEventStack[i]; processUiEvent(uiEvent); if (uiEvent.callback != "") { // callback may come from old event, in case of a single tap Verbose("Triggering callback event."); callBack.label = uiEvent.callback; callBack.sender = uiEvent.target2D; callBack.trigger = true; } // If an old event is no longer inert or springing, remove it. if (uiEvent != activeUiEvent && uiEvent.isInert == false && uiEvent.isSpringing == false && uiEvent.tapTimeOut < float.Epsilon) { uiEventStack.RemoveAt(i); Verbose("Removing event, total left " + uiEventStack.Count); i--; } i++; } // if the event ended, handle different outcomes. if (activeUiEvent.touch == TOUCH.ENDED) { Verbose("Touch ended"); // the active event just ended. set inert and springing to true. activeUiEvent.touch = TOUCH.NONE; //if (activeUiEvent.action == ACTION.TAP) //{ // // tap has been exectued in processevent // // must only be executed once, after that make it a 'normal' singledrag event. // activeUiEvent.action = ACTION.SINGLEDRAG; // Verbose("Tapped, converting to singledrag"); //} if (activeUiEvent.targetButton != null) { // if the event had a button as target, set inertia and springing. activeUiEvent.isInert = true; Verbose("Set to inert"); // if normal dragging if (activeUiEvent.targetButton.GetDragTarget() != null) { activeUiEvent.isSpringing = true; Verbose("Setting to springing: free direction dragtarget is " + activeUiEvent.targetButton.GetDragTarget().name); } // If ortho dragging else if (activeUiEvent.targetButton.orthoDragging) { // if a direction is set, we create an additional event for the other direction. if (activeUiEvent.direction != DIRECTION.FREE) { Verbose("setting to ortho springing"); activeUiEvent.isSpringing = true; Event springEvent = activeUiEvent.clone(); springEvent.direction = activeUiEvent.direction == DIRECTION.HORIZONTAL ? DIRECTION.VERTICAL : DIRECTION.HORIZONTAL; springEvent.action = ACTION.SINGLEDRAG; Verbose("cloning event for springing"); uiEventStack.Add(springEvent); } else { Verbose("touch ended, ortho button, direction free"); // Direction was never set (tap) We'll create springing events for both direcionts. activeUiEvent.isSpringing = true; activeUiEvent.isInert = true; // if it was a tap, we're not going to use inertia activeUiEvent.direction = DIRECTION.VERTICAL; Event springEvent = activeUiEvent.clone(); springEvent.direction = DIRECTION.HORIZONTAL; springEvent.action = ACTION.SINGLEDRAG; Verbose("cloning event for ortho springing"); uiEventStack.Add(springEvent); } } } // Create a new uievent to catch the next interaction Event newEvent = new Event(); uiEventStack.Add(newEvent); activeUiEvent = newEvent; Verbose("added new event"); } int stackSizeNew = uiEventStack.Count; if (stackSize != stackSizeNew) { // Log.Message ( cycle + " Event stack size changed: " + stackSizeNew); } if (stackSizeNew > 10) { Warning("Ui event stack exceeds 10, potential overflow."); } AnimateButtons(); return(callBack); }
public bool TaskHandler(StoryTask task) { bool done = false; switch (task.Instruction) { case "startevolution": ZeeSterEvolutie = new ZeeSterEvolutie(); pop = ZeeSterEvolutie.GetPop(); done = true; break; case "evolve": int[] Score = new int[AgentCount]; for (int a = 0; a < AgentCount; a++) { GameObject go = pop[a].GameObject; float distance = 0; if (go != null) { distance = go.transform.position.magnitude; } Score[a] = (int)(distance); pop = ZeeSterEvolutie.Evolution(Score); } done = true; break; case "spawn": //int AgentCount = 10; for (int a = 0; a < AgentCount; a++) { // Shape input Zeester ster = pop[a]; int NumberOfLegs = ster.NumberOfLegs; int LegLength = ster.LegLength; float Hue = 1f / 7f * ster.Hue; float Sat = 1f / 7f * ster.Sat; float Val = 1f / 7f * ster.Val; // Behaviour input float Freq = (1f / 7f * ster.Freq) * 4f; float Amp = 5f + 5f * ster.Amp; //0-7 float Phase = 1f / 7f * ster.Phase; /* * int NumberOfLegs = Random.Range(1, 8); * int LegLength = Random.Range(1, 8); * float Hue = Random.Range(0f, 1f); * float Sat = Random.Range(0f, 1f); * float Val = Random.Range(0f, 1f); * * // Behaviour input * float Freq = Random.Range(0f, 4f); * float Amp = Random.Range(5f, 45f); * float Phase = Random.Range(0f, 1f); */ // Spawn // Log("h: " + Hue); GameObject body = Instantiate(BodyPrefab); ster.GameObject = body; body.transform.SetParent(Root.transform, false); body.transform.localPosition = new Vector3(0, 0, Random.Range(0f, 4f)); Agent agt = body.GetComponent <Agent>(); agt.Legs = new GameObject[NumberOfLegs]; Material newMaterial = new Material(Shader.Find("Standard")); newMaterial.color = Color.HSVToRGB(Hue, Sat, Val); //newMaterial.color = Color.red; agt.mat = newMaterial; body.GetComponentInChildren <Renderer>().material = newMaterial; for (int l = 0; l < NumberOfLegs; l++) { GameObject Leg = Instantiate(LegPrefab); Leg.transform.SetParent(body.transform, false); Leg.transform.localScale = new Vector3(1, 1, LegLength); Leg.transform.localRotation = Quaternion.Euler(10f, 360f / NumberOfLegs * l, 0); Leg.transform.GetChild(0).transform.localPosition = new Vector3(0, 0, 0.5f); agt.Legs[l] = Leg; Leg.GetComponentInChildren <Renderer>().material = newMaterial; } agt.Freq = Freq; agt.Amp = Amp; agt.Phase = Phase; } done = true; break; case "kill": foreach (Transform child in Root.transform) { Destroy(child.gameObject); } done = true; break; case "makeinterface": // Create a controller Controller = new Controller(); // Create a layout (can hold multiple planes and interfaces) MainLayout = new Layout(); // Create a plane //Plane UpperPlane3d = new Plane(GameObject.Find("UpperPlane")); //Plane LowerPlane3d = new Plane(GameObject.Find("LowerPlane")); // Create an interface UpperInterface = new InterFace(UserCanvas.gameObject, "upper"); //LowerInterface = new InterFace(UserCanvas.gameObject, "lower"); // Create a mapping and add it to the interface MainMapping = new Mapping(); MainMapping.ux_single_none += Methods.OrbitCamera; MainMapping.ux_double_none += Methods.LateralCamera; MainMapping.ux_double_none += Methods.LongitudinalCamera; MainMapping.ux_single_2d += Methods.Drag2D; MainMapping.ux_tap_2d += Methods.tapButton2D; // Create an orbit cam with a pitch constraint. Constraint orbitConstraint = new Constraint() { pitchClamp = true, pitchClampMin = 15f, pitchClampMax = 85f }; UiCam3D uppercam = new UiCam3D(GameObject.Find("MainCamera")); uppercam.AddContraint(orbitConstraint); //UiCam3D lowercam = new UiCam3D(GameObject.Find("CameraLower")); //lowercam.AddContraint(orbitConstraint); // Create an exit button and add it to the interface //button = new Button("Exit"); //button.AddConstraint(Constraint.LockInPlace(button)); //button.AddCallback("startmenu"); //UpperInterface.addButton(button); // Add together. UpperInterface.AddUiCam3D(uppercam); //LowerInterface.AddUiCam3D(lowercam); UpperInterface.AddMapping(MainMapping); //LowerInterface.AddMapping(MainMapping); //UpperPlane3d.AddInterface(UpperInterface); //LowerPlane3d.AddInterface(LowerInterface); // Add to layout MainLayout.AddInterface(UpperInterface); //MainLayout.AddPlane(UpperPlane3d); //MainLayout.AddPlane(LowerPlane3d); done = true; break; case "interface": // Update the interface(s) and get result. UserCallBack result = Controller.updateUi(MainLayout); if (result.trigger) { Log("User tapped " + result.sender + ", starting storyline " + result.label); Director.Instance.NewStoryLine(result.label); } break; case "task1": case "task2": case "task3": case "repeatingtask": if (task.GetFloatValue("wait", out wait)) { done |= Time.time > wait; } else { task.SetFloatValue("wait", Time.time + 3f); Log("Executing task " + task.Instruction); } break; case "wait5": if (task.GetFloatValue("wait", out wait)) { done |= Time.time > wait; } else { task.SetFloatValue("wait", Time.time + 5f); } break; case "wait10": if (task.GetFloatValue("wait", out wait)) { done |= Time.time > wait; } else { task.SetFloatValue("wait", Time.time + 10f); } break; default: done = true; break; } return(done); }
internal AsyncStreamReader(Process process, Stream stream, UserCallBack callback, Encoding encoding) : this(process, stream, callback, encoding, 1024) { }
public bool TaskHandler(StoryTask task) { bool done = false; switch (task.Instruction) { case "makeinterface": // Create a controller Controller = new Controller(); // Create a layout (can hold multiple planes and interfaces) MainLayout = new Layout(); // Create an interface MainInterface = new InterFace(UserCanvas.gameObject, "demo"); // Create a mapping and add it to the interface MainMapping = new Mapping(); MainMapping.ux_single_2d += Methods.Drag2D; MainMapping.ux_tap_2d += Methods.tapButton2D; MainInterface.AddMapping(MainMapping); // Create locked buttons and add them to the interface Button button; button = new Button("Simple"); button.AddConstraint(Constraint.LockInPlace(button)); button.AddCallback("startsimple"); MainInterface.addButton(button); button = new Button("NetworkedServer"); button.AddConstraint(Constraint.LockInPlace(button)); button.AddCallback("startnetworkedserver"); MainInterface.addButton(button); button = new Button("NetworkedClient"); button.AddConstraint(Constraint.LockInPlace(button)); button.AddCallback("startnetworkedclient"); MainInterface.addButton(button); button = new Button("Interface2d"); button.AddConstraint(Constraint.LockInPlace(button)); button.AddCallback("startinterface2d"); MainInterface.addButton(button); button = new Button("Interfaceplanes"); button.AddConstraint(Constraint.LockInPlace(button)); button.AddCallback("startinterfaceplanes"); MainInterface.addButton(button); button = new Button("Interfaceplanes3d"); button.AddConstraint(Constraint.LockInPlace(button)); button.AddCallback("startinterfaceplanes3d"); MainInterface.addButton(button); // Just add the interface directly to the layout, it will assign it to the root plane. MainLayout.AddInterface(MainInterface); done = true; break; case "interface": // Update the interface(s) and get result. UserCallBack result = Controller.updateUi(MainLayout); if (result.trigger) { Log("User tapped " + result.sender + ", starting storyline " + result.label); Director.Instance.NewStoryLine(result.label); } break; default: done = true; break; } return(done); }
// ------------------------------------ MAIN UPDATE METHOD ------------------------------------------------------------------- // Checks and applies user interaction. Keeps a stack of ui events to allow for inertia, springing. /*!\brief Main method to be called to run user interaction, returns callback. * * Keeps a stack of ui Event objects to allow for intertia and springing. * Always has 1 active ui Event that contains current user activity */ public UserCallBack updateUi(Layout _layout) { cycle = (cycle + 1) % 1000; UserCallBack callBack = new UserCallBack(); int stackSize = uiEventStack.Count; activeUiEvent.GetUserActivity(); // get (unscaled) mouse movement, touches, taps //activeUiEvent.plane = _layout.FindPlaneByPoint(activeUiEvent.position); // get the plane the user is active in // If a user touch/click just began, set targets and remove any old event targeting the same objects. if (activeUiEvent.touch == TOUCH.BEGAN) { activeUiEvent.plane = _layout.FindPlaneByPoint(activeUiEvent.position); // get the plane the user is active in by screen coordinates //Debug.Log("targeting "+activeUiEvent.plane.address); activeUiEvent.SetTargets(); int e = uiEventStack.Count - 1; while (e >= 0) { Event oldEvent = uiEventStack[e]; if (oldEvent != activeUiEvent) { bool removeOld = false; if (activeUiEvent.targetButton != null) { // we check all the new events button targets against the actual single target of the check event. if (oldEvent.targetButton != null && activeUiEvent.targetButton.HasDragTarget(oldEvent.targetButton.GetDragTarget(oldEvent.direction))) { removeOld = true; // Debug.Log("Removing ui event targeting the same dragtarget"); } } else if (activeUiEvent.target3D != null) { // if same 3d target, remove old. if (oldEvent.target3D == activeUiEvent.target3D) { removeOld = true; } } else { // if both have no targets at all, remove old. if (oldEvent.targetButton == null && oldEvent.target2D == null && oldEvent.target3D == null) { removeOld = true; } } if (removeOld) { uiEventStack.RemoveAt(e); } } e--; } } // When we get user activity from mouse/touch we get screen coordinates. // Before we start applying drag etc to object, we need to scale the delta values. //float scale = (activeUiEvent.plane.interFace) //activeUiEvent.CorrectForCanvasScale(); // now handle the stack of ui events. this way, events can play out (inertia, springing) while the user starts new interaction. // create empty callback object int i = 0; //Log("events "+uiEventStack.Count); while (i < uiEventStack.Count) { Event uiEvent = uiEventStack[i]; // Log.Message ( "handling event stack of size " + uiEventStack.Count); processUiEvent(uiEvent); // If an old event is no longer inert or springing, remove it. if (uiEvent != activeUiEvent && uiEvent.isInert == false && uiEvent.isSpringing == false) { uiEventStack.RemoveAt(i); Verbose("Removing event, total left " + uiEventStack.Count); i--; } i++; } //foreach (Event e in uiEventStack) //{ // if (e.target2D != null) // Verbose("event button " + e.target2D.name); // else // Verbose("event without target "); //} if (activeUiEvent.callback != "") { callBack.label = activeUiEvent.callback; callBack.sender = activeUiEvent.target2D; callBack.trigger = true; //Debug.Log ("callbackResult: " + callBack.label); } if (activeUiEvent.touch == TOUCH.ENDED) { // the active event just ended. set inert and springing to true. activeUiEvent.touch = TOUCH.NONE; // if (activeUiEvent.action==ACTION.) activeUiEvent.isInert = true; if (activeUiEvent.targetButton != null) { if (activeUiEvent.targetButton.GetDragTarget() != null) { activeUiEvent.isSpringing = true; } // If we were dragging an ortho button, we want an event on the other direction to spring. //if (activeUiEvent.targetButton.orthoDragging) //{ // if (activeUiEvent.direction != DIRECTION.FREE) // { // // Debug.Log("adding springing event for " + (activeUiEvent.direction == DIRECTION.HORIZONTAL ? "vertical" :"horizontal")); // Event springEvent = activeUiEvent.clone(); // springEvent.direction = activeUiEvent.direction == DIRECTION.HORIZONTAL ? DIRECTION.VERTICAL : DIRECTION.HORIZONTAL; // springEvent.isSpringing = true; // springEvent.action = ACTION.SINGLEDRAG; // Verbose("cloning event for springing"); // uiEventStack.Add(springEvent); // } // else // { // // Debug.Log("touch ended, ortho button, direction free"); // // Direction was never set. We'll create springing events for both direcionts. // // ??? direction not set means it didn't go anywhere?? // //activeUiEvent.direction = DIRECTION.HORIZONTAL; // //Event springEvent = activeUiEvent.clone(); // //springEvent.direction = DIRECTION.VERTICAL; // //Verbose("cloning event for ortho springing"); // //uiEventStack.Add(springEvent); // } //} } if (activeUiEvent.action == ACTION.TAP) { // tap must only be executed once, after that it becomes an inert singledrag event. activeUiEvent.action = ACTION.SINGLEDRAG; Log("tap -> singledrag"); //Debug.Log("tap -> singledrag"); } // Create a new uievent to catch the next interaction Event newEvent = new Event(); uiEventStack.Add(newEvent); activeUiEvent = newEvent; Verbose("added new event"); } int stackSizeNew = uiEventStack.Count; if (stackSize != stackSizeNew) { // Log.Message ( cycle + " Event stack size changed: " + stackSizeNew); } if (stackSizeNew > 10) { Warning("Ui event stack exceeds 10, potential overflow."); } AnimateButtons(); return(callBack); }
public bool TaskHandler(StoryTask task) { bool done = false; switch (task.Instruction) { case "makeinterface2d": // Create a controller Controller = new Controller(); // Create a layout (can hold multiple planes and interfaces) MainLayout = new Layout(); // Create an interface MainInterface = new InterFace(UserCanvas.gameObject, "demo"); // Create a mapping and add it to the interface MainMapping = new Mapping(); MainMapping.ux_single_2d += Methods.Drag2D; MainMapping.ux_tap_2d += Methods.tapButton2D; MainInterface.AddMapping(MainMapping); // Create a free moving button and add it to the interface Button button; button = new Button("Freemoving"); button.AddCallback("freemovingcallback"); MainInterface.addButton(button); // Create a free moving button and add it to the interface button = new Button("Locked"); button.AddCallback("lockedcallback"); button.AddConstraint(Constraint.LockInPlace(button)); MainInterface.addButton(button); // Create a constrained button and add it to the interface. Coordinates are local. Constraint slideConstraint = new Constraint() { hardClamp = true, hardClampMin = new Vector2(-250f, 350f), hardClampMax = new Vector2(250f, 350f), edgeSprings = true, edgeSpringMin = new Vector2(-200f, 350f), edgeSpringMax = new Vector2(200f, 350f) }; button = new Button("Slide"); button.AddConstraint(slideConstraint); MainInterface.addButton(button); // Create a button with spring positions and add it to the interface. Constraint springConstraint = new Constraint() { hardClamp = true, hardClampMin = new Vector2(-250f, 250f), hardClampMax = new Vector2(250f, 250f), springs = true, springPositions = new Vector2[] { new Vector2(-200f, 250f), new Vector2(-100f, 250f), new Vector2(0f, 250f), new Vector2(100f, 250f), new Vector2(200f, 250f) } }; button = new Button("Springs"); button.AddConstraint(springConstraint); MainInterface.addButton(button); // Create two buttons with the same drag target, so they work as a group. button = new Button("Option1", GameObject.Find("MenuFree")); MainInterface.addButton(button); button = new Button("Option2", GameObject.Find("MenuFree")); MainInterface.addButton(button); // Create a button with orthogonal dragging (so either horizontal or vertical) and add it to the interface. Constraint verticalConstraint = new Constraint() { hardClamp = true, hardClampMin = new Vector2(0f, -200f), hardClampMax = new Vector2(0f, 200f) }; Constraint horizontalConstraint = new Constraint() { hardClamp = true, hardClampMin = new Vector2(-200f, -350f), hardClampMax = new Vector2(200f, -350f) }; button = new Button("Ortho"); button.AddOrthoConstraints(GameObject.Find("Layer"), horizontalConstraint, GameObject.Find("Sublayer"), verticalConstraint); //button.AddConstraint(circleConstraint); MainInterface.addButton(button); // Create a button with circular constraint and add it to the interface. // Works from 0,0 local position Constraint circleConstraint = new Constraint() { radiusClamp = true, radiusClampMin = 100f, radiusClampMax = 100f }; button = new Button("Circle"); button.AddConstraint(circleConstraint); MainInterface.addButton(button); // Create a free moving button and add it to the interface button = new Button("Exit"); button.AddConstraint(Constraint.LockInPlace(button)); button.AddCallback("startmenu"); MainInterface.addButton(button); // Just using single plane for demo, add the interface to it MainLayout.AddInterface(MainInterface); done = true; break; case "makeinterfaceplanes": // Create a controller Controller = new Controller(); // Create a layout (can hold multiple planes and interfaces) MainLayout = new Layout(); // Create a plane Plane UpperPlane = new Plane(GameObject.Find("UpperPlane")); Plane LowerPlane = new Plane(GameObject.Find("LowerPlane")); // Create an interface UpperInterface = new InterFace(UserCanvas.gameObject, "upper"); LowerInterface = new InterFace(UserCanvas.gameObject, "lower"); // Create a mapping and add it to the interface MainMapping = new Mapping(); MainMapping.ux_single_2d += Methods.Drag2D; MainMapping.ux_tap_2d += Methods.tapButton2D; // Add together. UpperInterface.AddMapping(MainMapping); UpperPlane.AddInterface(UpperInterface); LowerInterface.AddMapping(MainMapping); LowerPlane.AddInterface(LowerInterface); // Create buttons button = new Button("Button01"); UpperInterface.addButton(button); button = new Button("Button02"); LowerInterface.addButton(button); // Create an exit button and add it to the interface button = new Button("Exit"); button.AddConstraint(Constraint.LockInPlace(button)); button.AddCallback("startmenu"); UpperInterface.addButton(button); // Add to layout. MainLayout.AddPlane(UpperPlane); MainLayout.AddPlane(LowerPlane); done = true; break; case "makeinterfaceplanes3d": // Create a controller Controller = new Controller(); // Create a layout (can hold multiple planes and interfaces) MainLayout = new Layout(); // Create a plane Plane UpperPlane3d = new Plane(GameObject.Find("UpperPlane")); Plane LowerPlane3d = new Plane(GameObject.Find("LowerPlane")); // Create an interface UpperInterface = new InterFace(UserCanvas.gameObject, "upper"); LowerInterface = new InterFace(UserCanvas.gameObject, "lower"); // Create a mapping and add it to the interface MainMapping = new Mapping(); MainMapping.ux_single_none += Methods.OrbitCamera; MainMapping.ux_double_none += Methods.LateralCamera; MainMapping.ux_double_none += Methods.LongitudinalCamera; MainMapping.ux_single_2d += Methods.Drag2D; MainMapping.ux_tap_2d += Methods.tapButton2D; // Create an orbit cam with a pitch constraint. Constraint orbitConstraint = new Constraint() { pitchClamp = true, pitchClampMin = 15f, pitchClampMax = 85f }; UiCam3D uppercam = new UiCam3D(GameObject.Find("CameraUpper")); uppercam.AddContraint(orbitConstraint); UiCam3D lowercam = new UiCam3D(GameObject.Find("CameraLower")); lowercam.AddContraint(orbitConstraint); // Create an exit button and add it to the interface button = new Button("Exit"); button.AddConstraint(Constraint.LockInPlace(button)); button.AddCallback("startmenu"); UpperInterface.addButton(button); // Add together. UpperInterface.AddUiCam3D(uppercam); LowerInterface.AddUiCam3D(lowercam); UpperInterface.AddMapping(MainMapping); LowerInterface.AddMapping(MainMapping); UpperPlane3d.AddInterface(UpperInterface); LowerPlane3d.AddInterface(LowerInterface); // Add to layout MainLayout.AddPlane(UpperPlane3d); MainLayout.AddPlane(LowerPlane3d); done = true; break; case "interface": // Update the interface(s) and get result. UserCallBack result = Controller.updateUi(MainLayout); if (result.trigger) { Log("User tapped " + result.sender + ", starting storyline " + result.label); Director.Instance.NewStoryLine(result.label); } break; case "startallsamples": SceneManager.LoadScene("AllSamples", LoadSceneMode.Single); done = true; break; default: done = true; break; } return(done); }
internal AsyncStreamReader(Process process, Stream stream, UserCallBack callback, Encoding encoding, int bufferSize) { this.Init(process, stream, callback, encoding, bufferSize); this.messageQueue = new System.Collections.Queue(); }