Esempio n. 1
0
    public void ApplyCurrentOperation()
    {
        operandSlots.Init();

        //setup operands
        var operandCount = mOperation.operands.Length;

        for (int i = 0; i < operandCount; i++)
        {
            var operand = mOperation.operands[i];

            CardWidget newCard;

            if (operand.isEmpty)
            {
                newCard = null;
            }
            else
            {
                mCardParms[CardWidget.parmWholeEnabled]   = cardWholeEnabled;
                mCardParms[CardWidget.parmNumber]         = operand.number;
                mCardParms[CardWidget.parmCanDragInside]  = true;
                mCardParms[CardWidget.parmCanDragOutside] = false;
                mCardParms[CardWidget.parmFractionVisual] = true;
                mCardParms[CardWidget.parmCardDrop]       = operandSlots;
                mCardParms[CardWidget.parmCardDropIndex]  = i;

                newCard = mPool.Spawn <CardWidget>(cardTemplate.name, "", null, mCardParms);
            }

            operandSlots.SetCard(i, newCard);
        }

        for (int i = operandCount; i < operandSlots.slots.Length; i++) //hide other operands
        {
            operandSlots.SetActive(i, false);
        }
        //

        //setup operators
        int operatorCount = mOperation.operators.Length;

        for (int i = 0; i < operatorCount; i++)
        {
            var op     = mOperation.operators[i];
            var opSlot = operatorSlots[i];

            opSlot.SetOperator(op);
            opSlot.gameObject.SetActive(true);
        }

        for (int i = operatorCount; i < operatorSlots.Length; i++) //hide other operands
        {
            operatorSlots[i].gameObject.SetActive(false);
        }
        //

        //setup answer input
        RefreshAnswerInput();
    }
Esempio n. 2
0
    public GameObject Spawn(string templateName, Vector2 position, float rotate, M8.GenericParams parms)
    {
        GameObject spawnGO = null;

        TemplateInfo template = null;

        for (int i = 0; i < templates.Length; i++)
        {
            if (templates[i].name == templateName)
            {
                template = templates[i];
                break;
            }
        }

        if (template != null)
        {
            mSpawnParms.Clear();

            mSpawnParms[JellySpriteSpawnController.parmPosition] = position;
            mSpawnParms[JellySpriteSpawnController.parmRotation] = rotate;

            mSpawnParms.Merge(parms, true);

            var spawn = mPool.Spawn(templateName, templateName, null, mSpawnParms);
            spawnGO = spawn.gameObject;
        }
        else
        {
            Debug.LogWarning("Template does not exists: " + templateName);
        }

        return(spawnGO);
    }
Esempio n. 3
0
    public GridEntity Spawn(GridCell cell, GridCell cellSize)
    {
        GridEntity ret = null;

        //ensure we can spawn on given cell info
        var container = GridEditController.instance.entityContainer;

        if (container.IsPlaceable(cell, cellSize, null))
        {
            if (!mPool)
            {
                mPool = M8.PoolController.CreatePool(poolGroup);
                mPool.AddType(template, poolCapacity, poolCapacity);
            }

            if (mSpawnParms == null)
            {
                mSpawnParms = new M8.GenericParams();
            }

            mSpawnParms[GridEntity.parmData]      = this;
            mSpawnParms[GridEntity.parmCellIndex] = cell;
            mSpawnParms[GridEntity.parmCellSize]  = cellSize;

            ret = mPool.Spawn <GridEntity>(template.name, name, container.root, mSpawnParms);
        }

        return(ret);
    }
Esempio n. 4
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);
            }
        }
    }
Esempio n. 5
0
    IEnumerator DoSpawn()
    {
        var waitStart      = new WaitForSeconds(startDelay);
        var waitAfterSpawn = new WaitForSeconds(spawnAfterDelay);

        yield return(waitStart);

        while (true)
        {
            Vector2 spawnPt = spawnPoint.position;

#if UNITY_EDITOR
            ApplyParams();
#endif

            var spawn = mPool.Spawn(template.name, template.name, null, mParms);
            spawn.despawnCallback += OnSpawnRelease;

            spawn.transform.position = spawnPt;

            mActives.Add(spawn);

            while (mActives.Count == activeCount)
            {
                yield return(null);
            }

            yield return(waitAfterSpawn);
        }
    }
