Пример #1
0
    public override void OnInspectorGUI()
    {
        tk2dClippedSprite sprite = (tk2dClippedSprite)target;

        base.OnInspectorGUI();

        bool newCreateBoxCollider = EditorGUILayout.Toggle("Create Box Collider", sprite.CreateBoxCollider);

        if (newCreateBoxCollider != sprite.CreateBoxCollider)
        {
            Undo.RegisterUndo(targetClippedSprites, "Create Box Collider");
            sprite.CreateBoxCollider = newCreateBoxCollider;
        }

        Rect newClipRect = EditorGUILayout.RectField("Clip Region", sprite.ClipRect);

        if (newClipRect != sprite.ClipRect)
        {
            Undo.RegisterUndo(targetClippedSprites, "Clipped Sprite Rect");
            foreach (tk2dClippedSprite spr in targetClippedSprites)
            {
                spr.ClipRect = newClipRect;
            }
        }
        EditorGUI.indentLevel--;

        if (GUI.changed)
        {
            foreach (tk2dClippedSprite spr in targetClippedSprites)
            {
                EditorUtility.SetDirty(spr);
            }
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        if (mBoss == null)
        {
            GameObject[] objs = GameObject.FindGameObjectsWithTag(constant.TAG_ENEMY);
            foreach (GameObject obj in objs)
            {
                enemy_property pro = obj.GetComponent <enemy_property>();
                if (pro.mIsBoss)
                {
                    mBoss = obj;
                    break;
                }
            }
        }

        if (mBoss != null)
        {
            this.gameObject.SetActive(true);
            GameObject        bossHpObj = GameObject.FindGameObjectWithTag("BossHp");
            GameObject        hpObj     = constant.getChildGameObject(bossHpObj, "hp");
            tk2dClippedSprite spr       = hpObj.GetComponent <tk2dClippedSprite> ();

            enemy_property pro = mBoss.GetComponent <enemy_property> ();
            float          w   = ((float)pro.Hp) / pro.MaxHp;
            //Debug.Log ("hp:" + pro.Hp + "," + pro.MaxHp + "," + w);
            //spr.clipTopRight = new Vector2(0, w);
            spr.ClipRect = new Rect(0, 0, w, 1);
        }
        else
        {
            this.gameObject.SetActive(false);
        }
    }
Пример #3
0
    // This is used by other parts of code
    public static void RestoreBatchedSprite(GameObject go, tk2dBatchedSprite bs)
    {
        tk2dBaseSprite baseSprite = null;

        switch (bs.type)
        {
        case tk2dBatchedSprite.Type.EmptyGameObject:
        {
            break;
        }

        case tk2dBatchedSprite.Type.Sprite:
        {
            tk2dSprite s = tk2dBaseSprite.AddComponent <tk2dSprite>(go, bs.spriteCollection, bs.spriteId);
            baseSprite = s;
            break;
        }

        case tk2dBatchedSprite.Type.TiledSprite:
        {
            tk2dTiledSprite s = tk2dBaseSprite.AddComponent <tk2dTiledSprite>(go, bs.spriteCollection, bs.spriteId);
            baseSprite          = s;
            s.dimensions        = bs.Dimensions;
            s.anchor            = bs.anchor;
            s.CreateBoxCollider = bs.CheckFlag(tk2dBatchedSprite.Flags.Sprite_CreateBoxCollider);
            RestoreBoxColliderSettings(s.gameObject, bs.BoxColliderOffsetZ, bs.BoxColliderExtentZ);
            break;
        }

        case tk2dBatchedSprite.Type.SlicedSprite:
        {
            tk2dSlicedSprite s = tk2dBaseSprite.AddComponent <tk2dSlicedSprite>(go, bs.spriteCollection, bs.spriteId);
            baseSprite   = s;
            s.dimensions = bs.Dimensions;
            s.anchor     = bs.anchor;

            s.BorderOnly = bs.CheckFlag(tk2dBatchedSprite.Flags.SlicedSprite_BorderOnly);
            s.SetBorder(bs.SlicedSpriteBorderBottomLeft.x, bs.SlicedSpriteBorderBottomLeft.y, bs.SlicedSpriteBorderTopRight.x, bs.SlicedSpriteBorderTopRight.y);

            s.CreateBoxCollider = bs.CheckFlag(tk2dBatchedSprite.Flags.Sprite_CreateBoxCollider);
            RestoreBoxColliderSettings(s.gameObject, bs.BoxColliderOffsetZ, bs.BoxColliderExtentZ);
            break;
        }

        case tk2dBatchedSprite.Type.ClippedSprite:
        {
            tk2dClippedSprite s = tk2dBaseSprite.AddComponent <tk2dClippedSprite>(go, bs.spriteCollection, bs.spriteId);
            baseSprite       = s;
            s.clipBottomLeft = bs.ClippedSpriteRegionBottomLeft;
            s.clipTopRight   = bs.ClippedSpriteRegionTopRight;

            s.CreateBoxCollider = bs.CheckFlag(tk2dBatchedSprite.Flags.Sprite_CreateBoxCollider);
            RestoreBoxColliderSettings(s.gameObject, bs.BoxColliderOffsetZ, bs.BoxColliderExtentZ);
            break;
        }
        }
        baseSprite.scale = bs.baseScale;
        baseSprite.color = bs.color;
    }
    // Use this for initialization
    void Start()
    {
        sprite = GetComponent<tk2dClippedSprite>();

        if (sprite != null)
        {
            sprite._clipTopRight = clipTopRight;
        }
    }
Пример #5
0
    public static void FillBatchedSprite(tk2dBatchedSprite bs, GameObject go)
    {
        tk2dSprite        srcSprite        = go.transform.GetComponent <tk2dSprite>();
        tk2dTiledSprite   srcTiledSprite   = go.transform.GetComponent <tk2dTiledSprite>();
        tk2dSlicedSprite  srcSlicedSprite  = go.transform.GetComponent <tk2dSlicedSprite>();
        tk2dClippedSprite srcClippedSprite = go.transform.GetComponent <tk2dClippedSprite>();

        tk2dBaseSprite baseSprite = go.GetComponent <tk2dBaseSprite>();

        bs.spriteId         = baseSprite.spriteId;
        bs.spriteCollection = baseSprite.Collection;
        bs.baseScale        = baseSprite.scale;
        bs.color            = baseSprite.color;
        bs.renderLayer      = baseSprite.SortingOrder;
#if !STRIP_PHYSICS_3D
        if (baseSprite.boxCollider != null)
        {
            bs.BoxColliderOffsetZ = baseSprite.boxCollider.center.z;
            bs.BoxColliderExtentZ = baseSprite.boxCollider.size.z * 0.5f;
        }
        else
#endif
        {
            bs.BoxColliderOffsetZ = 0.0f;
            bs.BoxColliderExtentZ = 1.0f;
        }

        if (srcSprite)
        {
            bs.type = tk2dBatchedSprite.Type.Sprite;
        }
        else if (srcTiledSprite)
        {
            bs.type       = tk2dBatchedSprite.Type.TiledSprite;
            bs.Dimensions = srcTiledSprite.dimensions;
            bs.anchor     = srcTiledSprite.anchor;
            bs.SetFlag(tk2dBatchedSprite.Flags.Sprite_CreateBoxCollider, srcTiledSprite.CreateBoxCollider);
        }
        else if (srcSlicedSprite)
        {
            bs.type       = tk2dBatchedSprite.Type.SlicedSprite;
            bs.Dimensions = srcSlicedSprite.dimensions;
            bs.anchor     = srcSlicedSprite.anchor;
            bs.SetFlag(tk2dBatchedSprite.Flags.Sprite_CreateBoxCollider, srcSlicedSprite.CreateBoxCollider);
            bs.SetFlag(tk2dBatchedSprite.Flags.SlicedSprite_BorderOnly, srcSlicedSprite.BorderOnly);
            bs.SlicedSpriteBorderBottomLeft = new Vector2(srcSlicedSprite.borderLeft, srcSlicedSprite.borderBottom);
            bs.SlicedSpriteBorderTopRight   = new Vector2(srcSlicedSprite.borderRight, srcSlicedSprite.borderTop);
        }
        else if (srcClippedSprite)
        {
            bs.type = tk2dBatchedSprite.Type.ClippedSprite;
            bs.ClippedSpriteRegionBottomLeft = srcClippedSprite.clipBottomLeft;
            bs.ClippedSpriteRegionTopRight   = srcClippedSprite.clipTopRight;
            bs.SetFlag(tk2dBatchedSprite.Flags.Sprite_CreateBoxCollider, srcClippedSprite.CreateBoxCollider);
        }
    }
    static void DoCreateClippedSpriteObject()
    {
        tk2dSpriteGuiUtility.GetSpriteCollectionAndCreate((sprColl) => {
            GameObject go            = tk2dEditorUtility.CreateGameObjectInScene("Clipped Sprite");
            tk2dClippedSprite sprite = go.AddComponent <tk2dClippedSprite>();
            sprite.SetSprite(sprColl, sprColl.FirstValidDefinitionIndex);
            sprite.Build();

            Selection.activeGameObject = go;
            Undo.RegisterCreatedObjectUndo(go, "Create Clipped Sprite");
        });
    }
Пример #7
0
        //-------------------------------------------------------------------------
        public void load(string prefab_name, _eLevelLayer layer)
        {
            mBgSprite = mBackgroundLoader.newBackgroundStillSprite(prefab_name, mScene);
            mBgSprite.setPosition(EbVector3.Zero);
            mBgSprite.setDirection(0);
            mBgSprite.setLayer(mScene.getLayerAlloter().getLayer(layer));
            mBgClippedSprite = mBgSprite.gameObject.GetComponent <tk2dClippedSprite>();

#if UNITY_EDITOR
            mBgSprite.gameObject.name = "TkBackground";
#endif
        }
    public override void OnInspectorGUI()
    {
        tk2dClippedSprite sprite = (tk2dClippedSprite)target;

        base.OnInspectorGUI();

        if (sprite.CurrentSprite == null)
        {
            return;
        }

        var spriteData = sprite.GetCurrentSpriteDef();

        if (spriteData != null)
        {
            WarnSpriteRenderType(spriteData);
        }

        bool newCreateBoxCollider = base.DrawCreateBoxColliderCheckbox(sprite.CreateBoxCollider);

        if (newCreateBoxCollider != sprite.CreateBoxCollider)
        {
            sprite.CreateBoxCollider = newCreateBoxCollider;
            if (sprite.CreateBoxCollider)
            {
                sprite.EditMode__CreateCollider();
            }
        }

        Rect newClipRect = EditorGUILayout.RectField("Clip Region", sprite.ClipRect);

        if (newClipRect != sprite.ClipRect)
        {
            tk2dUndo.RecordObjects(targetClippedSprites, "Clipped Sprite Rect");
            foreach (tk2dClippedSprite spr in targetClippedSprites)
            {
                spr.ClipRect = newClipRect;
            }
        }

        showSceneClipControl = EditorGUILayout.Toggle("Edit Region in Scene", showSceneClipControl);

        EditorGUI.indentLevel--;

        if (GUI.changed)
        {
            foreach (tk2dClippedSprite spr in targetClippedSprites)
            {
                EditorUtility.SetDirty(spr);
            }
        }
    }
Пример #9
0
    static void DoCreateClippedSpriteObject()
    {
        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 Clipped Sprite", "Unable to create clipped sprite as no SpriteCollections have been found.", "Ok");
                return;
            }
        }

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

        sprite.SwitchCollectionAndSprite(sprColl, sprColl.FirstValidDefinitionIndex);
        sprite.Build();

        Selection.activeGameObject = go;
        Undo.RegisterCreatedObjectUndo(go, "Create Clipped Sprite");
    }
