예제 #1
0
    private static void DrawDecoration(GameObject obj, ColorObj decorator, Rect rect)
    {
        if (decorator.applyBackgroundColor)
        {
            Texture2D t = new Texture2D(1, 1);
            Color     c = decorator.backgroundColor;
            t.SetPixel(1, 1, c);
            t.Apply();
            GUI.DrawTexture(rect, t, ScaleMode.StretchToFill);
        }
        if (decorator.applyCustomTextColor)
        {
            GUI.contentColor = decorator.gameObjectTextColor;

            Rect nameOfObject = new Rect(rect.x + 16, rect.y + 1, rect.width, rect.height);
            GUI.Label(nameOfObject, obj.name);

            GUI.contentColor = Color.white;
        }
        if (decorator.applyDescription)
        {
            GUI.contentColor = decorator.descriptionTextColor;

            Rect labelRect = new Rect(rect.x + 150, rect.y, rect.width - 150, rect.height);
            GUI.Label(labelRect, decorator.description);

            GUI.contentColor = Color.white;
        }
        if (decorator.icon != null)
        {
            Rect r = new Rect(rect.x + rect.width - 16, rect.y, 16, 16);
            GUI.DrawTexture(r, decorator.icon);
        }
        EditorApplication.RepaintHierarchyWindow();
    }
예제 #2
0
    private static void EvaluateIcons(int instanceId, Rect selectionRect)
    {
        GameObject go = EditorUtility.InstanceIDToObject(instanceId) as GameObject;

        if (go != null)
        {
            ColorObj decorator = go.GetComponent <ColorObj>();

            if (decorator != null)
            {
                DrawDecoration(go, decorator, selectionRect);
            }
        }
    }
