Ejemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     anim = GetComponent <Animator>();
     mh   = GetComponent <MoveHorizontalUntilCollision>();
     if (mh != null)
     {
         moveHorizOriginalSpeed = mh.speed;
     }
     d = GetComponent <Damage>();
 }
Ejemplo n.º 2
0
    private string getSaveEntryString(GameObject objectToSave, GameObject staticObjectToSave)
    {
        string entry = "";

        entry += staticObjectToSave.GetComponent <RFIDKey>().rfidKey + ",";
        Vector3 position = staticObjectToSave.transform.position;

        entry += position.x + "," + position.y + "," + position.z + ",";
        Vector3 scale = staticObjectToSave.transform.localScale;

        entry += scale.x + "," + scale.y + "," + scale.z + ",";

        PathFollowing p = objectToSave.GetComponent <PathFollowing>();

        if (p != null)
        {
            entry += p.pathSpeed + ",";
            entry += p.pathPoints.Count + ",";

            for (int i = 0; i < p.pathPoints.Count; i++)
            {
                entry += p.pathPoints[i].x + "," + p.pathPoints[i].y + "," + p.pathPoints[i].z + ",";
            }
        }

        Jump j = objectToSave.GetComponent <Jump>();

        if (j != null)
        {
            entry += j.burst + ",";
        }

        Move m = objectToSave.GetComponent <Move>();

        if (m != null)
        {
            entry += m.maxSpeed[0] + "," + m.maxSpeed[1] + "," + m.maxSpeed[2] + "," + m.maxSpeed[3] + ",";
        }

        MoveHorizontalUntilCollision mh = objectToSave.GetComponent <MoveHorizontalUntilCollision>();

        if (mh != null)
        {
            entry += mh.speed;
        }

        return(entry);
    }
Ejemplo n.º 3
0
    private void specialPlacementLogic(GameObject g, GameObject sg = null, GameObject oldG = null)
    {
        if (sg != null)
        {
            // Special behaviour for Resize component
            Resize r = sg.GetComponent <Resize>();
            if (r != null)
            {
                r.nonStatic = g;
            }
        }

        // Special behaviour for CollideTrigger component
        CollideTrigger ct = g.GetComponent <CollideTrigger>();

        if (ct != null)
        {
            ct.initialize();
        }

        if (oldG != null)
        {
            Transfigure oldT = oldG.GetComponent <Transfigure>();
            if (oldT != null)
            {
                Transfigure t = g.GetComponent <Transfigure>();
                t.targetAndTags.Clear();
                foreach (TargetAnimControllerAndTags tar in oldT.targetAndTags)
                {
                    TargetAnimControllerAndTags newTar = new TargetAnimControllerAndTags();
                    newTar.targetAnimController = tar.targetAnimController;
                    newTar.includedTags         = new List <string>(tar.includedTags);
                    newTar.excludedTags         = new List <string>(tar.excludedTags);
                    newTar.repeatable           = tar.repeatable;
                    newTar.id   = tar.id;
                    newTar.done = false;
                    t.targetAndTags.Add(newTar);
                }
            }
        }

        TimeTrigger tt = g.GetComponent <TimeTrigger>();

        if (tt != null)
        {
            tt.initialize();
        }

        MoveHorizontalUntilCollision mh = g.GetComponent <MoveHorizontalUntilCollision>();

        if (mh != null)
        {
            mh.run();
        }

        KoopaTroopa kt = g.GetComponent <KoopaTroopa>();

        if (kt != null)
        {
            addResetListener(kt);
        }

        FirePower fp = g.GetComponent <FirePower>();

        if (fp != null)
        {
            addResetListener(fp);
        }

        Invisible i = g.GetComponent <Invisible>();

        if (i != null)
        {
            addResetListener(i);
        }
    }
Ejemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        if (!LevelManager.instance.paused)
        {
            if (anim == null)
            {
                anim = GetComponent <Animator>();
            }

            if (mh == null)
            {
                mh = GetComponent <MoveHorizontalUntilCollision>();
                moveHorizOriginalSpeed = mh.speed;
            }

            if (d == null)
            {
                d = GetComponent <Damage>();
            }

            if (dead && !kicked)
            {
                if (deathDelayTimer >= DEATH_DELAY && reviveTimer < REVIVE_TIME)
                {
                    reviveTimer += Time.deltaTime;

                    if (reviveTimer >= REVIVE_TIME)
                    {
                        dead            = false;
                        deathDelayTimer = 0f;
                        anim.SetBool("Dead", false);
                        reviveTimer = 0f;
                        mh.enabled  = true;
                        mh.speed    = moveHorizOriginalSpeed;
                        d.enabled   = true;
                    }
                    anim.SetFloat("ReviveTimer", reviveTimer);
                }
                else if (deathDelayTimer < DEATH_DELAY)
                {
                    deathDelayTimer += Time.deltaTime;
                }
            }
            else if (kicked)
            {
                if (!d.enabled)
                {
                    kickDamageDelayTimer += Time.deltaTime;

                    if (kickDamageDelayTimer >= KICK_DAMAGE_DELAY)
                    {
                        d.enabled            = true;
                        kickDamageDelayTimer = 0f;
                    }
                }

                SpriteRenderer sr = GetComponent <SpriteRenderer>();
                if (!sr.isVisible)
                {
                    gameObject.SetActive(false);
                }
            }
        }
    }
