コード例 #1
0
    private void specialRevertLogic(GameObject g, GameObject sg = null)
    {
        if (sg != null)
        {
        }

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

        if (p != null)
        {
            p.setStateToIdle();
        }

        CollideTrigger ct = g.GetComponent <CollideTrigger>();

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

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

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

        DeathTrigger dt = g.GetComponent <DeathTrigger>();

        if (dt != null)
        {
            dt.reset();
        }

        Health h = g.GetComponent <Health>();

        if (h != null)
        {
            h.hp = h.startHP;
        }

        StarPower sp = g.GetComponent <StarPower>();

        if (sp != null)
        {
            sp.reset();
        }
    }
コード例 #2
0
 public void OnCollision(CollideTrigger Other, Vector RelVector)
 {
 }
コード例 #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);
        }
    }
コード例 #4
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;
        }
    }