GetListOfSprites() public method

Convenience function that retrieves a list of all sprite names.
public GetListOfSprites ( ) : BetterList
return BetterList
Beispiel #1
0
        internal static string getSprite(UIAtlas atlas, string uispriteName, ExportPreset preset)
        {
            Material  atlasMaterial = atlas.spriteMaterial;
            Texture2D texture2D     = (Texture2D)atlasMaterial.GetTexture("_MainTex");
            string    res           = null;

            if (texture2D != null)
            {
                string picturePath = AssetDatabase.GetAssetPath(texture2D.GetInstanceID());
                //Texture2D copyTexture = DuplicateTexture(texture2D);

                //picturePath = path.Split('.')[0] + ".png";
                string texturePath = new WXTexture(texture2D).Export(preset);

                JSONObject metadata = TextureUtil.getMeta(texture2D);

                BetterList <string> allSpriteList = atlas.GetListOfSprites();
                string[]            list          = allSpriteList.ToArray();
                foreach (string spriteName in list)
                {
                    UISpriteData  currentData     = atlas.GetSprite(spriteName);
                    WXSpriteFrame spriteConverter = new WXSpriteFrame(currentData, texturePath, picturePath);
                    string        uuid            = spriteConverter.Export(preset);
                    // 这里不需要了,外部去给hierarchyContext addResource就好
                    if (spriteName == uispriteName)
                    {
                        res = uuid;
                        return(res);
                        //    WXBeefBallExportContext.addDep(uuid);
                    }
                    //else
                    //{
                    //    WXBeefBallExportContext.addNoDependence(uuid);
                    //}
                }
            }
            return(res);
        }
 public override void OnFooterGUI()
 {
     if (atlasFrom != null && atlasTo != null)
     {
         if (duplicateSprites.Count > 0)
         {
             if (GUILayout.Button(atlasFrom.name + " -> " + atlasTo.name))
             {
                 SwitchAtlas();
             }
         }
         NGUIEditorTools.DrawSeparator();
         EditorGUILayout.BeginHorizontal();
         EditorGUILayout.BeginVertical();
         EditorGUILayoutUtil.Popup <string>("Sprite From", ref spriteName1, atlasFrom.GetListOfSprites().ToArray());
         EditorGUILayoutUtil.Popup <string>("Sprite To", ref spriteName2, atlasTo.GetListOfSprites().ToArray());
         EditorGUILayout.EndVertical();
         if (GUILayout.Button("Replace", GUILayout.ExpandWidth(false), GUILayout.Height(30)))
         {
             SwitchSprite(spriteName1, spriteName2);
         }
         EditorGUILayout.EndHorizontal();
     }
 }
    /// <summary>
    /// Draw the custom wizard.
    /// </summary>

    void OnGUI()
    {
        NGUIEditorTools.SetLabelWidth(80f);

        if (NGUISettings.atlas == null)
        {
            GUILayout.Label("No Atlas selected.", "LODLevelNotifyText");
        }
        else
        {
            UIAtlas atlas = NGUISettings.atlas;
            bool    close = false;
            GUILayout.Label(atlas.name + " Sprites", "LODLevelNotifyText");
            NGUIEditorTools.DrawSeparator();

            GUILayout.BeginHorizontal();
            GUILayout.Space(84f);

            string before = NGUISettings.partialSprite;
            string after  = EditorGUILayout.TextField("", before, "SearchTextField");
            if (before != after)
            {
                NGUISettings.partialSprite = after;
            }

            if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f)))
            {
                NGUISettings.partialSprite = "";
                GUIUtility.keyboardControl = 0;
            }
            GUILayout.Space(84f);
            GUILayout.EndHorizontal();

            Texture2D tex = atlas.texture as Texture2D;

            if (tex == null)
            {
                GUILayout.Label("The atlas doesn't have a texture to work with");
                return;
            }

            BetterList <string> sprites = atlas.GetListOfSprites(NGUISettings.partialSprite);

            float size    = 80f;
            float padded  = size + 10f;
            int   columns = Mathf.FloorToInt(Screen.width / padded);
            if (columns < 1)
            {
                columns = 1;
            }

            int  offset = 0;
            Rect rect   = new Rect(10f, 0, size, size);

            GUILayout.Space(10f);
            mPos = GUILayout.BeginScrollView(mPos);
            int rows = 1;

            while (offset < sprites.size)
            {
                GUILayout.BeginHorizontal();
                {
                    int col = 0;
                    rect.x = 10f;

                    for (; offset < sprites.size; ++offset)
                    {
                        UISpriteData sprite = atlas.GetSprite(sprites[offset]);
                        if (sprite == null)
                        {
                            continue;
                        }

                        // Button comes first
                        if (GUI.Button(rect, ""))
                        {
                            if (Event.current.button == 0)
                            {
                                float delta = Time.realtimeSinceStartup - mClickTime;
                                mClickTime = Time.realtimeSinceStartup;

                                if (NGUISettings.selectedSprite != sprite.name)
                                {
                                    if (mSprite != null)
                                    {
                                        NGUIEditorTools.RegisterUndo("Atlas Selection", mSprite);
                                        mSprite.MakePixelPerfect();
                                        EditorUtility.SetDirty(mSprite.gameObject);
                                    }

                                    NGUISettings.selectedSprite = sprite.name;
                                    NGUIEditorTools.RepaintSprites();
                                    if (mCallback != null)
                                    {
                                        mCallback(sprite.name);
                                    }
                                }
                                else if (delta < 0.5f)
                                {
                                    close = true;
                                }
                            }
                            else
                            {
                                NGUIContextMenu.AddItem("Edit", false, EditSprite, sprite);
                                NGUIContextMenu.AddItem("Delete", false, DeleteSprite, sprite);
                                NGUIContextMenu.Show();
                            }
                        }

                        if (Event.current.type == EventType.Repaint)
                        {
                            // On top of the button we have a checkboard grid
                            NGUIEditorTools.DrawTiledTexture(rect, NGUIEditorTools.backdropTexture);
                            Rect uv = new Rect(sprite.x, sprite.y, sprite.width, sprite.height);
                            uv = NGUIMath.ConvertToTexCoords(uv, tex.width, tex.height);

                            // Calculate the texture's scale that's needed to display the sprite in the clipped area
                            float scaleX = rect.width / uv.width;
                            float scaleY = rect.height / uv.height;

                            // Stretch the sprite so that it will appear proper
                            float aspect   = (scaleY / scaleX) / ((float)tex.height / tex.width);
                            Rect  clipRect = rect;

                            if (aspect != 1f)
                            {
                                if (aspect < 1f)
                                {
                                    // The sprite is taller than it is wider
                                    float padding = size * (1f - aspect) * 0.5f;
                                    clipRect.xMin += padding;
                                    clipRect.xMax -= padding;
                                }
                                else
                                {
                                    // The sprite is wider than it is taller
                                    float padding = size * (1f - 1f / aspect) * 0.5f;
                                    clipRect.yMin += padding;
                                    clipRect.yMax -= padding;
                                }
                            }

                            GUI.DrawTextureWithTexCoords(clipRect, tex, uv);

                            // Draw the selection
                            if (NGUISettings.selectedSprite == sprite.name)
                            {
                                NGUIEditorTools.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f));
                            }
                        }

                        GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f);
                        GUI.contentColor    = new Color(1f, 1f, 1f, 0.7f);
                        GUI.Label(new Rect(rect.x, rect.y + rect.height, rect.width, 32f), sprite.name, "ProgressBarBack");
                        GUI.contentColor    = Color.white;
                        GUI.backgroundColor = Color.white;

                        if (++col >= columns)
                        {
                            ++offset;
                            break;
                        }
                        rect.x += padded;
                    }
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(padded);
                rect.y += padded + 26;
                ++rows;
            }
            GUILayout.Space(rows * 26);
            GUILayout.EndScrollView();

            if (close)
            {
                Close();
            }
        }
    }