예제 #3
0
    public void LoadLevel()
    {
        //objs.ForEach((x) => Debug.Log(x.obj.name + " " + x.hasAlphaNBT));

        /*if (GameObject.FindGameObjectWithTag("Player") != null)
         *   GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerStats>().lastCheckPoint = Vector3.zero;*/

        entityObjects.Clear();
        OBJPos.Clear();
        if (loadedOBJS.Count > 0)
        {
            for (int i = 0; i < loadedOBJS.Count; i++)
            {
                Destroy(loadedOBJS[i]);
            }
        }
        loadedOBJS.Clear();
        ColorObj lastObject = null;

        for (int i = 0; i < sprite.width * sprite.height; i++)
        {
            int   x = i % sprite.width;
            int   y = i / sprite.width;
            Color c = sprite.GetPixel(x, y);
            if (c.a > 0)
            {
                if (lastObject != null)
                {
                    var item = lastObject;
                    if (!item.hasAlphaNBT)
                    {
                        if (c.Equals(item.color))
                        {
                            if (CreatorManager.instance != null)
                            {
                                if (item.obj.name == "Player")
                                {
                                    GameObject gb = Instantiate(CreatorManager.instance.playerSpawn, new Vector2(x, y) - offset + new Vector2(0, 0.365f), Quaternion.identity);
                                    gb.transform.localScale = gb.transform.localScale * (1 + (1 - GameManager.instance.levelLoader.SpaceBetweenOBJS));
                                    gb.transform.SetParent(transform);
                                    if (gb.GetComponent(render.GetType()) == null)
                                    {
                                        gb.AddComponent(render.GetType());
                                    }
                                }
                                else
                                {
                                    GameObject gb = Instantiate(item.obj, new Vector2(x * SpaceBetweenOBJS, y * SpaceBetweenOBJS) - offset + item.offset, Quaternion.identity);
                                    if (item.isChild)
                                    {
                                        gb.transform.SetParent(transform);
                                    }
                                    if (item.isEntityObject)
                                    {
                                        OBJPos.Add(gb.transform.position, item);
                                        entityObjects.Add(gb);
                                    }
                                    if (gb.GetComponent(render.GetType()) == null)
                                    {
                                        gb.AddComponent(render.GetType());
                                    }
                                }
                            }
                            else
                            {
                                GameObject gb = Instantiate(item.obj, new Vector2(x * SpaceBetweenOBJS, y * SpaceBetweenOBJS) - offset + item.offset, Quaternion.identity);
                                if (item.isChild)
                                {
                                    gb.transform.SetParent(transform);
                                }
                                if (item.isEntityObject)
                                {
                                    OBJPos.Add(gb.transform.position, item);
                                    entityObjects.Add(gb);
                                }
                                loadedOBJS.Add(gb);
                                if (gb.GetComponent(render.GetType()) == null)
                                {
                                    gb.AddComponent(render.GetType());
                                }
                            }
                        }
                    }
                    else
                    {
                        if (c.r == item.color.r && c.b == item.color.b && c.g == item.color.g)
                        {
                            GameObject gb = Instantiate(item.obj, new Vector2(x * SpaceBetweenOBJS, y * SpaceBetweenOBJS) - offset + item.offset, Quaternion.identity);
                            if (item.isChild)
                            {
                                gb.transform.SetParent(transform);
                            }
                            if (item.isEntityObject)
                            {
                                ColorObj cO = new ColorObj(item.color, item.obj, item.isChild, item.isEntityObject, item.hasAlphaNBT, item.offset);
                                cO.color.a = c.a;
                                OBJPos.Add(gb.transform.position, cO);
                                entityObjects.Add(gb);
                            }
                            loadedOBJS.Add(gb);
                            gb.AddComponent <AlphaNBTTag>().setNBT((int)(c.a * 255));
                            if (gb.GetComponent(render.GetType()) == null)
                            {
                                gb.AddComponent(render.GetType());
                            }
                        }
                    }
                }

                foreach (var item in objs)
                {
                    if (!item.hasAlphaNBT)
                    {
                        if (c.Equals(item.color))
                        {
                            if (CreatorManager.instance != null)
                            {
                                if (item.obj.name == "Player")
                                {
                                    GameObject gb = Instantiate(CreatorManager.instance.playerSpawn, new Vector2(x, y) - offset + new Vector2(0, 0.365f), Quaternion.identity);
                                    gb.transform.localScale = gb.transform.localScale * (1 + (1 - GameManager.instance.levelLoader.SpaceBetweenOBJS));
                                    gb.transform.SetParent(transform);
                                    if (gb.GetComponent(render.GetType()) == null)
                                    {
                                        gb.AddComponent(render.GetType());
                                    }
                                }
                                else
                                {
                                    GameObject gb = Instantiate(item.obj, new Vector2(x * SpaceBetweenOBJS, y * SpaceBetweenOBJS) - offset + item.offset, Quaternion.identity);
                                    if (item.isChild)
                                    {
                                        gb.transform.SetParent(transform);
                                    }
                                    if (item.isEntityObject)
                                    {
                                        OBJPos.Add(gb.transform.position, item);
                                        entityObjects.Add(gb);
                                    }
                                    if (gb.GetComponent(render.GetType()) == null)
                                    {
                                        gb.AddComponent(render.GetType());
                                    }
                                }
                            }
                            else
                            {
                                GameObject gb = Instantiate(item.obj, new Vector2(x * SpaceBetweenOBJS, y * SpaceBetweenOBJS) - offset + item.offset, Quaternion.identity);
                                if (item.isChild)
                                {
                                    gb.transform.SetParent(transform);
                                }
                                if (item.isEntityObject)
                                {
                                    OBJPos.Add(gb.transform.position, item);
                                    entityObjects.Add(gb);
                                }
                                loadedOBJS.Add(gb);
                                if (gb.GetComponent(render.GetType()) == null)
                                {
                                    gb.AddComponent(render.GetType());
                                }
                            }
                        }
                    }
                    else
                    {
                        if (c.r == item.color.r && c.b == item.color.b && c.g == item.color.g)
                        {
                            GameObject gb = Instantiate(item.obj, new Vector2(x * SpaceBetweenOBJS, y * SpaceBetweenOBJS) - offset + item.offset, Quaternion.identity);
                            if (item.isChild)
                            {
                                gb.transform.SetParent(transform);
                            }
                            if (item.isEntityObject)
                            {
                                ColorObj cO = new ColorObj(item.color, item.obj, item.isChild, item.isEntityObject, item.hasAlphaNBT, item.offset);
                                cO.color.a = c.a;
                                OBJPos.Add(gb.transform.position, cO);
                                entityObjects.Add(gb);
                            }
                            loadedOBJS.Add(gb);
                            gb.AddComponent <AlphaNBTTag>().setNBT((int)(c.a * 255));
                            if (gb.GetComponent(render.GetType()) == null)
                            {
                                gb.AddComponent(render.GetType());
                            }
                        }
                    }
                    lastObject = item;
                }
            }
        }
        StartCoroutine(waitForPlayerSkin());
    }