浏览代码

update

/imageFlow
siyao 3 年前
当前提交
40f3aa4c
共有 2 个文件被更改,包括 208 次插入153 次删除
  1. 128
      AwesomeUIWidgets/Assets/Scenes/ImageFlow.unity
  2. 233
      AwesomeUIWidgets/Assets/Scripts/ImageFlowDemo.cs

128
AwesomeUIWidgets/Assets/Scenes/ImageFlow.unity


debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!28 &97997089
Texture2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 3
m_Width: 0
m_Height: 0
m_CompleteImageSize: 0
m_TextureFormat: 0
m_MipCount: 1
m_IsReadable: 1
m_IgnoreMasterTextureLimit: 0
m_IsPreProcessed: 0
m_StreamingMipmaps: 0
m_StreamingMipmapsPriority: 0
m_AlphaIsTransparency: 0
m_ImageCount: 0
m_TextureDimension: 2
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 0
m_WrapV: 0
m_WrapW: 0
m_LightmapFormat: 0
m_ColorSpace: 0
image data: 0
_typelessdata:
m_StreamData:
offset: 0
size: 0
path:
m_OriginalWidth: 0
m_OriginalHeight: 0
m_OriginalAssetGuid: 00000000000000000000000000000000
--- !u!1 &156319110
GameObject:
m_ObjectHideFlags: 0

m_Father: {fileID: 1882612342}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 169, y: -153}
m_SizeDelta: {x: 300, y: 400}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &373829884
MonoBehaviour:

m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Texture: {fileID: 0}
m_Texture: {fileID: 985023221}
m_UVRect:
serializedVersion: 2
x: 0

m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!114 &486503337
MonoBehaviour:
m_ObjectHideFlags: 0

- component: {fileID: 963194227}
- component: {fileID: 963194226}
m_Layer: 0
m_Name: Main Camera
m_Name: Main Cameraff
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 277, y: 187, z: -132}
m_LocalRotation: {x: -0, y: -0.9991026, z: -0, w: 0.04235741}
m_LocalPosition: {x: -8.95, y: 4.3, z: -4.52}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_LocalEulerAnglesHint: {x: 0, y: -175.145, z: 0}
--- !u!28 &985023221
Texture2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 3
m_Width: 0
m_Height: 0
m_CompleteImageSize: 0
m_TextureFormat: 0
m_MipCount: 1
m_IsReadable: 1
m_IgnoreMasterTextureLimit: 0
m_IsPreProcessed: 0
m_StreamingMipmaps: 0
m_StreamingMipmapsPriority: 0
m_AlphaIsTransparency: 0
m_ImageCount: 0
m_TextureDimension: 2
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 0
m_WrapV: 0
m_WrapW: 0
m_LightmapFormat: 0
m_ColorSpace: 0
image data: 0
_typelessdata:
m_StreamData:
offset: 0
size: 0
path:
m_OriginalWidth: 0
m_OriginalHeight: 0
m_OriginalAssetGuid: 00000000000000000000000000000000
--- !u!1 &1588079142
GameObject:
m_ObjectHideFlags: 0

m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Texture: {fileID: 97997089}
m_Texture: {fileID: 0}
m_UVRect:
serializedVersion: 2
x: 0

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1882612338}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -11}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 373829883}

m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 277.64478, y: 341.98712}
m_SizeDelta: {x: 398, y: 784}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 500, y: 800}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &2074331820
GameObject:

m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!65 &2074331821
BoxCollider:
m_ObjectHideFlags: 0

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2074331820}
m_LocalRotation: {x: 0, y: -0.3507795, z: 0, w: 0.9364581}
m_LocalPosition: {x: -174, y: 50.01288, z: 432}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalRotation: {x: 0, y: 1, z: 0, w: 0}
m_LocalPosition: {x: -8.84, y: 4.93, z: -14.53}
m_LocalScale: {x: 0.01, y: 0.01, z: 1}
m_LocalEulerAnglesHint: {x: 0, y: -41.07, z: 0}
m_LocalEulerAnglesHint: {x: 0, y: 180, z: 0}

233
AwesomeUIWidgets/Assets/Scripts/ImageFlowDemo.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Image = Unity.UIWidgets.widgets.Image;
using Text = Unity.UIWidgets.widgets.Text;
using ui_ = Unity.UIWidgets.widgets.ui_;
using TextStyle = Unity.UIWidgets.painting.TextStyle;

bodyText2: new TextStyle(fontSize: 14.0f)
)
),
home: new ImageFlow()
home: new Container(color: new Color(0xAF000000),
child: new ImageFlow())
);
}
}