Beispiel #4
0
 /// <summary>
 /// Convenience function that displays a list of sprites and returns the selected value.
 /// </summary>
 public static string SpriteField(UIAtlas atlas, string field, string name, params GUILayoutOption[] options)
 {
     List<string> sprites = atlas.GetListOfSprites();
     return (sprites != null && sprites.Count > 0) ? NGUIEditorTools.DrawList(field, sprites.ToArray(), name, options) : null;
 }
Beispiel #5
0
    /// <summary>
    /// Draw the custom wizard.
    /// </summary>

    void OnGUI()
    {
        EditorGUIUtility.LookLikeControls(80f);

        if (mAtlas == null)
        {
            GUILayout.Label("No Atlas selected.", "LODLevelNotifyText");
        }
        else
        {
            GUILayout.Label(mAtlas.name + " Sprites", "LODLevelNotifyText");
            NGUIEditorTools.DrawSeparator();

            GUILayout.BeginHorizontal();
            GUILayout.Space(84f);

            string before = NGUISettings.partialSprite;
            string after  = EditorGUILayout.TextField("", before, "SearchTextField");
            NGUISettings.partialSprite = after;

            if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f)))
            {
                NGUISettings.partialSprite = "";
                GUIUtility.keyboardControl = 0;
            }
            GUILayout.Space(84f);
            GUILayout.EndHorizontal();

            BetterList <string> sprites = mAtlas.GetListOfSprites(NGUISettings.partialSprite);
            Texture2D           tex     = mAtlas.texture as Texture2D;

            float size    = 80f;
            float padded  = size + 10f;
            int   columns = Mathf.FloorToInt(Screen.width / padded);
            if (columns < 1)
            {
                columns = 1;
            }

            int  offset = 0;
            Rect rect   = new Rect(10f, 0, size, size);

            GUILayout.Space(10f);
            mPos = GUILayout.BeginScrollView(mPos);

            while (offset < sprites.size)
            {
                GUILayout.BeginHorizontal();
                {
                    int col = 0;
                    rect.x = 10f;

                    for (; offset < sprites.size; ++offset)
                    {
                        UIAtlas.Sprite sprite = mAtlas.GetSprite(sprites[offset]);
                        if (sprite == null)
                        {
                            continue;
                        }

                        // Button comes first
                        if (GUI.Button(rect, "") && spriteName != sprite.name)
                        {
                            if (mSprite != null)
                            {
                                NGUIEditorTools.RegisterUndo("Atlas Selection", mSprite);
                                mSprite.spriteName = sprite.name;
                                mSprite.MakePixelPerfect();
                                EditorUtility.SetDirty(mSprite.gameObject);
                            }
                            else if (mCallback != null)
                            {
                                mName = sprite.name;
                                mCallback(sprite.name);
                            }
                        }

                        // On top of the button we have a checkboard grid
                        NGUIEditorTools.DrawTiledTexture(rect, NGUIEditorTools.backdropTexture);

                        Rect uv = sprite.outer;
                        if (mAtlas.coordinates == UIAtlas.Coordinates.Pixels)
                        {
                            uv = NGUIMath.ConvertToTexCoords(uv, tex.width, tex.height);
                        }

                        // Calculate the texture's scale that's needed to display the sprite in the clipped area
                        float scaleX = rect.width / uv.width;
                        float scaleY = rect.height / uv.height;

                        // Stretch the sprite so that it will appear proper
                        float aspect = scaleY / scaleX;
                        if (aspect < 1f)
                        {
                            scaleX *= aspect;
                        }
                        else
                        {
                            scaleY /= aspect;
                        }

                        Rect clipRect = rect;

                        if (aspect != 1f)
                        {
                            if (aspect < 1f)
                            {
                                // The sprite is taller than it is wider
                                float padding = size * (1f - aspect) * 0.5f;
                                clipRect.xMin += padding;
                                clipRect.xMax -= padding;
                            }
                            else
                            {
                                // The sprite is wider than it is taller
                                float padding = size * (1f - 1f / aspect) * 0.5f;
                                clipRect.yMin += padding;
                                clipRect.yMax -= padding;
                            }
                        }

                        GUI.DrawTextureWithTexCoords(clipRect, tex, uv);

                        // Draw the selection
                        if (spriteName == sprite.name)
                        {
                            NGUIEditorTools.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f));
                        }

                        if (++col >= columns)
                        {
                            ++offset;
                            break;
                        }
                        rect.x += padded;
                    }
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(padded);
                rect.y += padded;
            }
            GUILayout.EndScrollView();
        }
    }
