Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 70 additions & 4 deletions VelviE-R/Scripts/Editor/VGraphs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void CtrlVShortcutHandler(KeyDownEvent evt)
if (evt.ctrlKey)
{
ctrlHold = true;
//Debug.Log("CTRL PRESSED!");
//Debug.Log("CTRL PRESSED!");
}

if (evt.keyCode == KeyCode.C && ctrlHold)
Expand Down Expand Up @@ -317,6 +317,15 @@ public void SetToolbar()
vt.InsertVNodeComponentMenu(components.headerValue, components.name, components.vcolor);
}
}

if(EditorPrefs.HasKey("v-writer-v-mode") && EditorPrefs.GetBool("v-writer-v-mode"))
{
if(writerInspectorBox != null)
writerInspectorBox.RemoveFromHierarchy();

PortsUtils.VGraph?.WriterInspector(true);
PortsUtils.MockupIsActive = true;
}
}

private GraphViewChange OnGraphChange(GraphViewChange change)
Expand Down Expand Up @@ -511,7 +520,6 @@ public void InspectorWindow(Box box)
parentInspectorBox.style.width = new StyleLength(new Length(40, LengthUnit.Percent));
parentInspectorBox.name = "parentInspectorBox";
rootVisualElement.Add(parentInspectorBox);
parentInspectorBox.Add(new ResizableElement());

var paneTop = new VisualElement();
paneTop.style.alignContent = Align.Center;
Expand Down Expand Up @@ -843,15 +851,18 @@ private void ListProperties(ListView listV)
listV.focusable = true;
listV.pickingMode = PickingMode.Position;

