Esempio n. 1
0
    /// <summary>
    /// Load all items from Editor Prefs.
    /// </summary>

    void Load()
    {
        mTab  = NGUISettings.GetInt("NGUI Prefab Tab", 0);
        mMode = NGUISettings.GetEnum <Mode>("NGUI Prefab Mode", mMode);

        foreach (Item item in mItems)
        {
            DestroyTexture(item);
        }
        mItems.Clear();

        string data = NGUISettings.GetString(saveKey, "");

        if (string.IsNullOrEmpty(data))
        {
            Reset();
        }
        else
        {
            if (string.IsNullOrEmpty(data))
            {
                return;
            }
            string[] guids = data.Split('|');
            foreach (string s in guids)
            {
                AddGUID(s, -1);
            }
            RectivateLights();
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Load all items from Editor Prefs.
    /// </summary>

    void Load()
    {
        mTab  = NGUISettings.GetInt("NGUI Prefab Tab", 0);
        mMode = NGUISettings.GetEnum <Mode>("NGUI Prefab Mode", mMode);
        {
            // foreach(var item in mItems)
            var __enumerator5 = (mItems).GetEnumerator();
            while (__enumerator5.MoveNext())
            {
                var item = (Item)__enumerator5.Current;
                DestroyTexture(item);
            }
        }
        mItems.Clear();

        string data = NGUISettings.GetString(saveKey, "");

        if (string.IsNullOrEmpty(data))
        {
            Reset();
        }
        else
        {
            if (string.IsNullOrEmpty(data))
            {
                return;
            }
            string[] guids = data.Split('|');
            {
                var __array6       = guids;
                var __arrayLength6 = __array6.Length;
                for (int __i6 = 0; __i6 < __arrayLength6; ++__i6)
                {
                    var s = (string)__array6[__i6];
                    AddGUID(s, -1);
                }
            }
            RectivateLights();
        }
    }
Esempio n. 3
0
    // CheckSourceFolder
    #endregion

    #region CreateNewAtlas

    /// <summary>
    /// Create a new atlas
    /// </summary>
    /// <param name="psdAssetFolderPath"></param>
    /// <returns></returns>
    public static UIAtlas CreateNewAtlas(string psdAssetFolderPath)
    {
        CheckSourceFolder(psdAssetFolderPath);

        string prefabPath = string.Empty, matPath = string.Empty;
        string AtlasName = PsdImporter.NSettingsAtlasName;

        // If we have an atlas to work with, see if we can figure out the path for it and its material
        if (NGUISettings.atlas != null && NGUISettings.atlas.name == NGUISettings.GetString(AtlasName, string.Empty))
        {
            prefabPath = AssetDatabase.GetAssetPath(NGUISettings.atlas.gameObject.GetInstanceID());
            if (NGUISettings.atlas.spriteMaterial != null)
            {
                matPath = AssetDatabase.GetAssetPath(NGUISettings.atlas.spriteMaterial.GetInstanceID());
            }
        }

        // Assume default values if needed
        NGUISettings.SetString(AtlasName, PsdImporter.ObjPSDFolderToLoad.name);
        if (string.IsNullOrEmpty(prefabPath))
        {
            prefabPath = string.Format("{0}{1}.prefab", PsdImporter.SourceFolder, AtlasName);
        }
        if (string.IsNullOrEmpty(matPath))
        {
            matPath = string.Format("{0}{1}.mat", PsdImporter.SourceFolder, AtlasName);
        }

        // Try to load the prefab
        GameObject go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;

        if (NGUISettings.atlas == null && go != null)
        {
            NGUISettings.atlas = go.GetComponent <UIAtlas>();
        }

        // Try to load the material
        Material mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material;

        // If the material doesn't exist, create it
        if (mat == null)
        {
            mat = new Material(Shader.Find(STR_UnlitTransparentColored));

            // Save the material
            AssetDatabase.CreateAsset(mat, matPath);
            AssetDatabase.Refresh();

            // Load the material so it's usable
            mat = AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)) as Material;
        }

        // create atlas if one is not already loaded
        if (NGUISettings.atlas == null || NGUISettings.atlas.name != AtlasName)
        {
            // Create a new prefab for the atlas
            Object prefab = go ?? PrefabUtility.CreateEmptyPrefab(prefabPath);

            // Create a new game object for the atlas
            go = new GameObject(AtlasName);
            go.AddComponent <UIAtlas>().spriteMaterial = mat;

            // Update the prefab
            PrefabUtility.ReplacePrefab(go, prefab);

            DestroyImmediate(go);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            // Select the atlas
            go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;
            NGUISettings.atlas = go.GetComponent <UIAtlas>();
        }

        return(go.GetComponent <UIAtlas>());
    }