Beispiel #6
0
    /// <summary>
    /// 回复UIAtlas
    /// </summary>
    /// <param name="uiatlas"></param>
    public static void RecoverUIAtlasFromMeta(Object uiatlasobj)
    {
        UIAtlas uiatlas   = ((GameObject)uiatlasobj).GetComponent <UIAtlas>();
        string  assetpath = AssetDatabase.GetAssetPath(uiatlas.gameObject);

        if (null == uiatlas.spriteMaterial || null == uiatlas.spriteList)
        {
            return;
        }
        //先把纹理都恢复了
        Object[]         dependObjs  = new Object[] { uiatlas.spriteMaterial.mainTexture };//获取纹理
        List <Texture2D> textureList = new List <Texture2D>();

        for (int i = 0; i < dependObjs.Length; i++)
        {
            if (dependObjs[i] is Texture2D)
            {
                textureList.Add(dependObjs[i] as Texture2D);
            }
        }

        for (int i = textureList.Count - 1; i >= 0; --i)
        {
            try
            {
                RecoverTextureFromMeta(textureList[i]);
            }
            catch (System.Exception e)
            {
                Debug.Log(e.ToString() + " " + textureList[i].name);
            }
        }

        if (!AtlasAlreadyShrinked(assetpath))
        {//并未缩减过,则不对它进行操作
            return;
        }
        AtlasProperty afterAtlasPro = db.GetAtlasProperty(AssetDatabase.GetAssetPath(uiatlas.gameObject), true);

        uiatlas = ((GameObject)uiatlasobj).GetComponent <UIAtlas>();
        BetterList <string> sl = uiatlas.GetListOfSprites();

        if (sl == null)
        {
            return;
        }
        uiatlas.scale     = afterAtlasPro.scale;
        uiatlas.pixelSize = afterAtlasPro.pixelSize;
        for (int i = 0; i < afterAtlasPro.SpriteDetails.Count; i++)
        {
            UISpriteData sd  = uiatlas.GetSprite(sl[i]);
            SpriteDetail spd = afterAtlasPro.SpriteDetails[i];

            sd.x      = (int)spd.Demension.x;
            sd.y      = (int)spd.Demension.y;
            sd.width  = (int)spd.Demension.z;
            sd.height = (int)spd.Demension.w;

            sd.borderLeft   = (int)spd.Border.x;
            sd.borderRight  = (int)spd.Border.y;
            sd.borderBottom = (int)spd.Border.z;
            sd.borderTop    = (int)spd.Border.w;

            sd.paddingLeft   = (int)spd.Padding.x;
            sd.paddingRight  = (int)spd.Padding.y;
            sd.paddingBottom = (int)spd.Padding.z;
            sd.paddingTop    = (int)spd.Padding.w;
        }
        uiatlas.MarkAsDirty();
        AtlasProperty currentAtlas = GetAtlasProperty(uiatlas, true);

        SaveAtlasData(uiatlas, afterAtlasPro, currentAtlas);
    }