Esempio n. 6
0
    IEnumerator DoSpawnQueue()
    {
        var wait = new WaitForSeconds(spawnDelay);

        while (mSpawnQueue.Count > 0)
        {
            while (mBlobActives.IsFull) //wait for blobs to release
            {
                yield return(null);
            }

            yield return(wait);

            var spawnInfo = mSpawnQueue.Dequeue();

            //find valid spawn point
            Vector2 spawnPt = Vector2.zero;

            while (true)
            {
                var pt = mSpawnPts[mCurSpawnPtInd];
                mCurSpawnPtInd++;
                if (mCurSpawnPtInd == mSpawnPts.Length)
                {
                    mCurSpawnPtInd = 0;
                }

                //check if valid
                var coll = Physics2D.OverlapCircle(pt, spawnPointCheckRadius, spawnPointCheckMask);
                if (!coll)
                {
                    spawnPt = pt;
                    break;
                }

                //invalid, check next
                yield return(null);
            }

            //spawn
            mSpawnParms[JellySpriteSpawnController.parmPosition] = spawnPt;
            mSpawnParms[Blob.parmNumber] = spawnInfo.number;

            var template = templateGroups[spawnInfo.templateIndex].template;

            mBlobNameCache.Clear();
            mBlobNameCache.Append(template.name);
            mBlobNameCache.Append(' ');
            mBlobNameCache.Append(spawnInfo.number);

            var blob = mPool.Spawn <Blob>(template.name, mBlobNameCache.ToString(), null, mSpawnParms);

            blob.poolData.despawnCallback += OnBlobRelease;

            mBlobActives.Add(blob);
        }

        mSpawnRout = null;
    }
            public void Spawn()
            {
                Transform t = PoolController.Spawn(grp, type, type + id, null, pos, rot);

                SceneSerializer ss = t.GetComponent <SceneSerializer>();

                ss.__SetID(id);
            }
Esempio n. 8
0
    public void Play(Vector2 start, MixedNumber number)
    {
        //convert start, assume world space to screen space (UI)
        var     cam = M8.Camera2D.main.unityCamera;
        Vector2 pos = cam.WorldToScreenPoint(start);

        var widget = mPool.Spawn <MixedNumberWidget>("", transform, pos, null);

        widget.number = number;

        StartCoroutine(DoActive(widget));
    }