Ejemplo n.º 5
0
    private IEnumerator addComponentByName(GameObject go, GameObject staticGO, string name, string data1, string data2, string data3, string data4, string data5)
    {
        go.layer       = LayerMask.NameToLayer("BlockingLayer");
        staticGO.layer = LayerMask.NameToLayer("BlockingLayer");
        switch (name)
        {
        case "PathFollowing":
            go.AddComponent <PathFollowing>().initDrawing(0, true).setStateToIdle();
            staticGO.AddComponent <PathFollowing>().initDrawing(0, false).setStateToIdle();
            break;

        case "SpriteRenderer":
        {
            SpriteRenderer r  = go.AddComponent <SpriteRenderer>();
            SpriteRenderer sr = staticGO.AddComponent <SpriteRenderer>();
            if (data1.Length > 0)
            {
                int index = data1.LastIndexOf('_');
                if (index > 0)
                {
                    int spriteIndex;
                    if (Int32.TryParse(data1.Substring(index + 1), out spriteIndex))
                    {
                        string   path    = data1.Substring(0, index);
                        Sprite[] sprites = Resources.LoadAll <Sprite>(path);
                        if (spriteIndex < sprites.Length)
                        {
                            r.sprite  = sprites[spriteIndex];
                            sr.sprite = sprites[spriteIndex];
                        }
                    }
                }
                else
                {
                    r.sprite  = Resources.Load <Sprite>(data1);
                    sr.sprite = Resources.Load <Sprite>(data1);
                }
            }
            if (data2.Length > 0)
            {
                r.sortingLayerName  = data2;
                sr.sortingLayerName = data2;
            }
        }
        break;

        case "Animator":
            go.AddComponent <Animator>().runtimeAnimatorController       = Resources.Load <RuntimeAnimatorController>(data1);
            staticGO.AddComponent <Animator>().runtimeAnimatorController = Resources.Load <RuntimeAnimatorController>(data1);
            break;

        case "BoxCollider2D":
        {
            BoxCollider2D bc  = go.AddComponent <BoxCollider2D>();
            BoxCollider2D sbc = staticGO.AddComponent <BoxCollider2D>();
            bool          trigger;
            if (Boolean.TryParse(data1, out trigger))
            {
                bc.isTrigger  = trigger;
                sbc.isTrigger = trigger;
            }
        }
        break;

        case "RigidBody2D":
        {
            Rigidbody2D rb = go.AddComponent <Rigidbody2D>();
            bool        kinematic, fixedAngle;
            if (Boolean.TryParse(data1, out kinematic))
            {
                rb.isKinematic = kinematic;
            }
            if (Boolean.TryParse(data2, out fixedAngle))
            {
                rb.fixedAngle = fixedAngle;
            }
        }
        break;

        case "Tag":
            go.tag = data1;
            if (data1 == "PaintableBackground")
            {
                staticGO.tag = data1;
            }
            break;

        case "CustomScript":
            go.AddComponent(Type.GetType(data1));
            break;

        case "Move":
        {
            Move mc = go.AddComponent <Move>();
            mc.maxSpeed[0] = float.Parse(data1);
            mc.maxSpeed[1] = float.Parse(data2);
            mc.maxSpeed[2] = float.Parse(data3);
            mc.maxSpeed[3] = float.Parse(data4);
        }
        break;

        case "Jump":
        {
            go.AddComponent <Jump>();

            Rigidbody2D rb = null;
            rb = go.GetComponent <Rigidbody2D>();

            if (rb == null)
            {
                rb = go.AddComponent <Rigidbody2D>();
            }

            rb.isKinematic = false;
            rb.fixedAngle  = true;
        }
        break;

        case "Health":
        {
            BoxCollider2D c = null;
            c = go.GetComponent <BoxCollider2D>();

            if (c == null)
            {
                c = go.AddComponent <BoxCollider2D>();
            }

            Health h = go.AddComponent <Health>();
            Int32.TryParse(data1, out h.maxHP);
            Int32.TryParse(data2, out h.startHP);
            Int32.TryParse(data3, out h.directions);
            int deathAction;
            if (Int32.TryParse(data4, out deathAction))
            {
                h.setDeathAction(deathAction);
            }
            float.TryParse(data5, out h.damageCooldown);
        }
        break;

        case "Resize":
        {
            Resize r = staticGO.AddComponent <Resize>();
            r.arrowPrefab = pentaArrow;
            r.nonStatic   = go;
        }
        break;

        case "CollideTrigger":
        {
            CollideTrigger ct = go.GetComponent <CollideTrigger>();
            if (ct == null)
            {
                ct = go.AddComponent <CollideTrigger>();
            }
            CustomAction.ActionTypes a = (CustomAction.ActionTypes)Enum.Parse(typeof(CustomAction.ActionTypes), data1);
            int directions;
            Int32.TryParse(data2, out directions);

            string[]      delimiters = { "|" };
            string[]      tags = data3.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
            List <String> includedTags = new List <String>(), excludedTags = new List <String>();
            for (int i = 0; i < tags.Length; i++)
            {
                if (tags[i].StartsWith("!"))
                {
                    string tag = tags[i].Substring(1);
                    excludedTags.Add(tag);
                }
                else
                {
                    includedTags.Add(tags[i]);
                }
            }

            switch (a)
            {
            case CustomAction.ActionTypes.Spawn:
            {
                Spawn  s       = go.AddComponent <Spawn>();
                string rfidKey = data4;

                if (database.ContainsKey(rfidKey))
                {
                    s.toSpawn = database[rfidKey].first;
                }
                else
                {
                    string url = "http://" + databaseAddress + "/playtime/getComponents.php";
                    yield return(StartCoroutine(pollDatabase(url, rfidKey, false)));

                    if (database.ContainsKey(rfidKey))
                    {
                        s.toSpawn = database[rfidKey].first;
                    }
                }

                int spawnCount = 0;
                Int32.TryParse(data5, out spawnCount);
                s.setMaxSpawnCount(spawnCount);
                s.includedTags = includedTags;
                s.excludedTags = excludedTags;
                ct.actions.Add(s);
                ct.directions.Add(directions);
            }
            break;

            case CustomAction.ActionTypes.Despawn:
            {
                Despawn d = go.AddComponent <Despawn>();
                int     deathAnimID;
                int.TryParse(data4, out deathAnimID);
                d.deathAnimID        = deathAnimID;
                d.defaultDeathAnimID = deathAnimID;
                d.includedTags       = includedTags;
                d.excludedTags       = excludedTags;
                ct.actions.Add(d);
                ct.directions.Add(directions);
            }
            break;

            case CustomAction.ActionTypes.Transfigure:
            {
                Transfigure t = go.GetComponent <Transfigure>();
                if (t == null)
                {
                    t = go.AddComponent <Transfigure>();
                }
                bool repeatable;
                Boolean.TryParse(data5, out repeatable);
                t.addTargetAnimControllerAndTags(data4, includedTags, excludedTags, repeatable, ct.actions.Count);
                ct.actions.Add(t);
                ct.directions.Add(directions);
            }
            break;

            case CustomAction.ActionTypes.DespawnOther:
            {
                DespawnOther dOther = go.AddComponent <DespawnOther>();
                dOther.includedTags = includedTags;
                dOther.excludedTags = excludedTags;
                ct.actions.Add(dOther);
                ct.directions.Add(directions);
            }
            break;

            case CustomAction.ActionTypes.RespawnOther:
            {
                RespawnOther rOther = go.AddComponent <RespawnOther>();
                rOther.includedTags = includedTags;
                rOther.excludedTags = excludedTags;
                ct.actions.Add(rOther);
                ct.directions.Add(directions);
            }
            break;

            case CustomAction.ActionTypes.Damage:
            {
                Damage d = go.AddComponent <Damage>();
                d.includedTags = includedTags;
                d.excludedTags = excludedTags;
                Int32.TryParse(data4, out d.dmg);
                ct.actions.Add(d);
                ct.directions.Add(directions);
            }
            break;

            case CustomAction.ActionTypes.MoveHoriz:
            {
                MoveHorizontalUntilCollision m = go.AddComponent <MoveHorizontalUntilCollision>();
                m.includedTags = includedTags;
                m.excludedTags = excludedTags;
                float.TryParse(data4, out m.speed);
                m.tagsToIgnore = new List <string>(data5.Split(delimiters, StringSplitOptions.RemoveEmptyEntries));
                ct.actions.Add(m);
                ct.directions.Add(directions);
            }
            break;

            case CustomAction.ActionTypes.CustomScript:
            {
                Type         t    = Type.GetType(data4);
                Component    comp = go.AddComponent(t);
                CustomAction c    = (CustomAction)comp;
                c.includedTags = includedTags;
                c.excludedTags = excludedTags;
                ct.actions.Add(c);
                ct.directions.Add(directions);
            }
            break;

            case CustomAction.ActionTypes.Bounce:
            {
                Bounce b = go.AddComponent <Bounce>();
                b.includedTags = includedTags;
                b.excludedTags = excludedTags;
                float bounceHeight;
                float.TryParse(data4, out bounceHeight);
                b.bounceHeight = bounceHeight;
                ct.actions.Add(b);
                ct.directions.Add(directions);
            }
            break;

            default:
                break;
            }
        }
        break;

        case "TimeTrigger":
        {
            TimeTrigger tt = go.GetComponent <TimeTrigger>();
            if (tt == null)
            {
                tt = go.AddComponent <TimeTrigger>();
            }
            CustomAction.ActionTypes a = (CustomAction.ActionTypes)Enum.Parse(typeof(CustomAction.ActionTypes), data1);
            float time;
            float.TryParse(data2, out time);
            bool repeats = false;
            bool.TryParse(data3, out repeats);

            switch (a)
            {
            case CustomAction.ActionTypes.Spawn:
            {
                Spawn  s       = go.AddComponent <Spawn>();
                string rfidKey = data4;

                if (database.ContainsKey(rfidKey))
                {
                    s.toSpawn = database[rfidKey].first;
                }
                else
                {
                    string url = "http://" + databaseAddress + "/playtime/getComponents.php";
                    yield return(StartCoroutine(pollDatabase(url, rfidKey, false)));

                    if (database.ContainsKey(rfidKey))
                    {
                        s.toSpawn = database[rfidKey].first;
                    }
                }

                int spawnCount = 0;
                Int32.TryParse(data5, out spawnCount);
                s.setMaxSpawnCount(spawnCount);
                tt.actions.Add(s);
                tt.originalTimes.Add(time);
                tt.repeats.Add(repeats);
            }
            break;

            case CustomAction.ActionTypes.Despawn:
            {
                Despawn d = go.AddComponent <Despawn>();
                tt.actions.Add(d);
                tt.originalTimes.Add(time);
                tt.repeats.Add(repeats);
            }
            break;

            case CustomAction.ActionTypes.Transfigure:
            {
                Transfigure t = go.GetComponent <Transfigure>();
                if (t == null)
                {
                    t = go.AddComponent <Transfigure>();
                }
                bool repeatable;
                Boolean.TryParse(data5, out repeatable);
                List <string> tags = new List <string>();
                t.addTargetAnimControllerAndTags(data4, tags, tags, repeatable, tt.actions.Count);
                tt.actions.Add(t);
                tt.originalTimes.Add(time);
                tt.repeats.Add(repeats);
            }
            break;

            case CustomAction.ActionTypes.DespawnOther:
            {
                DespawnOther dOther = go.AddComponent <DespawnOther>();
                tt.actions.Add(dOther);
                tt.originalTimes.Add(time);
                tt.repeats.Add(repeats);
            }
            break;

            case CustomAction.ActionTypes.RespawnOther:
            {
                RespawnOther rOther = go.AddComponent <RespawnOther>();
                tt.actions.Add(rOther);
                tt.originalTimes.Add(time);
                tt.repeats.Add(repeats);
            }
            break;

            case CustomAction.ActionTypes.Damage:
            {
                Damage d = go.AddComponent <Damage>();
                Int32.TryParse(data4, out d.dmg);
                tt.actions.Add(d);
                tt.originalTimes.Add(time);
                tt.repeats.Add(repeats);
            }
            break;
            }
        }
        break;

        case "DeathTrigger":
        {
            DeathTrigger dt = go.GetComponent <DeathTrigger>();
            if (dt == null)
            {
                dt = go.AddComponent <DeathTrigger>();
            }
            CustomAction.ActionTypes a = (CustomAction.ActionTypes)Enum.Parse(typeof(CustomAction.ActionTypes), data1);

            switch (a)
            {
            case CustomAction.ActionTypes.Spawn:
            {
                Spawn  s       = go.AddComponent <Spawn>();
                string rfidKey = data2;

                if (database.ContainsKey(rfidKey))
                {
                    s.toSpawn = database[rfidKey].first;
                }
                else
                {
                    string url = "http://" + databaseAddress + "/playtime/getComponents.php";
                    yield return(StartCoroutine(pollDatabase(url, rfidKey, false)));

                    if (database.ContainsKey(rfidKey))
                    {
                        s.toSpawn = database[rfidKey].first;
                    }
                }

                int spawnCount = 0;
                Int32.TryParse(data3, out spawnCount);
                s.setMaxSpawnCount(spawnCount);
                s.spawnUnderParent = true;
                dt.actions.Add(s);
            }
            break;

            default:
                break;
            }
        }
        break;

        case "Invisible":
        {
            Invisible i = go.AddComponent <Invisible>();
            i.reset();
        }
        break;

        case "MoveHorizontalUntilCollision":
        {
            MoveHorizontalUntilCollision m = go.AddComponent <MoveHorizontalUntilCollision>();
            List <String> ignoredTags;
            string[]      delimiters = { "|" };
            string[]      tags       = data1.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
            ignoredTags    = new List <string>(tags);
            m.tagsToIgnore = ignoredTags;
        }
        break;

        case "Spawn":
        {
            Spawn  s       = go.AddComponent <Spawn>();
            string rfidKey = data1;

            if (database.ContainsKey(rfidKey))
            {
                s.toSpawn = database[rfidKey].first;
            }
            else
            {
                string url = "http://" + databaseAddress + "/playtime/getComponents.php";
                yield return(StartCoroutine(pollDatabase(url, rfidKey, false)));

                if (database.ContainsKey(rfidKey))
                {
                    s.toSpawn = database[rfidKey].first;
                }
            }

            int spawnCount = 0;
            int.TryParse(data2, out spawnCount);
            s.setMaxSpawnCount(spawnCount);
        }
        break;

        case "Despawn":
        {
            Despawn d = go.AddComponent <Despawn>();
            int     deathAnimID;
            int.TryParse(data1, out deathAnimID);
            d.deathAnimID        = deathAnimID;
            d.defaultDeathAnimID = deathAnimID;
        }
        break;

        case "ChildObject":
        {
            string     rfidKey = data1;
            GameObject child, staticChild;

            if (database.ContainsKey(rfidKey))
            {
                child       = database[rfidKey].first;
                staticChild = database[rfidKey].second;
            }
            else
            {
                string url = "http://" + databaseAddress + "/playtime/getComponents.php";
                yield return(StartCoroutine(pollDatabase(url, rfidKey, false)));

                if (database.ContainsKey(rfidKey))
                {
                    child       = database[rfidKey].first;
                    staticChild = database[rfidKey].second;

                    Vector2 offset = new Vector2();
                    float.TryParse(data2, out offset.x);
                    float.TryParse(data3, out offset.y);

                    child.transform.parent        = go.transform;
                    child.transform.localPosition = offset;
                    child.SetActive(true);
                    staticChild.transform.parent        = staticGO.transform;
                    staticChild.transform.localPosition = offset;
                    staticChild.SetActive(true);
                }
            }
        }
        break;

        case "JumpAI":
        {
            go.AddComponent <JumpAI>();
        }
        break;

        case "Chase":
        {
            go.AddComponent <Chase>();
        }
        break;

        case "Shoot":
        {
            Shoot  s       = go.AddComponent <Shoot>();
            string rfidKey = data1;

            if (database.ContainsKey(rfidKey))
            {
                s.projectile = database[rfidKey].first;
            }
            else
            {
                string url = "http://" + databaseAddress + "/playtime/getComponents.php";
                yield return(StartCoroutine(pollDatabase(url, rfidKey, false)));

                if (database.ContainsKey(rfidKey))
                {
                    s.projectile = database[rfidKey].first;
                }
            }
            float.TryParse(data2, out s.projectileSpeed);
        }
        break;

        case "Color":
        {
            ColorComponent c = go.AddComponent <ColorComponent>();
            float.TryParse(data1, out c.r);
            float.TryParse(data2, out c.g);
            float.TryParse(data3, out c.b);
            float.TryParse(data4, out c.a);
        }
        break;

        default:
            print("Component " + name + " is undefined.");
            break;
        }
    }
