コード例 #1
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        GUILayout.Space(10);

        if (GUILayout.Button("Generate icon"))
        {
            serializedObject.Update();

            BrickButton button = (BrickButton)target;

            var image = button.GetComponent <Image>();
            if (image != null)
            {
                //generate icon
                var    brick = Resources.Load(button.brickResourcePath) as GameObject;
                string path  = string.Format("Assets/Resources/Icons/{0}.png", brick.name);
                BrickUtils.GenerateIcon(brick.GetComponent <Brick>(), path, 256);

                //attache generated icon to button
//                AssetDatabase.ImportAsset(path);
//                Sprite sprite = AssetDatabase.LoadAssetAtPath<Sprite>(path);
//                image.sprite = sprite;
            }

            serializedObject.ApplyModifiedProperties();
        }
    }
コード例 #2
0
    /// <summary>
    /// Generate new brick button.
    /// </summary>
    /// <param name="file">Prefa file name.</param>
    /// <param name="number">Number added to name</param>
    /// <param name="parent">:arent node to new button.</param>
    void GenerateButton(string file, int number, Transform parent)
    {
        //create GameObject
        GameObject buttonObject = new GameObject();

        buttonObject.transform.SetParent(parent);
        buttonObject.name = string.Format("brick button {0}", number);

        //atache Image component
        Image image = buttonObject.AddComponent <Image>();

        //attach BrickButtonScript and configure it
        BrickButton button = buttonObject.AddComponent <BrickButton>();

        button.brickResourcePath = ExtractResourcesPath(file);

        //generate button icon
        GameObject    brickPrefab = (GameObject)EditorGUIUtility.Load(file);
        DragableBrick brick       = brickPrefab.GetComponent <DragableBrick>();
        var           s           = Path.DirectorySeparatorChar;
        string        iconPath    = string.Format(string.Concat("Assets", s, "Resources", s, "Icons", s, "{0}.png"), brick.name);

        BrickUtils.GenerateIcon(brick, iconPath, 256);

        //configure icon
        button.imageResourcePath = ExtractResourcesPath(iconPath);
        string standardIconPath = string.Concat("Assets", s, "Gfx", s, "UI", s, "Icons", s, "BrickButtonIcon.png");
        //AssetDatabase.ImportAsset(standardIconPath);
        Sprite sprite = AssetDatabase.LoadAssetAtPath <Sprite>(standardIconPath);

        image.sprite = sprite;

        //configure group
        if (file.Contains("AgaQ Lukowe Poziome i Pionowe STL"))
        {
            button.group = 1;
        }
        else if (file.Contains("AgaQ Prostopadłoscianowe STL"))
        {
            button.group = 2;
        }
        else if (file.Contains("AgaQ Rownolegloboczne poziome STL"))
        {
            button.group = 3;
        }
        else if (file.Contains("AgaQ Schodkowe STL"))
        {
            button.group = 4;
        }
        else if (file.Contains("AgaQ Skalowe przechodzace STL"))
        {
            button.group = 5;
        }
        else if (file.Contains("AgaQ Trapezowe STL"))
        {
            button.group = 6;
        }
    }
コード例 #3
0
    /// <summary>
    /// Rebuild all buttons icons.
    /// </summary>
    /// <param name="">.</param>
    void RebuildButtonsIcons(BricksList list)
    {
        var buttons = list.gameObject.GetComponentsInChildren <BrickButton>();

        foreach (var button in buttons)
        {
            var image = button.GetComponent <Image>();
            if (image != null)
            {
                //generate icon
                var    brick = Resources.Load(button.brickResourcePath) as GameObject;
                string path  = string.Format("Assets/Resources/Icons/{0}.png", brick.name);
                BrickUtils.GenerateIcon(brick.GetComponent <Brick>(), path, 256);
            }
        }
    }
コード例 #4
0
        /// <summary>
        /// Save currently selected group.
        /// </summary>
        /// <param name="name">group name</param>
        /// <param name="category">group category</param>
        /// <param name="path">path ehre to save group</param>
        /// <returns>File path where data where saved.</returns>
        public string SaveGroup(string name, int category, string path)
        {
            if (SelectionManager.instance.SelectedAmount < 1)
            {
                return("");
            }

            var toSave      = SelectionManager.instance.GetSelected()[0];
            var brickToSave = toSave.GetComponent <Brick>();

            if (brickToSave == null)
            {
                return("");
            }

            var separator = Path.DirectorySeparatorChar;
            var fileName  = name;

            foreach (var c in System.IO.Path.GetInvalidFileNameChars())
            {
                fileName = fileName.Replace(c, '_');
            }
            while (
                File.Exists(string.Concat(path, separator, fileName, ".meta")) ||
                File.Exists(string.Concat(path, separator, fileName, ".png")) ||
                File.Exists(string.Concat(path, separator, fileName, ".aga")))
            {
                fileName += "_";
            }

            try
            {
                //save meta file
                BricksGropuMetaData meta = new BricksGropuMetaData();
                meta.name     = name;
                meta.category = category;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string filePath = string.Concat(path, separator, fileName, ".meta");
                using (var file = File.Create(filePath))
                {
                    var x = new XmlSerializer(meta.GetType());
                    x.Serialize(file, meta);
                }

                //make icon and save it
                BrickUtils.GenerateIcon(brickToSave, string.Concat(path, separator, fileName, ".png"), 256);

                //save group
                Model.instance.Serialize(string.Concat(path, separator, fileName, ".aga"), brickToSave);

                return(filePath);
            }
            catch
            {
                try { File.Delete(string.Concat(path, separator, fileName, ".meta")); } catch {}
                try { File.Delete(string.Concat(path, separator, fileName, ".png")); } catch {}
                try { File.Delete(string.Concat(path, separator, fileName, ".aga")); } catch {}
                Dialog.ShowTranslatedInfo("CantSaveGroup");
                return("");
            }
        }