Exemple #1
0
    public static Transform getDiamond(Element.ElementType type, Transform parent)
    {
        GameObject go = ResourceManager.LoadGO(Setting.Path.PR_Diamond, parent);

        go.GetComponent <SpriteRenderer>().sprite = getDiamondSprite(type);
        return(go.transform);
    }
Exemple #2
0
        //MenuBar = 0,
        //ContentBackground = 1,
        //Button = 2,
        //ButtonPressed = 3,
        //SideButton = 4,
        //SideButtonPressed = 5,
        //TopButton = 6,
        //TopButtonPressed = 7,
        //Transparent = 8
        public Image GetElementImage(Element.ElementType type, bool Pressed = false)
        {
            switch (type)
            {
            case Element.ElementType.Button:
                if (Pressed)
                {
                    return(images[3]);
                }
                else
                {
                    return(images[2]);
                }

            case Element.ElementType.Content:
                return(images[1]);

            case Element.ElementType.TopBar:
                return(images[0]);

            case Element.ElementType.Textbox:
                return(images[8]);

            case Element.ElementType.Window:
                return(images[1]);

            default:
                return(images[8]);
            }
        }
Exemple #3
0
    static public Element.ElementType getGenerateType(Element.ElementType src)
    {
        switch (src)
        {
        case Element.ElementType.metal:
            return(Element.ElementType.water);

        case Element.ElementType.water:
            return(Element.ElementType.wood);

        case Element.ElementType.wood:
            return(Element.ElementType.fire);

        case Element.ElementType.fire:
            return(Element.ElementType.earth);

        case Element.ElementType.earth:
            return(Element.ElementType.metal);

        default:
            break;
        }
        Debug.Log("Error!");

        return(Element.ElementType.earth);
    }
Exemple #4
0
    public static Sprite getDiamondSprite(Element.ElementType type)
    {
        string spPath = "";

        switch (type)
        {
        case Element.ElementType.metal:
            spPath = Setting.Path.SP_DMetal;
            break;

        case Element.ElementType.water:
            spPath = Setting.Path.SP_DWater;
            break;

        case Element.ElementType.wood:
            spPath = Setting.Path.SP_DWood;
            break;

        case Element.ElementType.fire:
            spPath = Setting.Path.SP_DFire;
            break;

        case Element.ElementType.earth:
            spPath = Setting.Path.SP_DEarth;
            break;

        default:
            break;
        }
        return(ResourceManager.LoadTexture(spPath));
    }
Exemple #5
0
        private static void AddChildren(ref XmlNode parent, ref Element rootElement, ref BitmapHelper bitHelper)
        {
            for (int i = 0; i < parent.ChildNodes.Count; i++)
            {
                XmlNode child = parent.ChildNodes[i];
                List<Element.ElementProperties> Properties = new List<Element.ElementProperties>();
                Element.ElementProperties property = new Element.ElementProperties();
                int width = 0;
                int height = 0;
                string ElementText = "";
                if (child.Attributes != null)
                {
                    for (int pi = 0; pi < child.Attributes.Count; pi++)
                    {
                        property = new Element.ElementProperties();
                        property.Value = child.Attributes[pi].Value;
                        property.type = Element.GetPropertyType(child.Attributes[pi].Name);

                        if (property.type == Element.ElementProperties.PropertyType.Content)
                        {
                            ElementText = (string)property.Value;
                        }
                        Properties.Add(property);
                    }
                    Properties.Add(property);
                }
                Element.ElementProperties Width = GetProperty(Properties.ToArray(), Element.ElementProperties.PropertyType.Width);
                Element.ElementProperties Height = GetProperty(Properties.ToArray(), Element.ElementProperties.PropertyType.Height);

                Element.ElementType elementType = new Element.ElementType();
                elementType = Element.GetElementType(child.Name.ToLower());
                int[] size = bitHelper.GetTextWidth(ElementText);
                if (Width != null)
                {
                    int iWidth = int.Parse((string)Width.Value);
                    if (iWidth > size[0])
                        size[0] = iWidth;
                }
                if (Height != null)
                {
                    int iHeight = int.Parse((string)Height.Value);
                    size[1] = iHeight;
                }
                Bitmap AfterNine = (System.Drawing.Bitmap)bitHelper.GetImage(size, bitHelper.GetElementImage(elementType));
                System.Drawing.Bitmap finalImage = ResizeImage(AfterNine, new Size(AfterNine.Width, size[1]));
                if (ElementText.Length > 0)
                {
                    using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage))
                    {
                        g.DrawString(ElementText, new Font("Segoe UI", 11, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.Black, new RectangleF(0, 0, finalImage.Width, finalImage.Height)); // requires font, brush etc
                    }
                }

                Element.ElementData elementData = new Element.ElementData(finalImage, new TextureID(finalImage), Properties.ToArray());
                Element element = new Element(elementData, elementType);
                AddChildren(ref child, ref element, ref bitHelper);
                rootElement.Children.Add(element);
            }
        }
