Build() public method

public Build ( ) : void
return void
Ejemplo n.º 1
0
    private void createOverLayer(string spriteName)
    {
        _overSpr = new tk2dSprite[_needNum];

        for (int i = 0; i < _needNum; ++i)
        {
            GameObject tempGobj           = new GameObject("overBG");
            tk2dSprite spr                = tempGobj.AddComponent <tk2dSprite>();
            tk2dSpriteCollectionData tScd = GameManager.resourceManager.getSpriteCollection(spriteName);
            spr.SetSprite(tScd, tScd.GetSpriteIdByName(spriteName));
            spr.renderer.material = tScd.FirstValidDefinition.material;
            spr.Build();

            tempGobj.transform.parent = _transforms[i];

            _v   = tempGobj.transform.localPosition;
            _v.x = 0.0f;
            _v.y = 0.0f;
            _v.z = -0.1f;
            tempGobj.transform.localPosition = _v;

            _overSpr[i] = spr;

            spr.color = new Color(1.0f, 1.0f, 1.0f, 0.0f);
        }
    }
Ejemplo n.º 2
0
    void DrawInstanceGUI()
    {
        if (GUILayout.Button("Edit"))
        {
            foreach (var v in batcher.batchedSprites)
            {
                GameObject go = new GameObject(v.name);
                go.transform.parent        = batcher.transform;
                go.transform.localPosition = v.position;
                go.transform.localRotation = v.rotation;

                tk2dSprite s = go.AddComponent <tk2dSprite>();
                s.collection = batcher.spriteCollection;
                s.Build();

                s.spriteId = v.spriteId;
                s.EditMode__CreateCollider();                 // needed to recreate the collider after setting spriteId

                s.scale        = v.localScale;
                s.pixelPerfect = v.alwaysPixelPerfect;
                s.color        = v.color;
            }

            batcher.transform.localScale = batcher.scale;

            batcher.batchedSprites = null;
            batcher.Build();
            EditorUtility.SetDirty(target);
        }

        batcher.scale = EditorGUILayout.Vector3Field("Scale", batcher.scale);
    }
Ejemplo n.º 3
0
    public override void Generate()
    {
        // Grabs Ship information
        int   id         = gameObject.transform.parent.GetComponent <Ship>().GetID();
        int   Size       = gameObject.transform.parent.GetComponent <Ship>().GetSize();
        float ShipHeight = 0;

        GenerateColor();
        for (int index = 0; index < Size; index++)
        {
            // Add gameobject and sprite component
            GameObject temp = new GameObject();
            temp.name             = index.ToString();
            temp.transform.parent = gameObject.transform;
            temp.AddComponent <tk2dSprite>();
            tk2dSprite tempSprite = temp.GetComponent <tk2dSprite>();

            // Find Suitable ID
            id = Utility.Wrap <int>(id, 0, collection.spriteCollection.spriteDefinitions.Length - 1);
            while (collection.spriteCollection.spriteDefinitions[id].name == "")
            {
                id += (int)Random.Range(0, 4);
                id  = Utility.Wrap <int>(id, 0, collection.spriteCollection.Count - 1);
            }

            // Create Sprite
            tempSprite.SwitchCollectionAndSprite(collection.spriteCollection, id);
            tempSprite.Build();


            // Choose Location to position new Sprite
            // Based on the progress of the height of the ship, place a
            // sprite just above the previously placed midsection sprite.
            float randomNumber = 0;
            float heightSpace  = 0;
            if (ShipHeight != 0)
            {
                heightSpace  = ShipHeight + tempSprite.GetBounds().size.y;
                randomNumber = Random.Range(heightSpace - heightSpace / 5, heightSpace - heightSpace / 9);
                ShipHeight  += randomNumber - ShipHeight;
            }
            else
            {
                ShipHeight  += tempSprite.GetBounds().size.y;
                randomNumber = Random.Range(ShipHeight / 5, Mathf.Abs(ShipHeight - ShipHeight / 9));

                temp.transform.localPosition = new Vector3(0, .1f, .025f + index * .025f);
                id += (int)Random.Range(0, 4);
                temp.renderer.material.SetColor("_Color", color);
                continue;
            }
            temp.transform.localPosition += new Vector3(0, randomNumber, .025f + index * .025f);
            id += (int)Random.Range(0, 4);
            temp.renderer.material.SetColor("_Color", color);
        }
        DuplicateToOtherHalf();
    }
