示例#1
0
    void Start()
    {
        mLayer = GetComponent <GiraffeLayer>();
        mAtlas = mLayer.atlas;

        mBoxes    = new GiraffeSprite[4];
        mBoxes[0] = mAtlas.GetSprite("Box");
        mBoxes[1] = mAtlas.GetSprite("Box2");
        mBoxes[2] = mAtlas.GetSprite("Box3");
        mBoxes[3] = mAtlas.GetSprite("Box4");

        int count = 50 + UnityEngine.Random.Range(1, 20);

        mLayer.Begin(count);

        for (int i = 0; i < count; i++)
        {
            int x = UnityEngine.Random.Range(0, Screen.width);
            int y = UnityEngine.Random.Range(0, Screen.height);
            int b = UnityEngine.Random.Range(0, mBoxes.Length);
            mLayer.Add(x, y, mBoxes[b]);
        }

        mLayer.End();
    }
示例#2
0
 void OnEnable()
 {
     mAtlas = (GiraffeAtlas)this.target;
     mAtlas.RefreshSprites();
     TryResolveEditorData(mAtlas);
     mMode = 0;
 }
示例#3
0
    void Start()
    {
        mLayer = GetComponent <GiraffeLayer>();
        mAtlas = mLayer.atlas;

        mBoxes    = new GiraffeSprite[4];
        mBoxes[0] = mAtlas.GetSprite("Box");
        mBoxes[1] = mAtlas.GetSprite("Box1");

        mCount        = 50 + UnityEngine.Random.Range(1, 20);
        mTranslations = new Vector2[mCount];
        mRotations    = new float[mCount];
        mScales       = new Vector2[mCount];

        for (int i = 0; i < mCount; i++)
        {
            float time = UnityEngine.Random.Range(0.0f, 8.0f);
            float cx   = UnityEngine.Random.Range(0, Screen.width);
            float cy   = UnityEngine.Random.Range(0, Screen.width);

            GiraffeSprite sprite = mBoxes[i % 2];

            mTranslations[i] = new Vector2(cx, cy);
            mRotations[i]    = time;
            mScales[i]       = new Vector2(sprite.width, sprite.height) * Mathf.Sin(mRotations[i]) * 8.0f;
        }
    }
示例#4
0
文件: Tilesets.cs 项目: betajaen/dx8
    void Start()
    {
        mLayer = GetComponent <GiraffeLayer>();
        mAtlas = mLayer.atlas;

        ReadTileMap();


        int area          = mapWidth * mapHeight;
        int x             = 0;
        int y             = 0;
        int screenOriginX = Screen.width / 2 - (mapWidth * tileWidth) / 2;
        int screenOriginY = Screen.height / 2 - (mapHeight * tileHeight) / 2;

        mLayer.Begin(area);
        for (int i = 0; i < area; i++)
        {
            mLayer.Add(screenOriginX + x * tileWidth, screenOriginY + y * tileHeight, mAtlas.GetSpriteAt(map[i]));

            x++;
            if (x >= mapWidth)
            {
                x = 0;
                y++;
            }
        }
        mLayer.End();
    }
 void CacheSprites()
 {
     //if (mIsPrefab == false)
     //{
     GiraffeAtlas._GetNames(mAtlas, ref mSpriteNames);
     mCurrentSpriteNameId = GiraffeAtlas._FindSpriteIndex(mAtlas, mRenderer.spriteName);
     //}
 }
 void FindParts()
 {
     mLayer = GiraffeInternal.GiraffeUtils.FindRecursiveComponentBackwards <GiraffeLayer>(mRenderer.transform);
     if (mLayer != null)
     {
         mAtlas = mLayer.atlas;
     }
 }
 void OnEnable()
 {
     mAnimation = (GiraffeSpriteAnimation)this.target;
     GiraffeAtlas._GetNames(mAnimation.atlas, ref mSpriteNames);
     RefreshFrameNamesIds();
     if (mAnimation.atlas != null)
     {
         mAnimation.atlas.RefreshSprites();
         mAnimation.FetchSprites();
     }
     RefreshPreview();
 }
示例#8
0
    public static bool _ContainsSprite(GiraffeAtlas atlas, String spriteName)
    {
        if (atlas == null || String.IsNullOrEmpty(spriteName))
        {
            return(false);
        }

        for (int i = 0; i < atlas.mSprites.Count; i++)
        {
            if (spriteName == atlas.mSprites[i].name)
            {
                return(true);
            }
        }
        return(false);
    }
