Ejemplo n.º 1
0
        private void ConvertCoposite(CompositeCollider2D collider, List <GameObject> createdObjects)
        {
            if (collider.edgeRadius < Mathf.Epsilon)
            {
                for (int i = 0; i < collider.pathCount; i++)
                {
                    var path = new Vector2[collider.GetPathPointCount(i)];
                    collider.GetPath(i, path);

                    Mesh mesh         = Collider2DTo3DUtils.GetMeshFromPath(path, true);
                    var  obj          = GetObjectCopy(collider.gameObject, createdObjects);
                    var  meshCollider = obj.AddComponent <MeshCollider>();
                    meshCollider.sharedMesh = mesh;
                }
            }
            else
            {
                for (int i = 0; i < collider.pathCount; i++)
                {
                    var path = new Vector2[collider.GetPathPointCount(i)];
                    collider.GetPath(i, path);
                    ConvertPath(collider.gameObject, collider.edgeRadius, createdObjects, path, true);
                }
            }
        }
Ejemplo n.º 2
0
    protected override void Initialise()
    {
        if (compositeCollider == null)
        {
            compositeCollider = GetComponent <CompositeCollider2D>();
        }

        if (edgeCollider == null)
        {
            edgeCollider = GetComponent <EdgeCollider2D>();
        }


        edgeCollider.enabled = false;
        SearchOverlapPlatforms(compositeCollider, out m_SpikeTriggers, 30, false);

        if (isMovingAtStart)
        {
            m_Started = true;
            compositeCollider.isTrigger = false;
        }
        else
        {
            m_Started = false;
            compositeCollider.isTrigger = true;
        }

        m_OverlapCharacterContactFilter.layerMask    = overlapColliderMask;
        m_OverlapCharacterContactFilter.useLayerMask = true;
        m_OverlapCharacterContactFilter.useTriggers  = false;
    }
