示例#1
0
 void FixEditor()
 {
     GameObject[] objs = GameObject.FindGameObjectsWithTag("Slot");
     creator.slots = new SlotPreview[objs.Length];
     foreach (GameObject obj in objs)
     {
         SlotPreview slot = obj.GetComponent <SlotPreview> ();
         creator.slots [slot.position] = slot;
     }
 }
示例#2
0
    public void BuildPreview(Map map)
    {
        if (slots != null)
        {
            ClosePreview();
        }

        if (map != null)
        {
            difficulty = map.difficulty;
            timeLimit  = map.timeLimit;
            title      = map.title;
        }
        slots = new SlotPreview[xSize * ySize];
        for (int i = 0; i < slots.Length; i++)
        {
            GameObject  obj  = Instantiate(Resources.Load("SlotPreview" + cellName)) as GameObject;
            SlotPreview slot = obj.GetComponent <SlotPreview> ();
            slot.x = i % xSize;
            slot.y = i / xSize;
            slot.transform.parent   = transform;
            slot.transform.position = transform.position + new Vector3(slot.x * cellWidth - ((xSize - 1) * cellWidth / 2), -slot.y * cellWidth + offset, 0);
            slot.position           = i;

            if (map != null)
            {
                slot.slotType = map.types [i];
                if (map.textures != null && map.textures.Length == slots.Length)
                {
                    slot.cover.sprite = Resources.Load <Sprite> ("Icons/" + map.textures [i]);
                }
                if (map.types [i] == SlotType.Blank)
                {
                    slot.cover.color = Color.black - new Color(0f, 0f, 0f, 0.5f);
                }
                else if (map.types [i] == SlotType.Bomb)
                {
                    slot.cover.color = Color.white - new Color(0f, 0f, 0f, 0.5f);
                    slot.bombIcon.SetActive(true);
                }
                else if (map.types [i] == SlotType.Safe)
                {
                    slot.cover.color = Color.white - new Color(0f, 0f, 0f, 0.5f);
                    slot.safeIcon.SetActive(true);
                }
                else
                {
                    slot.cover.color = Color.white - new Color(0f, 0f, 0f, 0.5f);
                }
                slot.section = map.sections [i];
            }

            slots [i] = slot;
        }
    }
示例#3
0
    void OnSceneGUI(SceneView sceneView)
    {
        Event e = Event.current;

        if (e != null && (e.type == EventType.MouseDown || e.type == EventType.MouseDrag) && e.button == 0)
        {
            Ray        r   = HandleUtility.GUIPointToWorldRay(e.mousePosition);
            RaycastHit hit = new RaycastHit();
            if (Physics.Raycast(r, out hit))
            {
                SlotPreview        slot    = hit.collider.GetComponent <SlotPreview> ();
                List <SlotPreview> targets = new List <SlotPreview> ();

                if (isSmallBrush)
                {
                    targets.Add(slot);
                }
                else
                {
                    targets.Add(slot);

                    SlotPreview[] slots = creator.slots;
                    int           lastX = creator.xSize - 1;
                    int           lastY = creator.ySize - 1;

                    if (slot.x != 0)
                    {
                        targets.Add(slots [slot.position - 1]);
                    }
                    if (slot.x != lastX)
                    {
                        targets.Add(slots [slot.position + 1]);
                    }

                    if (slot.y != 0)
                    {
                        targets.Add(slots [slot.position - creator.xSize]);
                    }
                    if (slot.y != lastY)
                    {
                        targets.Add(slots [slot.position + creator.xSize]);
                    }

                    if (slot.x != 0 && slot.y != 0)
                    {
                        targets.Add(slots [slot.position - (creator.xSize + 1)]);
                    }
                    if (slot.x != 0 && slot.y != lastY)
                    {
                        targets.Add(slots [slot.position + (creator.xSize - 1)]);
                    }
                    if (slot.x != lastX && slot.y != 0)
                    {
                        targets.Add(slots [slot.position - (creator.xSize - 1)]);
                    }
                    if (slot.x != lastX && slot.y != lastY)
                    {
                        targets.Add(slots [slot.position + (creator.xSize + 1)]);
                    }
                }

                foreach (SlotPreview targ in targets)
                {
                    targ.slotType = type;
                    if (currentTex != null && type == SlotType.Normal)
                    {
                        targ.cover.sprite = currentTex;
                    }
                    targ.safeIcon.SetActive(false);
                    targ.bombIcon.SetActive(false);
                    switch (type)
                    {
                    case SlotType.Normal:
                        targ.cover.color = Color.white - new Color(0f, 0f, 0f, 0.5f);
                        break;

                    case SlotType.Safe:
                        targ.cover.color = Color.white - new Color(0f, 0f, 0f, 0.5f);
                        targ.safeIcon.SetActive(true);
                        break;

                    case SlotType.Bomb:
                        targ.cover.color = Color.white - new Color(0f, 0f, 0f, 0.5f);
                        targ.bombIcon.SetActive(true);
                        break;

                    case SlotType.Blank:
                        targ.cover.color = Color.black - new Color(0f, 0f, 0f, 0.5f);
                        break;
                    }
                }
            }
        }
    }