Beispiel #1
0
 // Start is called before the first frame update
 void Start()
 {
     rb = GetComponentInParent <Rigidbody2D>();
     bc = GetComponent <BoxCollider2D>();
 }
Beispiel #2
0
 protected void Awake()
 {
     base.Awake();
     bc2d = GetComponent <BoxCollider2D>();
 }
Beispiel #3
0
 private void Awake()
 {
     //return;
     colider    = GetComponent <BoxCollider2D>();
     Horizontal = colider.size.y;
 }
Beispiel #4
0
 private void Start()
 {
     lockSprite = GetComponent <SpriteRenderer>();
     coll       = GetComponent <BoxCollider2D>();
 }
Beispiel #5
0
    /// <summary>
    /// Show the popup list dialog.
    /// </summary>

    public virtual void Show()
    {
        if (enabled && NGUITools.GetActive(gameObject) && mChild == null && atlas != null && isValid && items.Count > 0)
        {
            mLabelList.Clear();
            StopCoroutine("CloseIfUnselected");

            // Ensure the popup's source has the selection
            UICamera.selectedObject = (UICamera.hoveredObject ?? gameObject);
            mSelection = UICamera.selectedObject;
            source     = UICamera.selectedObject;

            if (source == null)
            {
                Debug.LogError("Popup list needs a source object...");
                return;
            }

            mOpenFrame = Time.frameCount;

            // Automatically locate the panel responsible for this object
            if (mPanel == null)
            {
                mPanel = UIPanel.Find(transform);
                if (mPanel == null)
                {
                    return;
                }
            }

            // Calculate the dimensions of the object triggering the popup list so we can position it below it
            Vector3 min;
            Vector3 max;

            // Create the root object for the list
            mChild       = new GameObject("Drop-down List");
            mChild.layer = gameObject.layer;

            if (separatePanel)
            {
                if (GetComponent <Collider>() != null)
                {
                    Rigidbody rb = mChild.AddComponent <Rigidbody>();
                    rb.isKinematic = true;
                }
                else if (GetComponent <Collider2D>() != null)
                {
                    Rigidbody2D rb = mChild.AddComponent <Rigidbody2D>();
                    rb.isKinematic = true;
                }
                mChild.AddComponent <UIPanel>().depth = 1000000;
            }
            current = this;

            Transform t = mChild.transform;
            t.parent = mPanel.cachedTransform;
            Vector3 pos;

            // Manually triggered popup list on some other game object
            if (openOn == OpenOn.Manual && mSelection != gameObject)
            {
                pos             = UICamera.lastEventPosition;
                min             = mPanel.cachedTransform.InverseTransformPoint(mPanel.anchorCamera.ScreenToWorldPoint(pos));
                max             = min;
                t.localPosition = min;
                pos             = t.position;
            }
            else
            {
                Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(mPanel.cachedTransform, transform, false, false);
                min             = bounds.min;
                max             = bounds.max;
                t.localPosition = min;
                pos             = t.position;
            }

            StartCoroutine("CloseIfUnselected");

            t.localRotation = Quaternion.identity;
            t.localScale    = Vector3.one;

            // Add a sprite for the background
            mBackground       = NGUITools.AddSprite(mChild, atlas, backgroundSprite, separatePanel ? 0 : NGUITools.CalculateNextDepth(mPanel.gameObject));
            mBackground.pivot = UIWidget.Pivot.TopLeft;
            mBackground.color = backgroundColor;

            // We need to know the size of the background sprite for padding purposes
            Vector4 bgPadding = mBackground.border;
            mBgBorder = bgPadding.y;
            mBackground.cachedTransform.localPosition = new Vector3(0f, bgPadding.y, 0f);

            // Add a sprite used for the selection
            mHighlight       = NGUITools.AddSprite(mChild, atlas, highlightSprite, mBackground.depth + 1);
            mHighlight.pivot = UIWidget.Pivot.TopLeft;
            mHighlight.color = highlightColor;

            UISpriteData hlsp = mHighlight.GetAtlasSprite();
            if (hlsp == null)
            {
                return;
            }

            float          hlspHeight = hlsp.borderTop;
            float          fontHeight = activeFontSize;
            float          dynScale = activeFontScale;
            float          labelHeight = fontHeight * dynScale;
            float          x = 0f, y = -padding.y;
            List <UILabel> labels = new List <UILabel>();

            // Clear the selection if it's no longer present
            if (!items.Contains(mSelectedItem))
            {
                mSelectedItem = null;
            }

            // Run through all items and create labels for each one
            for (int i = 0, imax = items.Count; i < imax; ++i)
            {
                string s = items[i];

                UILabel lbl = NGUITools.AddWidget <UILabel>(mChild, mBackground.depth + 2);
                lbl.name         = i.ToString();
                lbl.pivot        = UIWidget.Pivot.TopLeft;
                lbl.bitmapFont   = bitmapFont;
                lbl.trueTypeFont = trueTypeFont;
                lbl.fontSize     = fontSize;
                lbl.fontStyle    = fontStyle;
                lbl.text         = isLocalized ? Localization.Get(s) : s;
                lbl.color        = textColor;
                lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x - lbl.pivotOffset.x, y, -1f);
                lbl.overflowMethod = UILabel.Overflow.ResizeFreely;
                lbl.alignment      = alignment;
                labels.Add(lbl);

                y -= labelHeight;
                y -= padding.y;
                x  = Mathf.Max(x, lbl.printedSize.x);

                // Add an event listener
                UIEventListener listener = UIEventListener.Get(lbl.gameObject);
                listener.onHover   = OnItemHover;
                listener.onPress   = OnItemPress;
                listener.parameter = s;

                // Move the selection here if this is the right label
                if (mSelectedItem == s || (i == 0 && string.IsNullOrEmpty(mSelectedItem)))
                {
                    Highlight(lbl, true);
                }

                // Add this label to the list
                mLabelList.Add(lbl);
            }

            // The triggering widget's width should be the minimum allowed width
            x = Mathf.Max(x, (max.x - min.x) - (bgPadding.x + padding.x) * 2f);

            float   cx       = x;
            Vector3 bcCenter = new Vector3(cx * 0.5f, -labelHeight * 0.5f, 0f);
            Vector3 bcSize   = new Vector3(cx, (labelHeight + padding.y), 1f);

            // Run through all labels and add colliders
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                UILabel lbl = labels[i];
                NGUITools.AddWidgetCollider(lbl.gameObject);
                lbl.autoResizeBoxCollider = false;
                BoxCollider bc = lbl.GetComponent <BoxCollider>();

                if (bc != null)
                {
                    bcCenter.z = bc.center.z;
                    bc.center  = bcCenter;
                    bc.size    = bcSize;
                }
                else
                {
                    BoxCollider2D b2d = lbl.GetComponent <BoxCollider2D>();
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
                    b2d.center = bcCenter;
#else
                    b2d.offset = bcCenter;
#endif
                    b2d.size = bcSize;
                }
            }

            int lblWidth = Mathf.RoundToInt(x);
            x += (bgPadding.x + padding.x) * 2f;
            y -= bgPadding.y;

            // Scale the background sprite to envelop the entire set of items
            mBackground.width  = Mathf.RoundToInt(x);
            mBackground.height = Mathf.RoundToInt(-y + bgPadding.y);

            // Set the label width to make alignment work
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                UILabel lbl = labels[i];
                lbl.overflowMethod = UILabel.Overflow.ShrinkContent;
                lbl.width          = lblWidth;
            }

            // Scale the highlight sprite to envelop a single item
            float scaleFactor = 2f * atlas.pixelSize;
            float w           = x - (bgPadding.x + padding.x) * 2f + hlsp.borderLeft * scaleFactor;
            float h           = labelHeight + hlspHeight * scaleFactor;
            mHighlight.width  = Mathf.RoundToInt(w);
            mHighlight.height = Mathf.RoundToInt(h);

            bool placeAbove = (position == Position.Above);

            if (position == Position.Auto)
            {
                UICamera cam = UICamera.FindCameraForLayer(mSelection.layer);

                if (cam != null)
                {
                    Vector3 viewPos = cam.cachedCamera.WorldToViewportPoint(pos);
                    placeAbove = (viewPos.y < 0.5f);
                }
            }

            // If the list should be animated, let's animate it by expanding it
            if (isAnimated)
            {
                AnimateColor(mBackground);

                if (Time.timeScale == 0f || Time.timeScale >= 0.1f)
                {
                    float bottom = y + labelHeight;
                    Animate(mHighlight, placeAbove, bottom);
                    for (int i = 0, imax = labels.Count; i < imax; ++i)
                    {
                        Animate(labels[i], placeAbove, bottom);
                    }
                    AnimateScale(mBackground, placeAbove, bottom);
                }
            }

            // If we need to place the popup list above the item, we need to reposition everything by the size of the list
            if (placeAbove)
            {
                min.y           = max.y - bgPadding.y;
                max.y           = min.y + mBackground.height;
                max.x           = min.x + mBackground.width;
                t.localPosition = new Vector3(min.x, max.y - bgPadding.y, min.z);
            }
            else
            {
                max.y = min.y + bgPadding.y;
                min.y = max.y - mBackground.height;
                max.x = min.x + mBackground.width;
            }

            Transform pt = mPanel.cachedTransform.parent;

            if (pt != null)
            {
                min = mPanel.cachedTransform.TransformPoint(min);
                max = mPanel.cachedTransform.TransformPoint(max);
                min = pt.InverseTransformPoint(min);
                max = pt.InverseTransformPoint(max);
            }

            // Ensure that everything fits into the panel's visible range
            Vector3 offset = mPanel.hasClipping ? Vector3.zero : mPanel.CalculateConstrainOffset(min, max);
            pos             = t.localPosition + offset;
            pos.x           = Mathf.Round(pos.x);
            pos.y           = Mathf.Round(pos.y);
            t.localPosition = pos;
        }
        else
        {
            OnSelect(false);
        }
    }