示例#9
0
    public static int _FindSpriteIndex(GiraffeAtlas atlas, String spriteName)
    {
        if (atlas == null || String.IsNullOrEmpty(spriteName))
        {
            return(0);
        }

        for (int i = 0; i < atlas.mSprites.Count; i++)
        {
            if (spriteName == atlas.mSprites[i].name)
            {
                return(i);
            }
        }
        return(0);
    }
示例#10
0
    public static void CreateAtlas()
    {
        string path = AssetDatabase.GetAssetPath(Selection.activeObject);
        if (path == "")
        {
          path = "Assets";
        }
        else if (Path.GetExtension(path) != "")
        {
          path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
        }

        GiraffeAtlas atlas = CreateAtlas(path, "New Giraffe Atlas");
        EditorUtility.FocusProjectWindow();
        Selection.activeObject = atlas;
    }
示例#11
0
    public static GiraffeAtlas CreateAtlas(String path, String assetName)
    {
        GiraffeAtlas atlas = ScriptableObject.CreateInstance <GiraffeAtlas>();

        System.Random rng = new System.Random();
        atlas.atlasIdA = rng.Next();
        atlas.atlasIdB = rng.Next();

        string atlasPath   = AssetDatabase.GenerateUniqueAssetPath(String.Format("{0}/{1}.asset", path, assetName));
        string texturePath = AssetDatabase.GenerateUniqueAssetPath(String.Format("{0}/{1} Texture.png", path, assetName));

        Texture2D pngTexture = new Texture2D(256, 256, TextureFormat.ARGB32, false, false);

        pngTexture.hideFlags = HideFlags.HideAndDontSave;
        byte[] bytes            = pngTexture.EncodeToPNG();
        System.IO.FileStream fs = System.IO.File.Create(texturePath);
        fs.Write(bytes, 0, bytes.Length);
        fs.Close();
        Object.DestroyImmediate(pngTexture);

        AssetDatabase.CreateAsset(atlas, atlasPath);

        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        Texture2D textureAsset = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)) as Texture2D;

        atlas.texture           = textureAsset;
        textureAsset.filterMode = FilterMode.Point;
        textureAsset.wrapMode   = TextureWrapMode.Clamp;

        TextureImporter texImporter = TextureImporter.GetAtPath(texturePath) as TextureImporter;

        texImporter.textureFormat       = TextureImporterFormat.AutomaticTruecolor;
        texImporter.alphaIsTransparency = true;
        texImporter.filterMode          = textureAsset.filterMode;
        texImporter.wrapMode            = textureAsset.wrapMode;
        texImporter.isReadable          = true;

        EditorUtility.SetDirty(atlas);
        EditorUtility.SetDirty(texImporter);
        AssetDatabase.SaveAssets();

        return(atlas);
    }
示例#12
0
    public static void _GetNames(GiraffeAtlas atlas, ref String[] names)
    {
        if (atlas == null)
        {
            names = new String[1]
            {
                "Giraffe/White"
            };
            return;
        }

        if (names == null || names.Length != atlas.mSprites.Count)
        {
            names = new String[atlas.mSprites.Count];
        }

        for (int i = 0; i < names.Length; i++)
        {
            names[i] = atlas.mSprites[i].name;
        }
    }
示例#13
0
 static void TryResolveEditorData(GiraffeAtlas atlas)
 {
     // atlas._sourceResolved:
     // 0 - no attempt
     // 1 - attempt, and found
     // 2 - attemped, and not found
     switch (atlas._importDataResolved)
     {
     case 0:
     case 2:
     {
         foreach (var n in AssetDatabase.GetAllAssetPaths())
         {
             if (n.StartsWith("Assets/") == false)
             {
                 continue;
             }
             if (n.EndsWith(".asset") == false)
             {
                 continue;
             }
             UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(n, typeof(GiraffeImportData));
             if (obj != null && obj is GiraffeImportData)
             {
                 GiraffeImportData source = obj as GiraffeImportData;
                 if (source.atlasIdA == atlas.atlasIdA && source.atlasIdB == atlas.atlasIdB)
                 {
                     atlas._importData         = source;
                     atlas._importDataResolved = 1;
                     source._atlas             = atlas;
                     source._atlasResolved     = 1;
                     return;
                 }
             }
         }
         atlas._importDataResolved = 2;
     }
     break;
     }
 }