Beispiel #7
0
    /// <summary>
    /// Convenience function that displays a list of sprites and returns the selected value.
    /// </summary>

    static public string SpriteField(UIAtlas atlas, string field, string name, params GUILayoutOption[] options)
    {
        List <string> sprites = atlas.GetListOfSprites();

        return((sprites != null && sprites.Count > 0) ? NGUIEditorTools.DrawList(field, sprites.ToArray(), name, options) : null);
    }
    public static string CheckEmotion(string str, UIAtlas atlas)
    {
        Tools_StringCheck.listEmotionData.Clear();
        int length = str.Length;
        int num    = -6;
        BetterList <string> listOfSprites = atlas.GetListOfSprites();

        for (int num2 = 0; num2 != length; num2++)
        {
            if (str[num2] == '#' && num2 + 4 < length && str[num2 + 1] == 'e')
            {
                EmotionData item = default(EmotionData);
                item.serialNumber = str.Substring(num2 + 2, 3);
                if (listOfSprites.Contains(item.serialNumber))
                {
                    if (Tools_StringCheck.IsShowVIPStr(str, num2))
                    {
                        int num3 = (num != 0) ? (num + 6) : (num + 7);
                        item.strContent    = str.Substring(num3, num2 + 5 - num3).Replace(str.Substring(num2, 5), (num2 != 0) ? "      " : "       ");
                        item.position      = num2;
                        item.row           = 1;
                        item.totalConSpace = item.strContent.Length;
                        item.totalNonSpace = (float)(str.Substring(num3, num2 + 5 - num3).Length - 5) + 1.5f;
                        Tools_StringCheck.listEmotionData.Add(item);
                        num = num2;
                        Regex regex = new Regex(str.Substring(num2, 5));
                        str    = regex.Replace(str, (num2 != 0) ? "      " : "       ", 1);
                        length = str.Length;
                    }
                }
            }
        }
        string text = string.Empty;

        if (Tools_StringCheck.listEmotionData != null && Tools_StringCheck.listEmotionData.Count != 0)
        {
            if (Tools_StringCheck.listEmotionData[Tools_StringCheck.listEmotionData.Count - 1].position == 0)
            {
                if (str.Length != 7)
                {
                    text = str.Substring(Tools_StringCheck.listEmotionData[Tools_StringCheck.listEmotionData.Count - 1].position + 7);
                }
            }
            else
            {
                text = str.Substring(Tools_StringCheck.listEmotionData[Tools_StringCheck.listEmotionData.Count - 1].position + 6);
            }
        }
        else
        {
            text = str;
        }
        string text2 = null;

        for (int num4 = 0; num4 != Tools_StringCheck.listEmotionData.Count; num4++)
        {
            text2 += Tools_StringCheck.listEmotionData[num4].strContent;
        }
        if (!string.IsNullOrEmpty(text))
        {
            text2 += text;
        }
        return(text2);
    }