Ejemplo n.º 4
0
        public void Setup(SpriteFlatData data)
        {
            _data   = data;
            _sprite = gameObject.AddComponent <tk2dSprite>();
            _sprite.SwitchCollectionAndSprite(data.data, 0);
            _sprite.Build();

            _dimensionsInit = new Vector3(data.regionWidth, data.regionHeight, 1f);
            dimensions      = new Vector3(data.width, data.height, 1f);
        }
Ejemplo n.º 5
0
        public void Setup(SpriteFlatData data)
        {
            _data = data;
            _sprite = gameObject.AddComponent<tk2dSprite>();
            _sprite.SwitchCollectionAndSprite(data.data, 0);
            _sprite.Build();

            _dimensionsInit = new Vector3(data.regionWidth, data.regionHeight, 1f);
            dimensions = new Vector3(data.width, data.height, 1f);
        }
Ejemplo n.º 6
0
    static void DoCreateSpriteObject()
    {
        tk2dSpriteGuiUtility.GetSpriteCollectionAndCreate((sprColl) => {
            GameObject go     = tk2dEditorUtility.CreateGameObjectInScene("Sprite");
            tk2dSprite sprite = go.AddComponent <tk2dSprite>();
            sprite.SetSprite(sprColl, sprColl.FirstValidDefinitionIndex);
            sprite.GetComponent <Renderer>().material = sprColl.FirstValidDefinition.material;
            sprite.Build();

            Selection.activeGameObject = go;
            Undo.RegisterCreatedObjectUndo(go, "Create Sprite");
        });
    }
Ejemplo n.º 7
0
    static void DoCreateSpriteObject()
    {
        tk2dSpriteCollectionData sprColl = null;

        if (sprColl == null)
        {
            // try to inherit from other Sprites in scene
            tk2dSprite spr = GameObject.FindObjectOfType(typeof(tk2dSprite)) as tk2dSprite;
            if (spr)
            {
                sprColl = spr.collection;
            }
        }

        if (sprColl == null)
        {
            tk2dSpriteCollectionIndex[] spriteCollections = tk2dEditorUtility.GetOrCreateIndex().GetSpriteCollectionIndex();
            foreach (var v in spriteCollections)
            {
                GameObject scgo = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(v.spriteCollectionDataGUID), typeof(GameObject)) as GameObject;
                var        sc   = scgo.GetComponent <tk2dSpriteCollectionData>();
                if (sc != null && sc.spriteDefinitions != null && sc.spriteDefinitions.Length > 0)
                {
                    sprColl = sc;
                    break;
                }
            }

            if (sprColl == null)
            {
                EditorUtility.DisplayDialog("Create Sprite", "Unable to create sprite as no SpriteCollections have been found.", "Ok");
                return;
            }
        }

        GameObject go     = tk2dEditorUtility.CreateGameObjectInScene("Sprite");
        tk2dSprite sprite = go.AddComponent <tk2dSprite>();

        sprite.collection        = sprColl;
        sprite.renderer.material = sprColl.FirstValidDefinition.material;
        sprite.Build();

        Selection.activeGameObject = go;
        Undo.RegisterCreatedObjectUndo(go, "Create Sprite");
    }