示例#14
0
    public override void OnInspectorGUI()
    {
        GiraffeLayer t = (GiraffeLayer)this.target;

        GUI.changed = false;
        GiraffeAtlas atlas = EditorGUILayout.ObjectField("Atlas", t.atlas, typeof(GiraffeAtlas), false) as GiraffeAtlas;

        if (GUI.changed)
        {
            t.atlas = atlas;
            if (Application.isPlaying == false)
            {
                EditorUtility.SetDirty(t);
            }
        }

        GUI.changed = false;
        int zOrder = EditorGUILayout.IntField("Z-Order", t.zOrder);

        if (GUI.changed)
        {
            t.zOrder = zOrder;
            if (Application.isPlaying == false)
            {
                EditorUtility.SetDirty(t);
            }
        }

        GUI.changed = false;
        int scale = EditorGUILayout.IntSlider("Scale", t.scale, 1, 8);

        if (GUI.changed)
        {
            t.scale = scale;
            if (Application.isPlaying == false)
            {
                EditorUtility.SetDirty(t);
            }
        }
    }
示例#15
0
 private void MakeSpriteNames()
 {
     GiraffeAtlas._GetNames(mFont.atlas, ref mSpriteNames);
     mCurrentSpriteNameId = GiraffeAtlas._FindSpriteIndex(mFont.atlas, mFont.spriteName);
 }
    public override void OnInspectorGUI()
    {
        GUILayout.BeginVertical();
        GUILayout.Label("Animation", EditorStyles.boldLabel);
        GUILayout.Space(4);
        EditorGUI.indentLevel++;

        bool changed = false;

        EditorGUILayout.LabelField("Name", mAnimation.name);

        GUI.changed      = false;
        mAnimation.atlas = EditorGUILayout.ObjectField("Atlas", mAnimation.atlas, typeof(GiraffeAtlas), false) as GiraffeAtlas;
        if (GUI.changed)
        {
            GiraffeAtlas._GetNames(mAnimation.atlas, ref mSpriteNames);
            if (mAnimation.atlas != null)
            {
                mAnimation.atlas.RefreshSprites();
            }
            changed = true;
        }

        GUI.changed       = false;
        mAnimation.length = EditorGUILayout.FloatField("Length", mAnimation.length);
        if (GUI.changed)
        {
            changed = true;
        }

        GUI.changed     = false;
        mAnimation.mode = (GiraffeAnimationMode)EditorGUILayout.EnumPopup("Mode", mAnimation.mode);
        if (GUI.changed)
        {
            changed = true;
        }


        EditorGUI.indentLevel--;

        GUILayout.BeginVertical();
        GUILayout.Label("Preview", EditorStyles.boldLabel);
        GUILayout.Space(4);
        GUILayout.EndVertical();

        GUILayout.BeginVertical(EditorStyles.objectFieldThumb, GUILayout.Height(128 + 30));

        GUILayout.BeginHorizontal(EditorStyles.toolbar);

        mAnimationPlay = GUILayout.Toggle(mAnimationPlay, mAnimationPlay ? "||" : "\u25B6", EditorStyles.toolbarButton,
                                          GUILayout.Width(25));

        if (GUI.changed)
        {
            RefreshPreview();
        }

        if (GUILayout.Button("|\u25C0", EditorStyles.toolbarButton, GUILayout.Width(25)))
        {
            mAnimationTime = 0.0f;
        }

        GUI.changed    = false;
        mAnimationTime = GUILayout.HorizontalSlider(mAnimationTime, 0.0f, mAnimation.length);
        if (GUI.changed)
        {
            RefreshPreview();
        }

        mAnimation2XZoom = GUILayout.Toggle(mAnimation2XZoom, "2x", EditorStyles.toolbarButton, GUILayout.Width(25));

        int spriteWidth = 0, spriteHeight = 0;

        if (mAnimationSprite != null)
        {
            spriteWidth  = mAnimationSprite.width;
            spriteHeight = mAnimationSprite.height;
        }

        if (mAnimation2XZoom)
        {
            spriteWidth  *= 2;
            spriteHeight *= 2;
        }

        GUILayout.EndHorizontal();

        GUILayout.FlexibleSpace();
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();

        GUILayout.BeginHorizontal(GUILayout.Width(spriteWidth), GUILayout.Height(spriteHeight));
        if (mAnimationSprite != null)
        {
            Rect baseRect = GUILayoutUtility.GetRect(spriteWidth, spriteHeight);

            GUI.DrawTextureWithTexCoords(baseRect, mAnimation.atlas.texture,
                                         new Rect(mAnimationSprite.x0, mAnimationSprite.y0, mAnimationSprite.x1 - mAnimationSprite.x0, mAnimationSprite.y1 - mAnimationSprite.y0), true);
        }
        GUILayout.EndHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label(String.Format("{0} {1:F2}s", mAnimationSpriteId, mAnimationTime), EditorStyles.miniLabel);
        GUILayout.EndVertical();


        GUILayout.BeginVertical();
        GUILayout.Label("Frames", EditorStyles.boldLabel);
        GUILayout.Space(4);
        GUILayout.EndVertical();


        mFramesScroll = GUILayout.BeginScrollView(mFramesScroll);
        EditorGUI.indentLevel++;

        for (int i = 0; i < mAnimation.frames.Count; i++)
        {
            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUILayout.Label(i.ToString(), EditorStyles.miniLabel, GUILayout.Width(25));
            GUI.changed = false;
            int newId = EditorGUILayout.Popup(mFrameNameIds[i], mSpriteNames, EditorStyles.toolbarDropDown, GUILayout.ExpandWidth(true));
            if (GUI.changed)
            {
                mFrameNameIds[i]     = newId;
                mAnimation.frames[i] = mSpriteNames[mFrameNameIds[i]];
                mAnimation.FetchSprites();
                RefreshPreview();
                changed = true;
            }

            GUI.enabled = false;
            if (i != 0)
            {
                GUI.enabled = true;
            }

            if (GUILayout.Button("\u25B2", EditorStyles.toolbarButton, GUILayout.Width(25)))
            {
                String a = mAnimation.frames[i];
                String b = mAnimation.frames[i - 1];
                mAnimation.frames[i]     = b;
                mAnimation.frames[i - 1] = a;
                mAnimation.FetchSprites();
                RefreshFrameNamesIds();
                RefreshPreview();
                changed = true;
            }
            GUI.enabled = false;
            if ((i != mAnimation.frames.Count - 1))
            {
                GUI.enabled = true;
            }
            if (GUILayout.Button("\u25BC", EditorStyles.toolbarButton, GUILayout.Width(25)))
            {
                String a = mAnimation.frames[i];
                String b = mAnimation.frames[i + 1];
                mAnimation.frames[i]     = b;
                mAnimation.frames[i + 1] = a;
                mAnimation.FetchSprites();
                RefreshFrameNamesIds();
                RefreshPreview();
                changed = true;
            }
            GUI.enabled = false;

            if (mAnimation.frames.Count > 1)
            {
                GUI.enabled = true;
            }

            if (GUILayout.Button("\u00D7", EditorStyles.toolbarButton, GUILayout.Width(25)))
            {
                mAnimation.frames.RemoveAt(i);
                mAnimation.FetchSprites();
                RefreshFrameNamesIds();
                RefreshPreview();
                changed = true;
                break;
            }
            GUI.enabled = true;

            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal(EditorStyles.toolbar);
        GUILayout.FlexibleSpace();

        if (GUILayout.Button("\u002B", EditorStyles.toolbarButton, GUILayout.Width(25)))
        {
            String nextName = "Giraffe/White";
            String lastName = mAnimation.frames[mAnimation.frames.Count - 1];

            String[] parts       = lastName.Split('/');
            int      frameNumber = 0;
            if (Int32.TryParse(parts[parts.Length - 1], out frameNumber))
            {
                parts[parts.Length - 1] = (frameNumber + 1).ToString();
                String n = String.Join("/", parts);

                if (GiraffeAtlas._ContainsSprite(mAnimation.atlas, n))
                {
                    nextName = n;
                }
            }

            mAnimation.frames.Add(nextName);
            RefreshFrameNamesIds();
        }

        GUILayout.EndHorizontal();

        GUILayout.EndScrollView();

        EditorGUI.indentLevel--;
        GUILayout.EndVertical();

        if (changed)
        {
            EditorUtility.SetDirty(mAnimation);
        }
    }