Ejemplo n.º 1
0
 private void OnColliderCreate()
 {
     if (PlayMakerUnity2d.isAvailable())
     {
         TasInfo.OnColliderCreate(gameObject);
     }
 }
Ejemplo n.º 2
0
        void DoRaycast()
        {
            repeat = repeatInterval.Value;

            Vector2 fromPos = fromPosition.Value;

            if (_fromTrans != null)
            {
                fromPos.x += _fromTrans.position.x;
                fromPos.y += _fromTrans.position.y;
            }

            Vector2 toPos = toPosition.Value;

            if (_toTrans != null)
            {
                toPos.x += _toTrans.position.x;
                toPos.y += _toTrans.position.y;
            }


            RaycastHit2D hitInfo;

            if (minDepth.IsNone && maxDepth.IsNone)
            {
                hitInfo = Physics2D.Linecast(fromPos, toPos, ActionHelpers.LayerArrayToLayerMask(layerMask, invertMask.Value));
            }
            else
            {
                float _minDepth = minDepth.IsNone? Mathf.NegativeInfinity : minDepth.Value;
                float _maxDepth = maxDepth.IsNone? Mathf.Infinity : maxDepth.Value;
                hitInfo = Physics2D.Linecast(fromPos, toPos, ActionHelpers.LayerArrayToLayerMask(layerMask, invertMask.Value), _minDepth, _maxDepth);
            }

            PlayMakerUnity2d.RecordLastRaycastHitInfo(this.Fsm, hitInfo);

            bool didHit = hitInfo.collider != null;

            storeDidHit.Value = didHit;

            if (didHit)
            {
                storeHitObject.Value   = hitInfo.collider.gameObject;
                storeHitPoint.Value    = hitInfo.point;
                storeHitNormal.Value   = hitInfo.normal;
                storeHitDistance.Value = hitInfo.fraction;
                Fsm.Event(hitEvent);
            }

            if (debug.Value)
            {
                Vector3 start = new Vector3(fromPos.x, fromPos.y, 0);
                Vector3 end   = new Vector3(toPos.x, toPos.y, 0);

                Debug.DrawLine(start, end, debugColor.Value);
            }
        }
 public void Start()
 {
     if (!PlayMakerUnity2d.isAvailable())
     {
         Debug.LogError("PlayMakerUnity2DProxy requires the 'PlayMaker Unity 2D' Prefab in the Scene.\nUse the menu 'PlayMaker/Addons/Unity 2D/Components/Add PlayMakerUnity2D to Scene' to correct the situation", this);
         enabled = false;
         return;
     }
     ModHooks.Instance.OnColliderCreate(gameObject);
     RefreshImplementation();
 }
Ejemplo n.º 4
0
        void StoreRaycastInfo()
        {
            RaycastHit2D _info = PlayMakerUnity2d.GetLastRaycastHitInfo(this.Fsm);

            if (_info.collider != null)
            {
                gameObjectHit.Value = _info.collider.gameObject;
                point.Value         = _info.point;
                normal.Value        = _info.normal;
                distance.Value      = _info.fraction;
            }
        }
    public void Start()
    {
        if (!PlayMakerUnity2d.isAvailable())
        {
            Debug.LogError("PlayMakerUnity2DProxy requires the 'PlayMaker Unity 2D' Prefab in the Scene.\n" +
                           "Use the menu 'PlayMaker/Addons/Unity 2D/Components/Add PlayMakerUnity2D to Scene' to correct the situation", this);
            this.enabled = false;
            return;
        }

        RefreshImplementation();
    }
    void OnCollisionEnter2D(Collision2D coll)
    {
        //if (debug) Debug.Log("OnCollisionEnter2D "+HandleCollisionEnter2D,this.gameObject);

        if (HandleCollisionEnter2D)
        {
            lastCollision2DInfo = coll;

            PlayMakerUnity2d.ForwardEventToGameObject(this.gameObject, PlayMakerUnity2d.OnCollisionEnter2DEvent);
        }

        if (this.OnCollisionEnter2dDelegates != null)
        {
            this.OnCollisionEnter2dDelegates(coll);
        }
    }
    void OnTriggerExit2D(Collider2D coll)
    {
        if (debug)
        {
            Debug.Log(this.gameObject.name + " OnTriggerExit2D " + coll.gameObject.name, this.gameObject);
        }

        if (HandleTriggerExit2D)
        {
            lastTrigger2DInfo = coll;

            PlayMakerUnity2d.ForwardEventToGameObject(this.gameObject, PlayMakerUnity2d.OnTriggerExit2DEvent);
        }

        if (this.OnTriggerExit2dDelegates != null)
        {
            this.OnTriggerExit2dDelegates(coll);
        }
    }