Ejemplo n.º 8
0
    public override void Generate()
    {
        // Grabs Ship information
        int id              = gameObject.transform.parent.GetComponent <Ship>().GetID();
        int Size            = gameObject.transform.parent.GetComponent <Ship>().GetSize();
        int extentsionCount = (int)Random.Range(1, Size);

        GenerateColor();
        for (int index = 0; index < extentsionCount; index++)
        {
            // Add gameobject and sprite component
            GameObject temp = new GameObject();
            temp.name             = index.ToString();
            temp.transform.parent = gameObject.transform;
            temp.AddComponent <tk2dSprite>();
            tk2dSprite tempSprite = temp.GetComponent <tk2dSprite>();

            // Find Suitable ID
            id = Utility.Wrap <int>(id, 0, collection.spriteCollection.spriteDefinitions.Length - 1);
            while (collection.spriteCollection.spriteDefinitions[id].name == "")
            {
                id += (int)Random.Range(0, 4);
                id  = Utility.Wrap <int>(id, 0, collection.spriteCollection.Count - 1);
            }

            // Create Sprite
            tempSprite.SwitchCollectionAndSprite(collection.spriteCollection, id);
            tempSprite.Build();


            // Choose Location to position new Sprite
            // Place in the middle of selected Last Midsection or Extension
            string placement = (Random.Range(0f, 1f) > .5f) ? "Extension" : "MidSection";

            int       count      = gameObject.transform.parent.FindChild(placement).GetChildCount();
            Transform midSection = gameObject.transform.parent.FindChild(placement).GetChild(count - 1);
            Vector3   spacing    = midSection.GetComponent <tk2dSprite>().GetBounds().size / 3;
            spacing.y = -spacing.y;
            spacing.z = .05f;
            temp.transform.localPosition = midSection.position + spacing;
            temp.renderer.material.SetColor("_Color", color);
        }
        DuplicateToOtherHalf();
    }
Ejemplo n.º 9
0
    static void DoCreateSpriteObject()
    {
        tk2dSpriteCollectionData sprColl = null;

        if (sprColl == null)
        {
            // try to inherit from other Sprites in scene
            tk2dSprite spr = GameObject.FindObjectOfType(typeof(tk2dSprite)) as tk2dSprite;
            if (spr)
            {
                sprColl = spr.collection;
            }
        }

        if (sprColl == null)
        {
            tk2dSpriteCollectionData[] spriteCollections = tk2dEditorUtility.GetOrCreateIndex().GetSpriteCollectionData();
            foreach (var v in spriteCollections)
            {
                sprColl = v;
            }

            if (sprColl == null)
            {
                EditorUtility.DisplayDialog("Create Sprite", "Unable to create sprite as no SpriteCollections have been found.", "Ok");
                return;
            }
        }

        GameObject go     = tk2dEditorUtility.CreateGameObjectInScene("Sprite");
        tk2dSprite sprite = go.AddComponent <tk2dSprite>();

        sprite.collection        = sprColl;
        sprite.renderer.material = sprColl.spriteDefinitions[0].material;
        sprite.Build();
    }
