示例#1
0
    public void ClearGroup(Group group)
    {
        for (int i = 0; i < mGroupActives.Count; i++)
        {
            if (mGroupActives[i] == group)
            {
                group.Clear();

                mGroupActives.RemoveAt(i);
                mGroupCache.Add(group);
                break;
            }
        }
    }
示例#2
0
    void OnGhostBlockRelease(M8.EntityBase ent)
    {
        if (mBlockGhost == ent)  //we shouldn't really get here with an active ghost
        {
            mBlockGhost.dimensionChangedCallback -= OnGhostBlockDimensionChanged;
            mBlockGhost.releaseCallback          -= OnGhostBlockRelease;
            mBlockGhost = null;

            ClearDragging();

            UpdateCount();
        }
        else
        {
            for (int i = 0; i < mGhostActives.Count; i++)
            {
                if (mGhostActives[i] == ent)
                {
                    mGhostActives[i].dimensionChangedCallback -= OnGhostBlockDimensionChanged;
                    mGhostActives[i].releaseCallback          -= OnGhostBlockRelease;

                    mGhostMatterCount -= mGhostActives[i].matterCount;

                    mGhostActives.RemoveAt(i);

                    UpdateCount();
                    break;
                }
            }
        }

        UpdateInteractible();
    }
示例#3
0
 protected void RemoveColl(int ind)
 {
     if (ind < mColls.Count)
     {
         mColls.RemoveAt(ind);
     }
 }
示例#4
0
    void OnTriggerExit2D(Collider2D collision)
    {
        //check surfaces
        for (int i = 0; i < mSurfaceCache.Count; i++)
        {
            var dat = mSurfaceCache[i];
            if (dat.coll == collision)
            {
                mSurfaceCache.RemoveAt(i);

                //recompute surface
                ComputeSurface(false);
                return;
            }
        }

        //check killables
        for (int i = 0; i < mKillableCache.Count; i++)
        {
            var dat = mKillableCache[i];
            if (dat.coll == collision)
            {
                mKillableCache.RemoveAt(i);
                return;
            }
        }
    }
示例#5
0
            public PoolDataController Allocate(string group, string name, Transform parent)
            {
                if (mAvailable.Count == 0)
                {
                    if (mActives.IsFull)
                    {
                        Debug.LogWarning(template.name + " is expanding beyond max capacity: " + maxCapacity);

                        Expand(group, maxCapacity);
                    }
                    else
                    {
                        Expand(group, 1);
                    }
                }

                PoolDataController pdc = mAvailable[mAvailable.Count - 1];

                mAvailable.RemoveAt(mAvailable.Count - 1);

                Transform t = pdc.transform;

                t.name = string.IsNullOrEmpty(name) ? template.name + (mNameHolder++) : name;

                t.SetParent(parent == null ? defaultParent : parent, false);

                t.gameObject.SetActive(true);

                mActives.Add(pdc);

                return(pdc);
            }
示例#6
0
    void OnTriggerExit2D(Collider2D collision)
    {
        if (!string.IsNullOrEmpty(tagFilter) && !collision.CompareTag(tagFilter))
        {
            return;
        }

        for (int i = 0; i < mBodies.Count; i++)
        {
            if (mBodies[i] && mBodies[i].gameObject == collision.gameObject)
            {
                mBodies.RemoveAt(i);
                break;
            }
        }
    }
示例#7
0
    void Update()
    {
        var activeCount = mPlantActives.Count;

        if (activeCount > mCurCount)
        {
            int count = activeCount - mCurCount;
            for (int i = 0; i < count; i++)
            {
                var pdc = mPlantActives.RemoveLast();
                mSpawnPts.Add(pdc.transform.parent);
                pdc.Release();
            }
        }
        else if (activeCount < mCurCount)
        {
            int count = mCurCount - activeCount;
            for (int i = 0; i < count; i++)
            {
                int spawnToInd   = Random.Range(0, mSpawnPts.Count);
                var spawnToTrans = mSpawnPts[spawnToInd];
                mSpawnPts.RemoveAt(spawnToInd);

                var parms = new M8.GenericParams();
                parms[Plant.parmSourceSun] = sourceSun;

                var pdc = mPoolCtrl.Spawn(template.name, "plant", spawnToTrans, parms);
                pdc.transform.localPosition = Vector3.zero;
                pdc.transform.localScale    = Vector3.one;

                mPlantActives.Add(pdc);
            }
        }
    }
