private void HandleDropImage(float dt) { foreach (var kv in ImageDropCommands.Commands) { if (kv.Key.WasIssued()) { kv.Key.Consume(); Document.Current.History.BeginTransaction(); foreach (string assetPath in ImageDropCommands.AssetPaths) { var node = Core.Operations.CreateNode.Perform(kv.Value); var widgetPos = MousePosition * Scene.CalcTransitionToSpaceOf(Document.Current.Container.AsWidget); var texture = new SerializableTexture(assetPath); Core.Operations.SetProperty.Perform(node, nameof(Widget.Texture), texture); Core.Operations.SetProperty.Perform(node, nameof(Widget.Position), widgetPos); Core.Operations.SetProperty.Perform(node, nameof(Widget.Pivot), Vector2.Half); Core.Operations.SetProperty.Perform(node, nameof(Widget.Size), (Vector2)texture.ImageSize); Core.Operations.SetProperty.Perform(node, nameof(Widget.Id), Path.GetFileNameWithoutExtension(assetPath)); } Document.Current.History.EndTransaction(); } else { kv.Key.Consume(); } } }
private void CreateSpriteAnimatedImage(List <string> files) { onBeforeDrop?.Invoke(); using (Document.Current.History.BeginTransaction()) { var node = CreateNode.Perform(typeof(Image)); SetProperty.Perform(node, nameof(Widget.Pivot), Vector2.Half); SetProperty.Perform(node, nameof(Widget.Id), "Temp"); postProcessNode?.Invoke(node); var i = 0; ITexture first = null; foreach (var file in files) { if (!Utils.ExtractAssetPathOrShowAlert(file, out var assetPath, out var assetType)) { continue; } var text = new SerializableTexture(assetPath); first = first ?? text; SetKeyframe.Perform(node, nameof(Widget.Texture), Document.Current.AnimationId, new Keyframe <ITexture> { Value = text, Frame = i++, Function = KeyFunction.Steep, }); } SetProperty.Perform(node, nameof(Widget.Size), (Vector2)first.ImageSize); Document.Current.History.CommitTransaction(); } }
public void AddTexture(SerializableTexture texture) { if (m_textures == null) { m_textures = new List <SerializableTexture>(); } m_textures.Add(texture); }
public void HandleDropImage() { foreach (var kv in imageDropCommands.Commands) { if (pendingImages != null && kv.Key.WasIssued()) { kv.Key.Consume(); using (Document.Current.History.BeginTransaction()) { foreach (var assetPath in pendingImages) { var node = CreateNode.Perform(kv.Value); var texture = new SerializableTexture(assetPath); var nodeSize = (Vector2)texture.ImageSize; var nodeId = Path.GetFileNameWithoutExtension(assetPath); if (node is Widget) { SetProperty.Perform(node, nameof(Widget.Texture), texture); SetProperty.Perform(node, nameof(Widget.Pivot), Vector2.Half); SetProperty.Perform(node, nameof(Widget.Size), nodeSize); SetProperty.Perform(node, nameof(Widget.Id), nodeId); } else if (node is ParticleModifier) { SetProperty.Perform(node, nameof(ParticleModifier.Texture), texture); SetProperty.Perform(node, nameof(ParticleModifier.Size), nodeSize); SetProperty.Perform(node, nameof(ParticleModifier.Id), nodeId); } OnNodeCreated(node); } Document.Current.History.CommitTransaction(); pendingImages = null; } } else { kv.Key.Consume(); } } }
private void CreateImageTypeInstance(Type type, List <string> files) { onBeforeDrop?.Invoke(); using (Document.Current.History.BeginTransaction()) { var nodes = new List <Node>(files.Count); foreach (var file in files) { if (!Utils.ExtractAssetPathOrShowAlert(file, out var assetPath, out var assetType)) { continue; } var node = CreateNode.Perform(type); nodes.Add(node); var texture = new SerializableTexture(assetPath); var nodeSize = (Vector2)texture.ImageSize; var nodeId = Path.GetFileNameWithoutExtension(assetPath); if (node is Widget) { SetProperty.Perform(node, nameof(Widget.Texture), texture); SetProperty.Perform(node, nameof(Widget.Pivot), Vector2.Half); SetProperty.Perform(node, nameof(Widget.Size), nodeSize); SetProperty.Perform(node, nameof(Widget.Id), nodeId); } else if (node is ParticleModifier) { SetProperty.Perform(node, nameof(ParticleModifier.Texture), texture); SetProperty.Perform(node, nameof(ParticleModifier.Size), nodeSize); SetProperty.Perform(node, nameof(ParticleModifier.Id), nodeId); } postProcessNode?.Invoke(node); } foreach (var node in nodes) { SelectNode.Perform(node); } Document.Current.History.CommitTransaction(); } }
private void VTAddCallbacks(VirtualTextureShaderProperty property) { // Draw Header m_VTReorderableList.drawHeaderCallback = (Rect rect) => { int indent = 14; var displayRect = new Rect(rect.x + indent, rect.y, (rect.width - indent) / 3, rect.height); EditorGUI.LabelField(displayRect, "Display Name"); var referenceRect = new Rect((rect.x) + (rect.width - indent) / 3, rect.y, (rect.width - indent) / 3, rect.height); EditorGUI.LabelField(referenceRect, "Reference Name"); var textureRect = new Rect((rect.x) + (rect.width - indent) / 3 * 2, rect.y, (rect.width - indent) / 3, rect.height); EditorGUI.LabelField(textureRect, "Texture Asset"); }; // Draw Element m_VTReorderableList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { SerializableVirtualTextureLayer entry = ((SerializableVirtualTextureLayer)m_VTReorderableList.list[index]); EditorGUI.BeginChangeCheck(); var layerName = EditorGUI.DelayedTextField(new Rect(rect.x, rect.y, rect.width / 3, EditorGUIUtility.singleLineHeight), entry.layerName, EditorStyles.label); var layerRefName = EditorGUI.DelayedTextField(new Rect((rect.x + rect.width) / 3, rect.y, rect.width / 3, EditorGUIUtility.singleLineHeight), entry.layerRefName, EditorStyles.label); var selectedObject = EditorGUI.ObjectField(new Rect((rect.x + rect.width) / 3 * 2, rect.y, rect.width / 3, EditorGUIUtility.singleLineHeight), entry.layerTexture.texture, typeof(Texture), false); SerializableTexture layerTexture = new SerializableTexture(); layerTexture.texture = (Texture)selectedObject; if (EditorGUI.EndChangeCheck()) { //need to sanitize each layer with all existing properties string oldLayerName = property.value.layers[index].layerName; if (layerName != oldLayerName) { var otherPropertyNames = graphData.BuildPropertyDisplayNameList(property, oldLayerName); layerName = GraphUtil.SanitizeName(otherPropertyNames, "{0} ({1})", layerName); } string oldLayerRefName = property.value.layers[index].layerRefName; if (layerRefName != oldLayerRefName) { if (!string.IsNullOrEmpty(layerRefName)) { string name = layerRefName.Trim(); if (!string.IsNullOrEmpty(layerRefName)) { if (Regex.IsMatch(name, @"^\d+")) { name = "_" + name; } name = Regex.Replace(name, @"(?:[^A-Za-z_0-9])|(?:\s)", "_"); var otherPropertyRefNames = graphData.BuildPropertyReferenceNameList(property, oldLayerRefName); layerRefName = GraphUtil.SanitizeName(otherPropertyRefNames, "{0}_{1}", name); } } } property.value.layers[index] = new SerializableVirtualTextureLayer(layerName, layerRefName, layerTexture); //DirtyNodes(); this._postChangeValueCallback(true); } }; // Element height m_VTReorderableList.elementHeightCallback = (int indexer) => { return(m_VTReorderableList.elementHeight); }; // Can add m_VTReorderableList.onCanAddCallback = (ReorderableList list) => { return(list.count < 4); }; // Can remove m_VTReorderableList.onCanRemoveCallback = (ReorderableList list) => { return(list.count > 1); }; void AddEntryLamda(ReorderableList list) => VTAddEntry(list, property); void RemoveEntryLamda(ReorderableList list) => VTRemoveEntry(list, property); // Add callback delegates m_VTReorderableList.onSelectCallback += VTSelectEntry; m_VTReorderableList.onAddCallback += AddEntryLamda; m_VTReorderableList.onRemoveCallback += RemoveEntryLamda; m_VTReorderableList.onReorderCallback += VTReorderEntries; }