Ejemplo n.º 3
0
    public void Start()
    {
        eventController.OnEnvChangeShapeEvent.AddListener(ResetAndCleanUp);

        Instance              = this;
        tilemapCollider       = GetComponent <CompositeCollider2D>();
        shadowCasterContainer = shadow_caster_go;
        //shadowCasterContainer = GetComponent<ShadowCaster2D>().gameObject;
        for (int i = 0; i < tilemapCollider.pathCount; i++)
        {
            Vector2[] pathVertices = new Vector2[tilemapCollider.GetPathPointCount(i)];
            tilemapCollider.GetPath(i, pathVertices);

            GameObject shadowCaster = new GameObject("shadow_caster_^" + i);
            shadowCasters.Add(shadowCaster);
            PolygonCollider2D shadowPolygon = (PolygonCollider2D)shadowCaster.AddComponent(typeof(PolygonCollider2D));
            shadowPolygons.Add(shadowPolygon);
            shadowCaster.transform.parent = shadowCasterContainer.transform;
            shadowPolygon.points          = pathVertices;
            shadowPolygon.enabled         = true;
            shadowPolygon.isTrigger       = true;
            //if (shadowCaster.GetComponent<ShadowCaster2D>() != null) // remove existing caster?
            //    Destroy(shadowCaster.GetComponent<ShadowCaster2D>());
            ShadowCaster2D shadowCasterComponent = shadowCaster.AddComponent <ShadowCaster2D>();
            shadowCasterComponents.Add(shadowCasterComponent);
            shadowCasterComponent.selfShadows = true;
        }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// 合并成功处理
    /// </summary>
    public void mergeDeal(float mergeAnimDuration)
    {
        transform.DOScale(new Vector3(1, 1, 1), mergeAnimDuration).OnComplete
            (delegate()
        {
            if (gameObject.GetComponent <CompositeCollider2D>() == null)
            {
                CompositeCollider2D collider2D = gameObject.AddComponent <CompositeCollider2D>();
                collider2D.geometryType        = CompositeCollider2D.GeometryType.Polygons;
                collider2D.generationType      = CompositeCollider2D.GenerationType.Synchronous;
            }

            //合并特效
            if (gameParticleControl != null)
            {
                //gameParticleControl.playMergeParticle(transform);
            }
            //摇晃镜头
            shakeCamer();
            SoundUtil.playSoundClipForMerge();
            //让缸体恢复移动
            Rigidbody2D thisRB = transform.GetComponent <Rigidbody2D>();
            if (thisRB != null)
            {
                thisRB.constraints = RigidbodyConstraints2D.None;
            }
            CommonData.IsDargMove = true;
            //检测是否完成游戏
            checkFinshGame();
        }
            );
    }
Ejemplo n.º 5
0
 private void Start()
 {
     myTileMapRenderer     = GetComponentInChildren <TilemapRenderer>();
     myCollider            = GetComponentInChildren <CompositeCollider2D>();
     myAudioSources        = GetComponents <AudioSource>();
     initialNumberChildren = transform.childCount;
 }
Ejemplo n.º 6
0
    public static List <Polygon2D> CreateFromCompositeCollider(CompositeCollider2D compositeCollider)
    {
        List <Polygon2D> list = new List <Polygon2D>();

        if (compositeCollider != null)
        {
            int pathCount = compositeCollider.pathCount;


            for (int i = 0; i < pathCount; i++)
            {
                int pointCount = compositeCollider.GetPathPointCount(i);

                Vector2[] pointsInPath = new Vector2[pointCount];

                compositeCollider.GetPath(i, pointsInPath);

                Polygon2D polygon = new Polygon2D();
                for (int j = 0; j < pointsInPath.Length; j++)
                {
                    polygon.AddPoint(pointsInPath[j]);
                }

                polygon.Normalize();

                list.Add(polygon);
            }
        }

        return(list);
    }
Ejemplo n.º 7
0
    public void Start()
    {
        tilemapCollider       = GetComponent <CompositeCollider2D>();
        shadowCasterContainer = GameObject.Find(ShadowCasterContainerName);

        if (!GameObject.Find(ShadowCasterContainerName))
        {
            shadowCasterContainer = new GameObject(ShadowCasterContainerName);
        }
        else
        {
            // Clear existing shadow casters
            if (Application.isPlaying)
            {
                foreach (Transform child in shadowCasterContainer.transform)
                {
                    Destroy(child.gameObject);
                }
            }
            else
            {
                while (shadowCasterContainer.transform.childCount != 0)
                {
                    DestroyImmediate(shadowCasterContainer.transform.GetChild(0).gameObject);
                }
            }
        }

        GenerateShadowCasters(false);
    }
Ejemplo n.º 8
0
    // Use this for initialization
    void Start()
    {
        my_box_collider = GetComponent <BoxCollider2D>();
        if (my_box_collider == null)
        {
            my_composite_collider = GetComponent <CompositeCollider2D>();
            if (my_composite_collider == null)
            {
                #if UNITY_EDITOR
                Debug.LogError("Missing BoxCollider2D or CompositeCollider2D: " + this.gameObject);
                #endif
                Destroy(this);   // remove component
                return;
            }
        }

        // Catch bad configuration.
        if (CollisionMasks.light_occlusion_mask != (CollisionMasks.light_occlusion_mask | LayerMask.GetMask(LayerMask.LayerToName(this.gameObject.layer))))
        {
            #if UNITY_EDITOR
            Debug.LogError("Light occluder object " + gameObject + " is not on a recognized light-occluding layer. " +
                           "It will not correctly occlude light. Move it to the correct layer, or add the current layer to the CollisionMasks.light_occlusion_mask.");
            #endif
            Destroy(this);   // remove component, so there is no visual / functional disparity. (Light/shadow graphics don't require correct layering, but detection logic does).
            return;
        }
    }
        private static void ReplaceWithEdgeCollider2Ds(CompositeCollider2D composite)
        {
            // Add an edge collider child for every path in our composite
            var go = composite.gameObject;

            List <Vector2> points = new List <Vector2>(1024 * 8);

            for (int p = 0; p < composite.pathCount; p++)
            {
                composite.GetPath(p, points);

                // Close the loop
                points.Add(points[0]);

                // Add the edge child
                var goEdge = new GameObject("Edge");
                go.AddChildWithUniqueName(goEdge);

                var edge = goEdge.AddComponent <EdgeCollider2D>();
                edge.isTrigger = composite.isTrigger;
                edge.points    = points.ToArray();

                goEdge.AddComponent <SuperColliderComponent>();
            }
        }
Ejemplo n.º 10
0
    public void Generate()
    {
        DestroyAllChildren();

        tilemapCollider = GetComponent <CompositeCollider2D>();

        for (int i = 0; i < tilemapCollider.pathCount; i++)
        {
            Vector2[] pathVertices = new Vector2[tilemapCollider.GetPathPointCount(i)];
            tilemapCollider.GetPath(i, pathVertices);
            GameObject shadowCaster = new GameObject("shadow_caster_" + i);
            shadowCaster.transform.parent = gameObject.transform;
            ShadowCaster2D shadowCasterComponent = shadowCaster.AddComponent <ShadowCaster2D>();
            shadowCasterComponent.selfShadows = this.selfShadows;

            Vector3[] testPath = new Vector3[pathVertices.Length];
            for (int j = 0; j < pathVertices.Length; j++)
            {
                testPath[j] = pathVertices[j];
            }

            shapePathField.SetValue(shadowCasterComponent, testPath);
            meshField.SetValue(shadowCasterComponent, new Mesh());
            generateShadowMeshMethod.Invoke(shadowCasterComponent, new object[] { meshField.GetValue(shadowCasterComponent), shapePathField.GetValue(shadowCasterComponent) });
        }

        // Debug.Log("Generate");
    }
Ejemplo n.º 11
0
 protected override void Initialise()
 {
     container     = GetComponentInParent <MovingContainer>();
     composite     = GetComponent <CompositeCollider2D>();
     catcher       = GetComponent <PlatformCatcher>();
     m_Rigidbody2D = GetComponent <Rigidbody2D>();
 }
        public static void ST2UGeneratePolygonGeometry(this CompositeCollider2D composite)
        {
            var go = composite.gameObject;

            composite.GenerateGeometry();

            if (composite.geometryType == CompositeCollider2D.GeometryType.Polygons)
            {
                ReplaceWithPolygonCollider2D(composite);
            }
            else
            {
                ReplaceWithEdgeCollider2Ds(composite);
            }

            // We no longer need the composite or rigid body
            Object.DestroyImmediate(composite);
            Object.DestroyImmediate(go.GetComponent <Rigidbody2D>());

            // We no longer need composite polygon children
            var childPolygons = go.GetComponentsInChildren <PolygonCollider2D>();

            foreach (var poly in childPolygons)
            {
                if (poly.usedByComposite == true)
                {
                    Object.DestroyImmediate(poly.gameObject);
                }
            }
        }
Ejemplo n.º 13
0
 void Start()
 {
     rb       = GetComponent <Rigidbody2D>();
     collider = GetComponent <CompositeCollider2D>();
     renderer = GetComponent <SpriteRenderer>();
     Health   = MaxHealth;
 }
Ejemplo n.º 14
0
    private void WrapRopeAroundObjects()
    {
        if (RopePositions.Count == 0)
        {
            return;
        }

        Vector2      lastRopePoint          = RopePositions.Last();
        RaycastHit2D playerToCurrentNextHit = Physics2D.Raycast(PlayerPosition, (lastRopePoint - PlayerPosition).normalized,
                                                                Vector2.Distance(PlayerPosition, lastRopePoint) - 0.01f, OnRopeStateData.whatCanYouAttachTo);

        if (playerToCurrentNextHit)
        {
            CompositeCollider2D platformsCollider = playerToCurrentNextHit.collider as CompositeCollider2D;

            if (platformsCollider != null)
            {
                Vector2 closestPointToHit = GetClosestColliderPointFromRaycastHit(playerToCurrentNextHit, platformsCollider);

                if (_wrapPointsLookup.ContainsKey(closestPointToHit))
                {
                    Player.OnRopeStateFinish.ResetRope();
                }
                else
                {
                    RopePositions.Add(closestPointToHit);
                    _wrapPointsLookup.Add(closestPointToHit, 0);
                    _distanceSet = false;
                }
            }
        }
    }
Ejemplo n.º 15
0
    // Despertado é chamado quando a instância do script for carregada
    private void Awake()
    {
        _sR = GetComponent <SpriteRenderer>();
        _rB = GetComponent <Rigidbody2D>();
        _cC = GetComponent <CompositeCollider2D>();

        if (_sR != null)
        {
            Debug.Log("Eu tenho um SpriteRenderer");
            _sR.gameObject.SetActive(false);
        }
        else
        {
            Debug.Log("Não tenho um SpriteRenderer");
        }

        if (_rB != null)
        {
            Debug.Log("Eu tenho um Rigidbody");
        }
        else
        {
            Debug.Log("Não tenho um Rigidbody");
        }

        if (_cC != null)
        {
            Debug.Log("Eu tenho um CompositeCollider2D");
        }
        else
        {
            Debug.Log("Não tenho um CompositeCollider2D");
        }
    }
Ejemplo n.º 16
0
    private void FixedUpdate()
    {
        bool wasGrounded = m_Grounded;

        m_Grounded = false;

        Collider2D[] colliders = Physics2D.OverlapCircleAll(m_GroundCheck.position, k_GroundedRadius, m_WhatIsGround);

        for (int i = 0; i < colliders.Length; i++)
        {
            if (colliders[i].gameObject != gameObject)
            {
                CompositeCollider2D DimCollider = colliders[i].gameObject.GetComponent <CompositeCollider2D>();
                if (DimCollider.isTrigger)
                {
                    continue;
                }
                m_Grounded = true;
                if (!wasGrounded)
                {
                    OnLandEvent.Invoke();
                }
            }
        }
    }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates and sets up the camera's confiner
        /// </summary>
        protected override void SetupConfiner()
        {
            // we add a rigidbody2D to it and set it up
            _confinerRigidbody2D             = _confinerGameObject.AddComponent <Rigidbody2D>();
            _confinerRigidbody2D.bodyType    = RigidbodyType2D.Static;
            _confinerRigidbody2D.simulated   = false;
            _confinerRigidbody2D.useAutoMass = true;
            _confinerRigidbody2D.bodyType    = RigidbodyType2D.Dynamic;

            // we copy the collider and set it up

            CopyCollider();
            _confinerGameObject.transform.localPosition = Vector3.zero;

            // we reset these settings, set differently initially to avoid a weird Unity warning
            _confinerRigidbody2D.bodyType    = RigidbodyType2D.Static;
            _confinerRigidbody2D.useAutoMass = false;

            // we add a composite collider 2D and set it up
            _confinerCompositeCollider2D = _confinerGameObject.AddComponent <CompositeCollider2D>();
            _confinerCompositeCollider2D.geometryType = CompositeCollider2D.GeometryType.Polygons;

            // we set the composite collider as the virtual camera's confiner
            _cinemachineConfiner = VirtualCamera.gameObject.MMGetComponentAroundOrAdd <CinemachineConfiner>();
            _cinemachineConfiner.m_ConfineMode        = CinemachineConfiner.Mode.Confine2D;
            _cinemachineConfiner.m_ConfineScreenEdges = true;
            _cinemachineConfiner.m_BoundingShape2D    = _confinerCompositeCollider2D;
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Build a 2D collider for the shape.
 /// </summary>
 protected override void AddColliderToGO(GameObject target)
 {
     CompositeCollider2D collider = new CompositeCollider2D();
     //foreach (VectorShape component in components)
     //{
     //}
 }
Ejemplo n.º 19
0
        private Tilemap CreateNewTilemap(TilemapKey key)
        {
            string     name = key.GetNameFormat(Layer.Type);
            GameObject tilemapGameObject = LayerGameObject.CreateChildGameObject(name);

            /*if (Importer.DeparentInRuntime)
             * {
             *  tilemapGameObject.AddComponent<LDtkDetachChildren>();
             * }*/

            Tilemap tilemap = tilemapGameObject.AddComponent <Tilemap>();


            if (Importer.IntGridValueColorsVisible)
            {
                TilemapRenderer renderer = tilemapGameObject.AddComponent <TilemapRenderer>();
                renderer.sortingOrder = SortingOrder.SortingOrderValue;
            }

            TilemapCollider2D collider = tilemapGameObject.AddComponent <TilemapCollider2D>();

            if (Importer.UseCompositeCollider)
            {
                Rigidbody2D rb = tilemapGameObject.AddComponent <Rigidbody2D>();
                rb.bodyType = RigidbodyType2D.Static;

                CompositeCollider2D composite = tilemapGameObject.AddComponent <CompositeCollider2D>();
                collider.usedByComposite = true;
            }

            return(tilemap);
        }
    public void Start()
    {
        Instance        = this;
        tilemapCollider = GetComponent <CompositeCollider2D>();

        shadowCasterContainer = new GameObject("Shadow Casters");
        Vector3 lP = shadowCasterContainer.transform.localPosition;

        shadowCasterContainer.transform.parent        = gameObject.transform;
        shadowCasterContainer.transform.localPosition = lP;
        for (int i = 0; i < tilemapCollider.pathCount; i++)
        {
            Vector2[] pathVertices = new Vector2[tilemapCollider.GetPathPointCount(i)];
            tilemapCollider.GetPath(i, pathVertices);
            GameObject shadowCaster = new GameObject("shadow_caster_" + i);
            shadowCasters.Add(shadowCaster);
            PolygonCollider2D shadowPolygon = (PolygonCollider2D)shadowCaster.AddComponent(typeof(PolygonCollider2D));
            shadowPolygons.Add(shadowPolygon);
            lP = shadowCaster.transform.localPosition;
            shadowCaster.transform.parent        = shadowCasterContainer.transform;
            shadowCaster.transform.localPosition = lP;
            shadowPolygon.points  = pathVertices;
            shadowPolygon.enabled = false;
            //if (shadowCaster.GetComponent<ShadowCaster2D>() != null) // remove existing caster?
            //    Destroy(shadowCaster.GetComponent<ShadowCaster2D>());
            ShadowCaster2D shadowCasterComponent = shadowCaster.AddComponent <ShadowCaster2D>();
            shadowCasterComponents.Add(shadowCasterComponent);
            shadowCasterComponent.selfShadows = selfShadows;
        }
    }
Ejemplo n.º 21
0
    /// <summary>
    /// 增加碰撞
    /// </summary>
    /// <param name="jigsawContainerObj"></param>
    public static CompositeCollider2D addCollider(GameObject jigsawContainerObj)
    {
        Transform[] childsTFs = jigsawContainerObj.GetComponentsInChildren <Transform>();
        if (childsTFs != null)
        {
            int childsTFsSize = childsTFs.Length;
            for (int childPosition = 0; childPosition < childsTFsSize; childPosition++)
            {
                Transform       childsItemTF = childsTFs[childPosition];
                NormalJigsawCpt jigsawItem   = childsItemTF.GetComponent <NormalJigsawCpt>();
                if (jigsawItem == null)
                {
                    continue;
                }
                JigsawBean jigsawData = jigsawItem.getJigsawData();
                if (jigsawData == null)
                {
                    continue;
                }
                JigsawObjBuilder.setCollider2D(childsItemTF.gameObject, jigsawData.CenterVector, jigsawData.JigsawWith, jigsawData.JigsawHigh);
            }
            ;
        }

        CompositeCollider2D jigsawContainerCollider = jigsawContainerObj.AddComponent <CompositeCollider2D>();

        if (jigsawContainerCollider != null)
        {
            jigsawContainerCollider.geometryType   = CompositeCollider2D.GeometryType.Polygons;
            jigsawContainerCollider.generationType = CompositeCollider2D.GenerationType.Synchronous;
        }
        return(jigsawContainerCollider);
    }
Ejemplo n.º 22
0
        bool ValidatePathCache()
        {
#if CINEMACHINE_PHYSICS_2D
            if (m_BoundingShape2DCache != m_BoundingShape2D)
            {
                InvalidatePathCache();
                m_BoundingShape2DCache = m_BoundingShape2D;
            }

            Type colliderType = m_BoundingShape2D == null ? null:  m_BoundingShape2D.GetType();
            if (colliderType == typeof(PolygonCollider2D))
            {
                PolygonCollider2D poly = m_BoundingShape2D as PolygonCollider2D;
                if (m_pathCache == null || m_pathCache.Count != poly.pathCount || m_pathTotalPointCount != poly.GetTotalPointCount())
                {
                    m_pathCache = new List <List <Vector2> >();
                    for (int i = 0; i < poly.pathCount; ++i)
                    {
                        Vector2[]      path = poly.GetPath(i);
                        List <Vector2> dst  = new List <Vector2>();
                        for (int j = 0; j < path.Length; ++j)
                        {
                            dst.Add(path[j]);
                        }
                        m_pathCache.Add(dst);
                    }
                    m_pathTotalPointCount = poly.GetTotalPointCount();
                }
                return(true);
            }
            else if (colliderType == typeof(CompositeCollider2D))
            {
                CompositeCollider2D poly = m_BoundingShape2D as CompositeCollider2D;
                if (m_pathCache == null || m_pathCache.Count != poly.pathCount || m_pathTotalPointCount != poly.pointCount)
                {
                    m_pathCache = new List <List <Vector2> >();
                    Vector2[] path       = new Vector2[poly.pointCount];
                    var       lossyScale = m_BoundingShape2D.transform.lossyScale;
                    Vector2   revertCompositeColliderScale = new Vector2(
                        1f / lossyScale.x,
                        1f / lossyScale.y);
                    for (int i = 0; i < poly.pathCount; ++i)
                    {
                        int            numPoints = poly.GetPath(i, path);
                        List <Vector2> dst       = new List <Vector2>();
                        for (int j = 0; j < numPoints; ++j)
                        {
                            dst.Add(path[j] * revertCompositeColliderScale);
                        }
                        m_pathCache.Add(dst);
                    }
                    m_pathTotalPointCount = poly.pointCount;
                }
                return(true);
            }
#endif
            InvalidatePathCache();
            return(false);
        }
Ejemplo n.º 23
0
 protected override void Start()
 {
     base.Start();
     radius       = GetComponent <CircleCollider2D>().radius;
     gridCollider = GameObject.Find("Grid").GetComponentInChildren <CompositeCollider2D>();
     InvokeRepeating("spawnProjectileBarrage", 2f, timeBetweenShooting);
     StartCoroutine(moveAway());
 }
        public static Vector2[] GetPathPoints(this CompositeCollider2D composite, int index)
        {
            int count = composite.GetPathPointCount(index);

            Vector2[] points = new Vector2[count];
            composite.GetPath(index, points);
            return(points);
        }
Ejemplo n.º 25
0
    void Start()
    {
        //hämtar komponenten CompositeCollider2D hos föräldern och ger cc det värdet
        cc = GetComponentInParent <CompositeCollider2D>();

        //hämtar komponenten TilemapRenderer hos föräldern och ger tmRend det värdet
        tmRend = GetComponentInParent <TilemapRenderer>();
    }
 // Use this for initialization
 void Start()
 {
     col           = GetComponent <CompositeCollider2D>();
     rend          = GetComponent <Renderer>();
     rend.enabled  = active;
     col.isTrigger = !active;
     player        = FindObjectOfType <PlayerController>();//.GetComponent<CapsuleCollider2D>();
 }
Ejemplo n.º 27
0
 void Awake()
 {
     _selfCollider = GetComponent <CompositeCollider2D>();
     if (FallClip != null)
     {
         FallClip.LoadAudioData();
     }
 }
Ejemplo n.º 28
0
        public CompositeCollider2D GetCompositeCollider()
        {
            if (compositeCollider == null)
            {
                compositeCollider = transform.GetComponent <CompositeCollider2D>();
            }

            return(compositeCollider);
        }
Ejemplo n.º 29
0
    void OnTriggerStay2D(Collider2D col)
    {
        CompositeCollider2D tileCollider = col.GetComponent <CompositeCollider2D>();

        if (tileCollider != null)
        {
            fistAttack.Collide();
        }
    }
        private void Awake()
        {
            confinerFinder = GetComponentInParent <ConfinerFinder>();

            if (!useCustomBounds)
            {
                compositeCollider2D = GetComponent <CompositeCollider2D>();
            }
        }