Ejemplo n.º 8
0
        bool DoRaycast()
        {
            GameObject testObject = GameObject.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : GameObject.GameObject.Value;

            // ActionHelpers uses a cache to try and minimize Raycasts
            RaycastHit2D hitInfo = Physics2D.GetRayIntersection(Camera.main.ScreenPointToRay(Input.mousePosition), Mathf.Infinity, ActionHelpers.LayerArrayToLayerMask(layerMask, invertMask.Value));

            // Store mouse pick info so it can be seen by Get Raycast Hit Info action
            PlayMakerUnity2d.RecordLastRaycastHitInfo(this.Fsm, hitInfo);

            if (hitInfo.transform != null)
            {
                if (hitInfo.transform.gameObject == testObject)
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 9
0
        void DoGetNextCollider()
        {
            // no more colliders?
            // check first to avoid errors.

            if (nextColliderIndex >= colliderCount)
            {
                hits = new RaycastHit2D[0];
                nextColliderIndex = 0;
                Fsm.Event(finishedEvent);
                return;
            }

            // get next collider
            PlayMakerUnity2d.RecordLastRaycastHitInfo(this.Fsm, hits[nextColliderIndex]);
            storeNextCollider.Value    = hits[nextColliderIndex].collider.gameObject;
            storeNextHitPoint.Value    = hits[nextColliderIndex].point;
            storeNextHitNormal.Value   = hits[nextColliderIndex].normal;
            storeNextHitDistance.Value = hits[nextColliderIndex].fraction;

            // no more colliders?
            // check a second time to avoid process lock and possible infinite loop if the action is called again.
            // Practically, this enabled calling again this state and it will start again iterating from the first child.

            if (nextColliderIndex >= colliderCount)
            {
                hits = new RaycastHit2D[0];
                nextColliderIndex = 0;
                Fsm.Event(finishedEvent);
                return;
            }

            // iterate the next collider
            nextColliderIndex++;

            if (loopEvent != null)
            {
                Fsm.Event(loopEvent);
            }
        }
Ejemplo n.º 10
0
        public override void OnUpdate()
        {
            if (Camera.main == null)
            {
                LogError("No MainCamera defined!");
                Finish();
                return;
            }

            if (Input.touchCount > 0)
            {
                var go = Fsm.GetOwnerDefaultTarget(gameObject);
                if (go == null)
                {
                    return;
                }

                foreach (var touch in Input.touches)
                {
                    if (fingerId.IsNone || touch.fingerId == fingerId.Value)
                    {
                        var screenPos = touch.position;

                        RaycastHit2D hitInfo = Physics2D.GetRayIntersection(Camera.main.ScreenPointToRay(screenPos), Mathf.Infinity);

                        // Store hitInfo so it can be accessed by other actions
                        // E.g., Get Raycast Hit 2d Info
                                                #if PLAYMAKER_1_8
                        Fsm.RecordLastRaycastHit2DInfo(Fsm, hitInfo);
                                                #else
                        PlayMakerUnity2d.RecordLastRaycastHitInfo(this.Fsm, hitInfo);
                                                #endif

                        if (hitInfo.transform != null)
                        {
                            if (hitInfo.transform.gameObject == go)
                            {
                                storeFingerId.Value = touch.fingerId;
                                storeHitPoint.Value = hitInfo.point;

                                switch (touch.phase)
                                {
                                case TouchPhase.Began:
                                    Fsm.Event(touchBegan);
                                    return;

                                case TouchPhase.Moved:
                                    Fsm.Event(touchMoved);
                                    return;

                                case TouchPhase.Stationary:
                                    Fsm.Event(touchStationary);
                                    return;

                                case TouchPhase.Ended:
                                    Fsm.Event(touchEnded);
                                    return;

                                case TouchPhase.Canceled:
                                    Fsm.Event(touchCanceled);
                                    return;
                                }
                            }
                        }
                        Fsm.Event(touchOutOfRange);
                        return;
                    }
                }
            }
        }
Ejemplo n.º 11
0
        void DoRaycast()
        {
            repeat = repeatInterval.Value;

            if (distance.Value == 0)
            {
                return;
            }

            Vector2 originPos = fromPosition.Value;

            if (_trans != null)
            {
                originPos.x += _trans.position.x;
                originPos.y += _trans.position.y;
            }

            float rayLength = Mathf.Infinity;

            if (distance.Value > 0)
            {
                rayLength = distance.Value;
            }

            Vector2 dirVector2 = direction.Value.normalized;             // normalized to get the proper distance later using fraction from the rayCastHitinfo.

            if (_trans != null && space == Space.Self)
            {
                Vector3 dirVector = _trans.TransformDirection(new Vector3(direction.Value.x, direction.Value.y, 0f));
                dirVector2.x = dirVector.x;
                dirVector2.y = dirVector.y;
            }

            RaycastHit2D hitInfo;

            if (minDepth.IsNone && maxDepth.IsNone)
            {
                hitInfo = Physics2D.Raycast(originPos, dirVector2, rayLength, ActionHelpers.LayerArrayToLayerMask(layerMask, invertMask.Value));
            }
            else
            {
                float _minDepth = minDepth.IsNone? Mathf.NegativeInfinity : minDepth.Value;
                float _maxDepth = maxDepth.IsNone? Mathf.Infinity : maxDepth.Value;
                hitInfo = Physics2D.Raycast(originPos, dirVector2, rayLength, ActionHelpers.LayerArrayToLayerMask(layerMask, invertMask.Value), _minDepth, _maxDepth);
            }

            PlayMakerUnity2d.RecordLastRaycastHitInfo(this.Fsm, hitInfo);

            bool didHit = hitInfo.collider != null;

            storeDidHit.Value = didHit;

            if (didHit)
            {
                storeHitObject.Value   = hitInfo.collider.gameObject;
                storeHitPoint.Value    = hitInfo.point;
                storeHitNormal.Value   = hitInfo.normal;
                storeHitDistance.Value = hitInfo.fraction;
                Fsm.Event(hitEvent);
            }

            if (debug.Value)
            {
                var     debugRayLength = Mathf.Min(rayLength, 1000);
                Vector3 start          = new Vector3(originPos.x, originPos.y, 0);
                Vector3 dirVector3     = new Vector3(dirVector2.x, dirVector2.y, 0);
                Vector3 end            = start + dirVector3 * debugRayLength;

                Debug.DrawLine(start, end, debugColor.Value);
            }
        }