Ejemplo n.º 10
0
        /// <summary>
        /// Let's attach a tk2d sprite.
        /// </summary>
        /// <param name="targetGameObject">The game object to attach to.</param>
        public void AttachTk2dSprite(GameObject targetGameObject, tk2dSpriteCollectionData spriteCollectionData)
        {
            // sanity.
            if (targetGameObject == null || tk2dSpriteName == null || spriteCollectionData == null)
            {
                return;
            }

            // triple check the sprite definitions... this is madness... this is SPARTA!
            List <tk2dSpriteDefinition> spriteDefinitions = new List <tk2dSpriteDefinition>(spriteCollectionData.spriteDefinitions);
            tk2dSpriteDefinition        spriteDef         = spriteDefinitions.Find(each => each.name == tk2dSpriteName);

            if (spriteDef == null || spriteDef.name == "")
            {
                // this condition should never happen because we're finding the definition by name...
                // if we do trip it up, then, at least don't die a horrible death.
                return;
            }

            // lookup the index
            int spriteIndex = spriteDefinitions.IndexOf(spriteDef);

            // create a tk2dsprite
            tk2dSprite spriteComponent = targetGameObject.AddComponent <tk2dSprite>() as tk2dSprite;

            // set the sprite based on the index because it's safer that way... :(
            spriteComponent.SetSprite(spriteCollectionData, spriteIndex);

            // update the sorting layer
            spriteComponent.GetComponent <Renderer>().sortingLayerName = sortingLayerName;
            spriteComponent.SortingOrder = sortingOrder;
            spriteComponent.Build();

            // set visibility
            spriteComponent.GetComponent <Renderer>().enabled = isVisible;
        }
    public override void OnInspectorGUI()
    {
        tk2dStaticSpriteBatcher batcher = (tk2dStaticSpriteBatcher)target;

        if (batcher.batchedSprites == null || batcher.batchedSprites.Length == 0)
        {
            if (GUILayout.Button("Commit"))
            {
                List <tk2dSprite>        sprites = new List <tk2dSprite>();
                tk2dSpriteCollectionData scd     = null;

                for (int i = 0; i < batcher.transform.childCount; ++i)
                {
                    Transform  t = batcher.transform.GetChild(i);
                    tk2dSprite s = t.GetComponent <tk2dSprite>();
                    if (s)
                    {
                        if (scd == null)
                        {
                            scd = s.collection;
                        }
                        if (scd != s.collection)
                        {
                            EditorUtility.DisplayDialog("StaticSpriteBatcher", "Error: Multiple sprite collections found", "Ok");
                            return;
                        }

                        if (scd.allowMultipleAtlases)
                        {
                            EditorUtility.DisplayDialog("StaticSpriteBatcher", "Error: Sprite collections with multiple atlases not allowed", "Ok");
                            return;
                        }

                        sprites.Add(s);
                    }
                }

                // sort sprites, smaller to larger z
                sprites.Sort((a, b) => b.transform.localPosition.z.CompareTo(a.transform.localPosition.z));

                batcher.spriteCollection = scd;
                batcher.batchedSprites   = new tk2dBatchedSprite[sprites.Count];
                int currBatchedSprite = 0;
                foreach (var s in sprites)
                {
                    tk2dBatchedSprite bs = new tk2dBatchedSprite();

                    bs.name               = s.gameObject.name;
                    bs.color              = s.color;
                    bs.localScale         = s.scale;
                    bs.position           = s.transform.localPosition;
                    bs.rotation           = s.transform.localRotation;
                    bs.spriteId           = s.spriteId;
                    bs.alwaysPixelPerfect = s.pixelPerfect;

                    batcher.batchedSprites[currBatchedSprite++] = bs;

                    GameObject.DestroyImmediate(s.gameObject);
                }

                batcher.Build();
                EditorUtility.SetDirty(target);
            }
        }
        else
        {
            if (GUILayout.Button("Edit"))
            {
                foreach (var v in batcher.batchedSprites)
                {
                    GameObject go = new GameObject(v.name);
                    go.transform.parent        = batcher.transform;
                    go.transform.localPosition = v.position;
                    go.transform.localRotation = v.rotation;

                    tk2dSprite s = go.AddComponent <tk2dSprite>();
                    s.collection = batcher.spriteCollection;
                    s.Build();

                    s.spriteId = v.spriteId;
                    s.EditMode__CreateCollider();                     // needed to recreate the collider after setting spriteId

                    s.scale        = v.localScale;
                    s.pixelPerfect = v.alwaysPixelPerfect;
                    s.color        = v.color;
                }

                batcher.batchedSprites = null;
                batcher.Build();
                EditorUtility.SetDirty(target);
            }
        }
    }