Beispiel #9
0
    // Use this for initialization
    void Start()
    {
        // Find assocciated minigame
        minigame = GetComponent<Minigame>();
        MinigameDifficulty.Difficulty difficulty = minigame.difficulty;

        // Initialize levels array
        myLevels = new GameObject[numLevels];

        // Easy or medium assets
        if(minigame.difficulty != MinigameDifficulty.Difficulty.HARD) {

            foodsAtlas = (UIAtlas) Resources.Load ("NPCs/Amy/AmyLargeFoodBuffetAtlas", typeof(UIAtlas));

            // Gets all large foods
            foreach(string s in foodsAtlas.GetListOfSprites()) {
                if(s.Contains("dess")) {
                    dessertItems.Add (s);
                } else if(s.Contains("app")) {
                    appetizerItems.Add (s);
                } else if(s.Contains("main")) {
                    mainItems.Add (s);
                }
            }

            // Randomizes the possible appetizer foods
            for(int appRandomizer = 0; appRandomizer < appetizerItems.Count; appRandomizer++) {
                int randomindex = Random.Range(appRandomizer, appetizerItems.Count - 1);
                string swap = (string)appetizerItems[randomindex];
                appetizerItems[randomindex] = appetizerItems[appRandomizer];
                appetizerItems[appRandomizer] = swap;
            }

            // Randomizes the possible main foods
            for(int mainRandomizer = 0; mainRandomizer < mainItems.Count; mainRandomizer++) {
                int randomindex = Random.Range(mainRandomizer, mainItems.Count - 1);
                string swap = (string)mainItems[randomindex];
                mainItems[randomindex] = mainItems[mainRandomizer];
                mainItems[mainRandomizer] = swap;
            }

            // Randomizes the possible dessert foods
            for(int dessertRandomizer = 0; dessertRandomizer < dessertItems.Count; dessertRandomizer++) {
                int randomindex = Random.Range(dessertRandomizer, dessertItems.Count - 1);
                string swap = (string)dessertItems[randomindex];
                dessertItems[randomindex] = dessertItems[dessertRandomizer];
                dessertItems[dessertRandomizer] = swap;
            }
        }

        // Hard assets
        if(minigame.difficulty == MinigameDifficulty.Difficulty.HARD) {

            foodsAtlas = (UIAtlas) Resources.Load ("NPCs/Amy/AmySmallFoodBuffetAtlas", typeof(UIAtlas));

            // Gets all large foods
            foreach(string s in foodsAtlas.GetListOfSprites()) {
                if(s.Contains("dess")) {
                    dessertItems.Add (s);
                } else if(s.Contains("app")) {
                    appetizerItems.Add (s);
                } else if(s.Contains("main")) {
                    mainItems.Add (s);
                }
            }

            // Randomizes the possible appetizer foods
            for(int appRandomizer = 0; appRandomizer < appetizerItems.Count; appRandomizer++) {
                int randomindex = Random.Range(appRandomizer, appetizerItems.Count - 1);
                string swap = (string)appetizerItems[randomindex];
                appetizerItems[randomindex] = appetizerItems[appRandomizer];
                appetizerItems[appRandomizer] = swap;
            }

            // Randomizes the possible main foods
            for(int mainRandomizer = 0; mainRandomizer < mainItems.Count; mainRandomizer++) {
                int randomindex = Random.Range(mainRandomizer, mainItems.Count - 1);
                string swap = (string)mainItems[randomindex];
                mainItems[randomindex] = mainItems[mainRandomizer];
                mainItems[mainRandomizer] = swap;
            }

            // Randomizes the possible dessert foods
            for(int dessertRandomizer = 0; dessertRandomizer < dessertItems.Count; dessertRandomizer++) {
                int randomindex = Random.Range(dessertRandomizer, dessertItems.Count - 1);
                string swap = (string)dessertItems[randomindex];
                dessertItems[randomindex] = dessertItems[dessertRandomizer];
                dessertItems[dessertRandomizer] = swap;
            }
        }

        // Get all the foods in the target trays
        ArrayList targetFoodsSmall = new ArrayList();
        foreach(Transform targetFood in smallTargetTray.transform) {
            if(!targetFood.gameObject.name.Contains("Tray")) {
                targetFoodsSmall.Add (targetFood.gameObject);
            }
        }
        ArrayList targetFoodsLarge = new ArrayList();
        foreach(Transform targetFood in largeTargetTray.transform) {
            if(!targetFood.gameObject.name.Contains("Tray")) {
                targetFoodsLarge.Add (targetFood.gameObject);
            }
        }

        // Remove two plates from the target trays
        for(int randomInt = 0; randomInt < 2; randomInt++) {
            int randomIndex = Random.Range(0, targetFoodsSmall.Count - 1);
            GameObject targetFoodToRemove = ((GameObject)targetFoodsSmall[randomIndex]).gameObject;
            targetFoodToRemove.SetActive(false);
            targetFoodsSmall.Remove(targetFoodToRemove);
            GameObject targetFoodToRemoveLarge = largeTargetTray.transform.FindChild(targetFoodToRemove.name).gameObject;
            targetFoodToRemoveLarge.SetActive(false);
            targetFoodsLarge.Remove(targetFoodToRemoveLarge);
        }

        // Get dropspots from player tray
        GameObject[] dropspots = new GameObject[5];
        for(int dropspotsCounterOne = 0; dropspotsCounterOne < 5; dropspotsCounterOne++)
            dropspots[dropspotsCounterOne] = playerTray.transform.FindChild("Slot" + (dropspotsCounterOne + 1).ToString()).gameObject;

        // Get all levels in the scene
        int i = 0;
        moveDistace.x = buffetTexture.transform.localScale.x;
        while(i < myLevels.Length)
        {
            Transform t = buffet.transform.FindChild("BuffetLevel" + i.ToString());
            if (t != null)
            {
                myLevels[i] = t.gameObject;

                // Get all food items in the current level
                ArrayList foods = new ArrayList();

                // Easy difficulty, 4 items
                if(difficulty == MinigameDifficulty.Difficulty.EASY) {
                    for(int easyCounter = 0; easyCounter < 4; easyCounter++) {
                        GameObject newFood = (GameObject) Instantiate(buffetItem);
                        newFood.transform.parent = myLevels[i].transform;
                        newFood.transform.localPosition = new Vector3(-250 + easyCounter * 90, 290 - easyCounter % 2 * 200, 10);
                        newFood.transform.localScale = new Vector3(2, 2, 2);
                        newFood.transform.FindChild("Buffet_ItemHard1").gameObject.SetActive(false);
                        newFood.transform.FindChild("Buffet_ItemHard2").gameObject.SetActive(false);
                        GameObject newFoodItem = newFood.transform.FindChild("Buffet_ItemEasy").gameObject;
                        newFoodItem.GetComponent<UISprite>().atlas = foodsAtlas;
                        for(int dropspotsCounter = 0; dropspotsCounter < 5; dropspotsCounter++)
                            newFood.GetComponent<DraggableObjectBuffet>().dropspots[dropspotsCounter] = dropspots[dropspotsCounter];
                        switch(i) {
                        case 0:
                            newFoodItem.GetComponent<UISprite>().spriteName = (string)appetizerItems[easyCounter];
                            break;
                        case 1:
                            newFoodItem.GetComponent<UISprite>().spriteName = (string)mainItems[easyCounter];
                            break;
                        case 2:
                            newFoodItem.GetComponent<UISprite>().spriteName = (string)dessertItems[easyCounter];
                            break;
                        default:
                            newFood.GetComponent<UISprite>().spriteName = (string)appetizerItems[easyCounter];
                            break;
                        }
                        foods.Add(newFood);
                    }
                }

                // Medium difficulty, 8 items
                if(difficulty == MinigameDifficulty.Difficulty.MEDIUM) {
                    for(int mediumCounter = 0; mediumCounter < 8; mediumCounter++) {
                        GameObject newFood = (GameObject) Instantiate(buffetItem);
                        newFood.transform.parent = myLevels[i].transform;
                        newFood.transform.localPosition = new Vector3(-370 + mediumCounter * 77 - (mediumCounter % 2)*30, 260 - mediumCounter % 2 * 180, 10);
                        newFood.transform.localScale = new Vector3(2, 2, 2);
                        newFood.transform.FindChild("Buffet_ItemHard1").gameObject.SetActive(false);
                        newFood.transform.FindChild("Buffet_ItemHard2").gameObject.SetActive(false);
                        GameObject newFoodItem = newFood.transform.FindChild("Buffet_ItemEasy").gameObject;
                        newFoodItem.GetComponent<UISprite>().atlas = foodsAtlas;
                        for(int dropspotsCounter = 0; dropspotsCounter < 5; dropspotsCounter++)
                            newFood.GetComponent<DraggableObjectBuffet>().dropspots[dropspotsCounter] = dropspots[dropspotsCounter];
                        switch(i) {
                        case 0:
                            newFoodItem.GetComponent<UISprite>().spriteName = (string)appetizerItems[mediumCounter];
                            break;
                        case 1:
                            newFoodItem.GetComponent<UISprite>().spriteName = (string)mainItems[mediumCounter];
                            break;
                        case 2:
                            newFoodItem.GetComponent<UISprite>().spriteName = (string)dessertItems[mediumCounter];
                            break;
                        default:
                            newFood.GetComponent<UISprite>().spriteName = (string)appetizerItems[mediumCounter];
                            break;
                        }
                        foods.Add(newFood);
                    }
                }

                // Hard difficulty, 8 items split
                if(difficulty == MinigameDifficulty.Difficulty.HARD) {
                    for(int hardCounter = 0; hardCounter < 8; hardCounter++) {
                        GameObject newFood = (GameObject) Instantiate(buffetItem);
                        newFood.transform.parent = myLevels[i].transform;
                        newFood.transform.localPosition = new Vector3(-370 + hardCounter * 77 - (hardCounter % 2)*30, 260 - hardCounter % 2 * 180, 10);
                        newFood.transform.localScale = new Vector3(2, 2, 2);
                        newFood.transform.localEulerAngles = new Vector3(0, 0, 30);
                        newFood.transform.FindChild("Buffet_ItemEasy").gameObject.SetActive(false);
                        GameObject newFoodItem1 = newFood.transform.FindChild("Buffet_ItemHard1").gameObject;
                        newFoodItem1.GetComponent<UISprite>().atlas = foodsAtlas;
                        GameObject newFoodItem2 = newFood.transform.FindChild("Buffet_ItemHard2").gameObject;
                        newFoodItem2.GetComponent<UISprite>().atlas = foodsAtlas;
                        for(int dropspotsCounter = 0; dropspotsCounter < 5; dropspotsCounter++)
                            newFood.GetComponent<DraggableObjectBuffet>().dropspots[dropspotsCounter] = dropspots[dropspotsCounter];
                        int nextHardCounter = hardCounter + 1;
                        if(nextHardCounter >= 8)
                            nextHardCounter = 0;
                        switch(i) {
                        case 0:
                            newFoodItem1.GetComponent<UISprite>().spriteName = (string)appetizerItems[hardCounter];
                            newFoodItem2.GetComponent<UISprite>().spriteName = (string)appetizerItems[nextHardCounter];
                            break;
                        case 1:
                            newFoodItem1.GetComponent<UISprite>().spriteName = (string)mainItems[hardCounter];
                            newFoodItem2.GetComponent<UISprite>().spriteName = (string)mainItems[nextHardCounter];
                            break;
                        case 2:
                            newFoodItem1.GetComponent<UISprite>().spriteName = (string)dessertItems[hardCounter];
                            newFoodItem2.GetComponent<UISprite>().spriteName = (string)dessertItems[nextHardCounter];
                            break;
                        default:
                            newFood.GetComponent<UISprite>().spriteName = (string)appetizerItems[hardCounter];
                            newFoodItem2.GetComponent<UISprite>().spriteName = (string)appetizerItems[nextHardCounter];
                            break;
                        }
                        foods.Add(newFood);
                    }
                }

                // Randomize the order of items in the buffet
                for(int foodsCounter = 0; foodsCounter < foods.Count; foodsCounter++) {
                    int randomindex = Random.Range(foodsCounter, foods.Count - 1);
                    // Swap positions
                    float x = ((GameObject)foods[randomindex]).transform.position.x;
                    float y = ((GameObject)foods[randomindex]).transform.position.y;
                    ((GameObject)foods[randomindex]).transform.position = new Vector3(
                        ((GameObject)foods[foodsCounter]).transform.position.x,
                        ((GameObject)foods[foodsCounter]).transform.position.y,
                        ((GameObject)foods[foodsCounter]).transform.position.z);
                    ((GameObject)foods[foodsCounter]).transform.position = new Vector3(x, y, ((GameObject)foods[foodsCounter]).transform.position.z);
                }

                // Make one item the target food
                GameObject correctFood = (GameObject)foods[Random.Range(0, foods.Count - 1)];
                GameObject correctFoodEasy = correctFood.transform.FindChild("Buffet_ItemEasy").gameObject;
                GameObject correctFoodHard1 = correctFood.transform.FindChild("Buffet_ItemHard1").gameObject;
                GameObject correctFoodHard2 = correctFood.transform.FindChild("Buffet_ItemHard2").gameObject;
                // Update the small and large food tray's plate for easy and medium
                if(difficulty != MinigameDifficulty.Difficulty.HARD) {
                    ((GameObject)targetFoodsSmall[i]).transform.FindChild("Buffet_ItemHard1").gameObject.SetActive(false);
                    ((GameObject)targetFoodsSmall[i]).transform.FindChild("Buffet_ItemHard2").gameObject.SetActive(false);
                    ((GameObject)targetFoodsSmall[i]).transform.FindChild("Buffet_ItemEasy").gameObject.GetComponent<UISprite>().atlas = foodsAtlas;
                    ((GameObject)targetFoodsSmall[i]).transform.FindChild("Buffet_ItemEasy").gameObject.GetComponent<UISprite>().spriteName =
                        correctFoodEasy.GetComponent<UISprite>().spriteName;
                    // Find and update the large food tray's plate
                    foreach(GameObject g in targetFoodsLarge) {
                        if(g.name == ((GameObject)targetFoodsSmall[i]).gameObject.name) {
                            g.transform.FindChild("Buffet_ItemHard1").gameObject.SetActive(false);
                            g.transform.FindChild("Buffet_ItemHard2").gameObject.SetActive(false);
                            g.transform.FindChild("Buffet_ItemEasy").gameObject.GetComponent<UISprite>().atlas = foodsAtlas;
                            g.transform.FindChild("Buffet_ItemEasy").GetComponent<UISprite>().spriteName = correctFoodEasy.GetComponent<UISprite>().spriteName;
                            break;
                        }
                    }
                } else if(difficulty == MinigameDifficulty.Difficulty.HARD) {
                    ((GameObject)targetFoodsSmall[i]).transform.localEulerAngles = new Vector3(0, 0, 30);
                    ((GameObject)targetFoodsSmall[i]).transform.FindChild("Buffet_ItemEasy").gameObject.SetActive(false);
                    ((GameObject)targetFoodsSmall[i]).transform.FindChild("Buffet_ItemHard1").gameObject.GetComponent<UISprite>().atlas = foodsAtlas;
                    ((GameObject)targetFoodsSmall[i]).transform.FindChild("Buffet_ItemHard1").gameObject.GetComponent<UISprite>().spriteName =
                        correctFoodHard1.GetComponent<UISprite>().spriteName;
                    ((GameObject)targetFoodsSmall[i]).transform.FindChild("Buffet_ItemHard2").gameObject.GetComponent<UISprite>().atlas = foodsAtlas;
                    ((GameObject)targetFoodsSmall[i]).transform.FindChild("Buffet_ItemHard2").gameObject.GetComponent<UISprite>().spriteName =
                        correctFoodHard2.GetComponent<UISprite>().spriteName;
                    // Find and update the large food tray's plate
                    foreach(GameObject g in targetFoodsLarge) {
                        if(g.name == ((GameObject)targetFoodsSmall[i]).gameObject.name) {
                            g.transform.localEulerAngles = new Vector3(0, 0, 30);
                            g.transform.FindChild("Buffet_ItemEasy").gameObject.SetActive(false);
                            g.transform.FindChild("Buffet_ItemHard1").GetComponent<UISprite>().atlas = foodsAtlas;
                            g.transform.FindChild("Buffet_ItemHard1").GetComponent<UISprite>().spriteName = correctFoodHard1.GetComponent<UISprite>().spriteName;
                            g.transform.FindChild("Buffet_ItemHard2").GetComponent<UISprite>().atlas = foodsAtlas;
                            g.transform.FindChild("Buffet_ItemHard2").GetComponent<UISprite>().spriteName = correctFoodHard2.GetComponent<UISprite>().spriteName;
                            break;
                        }
                    }
                }
                correctFood.GetComponent<DraggableObjectBuffet>().isSolution = true;
                correctFood.GetComponent<DraggableObjectBuffet>().correctSlot = ((GameObject)targetFoodsSmall[i]).name.Replace("Spot", "");

                myLevels[i].transform.localPosition = moveDistace * i;
            }
            else
                break;

            i++;
        }

        // Find all game objects related the minigame
        largeSample = GameObject.Find("SampleTrayLarge");
        smallSample = GameObject.Find("SampleTraySmall");
        smallSample.SetActive(false);
        smallSampleBubble = GameObject.Find("SampleTrayBubble");
        smallSampleBubble.SetActive(false);
        myTray = GameObject.Find ("PlayerTray");
        myTray.SetActive(false);
        endGame = GameObject.Find ("EndBackground");
        endGame.SetActive(false);
        buffet.SetActive(false);
        tutorialHand = GameObject.Find("TutorialHand");
        tutorialHand.SetActive(false);
        tutorialBuffet = GameObject.Find ("TutorialBuffet");
        tutorialObject = GameObject.Find ("TutorialObject");
        tutorialBuffet.SetActive(false);
        tutorialObject.SetActive(false);

        if(!minigame.isStandalone()) //if the minigame is part of the story, not free play mode
        {
            Destroy(tutorialOptions);
            if(showTutorial)
            {
                largeSample.SetActive(false);
                myTray.SetActive(true);
                tutorialBuffet.SetActive(true);
                StartCoroutine("startTutorial");
            }
            else
            {
                // Show the instructions of the minigame
                if (minigame != null && minigame.StartConversation() == false)
                {
                    Debug.Log("S: This is Amy's original order. She had a garden salad, burger and strawberries. We must remake Amy's lunch exactly as it appears, so choose the RIGHT item, and place it in the RIGHT location.");
                }

                Invoke ("LayBuffet", minigame.GetCurrentDialogueDuration());
            }
        }
    }