Esempio n. 9
0
        public static Transform Spawn(string group, string type, string name, Transform toParent, Vector3 position)
        {
            PoolController pc = GetPool(group);

            if (pc != null)
            {
                return(pc.Spawn(type, name, toParent, position));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 10
0
    IEnumerator DoSpawnAll(SpriteShape spriteShape, float delayPerSpawn)
    {
        var wait = new WaitForSeconds(delayPerSpawn);

        mParms[Rock.parmSpriteShape] = spriteShape;
        mParms[Rock.parmDir]         = (Vector2)spawnPoint.up;

        for (int i = 0; i < capacity; i++)
        {
            mPool.Spawn(name, "", null, spawnPoint.position, mParms);
            yield return(wait);
        }
    }
Esempio n. 11
0
    public void Fill(MixedNumber[] numbers)
    {
        if (!mPool)
        {
            mPool = M8.PoolController.CreatePool(cardPoolGroup);
            mPool.AddType(cardTemplate, cardPoolCapacity, cardPoolCapacity);
        }

        if (cards != null)
        {
            Clear();
        }
        else
        {
            cards = new CardWidget[slotAnchors.Length];
        }

        M8.ArrayUtil.Shuffle(numbers);

        count = numbers.Length;
        if (count > slotAnchors.Length)
        {
            count = slotAnchors.Length;
        }

        for (int i = 0; i < count; i++)
        {
            mCardParms[CardWidget.parmWholeEnabled]   = cardWholeEnabled;
            mCardParms[CardWidget.parmNumber]         = numbers[i];
            mCardParms[CardWidget.parmCanDragInside]  = false;
            mCardParms[CardWidget.parmCanDragOutside] = true;
            mCardParms[CardWidget.parmFractionVisual] = false;
            mCardParms[CardWidget.parmCardDrop]       = this;
            mCardParms[CardWidget.parmCardDropIndex]  = i;

            var newCard = mPool.Spawn <CardWidget>(cardTemplate.name, "", null, mCardParms);

            newCard.transform.SetParent(slotAnchors[i], false);
            newCard.transform.localPosition = Vector3.zero;

            cards[i] = newCard;

            slotAnchors[i].gameObject.SetActive(true);
        }

        for (int i = count; i < slotAnchors.Length; i++)
        {
            slotAnchors[i].gameObject.SetActive(false);
        }
    }
Esempio n. 12
0
        public static Transform Spawn(string group, string type, string name, Transform toParent, Vector2 position)
        {
            PoolController pc = GetPool(group);

            if (pc != null)
            {
                Transform t = pc.Spawn(type, name, toParent, position);
                Vector3   p = t.localPosition;
                p.z             = 0.0f;
                t.localPosition = p;
                return(t);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 13
0
    void AddNewPaletteItem(BlockInfo blockInfo, bool showIntro)
    {
        var parms = new M8.GenericParams();

        parms[PaletteItemWidget.paramBlockInfo] = blockInfo;
        parms[PaletteItemWidget.paramShowIntro] = showIntro;

        PaletteItemWidget widget = widgetPool.Spawn <PaletteItemWidget>(blockInfo.name, widgetContainer, parms);

        widget.releaseCallback += OnWidgetRelease;

        //hide if we are in play mode
        if (GameMapController.instance.mode == GameMapController.Mode.Play)
        {
            widget.gameObject.SetActive(false);
        }

        mActiveWidgets.Add(widget);
    }
Esempio n. 14
0
    protected override void DragEnd()
    {
        if (isDropValid)
        {
            if (curSpace == DragWidgetSpace.World)
            {
                var spawn = mPool.Spawn <M8.EntityBase>(entityTemplate.name, "", null, mParms);

                spawn.releaseCallback   += OnEntityRelease;
                spawn.transform.position = cursorWorld.spawnPoint;
                spawn.transform.rotation = Quaternion.AngleAxis(Vector2.SignedAngle(Vector2.up, cursorWorld.spawnUp), Vector3.forward);

                //spawn.transform.up = cursorWorld.spawnUp;

                mActiveUnits.Add(spawn);

                UpdateState();
            }
        }
    }
Esempio n. 15
0
    public M8.EntityBase Spawn()
    {
        if (!mIsForceSet)
        {
            SetForce(forceDefault);
        }
        if (!mIsDirSet)
        {
            SetDirAngle(angleDefault);
        }

        var parms = new M8.GenericParams();

        parms[UnitEntity.parmPosition]       = spawnPoint.position;
        parms[UnitStateForceApply.parmDir]   = mDir;
        parms[UnitStateForceApply.parmForce] = mForce;

        var ent = mPool.Spawn <M8.EntityBase>(template.name, "", null, parms);

        return(ent);
    }
Esempio n. 16
0
    void OnBlobDragBegin(Blob blob)
    {
        if (!mCurConnectDragging)
        {
            mConnectSpawnParms.Clear();
            //params?

            mCurConnectDragging = mPool.Spawn <BlobConnect>(connectTemplate.name, "", null, mConnectSpawnParms);
        }

        curBlobDragging = blob;

        var toOp = mCurOp;

        //determine what the operator is based on blob's current connect state

        mCurConnectDragging.op    = toOp;
        mCurConnectDragging.state = BlobConnect.State.Connecting;

        if (mCurConnectDragging.connectingSpriteRender)
        {
            mCurConnectDragging.connectingSpriteRender.color = curBlobDragging.color;
        }

        //determine if this is in a group
        curGroupDragging = GetGroup(blob);
        if (curGroupDragging != null)
        {
            //highlight entire group

            //flip operand order based if it's the first operand
            if (blob == curGroupDragging.blobOpLeft)
            {
                curGroupDragging.blobOpLeft  = curGroupDragging.blobOpRight;
                curGroupDragging.blobOpRight = blob;
            }
        }
    }
Esempio n. 17
0
        public static T Spawn <T>(string spawnGroup, string typeName, Vector3 position) where T : EntityBase
        {
#if POOLMANAGER
            SpawnPool pool = PoolManager.Pools[spawnGroup];

            Transform spawned = pool.Spawn(pool.prefabs[typeName]);
            T         ent     = spawned != null?spawned.GetComponent <T>() : null;

            if (ent != null)
            {
                ent.transform.position = position;

                //add pool data controller
            }

            return(ent);
#else
            Transform spawned = PoolController.Spawn(spawnGroup, typeName, typeName, null, position);
            T         ent     = spawned != null?spawned.GetComponent <T>() : null;

            return(ent);
#endif
        }
Esempio n. 18
0
    //returns true if we are done
    private void SpawnCurrentEnemies(bool generateTelemetry)
    {
        if (mCurSpawnInd == spawns.Length)
        {
            return;
        }

        var spawnDat = spawns[mCurSpawnInd];

        mSpawnReachGoalCount = 0;

        if (generateTelemetry)
        {
            mSpawnParm[UnitVelocityMoveController.parmSpeed] = (float)Random.Range(spawnDat.speedMin, spawnDat.speedMax + 1);
            mSpawnParm[UnitVelocityMoveController.parmAccel] = (float)Random.Range(spawnDat.accelMin, spawnDat.accelMax + 1);
        }

        int spawnCount = Mathf.Min(mEnterPoints.Length, spawnDat.pointIndices.Length);

        for (int i = 0; i < spawnCount; i++)
        {
            int spawnPtInd = Mathf.Clamp(spawnDat.pointIndices[i], 0, mEnterPoints.Length - 1); //fail-safe

            var enterPt = mEnterPoints[spawnPtInd];
            var spawnPt = new Vector2(enterPt.x + spawnStartDistance, enterPt.y);

            var ent = mPool.Spawn <M8.EntityBase>(spawnTemplate.name, "", null, spawnPt, mSpawnParm);

            ent.releaseCallback += OnSpawnReleased;

            mSpawns.Add(new SpawnData()
            {
                ent = ent, enterPt = enterPt, spawnPt = spawnPt
            });
        }
    }
Esempio n. 19
0
    IEnumerator DoRecording()
    {
        var waitFixed = new WaitForFixedUpdate();

        while (!points.IsFull && mBody.simulated && mBody.gameObject.activeInHierarchy)
        {
            var pt  = mBody.position;
            var rot = mBody.rotation;

            //var vel = mBody.velocity;
            Vector2 vel;
            if (points.Count == 0)
            {
                vel = Vector2.zero;
            }
            else
            {
                vel = (pt - points[points.Count - 1].position) / timeInterval;
            }

            Vector2 accel;

            if (points.Count == 0)
            {
                accel = Vector2.zero;
            }
            else
            {
                accel = (vel - points[points.Count - 1].velocity) / timeInterval;
            }

            mPool.Spawn(template.name, points.Count.ToString(), null, pt, null);

            if (points.Count == 0)
            {
                mMinPosition    = mMaxPosition = pt;
                mMinVelocity    = mMaxVelocity = vel;
                mMinAccelApprox = mMaxAccelApprox = accel;
            }
            else
            {
                if (pt.x < mMinPosition.x)
                {
                    mMinPosition.x = pt.x;
                }
                if (pt.x > mMaxPosition.x)
                {
                    mMaxPosition.x = pt.x;
                }

                if (pt.y < mMinPosition.y)
                {
                    mMinPosition.y = pt.y;
                }
                if (pt.y > mMaxPosition.y)
                {
                    mMaxPosition.y = pt.y;
                }

                if (vel.x < mMinVelocity.x)
                {
                    mMinVelocity.x = vel.x;
                }
                if (vel.x > mMaxVelocity.x)
                {
                    mMaxVelocity.x = vel.x;
                }

                if (vel.y < mMinVelocity.y)
                {
                    mMinVelocity.y = vel.y;
                }
                if (vel.y > mMaxVelocity.y)
                {
                    mMaxVelocity.y = vel.y;
                }

                if (accel.x < mMinAccelApprox.x)
                {
                    mMinAccelApprox.x = accel.x;
                }
                if (accel.x > mMaxAccelApprox.x)
                {
                    mMaxAccelApprox.x = accel.x;
                }

                if (accel.y < mMinAccelApprox.y)
                {
                    mMinAccelApprox.y = accel.y;
                }
                if (accel.y > mMaxAccelApprox.y)
                {
                    mMaxAccelApprox.y = accel.y;
                }
            }

            points.Add(new PointData()
            {
                position = pt, rotate = rot, velocity = vel, accelApprox = accel
            });

            float curTime = 0f;
            while (curTime < timeInterval)
            {
                yield return(waitFixed);

                curTime += Time.fixedDeltaTime;
            }
        }

        mRecordRout = null;
    }
Esempio n. 20
0
    void Populate()
    {
        string questionStr = mQuestionData.stem;

        //TODO: multi images?
        const string imageTag     = "[IMAGE]";
        int          imageTagSize = imageTag.Length;

        int imageInd = questionStr.IndexOf("[IMAGE]");

        if (imageInd == -1)
        {
            Text txt = pool.Spawn <Text>(textPoolRef, textPoolRef, content, null);
            txt.transform.SetSiblingIndex(0);
            txt.text = questionStr;
        }
        else
        {
            string line1 = "";
            if (imageInd > 0)
            {
                line1 = questionStr.Substring(0, imageInd).TrimEnd();
            }

            string line2 = "";
            if (imageInd + imageTagSize < questionStr.Length)
            {
                line2 = questionStr.Substring(imageInd + imageTagSize).Trim();
            }

            int ind = 0;

            if (line1.Length > 0)
            {
                Text txt = pool.Spawn <Text>(textPoolRef, textPoolRef, content, null);
                txt.transform.SetSiblingIndex(ind); ind++;
                txt.text = line1;
            }

            if (!string.IsNullOrEmpty(mQuestionData.imageURL))
            {
                RawImage img = pool.Spawn <RawImage>(imagePoolRef, imagePoolRef, content, null);
                img.transform.SetSiblingIndex(ind); ind++;

                StartCoroutine(DoLoadTexture(mQuestionData.imageURL, img));
            }
            if (line2.Length > 0)
            {
                Text txt = pool.Spawn <Text>(textPoolRef, textPoolRef, content, null);
                txt.transform.SetSiblingIndex(ind); ind++;
                txt.text = line2;
            }
        }

        //choices
        int c = Mathf.Min(choiceTexts.Length, mQuestionData.alternatives.Length);

        for (int i = 0; i < c; i++)
        {
            if (choiceTexts[i])
            {
                choiceTexts[i].gameObject.SetActive(true);
                choiceTexts[i].text = mQuestionData.alternatives[i].text;
            }
        }

        //fail-safe for cheeky questions with < 4 choices
        for (int i = c; i < choiceTexts.Length; i++)
        {
            if (choiceTexts[i])
            {
                choiceTexts[i].gameObject.SetActive(false);
            }
        }
    }
Esempio n. 21
0
    IEnumerator DoGoblins()
    {
        var knightSpawner         = (EntitySpawnerWidget)unitSpawnerWidget;
        int lastKnightActiveCount = 0;

        for (int i = goblinPts.Length - 1; i >= 0; i--)
        {
            var t = goblinPts[i];

            var goblin = mGoblinPoolCtrl.Spawn <UnitEntity>(goblinTemplate.name, "", null, t.position, null);

            mGoblins.Add(goblin);

            yield return(new WaitForSeconds(Random.Range(0.3f, 0.6f)));
        }

        bool isFirst = true;

        while (mGoblins.Count > 0)
        {
            var goblin = mGoblins.RemoveLast();

            while (!goblin.body.simulated) //wait for it to be physically active
            {
                yield return(null);
            }

            //wait for knight to be spawned
            while (knightSpawner.activeUnitCount == lastKnightActiveCount)
            {
                yield return(null);
            }

            lastKnightActiveCount = knightSpawner.activeUnitCount;

            //wait for block to be moving to the right
            while (block1.body.velocity.x <= block1VelocityXThreshold)
            {
                yield return(null);
            }

            //wait a bit
            if (isFirst)
            {
                isFirst = false;
                yield return(new WaitForSeconds(2f));
            }

            //move goblin
            goblin.bodyMoveCtrl.moveHorizontal = -1f;

            //activate goblin force display once it touches
            if (!block1ForceGoblinGO.activeSelf)
            {
                while ((goblin.bodyMoveCtrl.collisionFlags & CollisionFlags.CollidedSides) == CollisionFlags.None)
                {
                    yield return(null);
                }

                block1ForceGoblinGO.SetActive(true);
            }
        }
    }