示例#1
0
        public void __RemoveMouseEnabledObject(DisplayObjectContainer obj)
        {
            if (!_mouseEnabledObjectIds.ContainsKey(obj.Id))
            {
                return;
            }

            _mouseEnabledObjects.Remove(obj);
            _mouseEnabledObjectIds.Remove(obj.Id);
        }
示例#2
0
        public void __AddMouseEnabledObject(DisplayObjectContainer obj)
        {
            if (_mouseEnabledObjectIds.ContainsKey(obj.Id))
            {
                return;
            }

            _mouseEnabledObjects.Add(obj);
            _mouseEnabledObjectIds.Add(obj.Id, obj);
            __SortMouseEnabledObjects();
        }
        /// <summary>
        /// Gets the index of the child.
        /// </summary>
        /// <returns>
        /// The child index, or -1 if the child is not actually a child of this object.
        /// </returns>
        /// <param name='child'>
        /// Child.
        /// </param>
        public int GetChildIndex(DisplayObjectContainer child)
        {
            for (var i = 0; i < _children.Count; i++)
            {
                if (_children[i].Id == child.Id)
                {
                    return(i);
                }
            }

            return(-1);
        }
        /// <summary>
        /// Removes the child.
        /// </summary>
        /// <returns>
        /// The child.
        /// </returns>
        /// <param name='child'>
        /// Child.
        /// </param>
        /// <exception cref='ArgumentException'>
        /// Is thrown when an argument passed to a method is invalid.
        /// </exception>
        public DisplayObjectContainer RemoveChild(DisplayObjectContainer child)
        {
            var childIndex = _children.IndexOf(child);

            if (childIndex == -1)
            {
                throw new ArgumentException("Object is not a child of this parent");
            }

            RemoveChildAt(childIndex);
            return(child);
        }
示例#5
0
        public void Awake()
        {
            if (_instance != null)
            {
                throw new Exception("You can only have one instance of MouseInput");
            }

            _instance = this;

            _mouseEnabledObjects   = new List <DisplayObjectContainer>();
            _mouseEnabledObjectIds = new Dictionary <Guid, DisplayObjectContainer>();
            _lastMousePos          = new Vector2(-999999, -999999);
            _mouseOverObject       = Stage.Instance;
        }
        /// <summary>
        /// Sets the index of the child.
        /// </summary>
        /// <param name='child'>
        /// The child to move.  Must be a child of this object
        /// </param>
        /// <param name='index'>
        /// The index to set the child to.  Must be between 0 and NumChildren-1.
        /// </param>
        /// <exception cref='ArgumentException'>
        /// Thrown when child is not actually a child of this object, or index is outside acceptable range (see above)
        /// </exception>
        public void SetChildIndex(DisplayObjectContainer child, int index)
        {
            if (!Contains(child))
            {
                throw new ArgumentException("Parent must contain supplied child to set index");
            }

            if (index >= _children.Count)
            {
                throw new ArgumentException("index out of range");
            }

            _children.Remove(child);
            _children.Insert(index, child);
            __ChildrenUpdated = true;
        }
        /// <summary>
        /// Removes a child form its current parent, if any, and adds the child to this object's display hierarchy.  Can be used to floating an existing object to the top of this object's children.
        /// </summary>
        /// <returns>
        /// The child to add.
        /// </returns>
        /// <param name='child'>
        /// Child.
        /// </param>
        /// <exception cref='ArgumentNullException'>
        /// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> .
        /// </exception>
        public DisplayObjectContainer AddChild(DisplayObjectContainer child)
        {
            if (child == null)
            {
                throw new ArgumentNullException("child", "child cannot be null");
            }

            if (child.Parent == this)
            {
                SetChildIndex(child, _children.Count - 1);
                return(child);
            }

            AddChildInternal(child);
            _children.Add(child);
            return(child);
        }
        protected void __SetParent(DisplayObjectContainer parent)
        {
            bool changed = Parent != parent;

            Parent = parent;
            if (changed)
            {
                if (parent == null)
                {
                    __Removed();
                }
                else
                {
                    __Added();
                }
            }
        }
        protected void AddChildInternal(DisplayObjectContainer child)
        {
            if (child == null)
            {
                throw new ArgumentNullException("child", "child cannot be null");
            }

            if (child.Parent != null)
            {
                child.Parent.RemoveChild(child);
            }

            child.__SetParent(this);
            SetAsTransformChild(child.gameObject);
            __ChildrenUpdated = true;
            child.__UpdateMesh();
        }
        /// <summary>
        /// Swaps depths of the children.
        /// </summary>
        /// <param name='child1'>
        /// Child1
        /// </param>
        /// <param name='child2'>
        /// Child2
        /// </param>
        /// <exception cref='ArgumentException'>
        /// Thrown when either child1 or child2 are not actually children of this object.
        /// </exception>
        public void SwapChildren(DisplayObjectContainer child1, DisplayObjectContainer child2)
        {
            var index1 = GetChildIndex(child1);
            var index2 = GetChildIndex(child2);

            if (index1 < 0)
            {
                throw new ArgumentException("Argument 'child1' is not child of this parent.");
            }
            if (index2 < 0)
            {
                throw new ArgumentException("Argument 'child2' is not child of this parent.");
            }

            _children[index1] = child2;
            _children[index2] = child1;
            __ChildrenUpdated = true;
        }
        /// <summary>
        /// Removes the child from its current parent and adds it at the given index.
        /// </summary>
        /// <returns>
        /// The <see cref="DisplayObjectContainer"/> that was added
        /// </returns>
        /// <param name='child'>
        /// Child to add
        /// </param>
        /// <param name='index'>
        /// Index to add child at
        /// </param>
        /// <exception cref='ArgumentNullException'>
        /// Thrown when child is null
        /// </exception>
        /// <exception cref='ArgumentException'>
        /// Thrown when index is less than 0 or too high.
        /// </exception>
        public DisplayObjectContainer AddChildAt(DisplayObjectContainer child, int index)
        {
            if (child == null)
            {
                throw new ArgumentNullException("child", "child cannot be null");
            }

            if (index < 0 || index > _children.Count - 1)
            {
                throw new ArgumentException("index out of range");
            }

            if (child.Parent == this)
            {
                SetChildIndex(child, index);
                return(child);
            }

            AddChildInternal(child);
            _children.Insert(index, child);

            return(child);
        }