Exemple #6
0
        public DataMatrix(int width, int height, Element.ElementType type)
        {
            this.Width  = width;
            this.Height = height;
            matrixArray = new Element[width, height];

            InitializeMatrix(type);
        }
Exemple #7
0
    private static void makeSpritePrefabs(FileInfo file, string targetDir, int id, Element.ElementType type, string tag, string layer)
    {
        //获取全路径
        string allPath = file.FullName;

        MonoBehaviour.print(allPath);
        Debug.Log(file);

        //获取资源路径
        string assetPath = allPath.Substring(allPath.IndexOf("Assets"));

        MonoBehaviour.print("assetPath " + assetPath);

        //加载贴图
        Sprite sprite = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;

        //创建绑定了贴图的 GameObject 对象
        GameObject go = new GameObject(sprite.name);

        go.tag = tag;

        SpriteRenderer sr = go.AddComponent <SpriteRenderer>();

        sr.sprite           = sprite;
        sr.sortingLayerName = layer;

        BoxCollider2D bc2 = go.AddComponent <BoxCollider2D>();

        bc2.isTrigger = true;

        Element element = go.AddComponent <Element>();

        element.id   = id;
        element.type = type;
        EditorUtility.DisplayProgressBar("创建" + sprite.name, "创建" + sprite.name, 1f);

        //获取图片名称
        string imageName = assetPath.Replace("Assets" + ORIGIN_DIR + "\\", "");

        //去掉后缀
        imageName = tag + "_" + id; // imageName.Substring(0, imageName.IndexOf("."));

        //得到最终路径
        string prefabPath = targetDir + "\\" + imageName + ".prefab";

        //得到应用当前目录的路径
        prefabPath = prefabPath.Substring(prefabPath.IndexOf("Assets"));

        //创建目录
        Directory.CreateDirectory(prefabPath.Substring(0, prefabPath.LastIndexOf("\\")));

        //生成预制件
        PrefabUtility.CreatePrefab(prefabPath.Replace("\\", "/"), go);

        //销毁对象
        GameObject.DestroyImmediate(go);
    }
Exemple #8
0
 private void InitializeMatrix(Element.ElementType type)
 {
     for (int i = 0; i < Width; i++)
     {
         for (int j = 0; j < Width; j++)
         {
             matrixArray[i, j] = new Element(type);
         }
     }
 }
        private DataMatrix CalculateGridClicked(DataMatrix matrix, ActionTypes actionType, int x, int y)
        {
            int cellX = x / Constants.CELL_SIDE;
            int cellY = y / Constants.CELL_SIDE;

            Element.ElementType currentType = matrix[cellX, cellY].Type;
            Element.ElementType newType     = ElementStateMatrix.getElementWithState(currentType, actionType);
            matrix[cellX, cellY] = new Element(ElementStateMatrix.getElementWithState(matrix[cellX, cellY].Type, actionType));

            return(matrix);
        }
Exemple #10
0
    public static Element randomElement(Transform parent)
    {
        GameObject go = ResourceManager.LoadGO(Setting.Path.PR_Element, parent);

        Element.ElementType et = randomElementType();
        go.GetComponent <SpriteRenderer>().sprite = getElementSprite(et);
        Element e = go.GetComponent <Element>();

        e.type = et;
        return(e);
    }