if(!PortsUtils.PlayMode)
if (!PortsUtils.PlayMode)
{
listV.RegisterCallback<KeyDownEvent>(CtrlVShortcutHandler, TrickleDown.TrickleDown);
listV.RegisterCallback<KeyUpEvent>(CTRLVUp);
}

}
public void ShowSelectedVblockSerializedFields(bool refresh = false)
{
if (PortsUtils.MockupIsActive)
return;

if (listV != null && PortsUtils.activeVGraphAssets != null && PortsUtils.activeVNode != null && listV.selectedItem != null)
{
if (inspectorWindow == null)
Expand Down Expand Up @@ -1021,5 +1032,60 @@ public void HideInspector()
}
PortsUtils.SetActiveAssetDirty();
}
public VisualElement writerInspectorBox { get; set; }
public bool WriterIsActive { get; set; }
public void WriterInspector(bool show = true)
{
WriterIsActive = show;

if (writerInspectorBox != null)
{
writerInspectorBox.RemoveFromHierarchy();
}

if (show)
{
if (inspectorIsActive)
HideInspector();

if (parentInspectorBox != null)
{
parentInspectorBox.RemoveFromHierarchy();
parentInspectorBox = null;
}

writerInspectorBox = new VisualElement();
writerInspectorBox.style.flexDirection = FlexDirection.Row;
writerInspectorBox.style.height = new StyleLength(new Length(100, LengthUnit.Percent));
writerInspectorBox.style.width = new StyleLength(new Length(100, LengthUnit.Percent));
writerInspectorBox.name = "writerInspectorBox";
rootVisualElement.Add(writerInspectorBox);

var paneLeft = new VisualElement();
paneLeft.style.backgroundColor = Color.white;
paneLeft.style.alignContent = Align.Center;
var paneRight = new VisualElement();
paneRight.style.backgroundColor = Color.grey;
paneRight.style.alignContent = Align.Center;
paneLeft.name = "left";
paneRight.name = "right";

VEditorFunc.SetUIDynamicSize(paneLeft, 100, false);
VEditorFunc.SetUIDynamicSize(paneRight, 100, false);
VEditorFunc.SetUIDynamicSize(paneLeft, 40, true);
VEditorFunc.SetUIDynamicSize(paneRight, 60, true);

writerInspectorBox.Add(paneLeft);
writerInspectorBox.Add(paneRight);

(VisualElement, VisualElement) objDat = (paneLeft, paneRight);
writerInspectorBox.userData = ((VisualElement, VisualElement))objDat;

paneLeft.Add(VDubTool.DrawWriterTitle());
paneLeft.Add(VDubTool.DrawSearchField());
paneLeft.Add(VDubTool.MockupElement());
paneRight.Add(VDubTool.SplitContainerRightPane());
}
}
}
}
9 changes: 7 additions & 2 deletions VelviE-R/Scripts/Editor/VViews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ public class VViews : GraphView
{
private readonly Vector2 defaultNodeSize = new Vector2(100f, 150f);
private bool copied = false;

#region ContextMenu
public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
{
if (!PortsUtils.PlayMode)
{
if (evt.target is GraphView)
{
evt.menu.AppendAction("Add VNode", (e) => AddVNode("VNode", PortsUtils.VGraph, Vector2.zero, true));
evt.menu.AppendAction("Center", (e) => { viewTransform.position = Vector3.zero; viewTransform.scale = Vector3.one; });
evt.menu.AppendAction("Center", (e) =>
{
viewTransform.position = Vector3.zero; viewTransform.scale = Vector3.one;
});

evt.menu.AppendAction("Clear Selection", (e) => ClearSelection());

evt.menu.AppendAction("Paste", (e) =>
Expand Down Expand Up @@ -73,6 +77,7 @@ public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
}
}
}
#endregion
public void AddCacheToList()
{
foreach (var t in selection)
Expand Down
9 changes: 7 additions & 2 deletions VelviE-R/Scripts/Editor/utils/EditorStartupInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ static void LogPlayModeState(PlayModeStateChange state)
{
if (state.ToString().Equals("EnteredPlayMode"))
{
if(PortsUtils.MockupIsActive && VDubTool.MockupIsWriting)
VDubTool.StopVDubtool();

PortsUtils.LastPlayedVContainer = PortsUtils.activeVGraphAssets;
PortsUtils.PlayMode = true;
}
Expand Down Expand Up @@ -244,7 +247,9 @@ static void OnHierarchyChanged()
bool wasRemoved = false;
bool wasRenamed = false;
GameObject renamedGameobject = null;
CheckNames();

if(all != null && all.Length > 0)
CheckNames();

void CheckNames()
{
Expand Down Expand Up @@ -279,7 +284,7 @@ void CheckNames()
if (vgraphs.Count != all.Length)
{
bool runOnce = false;
//it was deleted. Immediately remove VGraphContainer .asset

for (int i = 0; i < vgraphs.Count; i++)
{
if (vgraphs[i] == null)
Expand Down
1 change: 1 addition & 0 deletions VelviE-R/Scripts/Editor/utils/PortsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class VEditorNotify
/////NOTE : Most editor custom classes are in EditorClassUtils.cs
public static class PortsUtils
{
public static bool MockupIsActive{get;set;}
public static VInventory ActiveInventory { get; set; }
public static VCharacterContainer VCharaContainer { get; set; }
public static Variables variable { get; set; }
Expand Down
202 changes: 202 additions & 0 deletions VelviE-R/Scripts/Editor/utils/SavWav.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
// Copyright (c) 2012 Calvin Rien
// http://the.darktable.com
//
// This software is provided 'as-is', without any express or implied warranty. In
// no event will the authors be held liable for any damages arising from the use
// of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not claim
// that you wrote the original software. If you use this software in a product,
// an acknowledgment in the product documentation would be appreciated but is not
// required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
// =============================================================================
//
// derived from Gregorio Zanon's script
// http://forum.unity3d.com/threads/119295-Writing-AudioListener.GetOutputData-to-wav-problem?p=806734&viewfull=1#post806734

using System;
using System.IO;
using UnityEngine;
using UnityEditor;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using UnityEngine.Audio;

namespace VIEditor
{
public class SavWav
{
const int HEADER_SIZE = 44;
private static CancellationTokenSource cts;

public static (bool state, string getFile) Save(string filename, AudioClip clip)
{
cts = new CancellationTokenSource();
filename += UnityEngine.Random.Range(0, int.MaxValue);

if (!filename.ToLower().EndsWith(".wav"))
{
filename += ".wav";
}

var filepath = Path.Combine(Application.dataPath + "/VelviE-R/Resources/characterRecording/" , filename);

using (var fileStream = CreateEmpty(filepath))
{
ConvertAndWrite(fileStream, clip);
WriteHeader(fileStream, clip);
}
return (true, filename);
}

public static AudioClip TrimSilence(AudioClip clip, float min)
{
var samples = new float[clip.samples];

clip.GetData(samples, 0);

return TrimSilence(new List<float>(samples), min, clip.channels, clip.frequency);
}

public static AudioClip TrimSilence(List<float> samples, float min, int channels, int hz)
{
return TrimSilence(samples, min, channels, hz, false);
}

public static AudioClip TrimSilence(List<float> samples, float min, int channels, int hz, bool stream)
{
int i;

for (i = 0; i < samples.Count; i++)
{
if (Mathf.Abs(samples[i]) > min)
{
break;
}
}

samples.RemoveRange(0, i);

for (i = samples.Count - 1; i > 0; i--)
{
if (Mathf.Abs(samples[i]) > min)
{
break;
}
}

samples.RemoveRange(i, samples.Count - i);

var clip = AudioClip.Create("TempClip", samples.Count, channels, hz, stream);

clip.SetData(samples.ToArray(), 0);

return clip;
}

static FileStream CreateEmpty(string filepath)
{
var fileStream = new FileStream(filepath, FileMode.Create);
byte emptyByte = new byte();

for (int i = 0; i < HEADER_SIZE; i++) //preparing the header
{
fileStream.WriteByte(emptyByte);
}

return fileStream;
}

static void ConvertAndWrite(FileStream fileStream, AudioClip clip)
{

var samples = new float[clip.samples];

clip.GetData(samples, 0);

Int16[] intData = new Int16[samples.Length];
//converting in 2 float[] steps to Int16[], //then Int16[] to Byte[]

Byte[] bytesData = new Byte[samples.Length * 2];
//bytesData array is twice the size of
//dataSource array because a float converted in Int16 is 2 bytes.

int rescaleFactor = 32767; //to convert float to Int16

for (int i = 0; i < samples.Length; i++)
{
intData[i] = (short)(samples[i] * rescaleFactor);
Byte[] byteArr = new Byte[2];
byteArr = BitConverter.GetBytes(intData[i]);
byteArr.CopyTo(bytesData, i * 2);
}

fileStream.Write(bytesData, 0, bytesData.Length);
}

static void WriteHeader(FileStream fileStream, AudioClip clip)
{

var hz = clip.frequency;
var channels = clip.channels;
var samples = clip.samples;

fileStream.Seek(0, SeekOrigin.Begin);

Byte[] riff = System.Text.Encoding.UTF8.GetBytes("RIFF");
fileStream.Write(riff, 0, 4);

Byte[] chunkSize = BitConverter.GetBytes(fileStream.Length - 8);
fileStream.Write(chunkSize, 0, 4);

Byte[] wave = System.Text.Encoding.UTF8.GetBytes("WAVE");
fileStream.Write(wave, 0, 4);

Byte[] fmt = System.Text.Encoding.UTF8.GetBytes("fmt ");
fileStream.Write(fmt, 0, 4);

Byte[] subChunk1 = BitConverter.GetBytes(16);
fileStream.Write(subChunk1, 0, 4);

UInt16 one = 1;

Byte[] audioFormat = BitConverter.GetBytes(one);
fileStream.Write(audioFormat, 0, 2);

Byte[] numChannels = BitConverter.GetBytes(channels);
fileStream.Write(numChannels, 0, 2);

Byte[] sampleRate = BitConverter.GetBytes(hz);
fileStream.Write(sampleRate, 0, 4);

Byte[] byteRate = BitConverter.GetBytes(hz * channels * 2); // sampleRate * bytesPerSample*number of channels, here 44100*2*2
fileStream.Write(byteRate, 0, 4);

UInt16 blockAlign = (ushort)(channels * 2);
fileStream.Write(BitConverter.GetBytes(blockAlign), 0, 2);

UInt16 bps = 16;
Byte[] bitsPerSample = BitConverter.GetBytes(bps);
fileStream.Write(bitsPerSample, 0, 2);

Byte[] datastring = System.Text.Encoding.UTF8.GetBytes("data");
fileStream.Write(datastring, 0, 4);

Byte[] subChunk2 = BitConverter.GetBytes(samples * channels * 2);
fileStream.Write(subChunk2, 0, 4);

fileStream.Close();
}
}
}
Loading