Beispiel #10
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <returns><c>true</c>, if data was inited, <c>false</c> otherwise.</returns>
        private bool InitData()
        {
            AtlasList.Clear();
            AtlasAssetDic.Clear();

            DirectoryInfo dic = new DirectoryInfo(AtlasWorkSpace);

            FileInfo[] atlases = dic.GetFiles();

            if (atlases == null)
            {
                return(false);
            }

            for (int i = 0; i < atlases.Length; i++)
            {
                if (atlases[i].Name.Contains("meta"))
                {
                    continue;
                }

                AtlasList.Add(atlases[i].Name);
                if (!AtlasAssetDic.ContainsKey(atlases[i].Name))
                {
                    UIAtlas atlas = AssetDatabase.LoadAssetAtPath <UIAtlas>(AtlasWorkSpace + atlases[i].Name);
                    if (atlas == null)
                    {
                        continue;
                    }
                    BetterList <string> sprites    = atlas.GetListOfSprites();
                    List <string>       spriteName = new List <string>();
                    foreach (var sp in sprites)
                    {
                        spriteName.Add(sp);
                        if (!SpriteLinkDic.ContainsKey(sp))
                        {
                            SpriteLinkDic.Add(sp, new List <string>()
                            {
                                atlases[i].Name
                            });
                        }
                        else
                        {
                            SpriteLinkDic[sp].Add(atlases[i].Name);
                        }
                    }
                    AtlasAssetDic.Add(atlases[i].Name, spriteName);
                }
                else
                {
                    UnityEngine.Debug.LogError("重复图集:" + atlases[i].Name);
                }
            }

            if (!LoadPrefab())
            {
                return(false);
            }

            return(true);
        }