示例#8
0
 void OnTriggerExit2D(Collider2D collision)
 {
     for (int i = 0; i < mTriggerContacts.Count; i++)
     {
         if (mTriggerContacts[i].coll == collision)
         {
             mTriggerContacts.RemoveAt(i);
             return;
         }
     }
 }
示例#9
0
    void OnCollisionExit2D(Collision2D collision)
    {
        var coll = collision.collider;

        for (int i = 0; i < mCollisionContacts.Count; i++)
        {
            if (mCollisionContacts[i].coll == coll)
            {
                mCollisionContacts.RemoveAt(i);
                return;
            }
        }
    }
示例#10
0
    void OnBlobRelease(M8.PoolDataController pdc)
    {
        pdc.despawnCallback -= OnBlobRelease;

        for (int i = 0; i < mBlobActives.Count; i++)
        {
            var blob = mBlobActives[i];
            if (blob && blob.poolData == pdc)
            {
                mBlobActives.RemoveAt(i);
                break;
            }
        }
    }
示例#11
0
    void OnSpawnReleased(M8.EntityBase ent)
    {
        for (int i = 0; i < mSpawns.Count; i++)
        {
            if (mSpawns[i].ent == ent)
            {
                ent.releaseCallback -= OnSpawnReleased;
                mSpawns.RemoveAt(i);

                //scoring

                break;
            }
        }
    }
示例#12
0
    void OnMoveCollisionExit(EntityHeroMoveController ctrl, Collision2D coll)
    {
        //check for heat controller
        var heatCtrl = coll.collider.GetComponent <HeatController>();

        if (heatCtrl)
        {
            for (int i = 0; i < mHeatCollides.Count; i++)
            {
                if (mHeatCollides[i].heat == heatCtrl)
                {
                    mHeatCollides.RemoveAt(i);
                    break;
                }
            }
        }
    }
示例#13
0
    /// <summary>
    /// Returns how much was added
    /// </summary>
    private int GroupAddEntities(GridEntity srcEnt, M8.CacheList <GridEntity> ents, List <GridEntity> group)
    {
        var addedCount = 0;

        var _cellInd  = new GridCell();
        var _cellSize = new GridCell();

        int curInd = ents.Count - 1;

        while (curInd >= 0)
        {
            var checkEnt = ents[curInd];
            if (checkEnt.data != srcEnt.data)
            {
                curInd--;
                continue;
            }

            //check with top/bottom extended
            _cellInd       = srcEnt.cellIndex;
            _cellInd.row  -= 1;
            _cellSize      = srcEnt.cellSize;
            _cellSize.row += 2;

            if (GridCell.IsIntersectFloor(_cellInd, _cellSize, checkEnt.cellIndex, checkEnt.cellSize))
            {
                ents.RemoveAt(curInd);
                group.Add(checkEnt);
                addedCount++;

                //check this entity with the rest
                var subAddCount = GroupAddEntities(checkEnt, ents, group);
                if (subAddCount > 0)
                {
                    addedCount += subAddCount;
                    curInd      = ents.Count - 1;
                }
                else
                {
                    curInd--;
                }

                continue;
            }

            //check with left/right extended
            _cellInd       = srcEnt.cellIndex;
            _cellInd.col  -= 1;
            _cellSize      = srcEnt.cellSize;
            _cellSize.col += 2;
            if (GridCell.IsIntersectFloor(_cellInd, _cellSize, checkEnt.cellIndex, checkEnt.cellSize))
            {
                ents.RemoveAt(curInd);
                group.Add(checkEnt);
                addedCount++;

                //check this entity with the rest
                var subAddCount = GroupAddEntities(checkEnt, ents, group);
                if (subAddCount > 0)
                {
                    addedCount += subAddCount;
                    curInd      = ents.Count - 1;
                }
                else
                {
                    curInd--;
                }

                continue;
            }

            curInd--;
        }

        return(addedCount);
    }