Пример #10
0
    // Use this for initialization
    void Start()
    {
        myTransform = transform;
        image       = myTransform.FindChild("Image").GetComponent <tk2dSprite>();
        mask        = myTransform.FindChild("Mask").GetComponent <tk2dClippedSprite>();

        switch (plantType)
        {
        case PlantType.Sunflower:
            image.SetSprite("SunFlower");
            break;

        case PlantType.Peashooter:
            image.SetSprite("Peashooter");
            break;

        case PlantType.SnowPeashooter:
            image.SetSprite("SnowPea");
            break;

        case PlantType.PotatoMine:
            image.SetSprite("PotatoMine");
            break;

        case PlantType.WallNut:
            image.SetSprite("WallNut");
            break;

        default:
            break;
        }
        if (canBeSelected)
        {
            image.color   = Color.white;
            mask.ClipRect = new Rect(0, 1, 1, 1);
        }
        StartCoroutine(UpdateMask());
    }
    public override void OnInspectorGUI()

    {
        tk2dGuiUtility.LookLikeInspector();

        bool markAsDirty = false;

        tk2dUIProgressBar progressBar = (tk2dUIProgressBar)target;



        if (progressBar.clippedSpriteBar != null) //can only be one

        {
            progressBar.scalableBar = null;

            progressBar.slicedSpriteBar = null;
        }



        if (progressBar.slicedSpriteBar != null)

        {
            progressBar.clippedSpriteBar = null;

            progressBar.scalableBar = null;
        }



        tk2dClippedSprite tempClippedSpriteBar = tk2dUICustomEditorGUILayout.SceneObjectField("Clipped Sprite Bar", progressBar.clippedSpriteBar, target);

        if (tempClippedSpriteBar != progressBar.clippedSpriteBar)

        {
            markAsDirty = true;

            progressBar.clippedSpriteBar = tempClippedSpriteBar;

            progressBar.scalableBar = null; //can only be one

            progressBar.slicedSpriteBar = null;
        }



        tk2dSlicedSprite tempSlicedSpriteBar = tk2dUICustomEditorGUILayout.SceneObjectField("Sliced Sprite Bar", progressBar.slicedSpriteBar, target);

        if (tempSlicedSpriteBar != progressBar.slicedSpriteBar)

        {
            markAsDirty = true;

            progressBar.slicedSpriteBar = tempSlicedSpriteBar;

            progressBar.scalableBar = null; //can only be one

            progressBar.clippedSpriteBar = null;
        }



        Transform tempScalableBar = tk2dUICustomEditorGUILayout.SceneObjectField("Scalable Bar", progressBar.scalableBar, target);

        if (tempScalableBar != progressBar.scalableBar)

        {
            markAsDirty = true;

            progressBar.scalableBar = tempScalableBar;

            progressBar.clippedSpriteBar = null; //can only be one

            progressBar.slicedSpriteBar = null;
        }



        float tempPercent = EditorGUILayout.FloatField("Value", progressBar.Value);

        if (tempPercent != progressBar.Value)

        {
            markAsDirty = true;

            progressBar.Value = tempPercent;
        }



        tk2dUIMethodBindingHelper methodBindingUtil = new tk2dUIMethodBindingHelper();

        progressBar.sendMessageTarget = methodBindingUtil.BeginMessageGUI(progressBar.sendMessageTarget);

        methodBindingUtil.MethodBinding("On Progress Complete", typeof(tk2dUIProgressBar), progressBar.sendMessageTarget, ref progressBar.SendMessageOnProgressCompleteMethodName);

        methodBindingUtil.EndMessageGUI();



        if (markAsDirty || GUI.changed)

        {
            tk2dUtil.SetDirty(progressBar);
        }
    }