"lottieflow-social-networks-16-7-000000-easey.json",
};
public static List<string> imageUrls = new List<string>()
{
"https://cdn.pixabay.com/photo/2016/10/21/14/50/plouzane-1758197_960_720.jpg",
"https://cdn.pixabay.com/photo/2016/11/16/10/59/mountains-1828596_960_720.jpg",
"https://cdn.pixabay.com/photo/2017/08/24/22/37/gyrfalcon-2678684_960_720.jpg",
"https://cdn.pixabay.com/photo/2013/01/17/08/25/sunset-75159_960_720.jpg",
"https://cdn.pixabay.com/photo/2021/04/06/21/08/crown-anemone-6157488_960_720.jpg",
"https://cdn.pixabay.com/photo/2021/05/10/10/46/yellow-wall-6243164_960_720.jpg",
};
public static bool UseImage = true;
public static T RandomSelect<T>(this List<T> a)
{

class ImageFlowState : State<ImageFlow>
{
readonly List<StaggeredTile> _staggeredTiles = new List<StaggeredTile>
public ImageFlowState()
StaggeredTile.count(2, 2),
StaggeredTile.count(2, 1),
};
UpdateTiles();
}
private readonly List<StaggeredTile> _staggeredTiles = new List<StaggeredTile>();
private readonly List<Widget> _tiles = new List<Widget>();
private int count = 4;
private int tileCount = 10;
readonly List<Widget> _tiles = new List<Widget>
public void UpdateTiles()
new LottieTile(Colors.green, "1055-world-locations.json"),
new LottieTile(Colors.lightBlue, "1370-confetti.json"),
};
while (_tiles.Count < tileCount)
{
if (Utils.UseImage)
{
_tiles.Add(
new ImageTile(
Utils.colors.RandomSelect(),
Utils.imageUrls.RandomSelect()
)
);
}
else
{
_tiles.Add(
new LottieTile(
Utils.colors.RandomSelect(),
Utils.lotties.RandomSelect()
)
);
}
_staggeredTiles.Add(
StaggeredTile.count(
Utils.random.Next(2) + 1,
Utils.random.Next(2) + 1)
);
}
private int count = 4;
while (_tiles.Count > tileCount)
{
_tiles.RemoveAt(0);
_staggeredTiles.RemoveAt(0);
}
}
return new Scaffold(
appBar: new AppBar(
title: new Text("Flow")
),
body:
new Column(
children: new List<Widget>()
{
new Expanded(child:
new Container(
child:
StaggeredGridView.count(
crossAxisCount: count,
staggeredTiles: _staggeredTiles,
mainAxisSpacing: 3,
crossAxisSpacing: 3,
padding: EdgeInsets.all(4),
children: _tiles
)
)),
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: new List<Widget>()
return new Column(
children: new List<Widget>()
{
new Expanded(child:
new Container(
child:
StaggeredGridView.count(
crossAxisCount: count,
staggeredTiles: _staggeredTiles,
mainAxisSpacing: 3,
crossAxisSpacing: 3,
padding: EdgeInsets.all(4),
children: _tiles
)
)),
new Slider(
activeColor: Colors.blue,
inactiveColor: Colors.white,
value: count,
min: 2,
max: 8,
divisions: 6,
label: count.ToString(),
onChanged: v =>
{
int newCount = (int) v;
if (newCount != count)
{
setState(() => { count = newCount; });
}
}
),
new Slider(
activeColor: Colors.blue,
inactiveColor: Colors.white,
value: tileCount,
min: 0,
max: 20,
divisions: 20,
label: tileCount.ToString(),
onChanged: v =>
{
int newCount = (int) v;
if (newCount != tileCount)
new Expanded(
child:
new MaterialButton(
color: Colors.amber,
child: new Text("Expand Column", style: new TextStyle(fontSize: 10)),
onPressed: () => { setState(() => { count++; }); })
),
new Expanded(child:
new MaterialButton(
color: Colors.blue,
child: new Text("Shrink Column", style: new TextStyle(fontSize: 10)),
onPressed: () => { setState(() => { count--; }); })
),
new Expanded(child:
new MaterialButton(
color: Colors.green,
child: new Text("Remove Tile", style: new TextStyle(fontSize: 10)),
onPressed: () =>
{
if (!_tiles.isEmpty())
{
setState(() =>
{
_tiles.RemoveAt(0);
_staggeredTiles.RemoveAt(0);
});
}
})
),
new Expanded(child:
new MaterialButton(
color: Colors.pink,
child: new Text("Add Tile", style: new TextStyle(fontSize: 10)),
onPressed: () =>
{
setState(() =>
{
_tiles.Add(
new LottieTile(
Utils.colors.RandomSelect(),
Utils.lotties.RandomSelect()
)
);
_staggeredTiles.Add(
StaggeredTile.count(
Utils.random.Next(2) + 1,
Utils.random.Next(2) + 1)
);
});
})
),
setState(() =>
{
tileCount = newCount;
UpdateTiles();
});
)
}
}
),
}
);
}
}
internal class ImageTile : StatefulWidget
{
internal ImageTile(Color backgroundColor, string path)
{
this.backgroundColor = backgroundColor;
this.path = path;
}
public readonly Color backgroundColor;
public readonly string path;
public override State createState()
{
return new ImageTileState();
}
}
internal class ImageTileState : State<ImageTile>
{
public override Widget build(BuildContext context)
{
return new Card(
color: widget.backgroundColor,
child: new InkWell(
onTap: () => { },
child: Image.network(
widget.path,
fit: BoxFit.cover
)
)
);
}

public readonly Color backgroundColor;
public readonly string path;
public override State createState()
{

正在加载...
取消
保存