Beispiel #6
0
 // Start is called before the first frame update
 void Start()
 {
     Fire_HitBox = GetComponent <BoxCollider2D>();
     StartCoroutine(Spray_Hit_Toggle());
 }
 // Use this for initialization
 void Start()
 {
     groundCollider         = GetComponent <BoxCollider2D>();
     groundHorizontalLength = groundCollider.size.x - 9.216434f;
 }
Beispiel #8
0
 public virtual void Awake()
 {
     collider = GetComponent <BoxCollider2D> ();
 }
Beispiel #9
0
 protected override void SetUp()
 {
     hitbox        = GetComponent <BoxCollider2D>();
     push.strength = pushStrengh;
 }
 // Use this for initialization
 public override void Start()
 {
     base.Start();
     m_PlantZone = this.GetComponentsInChildren <BoxCollider2D> ()[1];
     _Player     = GameObject.Find("Player");
 }
 // Start is called before the first frame update
 void Start()
 {
     enemyAnimator      = GetComponent <Animator>();
     enemyBoxCollider2D = GetComponent <BoxCollider2D>();
     currentHealth      = startingHealth;
 }
    private void SetDrop()
    {
        // Check if its near of some wall or object
        float nearDistantObject = GetMinDistanceObj("") != null?GetMinDistanceObj("").RangeDistance : 1;

        float nearAngleObject = GetMinDistanceObj("") != null?GetMinDistanceObj("").RangeAngle : 0;

        string nearTagObject = GetMinDistanceObj("") != null?GetMinDistanceObj("").RangeGameObject.tag : "";

        bool canDrop = false;

        // Check if I can drop the item
        if (nearDistantObject > 0.25)
        {
            canDrop = true;
        }
        else if ((nearAngleObject > 20 || nearAngleObject == 0) && nearTagObject == "Pickup")
        {
            canDrop = true;
        }
        else
        {
            canDrop = false;
        }

        if (canDrop)
        {
            // Remove Item from player parent
            _pickedItem.transform.parent        = null;
            _pickedItem.rigidbody2D.isKinematic = true;

            BoxCollider2D pick = (BoxCollider2D)_pickedItem.rigidbody2D.collider2D;
            BoxCollider2D user = (BoxCollider2D)obj.collider2D;

            // Get Collider Diference
            float colliderSizeX = (pick.center + new Vector2(pick.size.x * 0.5f, 0)).x + ((user.center * lookDirX) + new Vector2(user.size.x * 0.5f, 0)).x;
            float colliderSizeY = ((pick.center * (-lookDirY)) + new Vector2(0, pick.size.y * 0.5f)).y + ((user.center * lookDirY) + new Vector2(0, user.size.y * 0.5f)).y;
            //Set New Position to drop item
            float newY, newX;

            if (lookDirY == -1)
            {
                // Looking up: Use Player Collider Size + Y position
                newY = (colliderSizeY + 0.02f) * -1F;
            }
            else if (lookDirY == 1)
            {
                // Looking down: Use item Collider Size + Y position
                newY = colliderSizeY + 0.02f;
            }
            else
            {
                // Adjust object to the player foot
                newY = (user.bounds.size.y - pick.bounds.size.y) * -1;
            }
            // Since X collider is in X = 0, the logis is simplier
            newX = (colliderSizeX + 0.02f) * lookDirX;
            //Set New Position to drop item
            _pickedItem.rigidbody2D.position =
                new Vector2(
                    (obj.transform.position.x + newX),
                    (obj.transform.position.y + newY)
                    );
            // Adjust Object Layer
            _pickedItem.gameObject.layer = 9;
            _pickedItem.GetComponent <SpriteRenderer>().sortingLayerName = "Player";
            // Adjust Object Order
            _pickedItem.GetComponent <SpriteRenderer>().sortingOrder = (int)((10 * ((obj.transform.position.y + (lookDirY * 0.25f)) * -1)));
            // Set no item is picked
            _pickedItem = null;
            _picking    = false;
        }
    }
 protected virtual void Start()
 {
     collider = GetComponent <BoxCollider2D>();
     CalculateRaySpacing();
 }