Пример #12
0
 //-------------------------------------------------------------------------
 public void destroy()
 {
     mBackgroundLoader.freeBackgroundStillSprite(mBgSprite);
     mBgSprite        = null;
     mBgClippedSprite = null;
 }
Пример #13
0
    public new void OnSceneGUI()
    {
        if (tk2dPreferences.inst.enableSpriteHandles == false)
        {
            return;
        }

        tk2dClippedSprite spr = (tk2dClippedSprite)target;
        var sprite            = spr.CurrentSprite;

        if (sprite == null)
        {
            return;
        }

        Transform t         = spr.transform;
        Bounds    b         = spr.GetUntrimmedBounds();
        Rect      localRect = new Rect(b.min.x, b.min.y, b.size.x, b.size.y);
        Rect      clipRect  = new Rect(b.min.x + b.size.x * spr.clipBottomLeft.x, b.min.y + b.size.y * spr.clipBottomLeft.y,
                                       b.size.x * spr.ClipRect.width, b.size.y * spr.ClipRect.height);
        Vector3 unscaledBoundsSize = sprite.untrimmedBoundsData[1];

        // Draw rect outline
        Handles.color = new Color(1, 1, 1, 0.5f);
        tk2dSceneHelper.DrawRect(localRect, t);

        // Clip region outline (if editing)
        if (showSceneClipControl)
        {
            Handles.color = new Color(1, 0, 0, 0.5f);
            tk2dSceneHelper.DrawRect(clipRect, t);
        }

        Handles.BeginGUI();
        if (!showSceneClipControl)
        {
            // Do the normal resize and rotate controls
            if (tk2dSceneHelper.RectControlsToggle())
            {
                EditorGUI.BeginChangeCheck();
                Rect resizeRect = tk2dSceneHelper.RectControl(102030, localRect, t);
                if (EditorGUI.EndChangeCheck())
                {
                    Vector3 newScale = new Vector3(resizeRect.width / unscaledBoundsSize.x, resizeRect.height / unscaledBoundsSize.y, spr.scale.z);
                    if (newScale != spr.scale)
                    {
                        Undo.RegisterUndo(new Object[] { t, spr }, "Resize");
                        float   factorX = (Mathf.Abs(spr.scale.x) > Mathf.Epsilon) ? (newScale.x / spr.scale.x) : 0.0f;
                        float   factorY = (Mathf.Abs(spr.scale.y) > Mathf.Epsilon) ? (newScale.y / spr.scale.y) : 0.0f;
                        Vector3 offset  = new Vector3(resizeRect.xMin - localRect.xMin * factorX,
                                                      resizeRect.yMin - localRect.yMin * factorY, 0.0f);
                        Vector3 newPosition = t.TransformPoint(offset);
                        if (newPosition != t.position)
                        {
                            t.position = newPosition;
                        }
                        spr.scale = newScale;
                        EditorUtility.SetDirty(spr);
                    }
                }
            }
            // Rotate handles
            if (!tk2dSceneHelper.RectControlsToggle())
            {
                EditorGUI.BeginChangeCheck();
                float theta = tk2dSceneHelper.RectRotateControl(405060, localRect, t, new List <int>());
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RegisterUndo(t, "Rotate");
                    if (Mathf.Abs(theta) > Mathf.Epsilon)
                    {
                        t.Rotate(t.forward, theta);
                    }
                }
            }
        }
        else
        {
            // Clip region control
            EditorGUI.BeginChangeCheck();
            Rect resizeRect = tk2dSceneHelper.RectControl(708090, clipRect, t);
            if (EditorGUI.EndChangeCheck())
            {
                Rect newSprClipRect = new Rect((resizeRect.xMin - localRect.xMin) / localRect.width, (resizeRect.yMin - localRect.yMin) / localRect.height,
                                               resizeRect.width / localRect.width, resizeRect.height / localRect.height);
                if (newSprClipRect != spr.ClipRect)
                {
                    Undo.RegisterUndo(spr, "Resize");
                    spr.ClipRect = newSprClipRect;
                    EditorUtility.SetDirty(spr);
                }
            }
        }
        Handles.EndGUI();

        // Sprite selecting
        tk2dSceneHelper.HandleSelectSprites();

        // Move targeted sprites
        tk2dSceneHelper.HandleMoveSprites(t, localRect);
    }
