RemovePlane() public method

public RemovePlane ( exPlane, _plane ) : bool
_plane exPlane,
return bool
    // ------------------------------------------------------------------
    /// \param _spriteFont the sprite font
    /// build the sprite font
    // ------------------------------------------------------------------

    public static void Build(this exSpriteFont _spriteFont)
    {
#if UNITY_3_4
        bool isPrefab = (EditorUtility.GetPrefabType(_spriteFont) == PrefabType.Prefab);
#else
        bool isPrefab = (PrefabUtility.GetPrefabType(_spriteFont) == PrefabType.Prefab);
#endif

        // when build, alway set dirty
        EditorUtility.SetDirty(_spriteFont);

        if (_spriteFont.fontInfo == null)
        {
            _spriteFont.clippingPlane = null;
            GameObject.DestroyImmediate(_spriteFont.meshFilter.sharedMesh, true);
            _spriteFont.meshFilter.sharedMesh   = null;
            _spriteFont.renderer.sharedMaterial = null;
            return;
        }

        // prefab do not need rebuild mesh
        if (isPrefab == false)
        {
            exClipping clipping = _spriteFont.clippingPlane;
            if (clipping != null)
            {
                clipping.RemovePlane(_spriteFont);
            }

            //
            Mesh newMesh = new Mesh();
            newMesh.hideFlags = HideFlags.DontSave;
            newMesh.Clear();

            // update material
            _spriteFont.renderer.sharedMaterial = _spriteFont.fontInfo.pageInfos[0].material;

            // update mesh
            _spriteFont.ForceUpdateMesh(newMesh);

            //
            GameObject.DestroyImmediate(_spriteFont.meshFilter.sharedMesh, true);   // delete old mesh (to avoid leaking)
            _spriteFont.meshFilter.sharedMesh = newMesh;

            //
            if (clipping != null)
            {
                clipping.AddPlaneInEditor(_spriteFont);
            }
        }

        // update collider
        if (_spriteFont.collisionHelper)
        {
            _spriteFont.collisionHelper.UpdateCollider();
        }
    }
Esempio n. 2
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    protected void OnDestroy()
    {
        if (clippingPlane)
        {
            clippingPlane.RemovePlane(this);
        }
        if (meshFilter)
        {
            DestroyImmediate(meshFilter.sharedMesh, true);
        }
    }
Esempio n. 3
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    IEnumerator Start()
    {
        foreach (exPlane plane in planes)
        {
            clipPlane.AddPlane(plane);
        }

        yield return(new WaitForSeconds(2.0f));

        foreach (exPlane plane in planes)
        {
            clipPlane.RemovePlane(plane);
        }

        yield return(new WaitForSeconds(2.0f));

        foreach (exPlane plane in planes)
        {
            clipPlane.AddPlane(plane);
        }
    }
Esempio n. 4
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public static void RemovePlaneInEditor(this exClipping _clipping, exPlane _plane)
    {
        _clipping.RemovePlane(_plane);
    }
Esempio n. 5
0
    // ------------------------------------------------------------------
    /// \param _sprite the sprite
    /// \param _texture the raw texture used in the sprite
    /// build the sprite by texture
    // ------------------------------------------------------------------

    public static void Build(this exSprite _sprite, Texture2D _texture = null)
    {
#if UNITY_3_4
        bool isPrefab = (EditorUtility.GetPrefabType(_sprite) == PrefabType.Prefab);
#else
        bool isPrefab = (PrefabUtility.GetPrefabType(_sprite) == PrefabType.Prefab);
#endif
        EditorUtility.SetDirty(_sprite);

        //
        if (_sprite.atlas == null && _texture == null)
        {
            _sprite.clippingPlane = null;
            GameObject.DestroyImmediate(_sprite.meshFilter.sharedMesh, true);
            _sprite.meshFilter.sharedMesh   = null;
            _sprite.renderer.sharedMaterial = null;
            return;
        }

        exClipping clipping = _sprite.clippingPlane;
        if (clipping != null)
        {
            clipping.RemovePlane(_sprite);
        }

        // set a texture to it
        if (_sprite.atlas != null)
        {
            _sprite.renderer.sharedMaterial = _sprite.atlas.material;
        }
        else if (_texture != null)
        {
            _sprite.renderer.sharedMaterial = exEditorHelper.GetDefaultMaterial(_texture, _texture.name);
        }
        EditorUtility.UnloadUnusedAssets();

        //
        if (_sprite.useAtlas == false && _sprite.customSize == false && _sprite.trimTexture == false)
        {
            _sprite.width  = _texture.width;
            _sprite.height = _texture.height;
        }

        // prefab do not need rebuild mesh
        if (isPrefab == false)
        {
            // NOTE: it is possible user duplicate an GameObject,
            //       if we directly change the mesh, the original one will changed either.
            Mesh newMesh = new Mesh();
            newMesh.hideFlags = HideFlags.DontSave;
            newMesh.Clear();

            // build vertices, normals, uvs and colors.
            _sprite.ForceUpdateMesh(newMesh);

            // set the new mesh in MeshFilter
            GameObject.DestroyImmediate(_sprite.meshFilter.sharedMesh, true);   // delete old mesh (to avoid leaking)
            _sprite.meshFilter.sharedMesh = newMesh;
        }

        // update collider
        if (_sprite.collisionHelper)
        {
            _sprite.collisionHelper.UpdateCollider();
        }

        //
        if (clipping != null)
        {
            clipping.AddPlaneInEditor(_sprite);
        }
    }