Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing Containers (UIAbstractContainers), and their contents from the scene. #140

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Assets/DemoSceneScripts/PanelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ public class PanelManager : MonoBehaviour
{
void Start()
{

Debug.LogError("PanelManager.Start()");

// IMPORTANT: depth is 1 on top higher numbers on the bottom. This means the lower the number is the closer it gets to the camera.
var playButton = UIButton.create( "playUp.png", "playDown.png", 0, 0 );

Expand Down
2 changes: 1 addition & 1 deletion Assets/DemoSceneScripts/TextManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void Start()
textWrap2 = wrapText.addTextInstance( "This should be hyphenated. Check baseline - tytyt", 0, 0, 0.5f, 1, Color.green, UITextAlignMode.Center, UITextVerticalAlignMode.Bottom );
textWrap2.positionFromBottom( 0f );

StartCoroutine( modifyTextInstances() );
//StartCoroutine( modifyTextInstances() );
}


Expand Down
Binary file modified Assets/DemoScenes/ExtendedTextTest.unity
Binary file not shown.
6 changes: 3 additions & 3 deletions Assets/Plugins/UIToolkit/BaseElements/ITouchable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public interface ITouchable
bool hitTest( Vector2 point );


void onTouchBegan( Touch touch, Vector2 touchPos );
void onTouchBegan( UITouchWrapper touch, Vector2 touchPos );


void onTouchMoved( Touch touch, Vector2 touchPos );
void onTouchMoved( UITouchWrapper touch, Vector2 touchPos );


void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame );
void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame );

}
14 changes: 13 additions & 1 deletion Assets/Plugins/UIToolkit/BaseElements/UIAbstractContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,19 @@ public void removeChild( UISprite child, bool removeFromManager )
if( removeFromManager )
child.manager.removeElement( child );
}


/// <summary>
/// A way to remove a container and all it holds.
/// </summary>
public void destroy()
{
while(_children.Count > 0)
{
removeChild(_children[0], true);
}

Object.Destroy(client);
}

/// <summary>
/// Call this when changing multiple properties at once that result in autolayout. Must be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class UIAbstractTouchableContainer : UIAbstractContainer, ITouch

// touch handling helpers
protected float _deltaTouch;
protected Touch _lastTouch;
protected UITouchWrapper _lastTouch;
protected Vector2 _lastTouchPosition;
protected ITouchable _activeTouchable;

Expand Down Expand Up @@ -392,8 +392,8 @@ public bool hitTest( Vector2 point )
}


// Touch handlers. Subclasses should override onTouchMoved
public virtual void onTouchBegan( Touch touch, Vector2 touchPos )
// UITouchWrapper handlers. Subclasses should override onTouchMoved
public virtual void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
{
// sanity check in case we lost a touch (happens with Unity on occassion)
if( _activeTouchable != null )
Expand All @@ -412,13 +412,13 @@ public virtual void onTouchBegan( Touch touch, Vector2 touchPos )
}


public virtual void onTouchMoved( Touch touch, Vector2 touchPos )
public virtual void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
{

}


public virtual void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
public virtual void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
{
_isDragging = false;

Expand Down
8 changes: 4 additions & 4 deletions Assets/Plugins/UIToolkit/BaseElements/UIControlTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ public override bool highlighted
}


// Touch handlers
public override void onTouchBegan( Touch touch, Vector2 touchPos )
// UITouchWrapper handlers
public override void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
{
highlighted = true;
}


public virtual void onTouchMoved( Touch touch, Vector2 touchPos )
public virtual void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
{
highlighted = true;
}


public override void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
public override void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
{
highlighted = false;
}
Expand Down
8 changes: 4 additions & 4 deletions Assets/Plugins/UIToolkit/BaseElements/UITouchableSprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,20 @@ public override void centerize()

#region ITouchable

// Touch handlers. Subclasses should override these to get their specific behaviour
public virtual void onTouchBegan( Touch touch, Vector2 touchPos )
// UITouchWrapper handlers. Subclasses should override these to get their specific behaviour
public virtual void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
{
highlighted = true;
}


public virtual void onTouchMoved( Touch touch, Vector2 touchPos )
public virtual void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
{

}