Ejemplo n.º 12
0
    void DrawInstanceGUI()
    {
        if (GUILayout.Button("Edit"))
        {
            Vector3    batcherPos      = batcher.transform.position;
            Quaternion batcherRotation = batcher.transform.rotation;
            batcher.transform.position = Vector3.zero;
            batcher.transform.rotation = Quaternion.identity;

            Dictionary <int, Transform> parents  = new Dictionary <int, Transform>();
            List <Transform>            children = new List <Transform>();

            int id = 0;
            foreach (var v in batcher.batchedSprites)
            {
                GameObject go = new GameObject(v.name);

                go.transform.localPosition = v.position;
                go.transform.localRotation = v.rotation;

                if (v.spriteId != -1)
                {
                    tk2dSprite s = go.AddComponent <tk2dSprite>();
                    s.collection = batcher.spriteCollection;
                    s.Build();

                    s.spriteId = v.spriteId;
                    s.EditMode__CreateCollider();                     // needed to recreate the collider after setting spriteId

                    s.scale        = v.localScale;
                    s.pixelPerfect = v.alwaysPixelPerfect;
                    s.color        = v.color;
                }

                parents[id++] = go.transform;
                children.Add(go.transform);
            }

            int idx = 0;
            foreach (var v in batcher.batchedSprites)
            {
                Transform parent = batcher.transform;
                if (v.parentId != -1)
                {
                    parents.TryGetValue(v.parentId, out parent);
                }

                children[idx].parent = parent;
                ++idx;
            }

            batcher.transform.localScale = batcher.scale;

            batcher.batchedSprites = null;
            batcher.Build();
            EditorUtility.SetDirty(target);

            batcher.transform.position = batcherPos;
            batcher.transform.rotation = batcherRotation;
        }

        batcher.scale = EditorGUILayout.Vector3Field("Scale", batcher.scale);
    }
Ejemplo n.º 13
0
    public void create(int scrollType, float scrollSpeed, Transform parent, string spriteName, float depth, bool useOverLayer = false)
    {
        _scrollSpeed = scrollSpeed;

        // 첫번째 이미지를 가져온다...
        GameObject gobj = new GameObject("background");

        gobj.transform.parent = parent;        //

        tk2dSprite spr = gobj.AddComponent <tk2dSprite>();
        tk2dSpriteCollectionData scd = GameManager.resourceManager.getSpriteCollection(spriteName);

        spr.SetSprite(scd, scd.FirstValidDefinitionIndex);
        spr.renderer.material = scd.FirstValidDefinition.material;
        spr.Build();

        _scrollType = scrollType;

        _width  = spr.GetBounds().extents.x *2.0f;
        _height = spr.GetBounds().extents.y *2.0f;

        _needNum = Mathf.RoundToInt((GameManager.me.tk2dGameCamera.targetResolution.y) / _height) + 2;

        _indexNum = new int[_needNum];

        _sprites    = new tk2dSprite[_needNum];
        _transforms = new Transform[_needNum];

        _vectors = new Vector3[_needNum];

        _tempNum = new int[_needNum];

        int i = 0;

        for (i = 0; i < _needNum; ++i)
        {
            _vectors[i] = Vector3.zero;

            if (i == 0)
            {
                _sprites[i] = spr;
            }
            else
            {
                GameObject tempGobj = new GameObject("background");
                tempGobj.transform.parent = parent;                //

                _sprites[i] = tempGobj.AddComponent <tk2dSprite>();
                tk2dSpriteCollectionData tScd = GameManager.resourceManager.getSpriteCollection(spriteName);
                _sprites[i].SetSprite(tScd, tScd.GetSpriteIdByName(spriteName));
                _sprites[i].renderer.material = tScd.FirstValidDefinition.material;
                _sprites[i].Build();
            }

            _indexNum[i]   = i;
            _transforms[i] = _sprites[i].transform;
        }

        _vectors[0]   = _transforms[0].position;
        _vectors[0].x = GameManager.me.tk2dGameCamera.targetResolution.x / 2.0f;
        _vectors[0].y = GameManager.me.tk2dGameCamera.targetResolution.y / 2.0f;
        _vectors[0].z = depth;

        for (i = 0; i < _needNum; ++i)
        {
            _transforms[i].position = _vectors[0];
        }

        _hasOverLayer = useOverLayer;
        if (useOverLayer)
        {
            createOverLayer(spriteName);
        }
        //createOverLayer(spriteName);

        resetPosition();
    }
Ejemplo n.º 14
0
 void setSpriteByIndex(int index)
 {
     comboSprite.SetSprite("x" + index.ToString());
     comboSprite.Build();
 }