Ejemplo n.º 6
0
    private void handleSliderTouches(Vector2 touchPosition)
    {
        if (pathSliderTouchID > -1)
        {
            bool found = false;

            for (int i = 0; i < touchManager.ActiveTouches.Count; i++)
            {
                if (touchManager.ActiveTouches[i].Id == pathSliderTouchID)
                {
                    found = true;

                    float xpos = Camera.main.ScreenToWorldPoint(touchManager.ActiveTouches[i].Position).x;
                    xpos = Mathf.Max(Mathf.Min(xpos, pathSliderGroup.transform.position.x + SLIDER_MAX_X), pathSliderGroup.transform.position.x + SLIDER_MIN_X);

                    pathSliderTab.transform.position = new Vector3(xpos, pathSliderTab.transform.position.y, pathSliderTab.transform.position.z);

                    float newPathSpeed = ((pathSliderTab.transform.localPosition.x + 2.8f) / 5.6f) * 8f + 1f;
                    Pair <GameObject, GameObject> selectedObject = levelManager.getObjectAtPosition(touchPosition);
                    if (selectedObject != null)
                    {
                        PathFollowing p = selectedObject.first.GetComponent <PathFollowing>();
                        if (p != null)
                        {
                            p.pathSpeed = newPathSpeed;
                        }
                    }
                    break;
                }
            }

            if (!found)
            {
                pathSliderTouchID = -1;
            }
        }

        if (jumpSliderTouchID > -1)
        {
            bool found = false;

            for (int i = 0; i < touchManager.ActiveTouches.Count; i++)
            {
                if (touchManager.ActiveTouches[i].Id == jumpSliderTouchID)
                {
                    found = true;

                    float ypos = Camera.main.ScreenToWorldPoint(touchManager.ActiveTouches[i].Position).y;
                    ypos = Mathf.Max(Mathf.Min(ypos, jumpSliderGroup.transform.position.y + SLIDER_MAX_X), jumpSliderGroup.transform.position.y + SLIDER_MIN_X);

                    jumpSliderTab.transform.position = new Vector3(jumpSliderTab.transform.position.x, ypos, jumpSliderTab.transform.position.z);

                    float newJumpBurst = ((jumpSliderTab.transform.localPosition.x + 2.8f) / 5.6f) * 8f + 2f;
                    Pair <GameObject, GameObject> selectedObject = levelManager.getObjectAtPosition(touchPosition);
                    if (selectedObject != null)
                    {
                        Jump j = selectedObject.first.GetComponent <Jump>();
                        if (j != null)
                        {
                            j.burst = newJumpBurst;
                        }
                    }
                    break;
                }
            }

            if (!found)
            {
                jumpSliderTouchID = -1;
            }
        }

        if (moveSliderTouchID > -1)
        {
            bool found = false;

            for (int i = 0; i < touchManager.ActiveTouches.Count; i++)
            {
                if (touchManager.ActiveTouches[i].Id == moveSliderTouchID)
                {
                    found = true;

                    float xpos = Camera.main.ScreenToWorldPoint(touchManager.ActiveTouches[i].Position).x;
                    xpos = Mathf.Max(Mathf.Min(xpos, moveSliderGroup.transform.position.x + SLIDER_MAX_X), moveSliderGroup.transform.position.x + SLIDER_MIN_X);

                    moveSliderTab.transform.position = new Vector3(xpos, moveSliderTab.transform.position.y, moveSliderTab.transform.position.z);

                    float newMoveSpeed = ((moveSliderTab.transform.localPosition.x + 2.8f) / 5.6f) * 8f + 2f;
                    Pair <GameObject, GameObject> selectedObject = levelManager.getObjectAtPosition(touchPosition);
                    if (selectedObject != null)
                    {
                        Move m = selectedObject.first.GetComponent <Move>();
                        if (m != null)
                        {
                            m.setMaxSpeed(newMoveSpeed);
                        }
                    }
                    break;
                }
            }

            if (!found)
            {
                moveSliderTouchID = -1;
            }
        }

        if (aiHorizMoveSliderTouchID > -1)
        {
            bool found = false;

            for (int i = 0; i < touchManager.ActiveTouches.Count; i++)
            {
                if (touchManager.ActiveTouches[i].Id == aiHorizMoveSliderTouchID)
                {
                    found = true;

                    float xpos = Camera.main.ScreenToWorldPoint(touchManager.ActiveTouches[i].Position).x;
                    xpos = Mathf.Max(Mathf.Min(xpos, aiHorizMoveSliderGroup.transform.position.x + SLIDER_MAX_X), aiHorizMoveSliderGroup.transform.position.x + SLIDER_MIN_X);

                    aiHorizMoveSliderTab.transform.position = new Vector3(xpos, aiHorizMoveSliderTab.transform.position.y, aiHorizMoveSliderTab.transform.position.z);

                    float newMoveSpeed = ((aiHorizMoveSliderTab.transform.localPosition.x + 2.8f) / 5.6f) * 8f;
                    Pair <GameObject, GameObject> selectedObject = levelManager.getObjectAtPosition(touchPosition);
                    if (selectedObject != null)
                    {
                        MoveHorizontalUntilCollision mh = selectedObject.first.GetComponent <MoveHorizontalUntilCollision>();
                        if (mh != null)
                        {
                            mh.speed = newMoveSpeed;
                        }
                    }
                    break;
                }
            }

            if (!found)
            {
                moveSliderTouchID = -1;
            }
        }
    }