public virtual void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
public virtual void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
{
highlighted = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected override void clipChild( UISprite child )

#region ITouchable

public override void onTouchMoved( Touch touch, Vector2 touchPos )
public override void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
{
// increment deltaTouch so we can pass on the touch if necessary
_deltaTouch += touch.deltaPosition.x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected override void clipChild( UISprite child )

#region ITouchable

public override void onTouchMoved( Touch touch, Vector2 touchPos )
public override void onTouchMoved( UITouchWrapper touch, Vector2 touchPos )
{
// increment deltaTouch so we can pass on the touch if necessary
_deltaTouch += touch.deltaPosition.y;
Expand Down
Binary file modified Assets/Plugins/UIToolkit/Materials/UIToolkitMaterial.mat
Binary file not shown.
53 changes: 35 additions & 18 deletions Assets/Plugins/UIToolkit/Structs/UITouchMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,58 +15,75 @@ public enum UIMouseState


/// <summary>
/// this class now exists only to allow standalones/web players to create Touch objects
/// this class now exists only to allow standalones/web players to create UITouchWrapper objects
/// </summary>
public struct UITouchMaker
{
public static Touch createTouch( int finderId, int tapCount, Vector2 position, Vector2 deltaPos, float timeDelta, TouchPhase phase )
public static UITouchWrapper createTouch( int finderId, int tapCount, Vector2 position, Vector2 deltaPos, float timeDelta, TouchPhase phase )
{
var self = new Touch();
ValueType valueSelf = self;
var type = typeof( Touch );

var self = new UITouchWrapper();
//ValueType valueSelf = self;
//var type = typeof( UITouchWrapper );
/*
type.GetField( "m_FingerId", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, finderId );
type.GetField( "m_TapCount", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, tapCount );
type.GetField( "m_Position", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, position );
type.GetField( "m_PositionDelta", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, deltaPos );
type.GetField( "m_TimeDelta", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, timeDelta );
type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, phase );

return (Touch)valueSelf;
return (UITouchWrapper)valueSelf;
*/

self.fingerId = finderId;
self.tapCount = tapCount;
self.position = position;
self.deltaPosition = deltaPos;
self.deltaTime = timeDelta;
self.phase = phase;
return self;
}


public static Touch createTouchFromInput( UIMouseState mouseState, ref Vector2? lastMousePosition )
public static UITouchWrapper createTouchFromInput( UIMouseState mouseState, ref Vector2? lastMousePosition )
{
var self = new Touch();
ValueType valueSelf = self;
var type = typeof( Touch );
//var self = new UITouchWrapper();
//ValueType valueSelf = self;
//var type = typeof( UITouchWrapper );

var self = new UITouchWrapper();

var currentMousePosition = new Vector2( Input.mousePosition.x, Input.mousePosition.y );

if(lastMousePosition.HasValue)
// if we have a lastMousePosition use it to get a delta
if( lastMousePosition.HasValue )
type.GetField( "m_PositionDelta", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, currentMousePosition - lastMousePosition );
if( lastMousePosition.HasValue ) self.deltaPosition = currentMousePosition - (Vector2)lastMousePosition;
//type.GetField( "m_PositionDelta", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, currentMousePosition - lastMousePosition );

if( mouseState == UIMouseState.DownThisFrame ) // equivalent to touchBegan
{
type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, TouchPhase.Began );
//type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, TouchPhase.Began );
self.phase = TouchPhase.Began;
lastMousePosition = Input.mousePosition;
}
else if( mouseState == UIMouseState.UpThisFrame ) // equivalent to touchEnded
{
type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, TouchPhase.Ended );
//type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, TouchPhase.Ended );
self.phase = TouchPhase.Ended;
lastMousePosition = null;
}
else // UIMouseState.HeldDown - equivalent to touchMoved/Stationary
{
type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, TouchPhase.Moved );
//type.GetField( "m_Phase", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, TouchPhase.Moved );
self.phase = TouchPhase.Moved;
lastMousePosition = Input.mousePosition;
}

type.GetField( "m_Position", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, currentMousePosition );
//type.GetField( "m_Position", BindingFlags.Instance | BindingFlags.NonPublic ).SetValue( valueSelf, currentMousePosition );
self.position = currentMousePosition;

return (Touch)valueSelf;
return self;
//return (UITouchWrapper)valueSelf;
}
}
#endif
104 changes: 104 additions & 0 deletions Assets/Plugins/UIToolkit/Structs/UITouchWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System;
using UnityEngine;

public class UITouchWrapper
{

private int m_FingerId = 0;
private Vector2 m_Position = new Vector2();
private Vector2 m_PositionDelta = new Vector2();
private float m_TimeDelta = 0f;
private int m_TapCount = 0;
private TouchPhase m_Phase = TouchPhase.Stationary;

private bool m_Locked = false;

public UITouchWrapper()
{
}


public bool locked
{
get
{
return m_Locked;
}

set
{
if(value == true) m_Locked = true;
}
}

public int fingerId
{
get
{
return this.m_FingerId;
}
set
{
if(!locked) this.m_FingerId = value;
}
}

public Vector2 position
{
get
{
return this.m_Position;
}
set
{
if(!locked) this.m_Position = value;
}
}
public Vector2 deltaPosition
{
get
{
return this.m_PositionDelta;
}
set
{
if(!locked) this.m_PositionDelta = value;
}
}

public float deltaTime
{
get
{
return this.m_TimeDelta;
}
set
{
if(!locked) this.m_TimeDelta = value;
}
}
public int tapCount
{
get
{
return this.m_TapCount;
}
set
{
if(!locked) this.m_TapCount = value;
}
}
public TouchPhase phase
{
get
{
return this.m_Phase;
}
set
{
if(!locked) this.m_Phase = value;
}
}

}

7 changes: 7 additions & 0 deletions Assets/Plugins/UIToolkit/Structs/UITouchWrapper.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/Plugins/UIToolkit/UIElements/TouchInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public TouchInfo( SwipeDirection swipesToDetect )
}


public void resetWithTouch( Touch touch )
public void resetWithTouch( UITouchWrapper touch )
{
// Initialize the detectionState only with the swipe types we want to listen for
swipeDetectionState = swipesToDetect;
Expand Down
6 changes: 3 additions & 3 deletions Assets/Plugins/UIToolkit/UIElements/UIButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public override bool highlighted
}


// Touch handlers
public override void onTouchBegan( Touch touch, Vector2 touchPos )
// UITouchWrapper handlers
public override void onTouchBegan( UITouchWrapper touch, Vector2 touchPos )
{
highlighted = true;

Expand All @@ -101,7 +101,7 @@ public override void onTouchBegan( Touch touch, Vector2 touchPos )



public override void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
public override void onTouchEnded( UITouchWrapper touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
{
// If someone has un-highlighted us through code we are deactivated
// and should not fire the event
Expand Down
Loading