示例#14
0
        protected virtual void FixedUpdate()
        {
#if UNITY_EDITOR
            mDefaultForceDir = MathUtil.RotateAngle(Vector2.up, defaultForceOrient);
            mDefaultForce    = defaultForce * mDefaultForceDir;
#endif

            //apply fields
            if (!ignoreFields)
            {
                var newOrient  = Vector2.zero;
                var newForce   = mDefaultForce;
                int fieldCount = 0;

                //global
                var forceField = ForceFieldBase2D.global;
                if (forceField && forceField.gameObject.activeSelf && forceField.enabled)
                {
                    var dir = forceField.GetDir(this);

                    newOrient += dir;
                    newForce  += forceField.GetForce(this) * dir;

                    fieldCount++;
                }

                //field contacts
                for (int i = mForceFields.Count - 1; i >= 0; i--)
                {
                    forceField = mForceFields[i];
                    if (forceField && forceField.gameObject.activeSelf && forceField.enabled)
                    {
                        var dir = forceField.GetDir(this);

                        newOrient += dir;
                        newForce  += forceField.GetForce(this) * dir;

                        fieldCount++;
                    }
                    else //not active, remove it
                    {
                        mForceFields.RemoveAt(i);
                    }
                }

                if (fieldCount > 0)
                {
                    if (fieldCount > 1)
                    {
                        newOrient.Normalize();
                    }

                    mOrientDestDir   = newOrient;
                    mOrientAngleToUp = Vector2.SignedAngle(mOrientDestDir, Vector2.up);
                    force            = newForce;
                }
            }
            else
            {
                mOrientDestDir   = mDefaultForceDir;
                mOrientAngleToUp = defaultForceOrient;
                force            = mDefaultForce;
            }

            //apply force
            if (!forceLocked)
            {
                body.AddForce(force * forceScale, ForceMode2D.Force);
            }

            //apply orient
            if (orient != OrientMode.None)
            {
                var curOrient = GetOrientDir();
                if (curOrient != mOrientDestDir)
                {
                    if (orientDelay > 0f)
                    {
                        float curAngleToUp = Vector2.SignedAngle(curOrient, Vector2.up);

                        float angleToUp = Mathf.SmoothDampAngle(curAngleToUp, mOrientAngleToUp, ref mOrientChangeVel, orientDelay, float.MaxValue, Time.fixedDeltaTime);

                        ApplyOrientDir(MathUtil.RotateAngle(Vector2.up, angleToUp));
                    }
                    else
                    {
                        ApplyOrientDir(mOrientDestDir);
                    }

                    /*float angle = Vector2.SignedAngle(curOrient, mOrientDestDir);
                     * float deltaAngle = Time.fixedDeltaTime * orientAngleSpeed;
                     *
                     * if(angle > 0f) {
                     *  if(angle - deltaAngle > 0f)
                     *      ApplyOrientDir(MathUtil.RotateAngle(curOrient, -deltaAngle));
                     *  else
                     *      ApplyOrientDir(mOrientDestDir);
                     * }
                     * else {
                     *  if(angle + deltaAngle < 0f)
                     *      ApplyOrientDir(MathUtil.RotateAngle(curOrient, deltaAngle));
                     *  else
                     *      ApplyOrientDir(mOrientDestDir);
                     * }*/
                }
            }
        }
        void Update()
        {
            if (mCurTime >= delay)
            {
                mCurTime = 0f;

                int count = PopulateCollisions(mColls);

                //remove some actives
                for (int i = mActives.Count - 1; i >= 0; i--)
                {
                    var active = mActives[i];

                    //no longer valid?
                    if (active.collider == null || !ArrayUtil.Contains(mColls, 0, count, active.collider))
                    {
                        if (active.activator)
                        {
                            active.activator.Deactivate();
                        }

                        mActives.RemoveAt(i);
                    }
                }

                //add new actives
                int activeCount = mActives.Count;
                for (int i = 0; i < count; i++)
                {
                    var coll = mColls[i];

                    //ignore if tag not match
                    if (tagFilters.Length > 0)
                    {
                        bool isTagMatch = false;
                        for (int t = 0; t < tagFilters.Length; t++)
                        {
                            if (coll.CompareTag(tagFilters[t]))
                            {
                                isTagMatch = true;
                                break;
                            }
                        }

                        if (!isTagMatch)
                        {
                            continue;
                        }
                    }

                    //check if it already exists
                    int activeInd = -1;
                    for (int j = 0; j < activeCount; j++)
                    {
                        var active = mActives[j];
                        if (active.collider == coll)
                        {
                            activeInd = j;
                            break;
                        }
                    }

                    //add
                    if (activeInd == -1)
                    {
                        var activator = coll.GetComponent <GOActivator>();
                        if (activator)
                        {
                            activator.Activate();

                            mActives.Add(new ActiveData {
                                collider = coll, activator = activator
                            });
                        }
                    }
                }
            }
            else
            {
                mCurTime += Time.deltaTime;
            }
        }