Beispiel #14
0
 // grab component references
 private void Awake()
 {
     bCollider = gameObject.GetComponent <BoxCollider2D>();
     sRender   = gameObject.GetComponent <SpriteRenderer>();
 }
 public void Start()
 {
     col         = GetComponent <BoxCollider2D>();
     enemyAmount = Random.Range(minEnemies, maxEnemies);
 }
Beispiel #16
0
 private void Awake()
 {
     groundCollider = GetComponent <BoxCollider2D>();
 }
Beispiel #17
0
 private void Start()
 {
     _body = GetComponent <Rigidbody2D>();
     _anim = GetComponent <Animator>();
     _box  = GetComponent <BoxCollider2D>();
 }
 // Use this for initialization
 void Start()
 {
     groundCollider         = GetComponent <BoxCollider2D>();
     groundHorizontalLenght = groundCollider.size.x;
 }
 // Use this for initialization; made protected and virtual so that various implementations of Start() may be created
 protected virtual void Start()
 {
     boxCollider     = GetComponent <BoxCollider2D>();
     rb2d            = GetComponent <Rigidbody2D>();
     inverseMoveTime = 1f / moveTime;
 }
Beispiel #20
0
 // Use this for initialization
 void Start()
 {
     anim = GetComponent <Animator>();
     coll = GetComponent <BoxCollider2D>();
     self = GetComponent <EntityScript>();
 }
 // Use this for initialization
 void Start()
 {
     bc2D             = GetComponent <BoxCollider2D> ();
     horizontalLength = bc2D.size.x;
 }
 // Use this for initialization
 void Start()
 {
     boxCollider    = transform.GetComponent <BoxCollider2D>();
     playerMovement = GameObject.Find("Player").GetComponent <PlayerMovement>();
     playerHealth   = GameObject.Find("Player").GetComponent <PlayerHealth>();
 }
 void Start()
 {
     boxCollider = GetComponent <BoxCollider2D>();
 }
 void Start()
 {
     isOpenTo     = -1;
     baseCollider = GetComponent <BoxCollider2D>();
 }
Beispiel #25
0
 void Start()
 {
     playerCollider = GetComponent <BoxCollider2D>();
     calculateRaySpacing();
 }
Beispiel #26
0
    private Animator m_Animator;              //metalic ground animator

    #endregion

    #region private methods

    private void Start()
    {
        m_Ground = GetComponent <BoxCollider2D>(); //initialize ground

        m_Animator = GetComponent <Animator>();    //initialize animator
    }
Beispiel #27
0
    void Awake()
    {
        BoxCollider2D backgroundCollider = GetComponent <BoxCollider2D>();

        width = backgroundCollider.size.x; //2.48
    }
Beispiel #28
0
 void Awake()
 {
     bc2d = GetComponent <BoxCollider2D> ();
 }
 public ObiBoxShapeTracker2D(ObiCollider2D source, BoxCollider2D collider)
 {
     this.source   = source;
     this.collider = collider;
 }
Beispiel #30
0
 // Use this for initialization
 void Start()
 {
     anim = GetComponent <Animator> ();
     box  = GetComponent <BoxCollider2D> ();
 }