Exemple #11
0
 public bool Contains(Element.ElementType type)
 {
     foreach (Element el in matrixArray)
     {
         if (el.Type == type)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #12
0
    ////// 将目录下所有图片转成Sprite prefab
    public static void batchCreateSpritePrefabInPath(Element.ElementType type, string tag, string layer)
    {
        string targetDir = Application.dataPath + TARGET_DIR;
        string originDir = Application.dataPath + ORIGIN_DIR;

        ////如果目录不存在创建空的目标目录
        DirectoryInfo originDirInfo = new DirectoryInfo(originDir);

        //创建prefab
        makeSpritePrefabs(originDirInfo.GetFiles("*.jpg", SearchOption.AllDirectories), targetDir, type, tag, layer);
        makeSpritePrefabs(originDirInfo.GetFiles("*.png", SearchOption.AllDirectories), targetDir, type, tag, layer);

        EditorUtility.ClearProgressBar();
    }
Exemple #13
0
    static public bool isCounter(Element.ElementType src, Element.ElementType tar)
    {
        int srcStandIn, tarStandIn;

        srcStandIn = (int)src;
        tarStandIn = (int)tar;
        //Debug.Log (src +":"+ srcStandIn + " ||" + tar +":"+ tarStandIn);
        srcStandIn = (srcStandIn + 1) % 5;
        if (srcStandIn == tarStandIn)
        {
            return(true);
        }
        return(false);
    }
Exemple #14
0
 private static void makeSpritePrefabs(FileInfo[] files, string targetDir, Element.ElementType type, string tag, string layer)
 {
     for (int i = 0; i < files.Length; i++)
     {
         if (type == Element.ElementType.Item)
         {
             FileInfo file = files[i];
             makeSpritePrefabs(file, targetDir, i + 1, type, tag, layer);
         }
         else if (type == Element.ElementType.Enemy)
         {
             if (i % 4 == 0)
             {
                 FileInfo file = files[i];
                 makeSpritePrefabs(file, targetDir, (i / 4) + 1, type, tag, layer);
             }
         }
     }
 }
 public static Element.ElementType getElementWithState(Element.ElementType j, ActionTypes i)
 {
     return(matrixArray[(short)i, (short)j]);
 }
Exemple #16
0
        private static void AddChildren(ref XmlNode parent, ref Element rootElement, ref BitmapHelper bitHelper)
        {
            for (int i = 0; i < parent.ChildNodes.Count; i++)
            {
                XmlNode child = parent.ChildNodes[i];
                List <Element.ElementProperties> Properties = new List <Element.ElementProperties>();
                Element.ElementProperties        property   = new Element.ElementProperties();
                int    width       = 0;
                int    height      = 0;
                string ElementText = "";
                if (child.Attributes != null)
                {
                    for (int pi = 0; pi < child.Attributes.Count; pi++)
                    {
                        property       = new Element.ElementProperties();
                        property.Value = child.Attributes[pi].Value;
                        property.type  = Element.GetPropertyType(child.Attributes[pi].Name);

                        if (property.type == Element.ElementProperties.PropertyType.Content)
                        {
                            ElementText = (string)property.Value;
                        }
                        Properties.Add(property);
                    }
                    Properties.Add(property);
                }
                Element.ElementProperties Width  = GetProperty(Properties.ToArray(), Element.ElementProperties.PropertyType.Width);
                Element.ElementProperties Height = GetProperty(Properties.ToArray(), Element.ElementProperties.PropertyType.Height);

                Element.ElementType elementType = new Element.ElementType();
                elementType = Element.GetElementType(child.Name.ToLower());
                int[] size = bitHelper.GetTextWidth(ElementText);
                if (Width != null)
                {
                    int iWidth = int.Parse((string)Width.Value);
                    if (iWidth > size[0])
                    {
                        size[0] = iWidth;
                    }
                }
                if (Height != null)
                {
                    int iHeight = int.Parse((string)Height.Value);
                    size[1] = iHeight;
                }
                Bitmap AfterNine = (System.Drawing.Bitmap)bitHelper.GetImage(size, bitHelper.GetElementImage(elementType));
                System.Drawing.Bitmap finalImage = ResizeImage(AfterNine, new Size(AfterNine.Width, size[1]));
                if (ElementText.Length > 0)
                {
                    using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage))
                    {
                        g.DrawString(ElementText, new Font("Segoe UI", 11, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.Black, new RectangleF(0, 0, finalImage.Width, finalImage.Height)); // requires font, brush etc
                    }
                }

                Element.ElementData elementData = new Element.ElementData(finalImage, new TextureID(finalImage), Properties.ToArray());
                Element             element     = new Element(elementData, elementType);
                AddChildren(ref child, ref element, ref bitHelper);
                rootElement.Children.Add(element);
            }
        }
 public void SetDiamond(Element.ElementType type)
 {
     diamond.Add(Util.getDiamond(type, this.transform));
 }
Exemple #18
0
 public Element(Element.ElementType type)
 {
     this.Type        = type;
     this.Highlighted = false;
 }