示例#12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Tween"/> class.
        /// </summary>
        /// <param name='targetObj'>
        /// The objet to perform the Tween on.
        /// </param>
        /// <param name='propertyName'>
        /// Property name, eg. "X", "Y", "ScaleX", "Alpha", etc.
        /// </param>
        /// <param name='endVal'>
        /// The value to tween to.  The tween will run from the property's value at start time to the end value.
        /// </param>
        /// <param name='duration'>
        /// Duration in seconds of the tween.
        /// </param>
        /// <param name='easingType'>
        /// Easing type.  Any function matching the see cref="EaseValue"/> delegate.
        /// </param>
        /// <param name='delay'>
        /// Delay, in seconds.
        /// </param>
        /// <param name='startCallback'>
        /// Called when tween starts (after any delay).
        /// </param>
        /// <param name='endCallback'>
        /// Called when tween ends
        /// </param>
        /// <exception cref='Exception'>
        /// Thrown when a Tween is created before Stage
        /// </exception>
        /// <exception cref='ArgumentException'>
        /// Thrown when targetObj param is null or targetObj does not have property referenced by propertyName arg.
        /// </exception>
        public Tween(DisplayObjectContainer targetObj, string propertyName, float endVal, float duration, EaseValue easingType, float delay = 0f, TweenCallback startCallback = null, TweenCallback endCallback = null)
        {
            if (TweenRunner.Instance == null)
            {
                throw new Exception("TweenRunner must be added to Stage before creating Tweens");
            }

            if (targetObj == null)
            {
                throw new ArgumentException("targetObj is null");
            }

            Id        = Guid.NewGuid();
            TargetObj = targetObj;
            if (!String.IsNullOrEmpty(propertyName))
            {
                Property = targetObj.GetType().GetProperty(propertyName);
                if (Property == null)
                {
                    throw new ArgumentException("targetObj does not have property named " + propertyName);
                }
            }
            //StartVal gets set when tween actually starts running, since the value may change during a delay
            EndVal        = endVal;
            StartTime     = TweenRunner.Instance.__GetCurrentTime();
            Duration      = duration;
            EasingType    = easingType;
            Delay         = delay;
            StartCallback = startCallback;
            EndCallback   = endCallback;

            if (!String.IsNullOrEmpty(propertyName))
            {
                TweenRunner.Instance.__AddTween(this);
            }
        }