Ejemplo n.º 7
0
    // Description:
    // Updates the UI position and displays the correct
    // menu for the input index in the grid.
    private void UpdatePlacementUI(Vector2 touchPosition, bool updatePosition = true)
    {
        // Update position
        if (updatePosition)
        {
            PlacementUI.transform.position = new Vector3(touchPosition.x, touchPosition.y, PlacementUI.transform.position.z);
        }

        bool foregroundObjectPresent = levelManager.isObjectAtPosition(touchPosition),
             backgroundObjectPresent = levelManager.isBackgroundObjectAtPosition(touchPosition);

        // Display correct menu
        if (!backgroundObjectPresent && !foregroundObjectPresent)
        {
            PlacementUI.transform.Find("ReplaceRemove").gameObject.SetActive(false);
            PlacementUI.transform.Find("ReplaceRemove/PathBtn").gameObject.SetActive(false);
        }
        else
        {
            PlacementUI.transform.Find("ReplaceRemove").gameObject.SetActive(true);
            PlacementUI.transform.Find("ReplaceRemove/PathBtn").gameObject.SetActive(false);
            bool showReplaceButton = activeKey != "" &&
                                     (database[activeKey].first.tag != "PaintableBackground" && foregroundObjectPresent ||
                                      database[activeKey].first.tag == "PaintableBackground" && backgroundObjectPresent);
            PlacementUI.transform.Find("ReplaceRemove/ReplaceBtn").gameObject.SetActive(showReplaceButton);
            pathSliderGroup.SetActive(false);
            jumpSliderGroup.SetActive(false);
            moveSliderGroup.SetActive(false);
            aiHorizMoveSliderGroup.SetActive(false);

            Pair <GameObject, GameObject> selectedObject;
            if (foregroundObjectPresent)
            {
                selectedObject = levelManager.getObjectAtPosition(touchPosition);
            }
            else
            {
                selectedObject = levelManager.getBackgroundObjectAtPosition(touchPosition);
            }

            PathFollowing p = selectedObject.second.GetComponent <PathFollowing>();
            if (p != null)
            {
                p.startDrawingPath();
            }

            p = selectedObject.first.GetComponent <PathFollowing>();
            if (p != null)
            {
                PlacementUI.transform.Find("ReplaceRemove/PathBtn").gameObject.SetActive(true);

                if (!p.isEmpty())
                {
                    pathSliderGroup.SetActive(true);
                }

                if (p.currentState == PathFollowing.PathState.Idle)
                {
                    p.setStateToPlaying();
                    lastObjectSelected = selectedObject;

                    // Set slider tab to correct position
                    float xpos = (((p.pathSpeed - 1f) / 8f) * 5.6f) - 2.8f;
                    pathSliderTab.transform.localPosition = new Vector3(xpos, pathSliderTab.transform.localPosition.y, 0f);
                }
            }

            Jump j = selectedObject.first.GetComponent <Jump>();
            if (j != null)
            {
                jumpSliderGroup.SetActive(true);
                float xpos = (((j.burst - 2f) / 8f) * 5.6f) - 2.8f;
                jumpSliderTab.transform.localPosition = new Vector3(xpos, jumpSliderTab.transform.localPosition.y, 0f);
            }

            Move m = selectedObject.first.GetComponent <Move>();
            if (m != null)
            {
                moveSliderGroup.SetActive(true);
                float speed = 0f;
                for (int i = 0; i < 4; i++)
                {
                    if (!Mathf.Approximately(m.maxSpeed[i], 0f))
                    {
                        speed = m.maxSpeed[i];
                        break;
                    }
                }

                if (!Mathf.Approximately(speed, 0f))
                {
                    float xpos = (((speed - 2f) / 8f) * 5.6f) - 2.8f;
                    moveSliderTab.transform.localPosition = new Vector3(xpos, moveSliderTab.transform.localPosition.y, 0f);
                }
            }

            MoveHorizontalUntilCollision mh = selectedObject.first.GetComponent <MoveHorizontalUntilCollision>();
            if (mh != null)
            {
                aiHorizMoveSliderGroup.SetActive(true);
                if (!Mathf.Approximately(mh.speed, 0f))
                {
                    float xpos = ((mh.speed / 8f) * 5.6f) - 2.8f;
                    aiHorizMoveSliderTab.transform.localPosition = new Vector3(xpos, aiHorizMoveSliderTab.transform.localPosition.y, 0f);
                }
            }
        }
    }