Пример #14
0
            //-------------------------------------------------------------------------
            public void load(string prefab_name, _eLevelLayer layer)
            {
                mBgSprite = mBackgroundLoader.newBackgroundStillSprite(prefab_name, mScene);
                mBgSprite.setPosition(EbVector3.Zero);
                mBgSprite.setDirection(0);
                mBgSprite.setLayer(mScene.getLayerAlloter().getLayer(layer));
                mBgClippedSprite = mBgSprite.gameObject.GetComponent<tk2dClippedSprite>();

                #if UNITY_EDITOR
                mBgSprite.gameObject.name = "TkBackground";
                #endif
            }
Пример #15
0
 //-------------------------------------------------------------------------
 public void destroy()
 {
     mBackgroundLoader.freeBackgroundStillSprite(mBgSprite);
     mBgSprite = null;
     mBgClippedSprite = null;
 }
    public override void OnInspectorGUI()
    {
        tk2dClippedSprite sprite = (tk2dClippedSprite)target;

        base.OnInspectorGUI();

        if (sprite.CurrentSprite == null)
        {
            return;
        }

        var spriteData = sprite.GetCurrentSpriteDef();

        if (spriteData != null)
        {
            WarnSpriteRenderType(spriteData);
        }

        bool newCreateBoxCollider = EditorGUILayout.Toggle("Create Box Collider", sprite.CreateBoxCollider);

        if (newCreateBoxCollider != sprite.CreateBoxCollider)
        {
            Undo.RegisterUndo(targetClippedSprites, "Create Box Collider");
            if (newCreateBoxCollider)
            {
                sprite.boxCollider = sprite.GetComponent <BoxCollider>();
                if (sprite.boxCollider == null)
                {
                    sprite.boxCollider = sprite.gameObject.AddComponent <BoxCollider>();
                }
            }
            else
            {
                var boxCollider = sprite.GetComponent <BoxCollider>();
                if (boxCollider != null)
                {
                    DestroyImmediate(boxCollider);
                }
                sprite.boxCollider = null;
            }
            sprite.CreateBoxCollider = newCreateBoxCollider;
        }

        Rect newClipRect = EditorGUILayout.RectField("Clip Region", sprite.ClipRect);

        if (newClipRect != sprite.ClipRect)
        {
            Undo.RegisterUndo(targetClippedSprites, "Clipped Sprite Rect");
            foreach (tk2dClippedSprite spr in targetClippedSprites)
            {
                spr.ClipRect = newClipRect;
            }
        }

        showSceneClipControl = EditorGUILayout.Toggle("Edit Region in Scene", showSceneClipControl);

        EditorGUI.indentLevel--;

        if (GUI.changed)
        {
            foreach (tk2dClippedSprite spr in targetClippedSprites)
            {
                EditorUtility.SetDirty(spr);
            }
        }
    }
    public new void OnSceneGUI()
    {
        if (tk2dPreferences.inst.enableSpriteHandles == false || !tk2dEditorUtility.IsEditable(target))
        {
            return;
        }

        tk2dClippedSprite spr = (tk2dClippedSprite)target;
        var sprite            = spr.CurrentSprite;

        if (sprite == null)
        {
            return;
        }

        Transform t         = spr.transform;
        Bounds    b         = spr.GetUntrimmedBounds();
        Rect      localRect = new Rect(b.min.x, b.min.y, b.size.x, b.size.y);
        Rect      clipRect  = new Rect(b.min.x + b.size.x * ((spr.scale.x > 0) ? spr.clipBottomLeft.x : (1.0f - spr.clipTopRight.x)),
                                       b.min.y + b.size.y * ((spr.scale.y > 0) ? spr.clipBottomLeft.y : (1.0f - spr.clipTopRight.y)),
                                       b.size.x * spr.ClipRect.width,
                                       b.size.y * spr.ClipRect.height);

        // Draw rect outline
        Handles.color = new Color(1, 1, 1, 0.5f);
        tk2dSceneHelper.DrawRect(localRect, t);

        // Clip region outline (if editing)
        if (showSceneClipControl)
        {
            Handles.color = new Color(1, 0, 0, 0.5f);
            tk2dSceneHelper.DrawRect(clipRect, t);
        }

        Handles.BeginGUI();
        if (!showSceneClipControl)
        {
            // Do the normal resize and rotate controls
            if (tk2dSceneHelper.RectControlsToggle())
            {
                EditorGUI.BeginChangeCheck();
                Rect resizeRect = tk2dSceneHelper.RectControl(102030, localRect, t);
                if (EditorGUI.EndChangeCheck())
                {
                    tk2dUndo.RecordObjects(new Object[] { t, spr }, "Resize");
                    spr.ReshapeBounds(new Vector3(resizeRect.xMin, resizeRect.yMin) - new Vector3(localRect.xMin, localRect.yMin),
                                      new Vector3(resizeRect.xMax, resizeRect.yMax) - new Vector3(localRect.xMax, localRect.yMax));
                    EditorUtility.SetDirty(spr);
                }
            }
            // Rotate handles
            if (!tk2dSceneHelper.RectControlsToggle())
            {
                EditorGUI.BeginChangeCheck();
                float theta = tk2dSceneHelper.RectRotateControl(405060, localRect, t, new List <int>());
                if (EditorGUI.EndChangeCheck())
                {
                    if (Mathf.Abs(theta) > Mathf.Epsilon)
                    {
                        tk2dUndo.RecordObject(t, "Rotate");
                        t.Rotate(t.forward, theta, Space.World);
                    }
                }
            }
        }
        else
        {
            // Clip region control
            EditorGUI.BeginChangeCheck();
            Rect resizeRect = tk2dSceneHelper.RectControl(708090, clipRect, t);
            if (EditorGUI.EndChangeCheck())
            {
                Rect newSprClipRect = new Rect(((spr.scale.x > 0) ? (resizeRect.xMin - localRect.xMin) : (localRect.xMax - resizeRect.xMax)) / localRect.width,
                                               ((spr.scale.y > 0) ? (resizeRect.yMin - localRect.yMin) : (localRect.yMax - resizeRect.yMax)) / localRect.height,
                                               resizeRect.width / localRect.width,
                                               resizeRect.height / localRect.height);
                if (newSprClipRect != spr.ClipRect)
                {
                    tk2dUndo.RecordObject(spr, "Resize");
                    spr.ClipRect = newSprClipRect;
                    EditorUtility.SetDirty(spr);
                }
            }
        }
        Handles.EndGUI();

        // Sprite selecting
        tk2dSceneHelper.HandleSelectSprites();

        // Move targeted sprites
        tk2dSceneHelper.HandleMoveSprites(t, localRect);

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
Пример #18
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeInspector();
        bool markAsDirty = false;
        tk2dUIProgressBar progressBar = (tk2dUIProgressBar)target;

        if (progressBar.clippedSpriteBar != null) //can only be one
        {
            progressBar.scalableBar     = null;
            progressBar.slicedSpriteBar = null;
        }

        if (progressBar.slicedSpriteBar != null)
        {
            progressBar.clippedSpriteBar = null;
            progressBar.scalableBar      = null;
        }

        tk2dClippedSprite tempClippedSpriteBar = tk2dUICustomEditorGUILayout.SceneObjectField("Clipped Sprite Bar", progressBar.clippedSpriteBar, target);

        if (tempClippedSpriteBar != progressBar.clippedSpriteBar)
        {
            markAsDirty = true;
            progressBar.clippedSpriteBar = tempClippedSpriteBar;
            progressBar.scalableBar      = null; //can only be one
            progressBar.slicedSpriteBar  = null;
        }

        tk2dSlicedSprite tempSlicedSpriteBar = tk2dUICustomEditorGUILayout.SceneObjectField("Sliced Sprite Bar", progressBar.slicedSpriteBar, target);

        if (tempSlicedSpriteBar != progressBar.slicedSpriteBar)
        {
            markAsDirty = true;
            progressBar.slicedSpriteBar  = tempSlicedSpriteBar;
            progressBar.scalableBar      = null; //can only be one
            progressBar.clippedSpriteBar = null;
        }

        Transform tempScalableBar = tk2dUICustomEditorGUILayout.SceneObjectField("Scalable Bar", progressBar.scalableBar, target);

        if (tempScalableBar != progressBar.scalableBar)
        {
            markAsDirty                  = true;
            progressBar.scalableBar      = tempScalableBar;
            progressBar.clippedSpriteBar = null; //can only be one
            progressBar.slicedSpriteBar  = null;
        }

        float tempPercent = EditorGUILayout.FloatField("Value", progressBar.Value);

        if (tempPercent != progressBar.Value)
        {
            markAsDirty       = true;
            progressBar.Value = tempPercent;
        }

        if (markAsDirty)
        {
            EditorUtility.SetDirty(progressBar);
        }
    }