示例#13
0
 public void Recycle(DisplayObjectContainer doc)
 {
 }
示例#14
0
 public static void MakeObjectInvisible(DisplayObjectContainer targetObj)
 {
     targetObj.Visible = false;
 }
示例#15
0
 public static void MakeObjectVisible(DisplayObjectContainer targetObj)
 {
     targetObj.Visible = true;
 }
示例#16
0
 public void Disable()
 {
     _mouseDownObject = null;
 }
示例#17
0
 public void Enable()
 {
     _mouseDown       = Input.GetMouseButton(0);
     _lastMousePos    = Stage.Instance.TheCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));
     _mouseOverObject = GetObjectUnderMouse();
 }
示例#18
0
        public void Update()
        {
            //just started
            if (_mouseOverObject == null)
            {
                _mouseOverObject = GetObjectUnderMouse();
            }

            var mouseDown = Input.GetMouseButton(0);
            var mousePos  = Stage.Instance.TheCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));
            var stagePos  = new Vector2(mousePos.x, mousePos.y) - Stage.Instance.__GetOffset();
            var localPos  = stagePos;

            if (_lastMousePos.x == -999999 && _lastMousePos.y == -999999)
            {
                _lastMousePos = mousePos;
            }

            var mouseMoved         = (Vector2)_lastMousePos != (Vector2)mousePos;
            var mouseButtonChanged = _mouseDown != mouseDown;

            DisplayObjectContainer newMouseOverObject = (mouseMoved || mouseButtonChanged) ?
                                                        (GetObjectUnderMouse() ?? Stage.Instance) :
                                                        _mouseOverObject;

            if (mouseMoved)
            {
                localPos = newMouseOverObject.GlobalToLocal(stagePos);

                if (newMouseOverObject != _mouseOverObject)
                {
                    if (_mouseOverObject != null)
                    {
                        var me = new MouseEvent(MouseEvent.MOUSE_OUT, _mouseOverObject, new Vector2(_mouseOverObject.MouseX, _mouseOverObject.MouseY), stagePos);
                        me.Bubbles = false;
                        _mouseOverObject.DispatchEvent(me);
                    }

                    if (newMouseOverObject != null)
                    {
                        var me = new MouseEvent(MouseEvent.MOUSE_OVER, newMouseOverObject, localPos, stagePos);
                        me.Bubbles = false;
                        newMouseOverObject.DispatchEvent(me);
                    }
                }

                //don't dispatch a move if we just entered or left
                if (newMouseOverObject == _mouseOverObject)
                {
                    var me = new MouseEvent(MouseEvent.MOUSE_MOVE, newMouseOverObject, localPos, stagePos);
                    me.Bubbles = false;
                    newMouseOverObject.DispatchEvent(me);
                }
            }

            if (mouseDown != _mouseDown)
            {
                if (mouseDown)
                {
                    newMouseOverObject.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, newMouseOverObject, localPos, stagePos));
                    _mouseDownObject = newMouseOverObject;
                }
                else
                {
                    newMouseOverObject.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_UP, newMouseOverObject, localPos, stagePos));

                    if (newMouseOverObject != _mouseDownObject && _mouseDownObject != null)
                    {
                        _mouseDownObject.DispatchEvent(new MouseEvent(MouseEvent.RELEASE_OUTSIDE, _mouseDownObject, localPos, stagePos));
                    }

                    _mouseDownObject = null;
                }
            }

            _mouseDown       = mouseDown;
            _lastMousePos    = mousePos;
            _mouseOverObject = newMouseOverObject;
        }
 /// <summary>
 /// Checks if container contains the specified child.
 /// </summary>
 /// <param name='child'>
 /// True if child is child of parent, otherwise false
 /// </param>
 public bool Contains(DisplayObjectContainer child)
 {
     return(_children.Contains(child));
 }