Ejemplo n.º 8
0
    private IEnumerator processSaveEntry(string entry)
    {
        string[] delimiters = { "," };
        string[] tokens     = entry.Split(delimiters, StringSplitOptions.None);

        if (tokens.Length > 0)
        {
            int    i       = 0;
            string rfidKey = tokens[i++];

            yield return(StartCoroutine(ldTime.rfidFoundCoroutine(rfidKey)));

            Vector3 position = new Vector3(float.Parse(tokens[i++]), float.Parse(tokens[i++]), float.Parse(tokens[i++]));
            Pair <GameObject, GameObject> p = ldTime.PlaceObject(position, true, true);

            if (p == null)
            {
                print("Could not load figure with RFID key " + rfidKey + ".");
                yield break;
            }

            Vector3 scale = new Vector3(float.Parse(tokens[i++]), float.Parse(tokens[i++]), float.Parse(tokens[i++]));
            Resize  r     = p.second.GetComponent <Resize>();
            if (r != null)
            {
                r.setNewScale(scale);
            }
            else
            {
                p.first.transform.localScale  = scale;
                p.second.transform.localScale = scale;
            }

            PathFollowing pf = p.first.GetComponent <PathFollowing>();
            if (pf != null)
            {
                pf.pathSpeed = float.Parse(tokens[i++]);
                int pathPointsCount = int.Parse(tokens[i++]);

                for (int k = 0; k < pathPointsCount; k++)
                {
                    Vector3 point = new Vector3(float.Parse(tokens[i++]), float.Parse(tokens[i++]), float.Parse(tokens[i++]));
                    pf.pathPoints.Add(point);
                }
            }

            Jump j = p.first.GetComponent <Jump>();
            if (j != null)
            {
                j.burst = float.Parse(tokens[i++]);
            }

            Move m = p.first.GetComponent <Move>();
            if (m != null)
            {
                m.maxSpeed[0] = float.Parse(tokens[i++]);
                m.maxSpeed[1] = float.Parse(tokens[i++]);
                m.maxSpeed[2] = float.Parse(tokens[i++]);
                m.maxSpeed[3] = float.Parse(tokens[i++]);
            }

            MoveHorizontalUntilCollision mh = p.first.GetComponent <MoveHorizontalUntilCollision>();
            if (mh != null)
            {
                mh.speed = float.Parse(tokens[i++]);
            }
        }
    }