mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
Initial commit
This commit is contained in:
commit
3c7cc0c973
8391 changed files with 704313 additions and 0 deletions
12
Assets/Scripts/ActorBody.cs
Normal file
12
Assets/Scripts/ActorBody.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class ActorBody : MonoBehaviour
|
||||
{
|
||||
public SpriteRenderer bodyRenderer;
|
||||
public SpriteRenderer headRenderer;
|
||||
}
|
||||
}
|
11
Assets/Scripts/ActorBody.cs.meta
Normal file
11
Assets/Scripts/ActorBody.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 511a9ed9093e7fc458dec8d3c657f9a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/AnimationComponents.meta
Normal file
8
Assets/Scripts/AnimationComponents.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8e8cb35b5659798458ffebd1b3a5e993
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
25
Assets/Scripts/AnimationComponents/Actor.cs
Normal file
25
Assets/Scripts/AnimationComponents/Actor.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class Actor
|
||||
{
|
||||
public List<string> defNames = new List<string>();
|
||||
public List<string> requiredGenitals = new List<string>();
|
||||
public bool controlGenitalAngle = false;
|
||||
public List<AlienRaceOffset> raceOffsets;
|
||||
public List<string> blacklistedRaces;
|
||||
public bool initiator = false;
|
||||
public string gender;
|
||||
public bool isFucking = false;
|
||||
public bool isFucked = false;
|
||||
public List<string> bodyDefTypes = new List<string>();
|
||||
public BodyTypeOffset bodyTypeOffset = new BodyTypeOffset();
|
||||
public Vector3 offset = new Vector2(0, 0);
|
||||
public List<string> requiredGender;
|
||||
public List<string> tags = new List<string>();
|
||||
}
|
||||
}
|
11
Assets/Scripts/AnimationComponents/Actor.cs.meta
Normal file
11
Assets/Scripts/AnimationComponents/Actor.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ca7cd67490c5773499bff5c06907bdf7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
10
Assets/Scripts/AnimationComponents/AlienRaceOffset.cs
Normal file
10
Assets/Scripts/AnimationComponents/AlienRaceOffset.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class AlienRaceOffset
|
||||
{
|
||||
public string defName;
|
||||
public Vector2 offset;
|
||||
}
|
||||
}
|
11
Assets/Scripts/AnimationComponents/AlienRaceOffset.cs.meta
Normal file
11
Assets/Scripts/AnimationComponents/AlienRaceOffset.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a3449cf2dd7e0444bbc5a7b654cf10c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/AnimationComponents/AnimationClips.meta
Normal file
8
Assets/Scripts/AnimationComponents/AnimationClips.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 20033872660014f4295d8ac40800a707
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,18 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public abstract class AnimationClip
|
||||
{
|
||||
[XmlIgnore]
|
||||
public Dictionary<int, string> SoundEffects = new Dictionary<int, string>();
|
||||
public List<string> types;
|
||||
public int duration;
|
||||
public abstract void BuildSimpleCurves();
|
||||
public string soundDef = null;
|
||||
public int actor;
|
||||
public List<string> tags = new List<string>();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: aeb406e171f70f14f88980439239ca59
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,112 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class PawnAnimationClip : AnimationClip
|
||||
{
|
||||
[XmlAttribute("Class")] public string className = "Rimworld_Animations.PawnAnimationClip";
|
||||
|
||||
[XmlArray("keyframes"), XmlArrayItem("li")] public List<PawnKeyframe> keyframes = new List<PawnKeyframe>();
|
||||
|
||||
public AltitudeLayer layer = AltitudeLayer.Pawn;
|
||||
|
||||
[XmlIgnore] public Dictionary<int, bool> quiver = new Dictionary<int, bool>();
|
||||
[XmlIgnore] public SimpleCurve GenitalAngle = new SimpleCurve();
|
||||
[XmlIgnore] public SimpleCurve BodyAngle = new SimpleCurve();
|
||||
[XmlIgnore] public SimpleCurve HeadAngle = new SimpleCurve();
|
||||
[XmlIgnore] public SimpleCurve HeadBob = new SimpleCurve();
|
||||
[XmlIgnore] public SimpleCurve BodyOffsetX = new SimpleCurve();
|
||||
[XmlIgnore] public SimpleCurve BodyOffsetZ = new SimpleCurve();
|
||||
[XmlIgnore] public SimpleCurve HeadFacing = new SimpleCurve();
|
||||
[XmlIgnore] public SimpleCurve BodyFacing = new SimpleCurve();
|
||||
|
||||
public override void BuildSimpleCurves()
|
||||
{
|
||||
int duration = 0;
|
||||
|
||||
foreach (PawnKeyframe frame in keyframes)
|
||||
{ duration += frame.tickDuration; }
|
||||
|
||||
this.duration = duration;
|
||||
|
||||
int keyframePosition = 0;
|
||||
foreach (PawnKeyframe frame in keyframes)
|
||||
{
|
||||
if (frame.atTick.HasValue)
|
||||
{
|
||||
if (frame.bodyAngle.HasValue)
|
||||
BodyAngle.Add((float)frame.atTick / (float)duration, frame.bodyAngle.Value, true);
|
||||
|
||||
if (frame.headAngle.HasValue)
|
||||
HeadAngle.Add((float)frame.atTick / (float)duration, frame.headAngle.Value, true);
|
||||
|
||||
if (frame.bodyOffsetX.HasValue)
|
||||
BodyOffsetX.Add((float)frame.atTick / (float)duration, frame.bodyOffsetX.Value, true);
|
||||
|
||||
if (frame.bodyOffsetZ.HasValue)
|
||||
BodyOffsetZ.Add((float)frame.atTick / (float)duration, frame.bodyOffsetZ.Value, true);
|
||||
|
||||
if (frame.headFacing.HasValue)
|
||||
HeadFacing.Add((float)frame.atTick / (float)duration, frame.headFacing.Value, true);
|
||||
|
||||
if (frame.bodyFacing.HasValue)
|
||||
BodyFacing.Add((float)frame.atTick / (float)duration, frame.bodyFacing.Value, true);
|
||||
|
||||
if (frame.headBob.HasValue)
|
||||
HeadBob.Add((float)frame.atTick / (float)duration, frame.headBob.Value, true);
|
||||
|
||||
if (frame.genitalAngle.HasValue)
|
||||
GenitalAngle.Add((float)frame.atTick / (float)duration, frame.genitalAngle.Value, true);
|
||||
|
||||
if (frame.soundEffect != null)
|
||||
{
|
||||
SoundEffects.Add((int)frame.atTick, frame.soundEffect);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (frame.bodyAngle.HasValue)
|
||||
BodyAngle.Add((float)keyframePosition / (float)duration, frame.bodyAngle.Value, true);
|
||||
|
||||
if (frame.headAngle.HasValue)
|
||||
HeadAngle.Add((float)keyframePosition / (float)duration, frame.headAngle.Value, true);
|
||||
|
||||
if (frame.bodyOffsetX.HasValue)
|
||||
BodyOffsetX.Add((float)keyframePosition / (float)duration, frame.bodyOffsetX.Value, true);
|
||||
|
||||
if (frame.bodyOffsetZ.HasValue)
|
||||
BodyOffsetZ.Add((float)keyframePosition / (float)duration, frame.bodyOffsetZ.Value, true);
|
||||
|
||||
if (frame.headFacing.HasValue)
|
||||
HeadFacing.Add((float)keyframePosition / (float)duration, frame.headFacing.Value, true);
|
||||
|
||||
if (frame.bodyFacing.HasValue)
|
||||
BodyFacing.Add((float)keyframePosition / (float)duration, frame.bodyFacing.Value, true);
|
||||
|
||||
if (frame.headBob.HasValue)
|
||||
HeadBob.Add((float)keyframePosition / (float)duration, frame.headBob.Value, true);
|
||||
|
||||
if (frame.genitalAngle.HasValue)
|
||||
GenitalAngle.Add((float)keyframePosition / (float)duration, frame.genitalAngle.Value, true);
|
||||
|
||||
if (frame.soundEffect != null)
|
||||
{
|
||||
SoundEffects.Add(keyframePosition, frame.soundEffect);
|
||||
}
|
||||
|
||||
if (frame.tickDuration != 1 && frame.quiver.HasValue)
|
||||
{
|
||||
|
||||
quiver.Add(keyframePosition, true);
|
||||
quiver.Add(keyframePosition + frame.tickDuration - 1, false);
|
||||
}
|
||||
|
||||
keyframePosition += frame.tickDuration;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b7f2dc95148378445919ef3ed8705c5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,71 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class ThingAnimationClip : AnimationClip
|
||||
{
|
||||
[XmlAttribute("Class")] public string className = "Rimworld_Animations.PawnAnimationClip";
|
||||
|
||||
[XmlArray("keyframes"), XmlArrayItem("li")] public List<ThingKeyframe> keyframes = new List<ThingKeyframe>();
|
||||
public string layer = "Pawn";
|
||||
|
||||
[XmlIgnore] public SimpleCurve PositionX = new SimpleCurve();
|
||||
[XmlIgnore] public SimpleCurve PositionZ = new SimpleCurve();
|
||||
[XmlIgnore] public SimpleCurve Rotation = new SimpleCurve();
|
||||
|
||||
public override void BuildSimpleCurves()
|
||||
{
|
||||
int duration = 0;
|
||||
//getting the length of the whole clip
|
||||
foreach (ThingKeyframe frame in keyframes)
|
||||
{
|
||||
duration += frame.tickDuration;
|
||||
}
|
||||
|
||||
//guarantees loops don't get cut off mid-anim
|
||||
this.duration = duration;
|
||||
|
||||
int keyframePosition = 0;
|
||||
foreach (ThingKeyframe frame in keyframes)
|
||||
{
|
||||
if (frame.atTick.HasValue)
|
||||
{
|
||||
if (frame.positionX.HasValue)
|
||||
PositionX.Add((float)frame.atTick / (float)duration, frame.positionX.Value, true);
|
||||
|
||||
if (frame.positionZ.HasValue)
|
||||
PositionZ.Add((float)frame.atTick / (float)duration, frame.positionZ.Value, true);
|
||||
|
||||
if (frame.rotation.HasValue)
|
||||
Rotation.Add((float)frame.atTick / (float)duration, frame.rotation.Value, true);
|
||||
|
||||
if (frame.soundEffect != null)
|
||||
{
|
||||
SoundEffects.Add((int)frame.atTick, frame.soundEffect);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (frame.positionX.HasValue)
|
||||
PositionX.Add((float)keyframePosition / (float)duration, frame.positionX.Value, true);
|
||||
|
||||
if (frame.positionZ.HasValue)
|
||||
PositionZ.Add((float)keyframePosition / (float)duration, frame.positionZ.Value, true);
|
||||
|
||||
if (frame.rotation.HasValue)
|
||||
Rotation.Add((float)keyframePosition / (float)duration, frame.rotation.Value, true);
|
||||
|
||||
if (frame.soundEffect != null)
|
||||
{
|
||||
SoundEffects.Add(keyframePosition, frame.soundEffect);
|
||||
}
|
||||
|
||||
keyframePosition += frame.tickDuration;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c4a44c0d3b9937c48b2ae8501126227e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
33
Assets/Scripts/AnimationComponents/AnimationDef.cs
Normal file
33
Assets/Scripts/AnimationComponents/AnimationDef.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class AnimationDef
|
||||
{
|
||||
public string defName = "Undefined";
|
||||
public string label = "Undefined";
|
||||
public bool sounds = false;
|
||||
public int animationTimeTicks = 0;
|
||||
public List<string> sexTypes = new List<string>();
|
||||
public List<string> interactionDefTypes = new List<string>();
|
||||
|
||||
[XmlArray("actors"), XmlArrayItem("li")]
|
||||
public List<Actor> actors = new List<Actor>();
|
||||
|
||||
[XmlArray("animationStages"), XmlArrayItem("li")]
|
||||
public List<AnimationStage> animationStages = new List<AnimationStage>();
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
animationTimeTicks = 0;
|
||||
|
||||
foreach (AnimationStage stage in animationStages)
|
||||
{
|
||||
stage.Initialize();
|
||||
animationTimeTicks += stage.playTimeTicks;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/AnimationComponents/AnimationDef.cs.meta
Normal file
11
Assets/Scripts/AnimationComponents/AnimationDef.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9cca833a1987a2749aa6e4d640d32266
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
30
Assets/Scripts/AnimationComponents/AnimationStage.cs
Normal file
30
Assets/Scripts/AnimationComponents/AnimationStage.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class AnimationStage
|
||||
{
|
||||
public string stageName = "default";
|
||||
public int stageIndex = 0;
|
||||
public int playTimeTicks = 0;
|
||||
public int playTimeTicksQuick = -1;
|
||||
public bool isLooping = true;
|
||||
|
||||
[XmlArray("animationClips"), XmlArrayItem("li")]
|
||||
public List<PawnAnimationClip> animationClips = new List<PawnAnimationClip>();
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
foreach (AnimationClip clip in animationClips)
|
||||
{
|
||||
clip.BuildSimpleCurves();
|
||||
|
||||
//select playTimeTicks as longest playtime of all the animations
|
||||
if (clip.duration > playTimeTicks)
|
||||
{ playTimeTicks = clip.duration; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/AnimationComponents/AnimationStage.cs.meta
Normal file
11
Assets/Scripts/AnimationComponents/AnimationStage.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4d62c568c0ad7ea4ba7ddd3b9aa6d0e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
33
Assets/Scripts/AnimationComponents/BodyTypeOffset.cs
Normal file
33
Assets/Scripts/AnimationComponents/BodyTypeOffset.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
//using Microsoft.Toolkit.Uwp.UI;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class BodyTypeOffset
|
||||
{
|
||||
public string Male;
|
||||
public string Female;
|
||||
public string Thin;
|
||||
public string Hulk;
|
||||
public string Fat;
|
||||
|
||||
public Vector3 GetOffset(string bodyType)
|
||||
{
|
||||
Debug.Log(bodyType);
|
||||
|
||||
FieldInfo bodyTypeOffsetInfo = typeof(BodyTypeOffset).GetField(bodyType);
|
||||
string bodyTypeOffsetString = (string)bodyTypeOffsetInfo.GetValue(this);
|
||||
|
||||
if (bodyTypeOffsetString == null || bodyTypeOffsetString == "")
|
||||
{ return new Vector2(); }
|
||||
|
||||
bodyTypeOffsetString = bodyTypeOffsetString.Trim();
|
||||
bodyTypeOffsetString = bodyTypeOffsetString.Replace("(", "");
|
||||
bodyTypeOffsetString = bodyTypeOffsetString.Replace(")", "");
|
||||
var bodyTypeOffsetStrings = bodyTypeOffsetString.Split(',');
|
||||
|
||||
return new Vector3(float.Parse(bodyTypeOffsetStrings[0]), 0f, float.Parse(bodyTypeOffsetStrings[1]));
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/AnimationComponents/BodyTypeOffset.cs.meta
Normal file
11
Assets/Scripts/AnimationComponents/BodyTypeOffset.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6db04cc11995126429fb12578d6620d7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/AnimationComponents/KeyFrames.meta
Normal file
8
Assets/Scripts/AnimationComponents/KeyFrames.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d3f1c8d8d1b51a147b17f5510eebb2cf
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
14
Assets/Scripts/AnimationComponents/KeyFrames/Keyframe.cs
Normal file
14
Assets/Scripts/AnimationComponents/KeyFrames/Keyframe.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class Keyframe
|
||||
{
|
||||
public int tickDuration = 1;
|
||||
public float? atTick;
|
||||
public string soundEffect;
|
||||
public List<string> tags = new List<string>();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c909440fcfe86c14c9e363377896367c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
19
Assets/Scripts/AnimationComponents/KeyFrames/PawnKeyframe.cs
Normal file
19
Assets/Scripts/AnimationComponents/KeyFrames/PawnKeyframe.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class PawnKeyframe : Keyframe
|
||||
{
|
||||
public float? bodyAngle;
|
||||
public float? headAngle;
|
||||
public float? headBob;
|
||||
public float? bodyOffsetX;
|
||||
public float? bodyOffsetZ;
|
||||
public float? headFacing;
|
||||
public float? bodyFacing;
|
||||
public float? genitalAngle;
|
||||
public bool? quiver;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fe4a7d5f472a25945bac2d1892a4e2fa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class ThingKeyframe : Keyframe
|
||||
{
|
||||
public float? positionX;
|
||||
public float? positionZ;
|
||||
public float? rotation;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 48d6c7ac273c73b498a8bf4c33fda2fc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
196
Assets/Scripts/AnimationController.cs
Normal file
196
Assets/Scripts/AnimationController.cs
Normal file
|
@ -0,0 +1,196 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Xml.Serialization;
|
||||
using UnityEngine;
|
||||
using SFB;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class AnimationController : MonoBehaviour
|
||||
{
|
||||
public Defs defs;
|
||||
public AnimationDef anim;
|
||||
public bool isAnimating = false;
|
||||
public bool isLooping = true;
|
||||
public int stageTick = 0;
|
||||
public int stageID = 0;
|
||||
|
||||
public bool autoAdvanceToNextStage = false;
|
||||
|
||||
//public InputField stageTickField;
|
||||
//public InputField stageLengthField;
|
||||
|
||||
//public InputField stageIDField;
|
||||
|
||||
public ActorBody actorBodyPrefab;
|
||||
public List<ActorBody> actorBodies = new List<ActorBody>();
|
||||
public List<Dropdown> bodyTypeDropdowns = new List<Dropdown>();
|
||||
|
||||
public Text stageTickField;
|
||||
public Text stageLengthField;
|
||||
|
||||
private float currentTime = 0;
|
||||
|
||||
public T ReadDataFromXML<T>(string inputPath)
|
||||
{
|
||||
using (StreamReader stringReader = new StreamReader(inputPath))
|
||||
{
|
||||
XmlSerializer serializer = new XmlSerializer(typeof(T));
|
||||
return (T)serializer.Deserialize(stringReader);
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadNewXML(string inputPath)
|
||||
{
|
||||
defs = ReadDataFromXML<Defs>(inputPath);
|
||||
|
||||
if (defs?.animationDefs != null)
|
||||
{
|
||||
Debug.Log(defs.animationDefs.Count);
|
||||
Debug.Log(defs.animationDefs[0].defName);
|
||||
|
||||
anim = defs.animationDefs[0];
|
||||
InitializeAnimation(anim);
|
||||
|
||||
UpdateAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenFileDialog()
|
||||
{
|
||||
var paths = StandaloneFileBrowser.OpenFilePanel("Open File", "", "", false);
|
||||
|
||||
Debug.Log(paths[0]);
|
||||
LoadNewXML(paths[0]);
|
||||
}
|
||||
|
||||
public void PlayAnimation(bool value)
|
||||
{
|
||||
isAnimating = value;
|
||||
}
|
||||
|
||||
public void ToggleAnimationLoop()
|
||||
{
|
||||
isLooping = !isLooping;
|
||||
}
|
||||
|
||||
public void UpdateStageID(InputField stageIDField)
|
||||
{
|
||||
if (anim == null)
|
||||
{
|
||||
stageIDField.text = "0";
|
||||
return;
|
||||
}
|
||||
|
||||
int i = int.Parse(stageIDField.text);
|
||||
stageID = Mathf.Clamp(i, 0, anim.animationStages.Count - 1);
|
||||
stageTick = 0;
|
||||
|
||||
stageIDField.text = stageID.ToString();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (anim == null || isAnimating == false) return;
|
||||
|
||||
currentTime += Time.deltaTime;
|
||||
|
||||
if (currentTime < 1f/60f)
|
||||
{ return; }
|
||||
|
||||
currentTime -= 1f/60f;
|
||||
stageTick += 1;
|
||||
|
||||
if (stageTick > anim.animationStages[stageID].playTimeTicks)
|
||||
{
|
||||
if (isLooping)
|
||||
{ stageTick = 1; }
|
||||
|
||||
else if (autoAdvanceToNextStage && stageID < anim.animationStages.Count - 1)
|
||||
{ stageTick = 1; stageID++; }
|
||||
|
||||
else
|
||||
{ stageTick = anim.animationStages[stageID].playTimeTicks; }
|
||||
}
|
||||
|
||||
UpdateAnimation();
|
||||
}
|
||||
|
||||
public void InitializeAnimation(AnimationDef anim)
|
||||
{
|
||||
ResetAnimation();
|
||||
|
||||
anim.Initialize();
|
||||
this.anim = anim;
|
||||
|
||||
for (int actorID = 0; actorID < anim.actors.Count; actorID++)
|
||||
{
|
||||
ActorBody actorBody = Instantiate(actorBodyPrefab, transform) as ActorBody;
|
||||
actorBodies.Add(actorBody);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetAnimation()
|
||||
{
|
||||
anim = null;
|
||||
stageID = 0;
|
||||
stageTick = 0;
|
||||
isAnimating = false;
|
||||
actorBodies.Clear();
|
||||
|
||||
foreach (Transform child in transform)
|
||||
{ Destroy(child.gameObject); }
|
||||
}
|
||||
|
||||
public void UpdateAnimation()
|
||||
{
|
||||
stageTickField.text = stageTick.ToString();
|
||||
stageLengthField.text = anim.animationStages[stageID].playTimeTicks.ToString();
|
||||
|
||||
for (int actorID = 0; actorID < actorBodies.Count; actorID++)
|
||||
{
|
||||
ActorBody actorBody = actorBodies[actorID];
|
||||
string bodyType = bodyTypeDropdowns[actorID].options[bodyTypeDropdowns[actorID].value].text;
|
||||
|
||||
PawnAnimationClip clip = anim.animationStages[stageID].animationClips[actorID];
|
||||
float clipPercent = (float)(stageTick % clip.duration) / clip.duration;
|
||||
|
||||
Vector3 deltaPos = new Vector3(clip.BodyOffsetX.Evaluate(clipPercent), 0, clip.BodyOffsetZ.Evaluate(clipPercent));
|
||||
deltaPos += anim.actors[actorID].bodyTypeOffset.GetOffset(bodyType);
|
||||
|
||||
float bodyAngle = clip.BodyAngle.Evaluate(clipPercent);
|
||||
float headAngle = clip.HeadAngle.Evaluate(clipPercent);
|
||||
|
||||
if (bodyAngle < 0) bodyAngle = 360 - ((-1f * bodyAngle) % 360);
|
||||
if (bodyAngle > 360) bodyAngle %= 360;
|
||||
|
||||
if (headAngle < 0) headAngle = 360 - ((-1f * headAngle) % 360);
|
||||
if (headAngle > 360) headAngle %= 360;
|
||||
|
||||
int bodyFacing = (int)clip.BodyFacing.Evaluate(clipPercent);
|
||||
int headFacing = (int)clip.HeadFacing.Evaluate(clipPercent);
|
||||
|
||||
Vector3 headBob = new Vector3(0, 0, clip.HeadBob.Evaluate(clipPercent)) + PawnUtility.BaseHeadOffsetAt(bodyType, bodyFacing);
|
||||
|
||||
Vector3 bodyPos = new Vector3(deltaPos.x, deltaPos.z, 0);
|
||||
Vector3 headPos = new Vector3(headBob.x, headBob.z, 0);
|
||||
|
||||
actorBody.transform.position = bodyPos;
|
||||
actorBody.transform.eulerAngles = new Vector3(0, 0, bodyAngle);
|
||||
|
||||
actorBody.headRenderer.transform.localPosition = headPos;
|
||||
actorBody.headRenderer.transform.eulerAngles = new Vector3(0, 0, headAngle);
|
||||
|
||||
actorBody.bodyRenderer.sprite = Resources.Load<Sprite>("Textures/Humanlike/Bodies/" + bodyType + bodyFacing);
|
||||
actorBody.headRenderer.sprite = Resources.Load<Sprite>("Textures/Humanlike/Heads/Head" + headFacing);
|
||||
|
||||
actorBody.bodyRenderer.sortingLayerName = clip.layer.ToString();
|
||||
actorBody.headRenderer.sortingLayerName = clip.layer.ToString();
|
||||
actorBody.headRenderer.sortingOrder = headFacing == 2 ? 1 : -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/AnimationController.cs.meta
Normal file
11
Assets/Scripts/AnimationController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5ce34f72fe7ef0c41a7bc163fce97970
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
49
Assets/Scripts/CurvePoint.cs
Normal file
49
Assets/Scripts/CurvePoint.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public struct CurvePoint
|
||||
{
|
||||
public Vector2 Loc
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.loc;
|
||||
}
|
||||
}
|
||||
|
||||
public float x
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.loc.x;
|
||||
}
|
||||
}
|
||||
|
||||
public float y
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.loc.y;
|
||||
}
|
||||
}
|
||||
|
||||
public CurvePoint(float x, float y)
|
||||
{
|
||||
this.loc = new Vector2(x, y);
|
||||
}
|
||||
|
||||
public CurvePoint(Vector2 loc)
|
||||
{
|
||||
this.loc = loc;
|
||||
}
|
||||
|
||||
public static implicit operator Vector2(CurvePoint pt)
|
||||
{
|
||||
return pt.loc;
|
||||
}
|
||||
|
||||
private Vector2 loc;
|
||||
}
|
||||
}
|
11
Assets/Scripts/CurvePoint.cs.meta
Normal file
11
Assets/Scripts/CurvePoint.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: eaf8d0c12cfb59543a665522d39528fc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
13
Assets/Scripts/Defs.cs
Normal file
13
Assets/Scripts/Defs.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
[XmlRoot("Defs")]
|
||||
public class Defs
|
||||
{
|
||||
[XmlElement("Rimworld_Animations.AnimationDef")]
|
||||
public List<AnimationDef> animationDefs = new List<AnimationDef>();
|
||||
}
|
||||
}
|
11
Assets/Scripts/Defs.cs.meta
Normal file
11
Assets/Scripts/Defs.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 92804390faa29b945818e67cf808b49c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
43
Assets/Scripts/Enums.cs
Normal file
43
Assets/Scripts/Enums.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
public enum AltitudeLayer
|
||||
{
|
||||
[XmlEnum(Name = "Terrain")] Terrain,
|
||||
[XmlEnum(Name = "TerrainScatter")] TerrainScatter,
|
||||
[XmlEnum(Name = "Floor")] Floor,
|
||||
[XmlEnum(Name = "Conduits")] Conduits,
|
||||
[XmlEnum(Name = "FloorCoverings")] FloorCoverings,
|
||||
[XmlEnum(Name = "FloorEmplacement")] FloorEmplacement,
|
||||
[XmlEnum(Name = "Filth")] Filth,
|
||||
[XmlEnum(Name = "Zone")] Zone,
|
||||
[XmlEnum(Name = "SmallWire")] SmallWire,
|
||||
[XmlEnum(Name = "LowPlant")] LowPlant,
|
||||
[XmlEnum(Name = "MoteLow")] MoteLow,
|
||||
[XmlEnum(Name = "Shadows")] Shadows,
|
||||
[XmlEnum(Name = "DoorMoveable")] DoorMoveable,
|
||||
[XmlEnum(Name = "Building")] Building,
|
||||
[XmlEnum(Name = "BuildingOnTop")] BuildingOnTop,
|
||||
[XmlEnum(Name = "MoteBelowThings")] MoteBelowThings,
|
||||
[XmlEnum(Name = "Item")] Item,
|
||||
[XmlEnum(Name = "ItemImportant")] ItemImportant,
|
||||
[XmlEnum(Name = "LayingPawn")] LayingPawn,
|
||||
[XmlEnum(Name = "PawnRope")] PawnRope,
|
||||
[XmlEnum(Name = "Projectile")] Projectile,
|
||||
[XmlEnum(Name = "Pawn")] Pawn,
|
||||
[XmlEnum(Name = "PawnUnused")] PawnUnused,
|
||||
[XmlEnum(Name = "PawnState")] PawnState,
|
||||
[XmlEnum(Name = "Blueprint")] Blueprint,
|
||||
[XmlEnum(Name = "MoteOverheadLow")] MoteOverheadLow,
|
||||
[XmlEnum(Name = "MoteOverhead")] MoteOverhead,
|
||||
[XmlEnum(Name = "Gas")] Gas,
|
||||
[XmlEnum(Name = "Skyfaller")] Skyfaller,
|
||||
[XmlEnum(Name = "Weather")] Weather,
|
||||
[XmlEnum(Name = "LightingOverlay")] LightingOverlay,
|
||||
[XmlEnum(Name = "VisEffects")] VisEffects,
|
||||
[XmlEnum(Name = "FogOfWar")] FogOfWar,
|
||||
[XmlEnum(Name = "WorldClipper")] WorldClipper,
|
||||
[XmlEnum(Name = "MapDataOverlay")] MapDataOverlay,
|
||||
[XmlEnum(Name = "MetaOverlays")] MetaOverlays,
|
||||
}
|
||||
|
11
Assets/Scripts/Enums.cs.meta
Normal file
11
Assets/Scripts/Enums.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7a40ab1285a8ce74082b0d1b481d41aa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
17
Assets/Scripts/GenMath.cs
Normal file
17
Assets/Scripts/GenMath.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public static class GenMath
|
||||
{
|
||||
public static float LerpDouble(float inFrom, float inTo, float outFrom, float outTo, float x)
|
||||
{
|
||||
float num = (x - inFrom) / (inTo - inFrom);
|
||||
return outFrom + (outTo - outFrom) * num;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/GenMath.cs.meta
Normal file
11
Assets/Scripts/GenMath.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d7d8a7c01a41f454aae46350b912fc9f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
35
Assets/Scripts/PawnUtility.cs
Normal file
35
Assets/Scripts/PawnUtility.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public static class PawnUtility
|
||||
{
|
||||
public static Vector3 BaseHeadOffsetAt(string bodyType, int rotation)
|
||||
{
|
||||
Vector2 headOffset = Vector3.zero;
|
||||
|
||||
switch (bodyType)
|
||||
{
|
||||
case "Male": headOffset = new Vector2(0.04f, 0.34f); break;
|
||||
case "Female": headOffset = new Vector2(0.10f, 0.34f); break;
|
||||
case "Thin": headOffset = new Vector2(0.09f, 0.34f); break;
|
||||
case "Hulk": headOffset = new Vector2(0.10f, 0.34f); break;
|
||||
case "Fat": headOffset = new Vector2(0.09f, 0.34f); break;
|
||||
}
|
||||
|
||||
switch (rotation)
|
||||
{
|
||||
case 0: return new Vector3(0f, 0f, headOffset.y);
|
||||
case 1: return new Vector3(headOffset.x, 0f, headOffset.y);
|
||||
case 2: return new Vector3(0f, 0f, headOffset.y);
|
||||
case 3: return new Vector3(-headOffset.x, 0f, headOffset.y);
|
||||
default: return Vector3.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/PawnUtility.cs.meta
Normal file
11
Assets/Scripts/PawnUtility.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d7c648d5b6a74be448da40e4ed79c8c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
285
Assets/Scripts/SimpleCurve.cs
Normal file
285
Assets/Scripts/SimpleCurve.cs
Normal file
|
@ -0,0 +1,285 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class SimpleCurve : IEnumerable<CurvePoint>, IEnumerable
|
||||
{
|
||||
public int PointsCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.points.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public List<CurvePoint> Points
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.points;
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleCurve(IEnumerable<CurvePoint> points)
|
||||
{
|
||||
this.SetPoints(points);
|
||||
}
|
||||
|
||||
public SimpleCurve()
|
||||
{
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return this.GetEnumerator();
|
||||
}
|
||||
|
||||
public IEnumerator<CurvePoint> GetEnumerator()
|
||||
{
|
||||
foreach (CurvePoint curvePoint in this.points)
|
||||
{
|
||||
yield return curvePoint;
|
||||
}
|
||||
|
||||
List<CurvePoint>.Enumerator enumerator = default(List<CurvePoint>.Enumerator);
|
||||
|
||||
yield break;
|
||||
yield break;
|
||||
}
|
||||
|
||||
public CurvePoint this[int i]
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.points[i];
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.points[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPoints(IEnumerable<CurvePoint> newPoints)
|
||||
{
|
||||
this.points.Clear();
|
||||
foreach (CurvePoint item in newPoints)
|
||||
{
|
||||
this.points.Add(item);
|
||||
}
|
||||
this.SortPoints();
|
||||
}
|
||||
|
||||
public void Add(float x, float y, bool sort = true)
|
||||
{
|
||||
CurvePoint newPoint = new CurvePoint(x, y);
|
||||
this.Add(newPoint, sort);
|
||||
}
|
||||
|
||||
public void Add(CurvePoint newPoint, bool sort = true)
|
||||
{
|
||||
this.points.Add(newPoint);
|
||||
if (sort)
|
||||
{
|
||||
this.SortPoints();
|
||||
}
|
||||
}
|
||||
|
||||
public void SortPoints()
|
||||
{
|
||||
this.points.Sort(SimpleCurve.CurvePointsComparer);
|
||||
}
|
||||
|
||||
public float ClampToCurve(float value)
|
||||
{
|
||||
if (this.points.Count == 0)
|
||||
{
|
||||
Debug.Log("Clamping a value to an empty SimpleCurve.");
|
||||
return value;
|
||||
}
|
||||
return Mathf.Clamp(value, this.points[0].y, this.points[this.points.Count - 1].y);
|
||||
}
|
||||
|
||||
public void RemovePointNear(CurvePoint point)
|
||||
{
|
||||
for (int i = 0; i < this.points.Count; i++)
|
||||
{
|
||||
if ((this.points[i].Loc - point.Loc).sqrMagnitude < 0.001f)
|
||||
{
|
||||
this.points.RemoveAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float Evaluate(float x)
|
||||
{
|
||||
if (this.points.Count == 0)
|
||||
{
|
||||
Debug.Log("Evaluating a SimpleCurve with no points.");
|
||||
return 0f;
|
||||
}
|
||||
|
||||
if (x <= this.points[0].x)
|
||||
{
|
||||
return this.points[0].y;
|
||||
}
|
||||
|
||||
if (x >= this.points[this.points.Count - 1].x)
|
||||
{
|
||||
return this.points[this.points.Count - 1].y;
|
||||
}
|
||||
|
||||
CurvePoint curvePoint = this.points[0];
|
||||
CurvePoint curvePoint2 = this.points[this.points.Count - 1];
|
||||
|
||||
int i = 0;
|
||||
while (i < this.points.Count)
|
||||
{
|
||||
if (x <= this.points[i].x)
|
||||
{
|
||||
curvePoint2 = this.points[i];
|
||||
if (i > 0)
|
||||
{
|
||||
curvePoint = this.points[i - 1];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
float t = (x - curvePoint.x) / (curvePoint2.x - curvePoint.x);
|
||||
return Mathf.Lerp(curvePoint.y, curvePoint2.y, t);
|
||||
}
|
||||
|
||||
public float EvaluateInverted(float y)
|
||||
{
|
||||
if (this.points.Count == 0)
|
||||
{
|
||||
Debug.Log("Evaluating a SimpleCurve with no points.");
|
||||
return 0f;
|
||||
}
|
||||
|
||||
if (this.points.Count == 1)
|
||||
{
|
||||
return this.points[0].x;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
while (i < this.points.Count - 1)
|
||||
{
|
||||
if ((y >= this.points[i].y && y <= this.points[i + 1].y) || (y <= this.points[i].y && y >= this.points[i + 1].y))
|
||||
{
|
||||
if (y == this.points[i].y)
|
||||
{
|
||||
return this.points[i].x;
|
||||
}
|
||||
|
||||
if (y == this.points[i + 1].y)
|
||||
{
|
||||
return this.points[i + 1].x;
|
||||
}
|
||||
|
||||
return GenMath.LerpDouble(this.points[i].y, this.points[i + 1].y, this.points[i].x, this.points[i + 1].x, y);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (y < this.points[0].y)
|
||||
{
|
||||
float result = 0f;
|
||||
float num = 0f;
|
||||
for (int j = 0; j < this.points.Count; j++)
|
||||
{
|
||||
if (j == 0 || this.points[j].y < num)
|
||||
{
|
||||
num = this.points[j].y;
|
||||
result = this.points[j].x;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
float result2 = 0f;
|
||||
float num2 = 0f;
|
||||
|
||||
for (int k = 0; k < this.points.Count; k++)
|
||||
{
|
||||
if (k == 0 || this.points[k].y > num2)
|
||||
{
|
||||
num2 = this.points[k].y;
|
||||
result2 = this.points[k].x;
|
||||
}
|
||||
}
|
||||
|
||||
return result2;
|
||||
}
|
||||
|
||||
public float PeriodProbabilityFromCumulative(float startX, float span)
|
||||
{
|
||||
if (this.points.Count < 2)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
if (this.points[0].y != 0f)
|
||||
{
|
||||
Debug.Log("PeriodProbabilityFromCumulative should only run on curves whose first point is 0.");
|
||||
}
|
||||
|
||||
float num = this.Evaluate(startX + span) - this.Evaluate(startX);
|
||||
|
||||
if (num < 0f)
|
||||
{
|
||||
Debug.Log("PeriodicProbability got negative probability from " + this + ": slope should never be negative.");
|
||||
num = 0f;
|
||||
}
|
||||
|
||||
if (num > 1f)
|
||||
{
|
||||
num = 1f;
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
public IEnumerable<string> ConfigErrors(string prefix)
|
||||
{
|
||||
for (int i = 0; i < this.points.Count - 1; i++)
|
||||
{
|
||||
if (this.points[i + 1].x < this.points[i].x)
|
||||
{
|
||||
yield return prefix + ": points are out of order";
|
||||
break;
|
||||
}
|
||||
}
|
||||
yield break;
|
||||
}
|
||||
|
||||
private List<CurvePoint> points = new List<CurvePoint>();
|
||||
|
||||
private static Comparison<CurvePoint> CurvePointsComparer = delegate (CurvePoint a, CurvePoint b)
|
||||
{
|
||||
if (a.x < b.x)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (b.x < a.x)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
}
|
11
Assets/Scripts/SimpleCurve.cs.meta
Normal file
11
Assets/Scripts/SimpleCurve.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bb5baea032352e541961de85524543e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/StandaloneFileBrowser.meta
Normal file
8
Assets/Scripts/StandaloneFileBrowser.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5992c02152ca3114bb1120d7350ac998
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
|
||||
namespace SFB {
|
||||
public interface IStandaloneFileBrowser {
|
||||
string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect);
|
||||
string[] OpenFolderPanel(string title, string directory, bool multiselect);
|
||||
string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions);
|
||||
|
||||
void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions, bool multiselect, Action<string[]> cb);
|
||||
void OpenFolderPanelAsync(string title, string directory, bool multiselect, Action<string[]> cb);
|
||||
void SaveFilePanelAsync(string title, string directory, string defaultName, ExtensionFilter[] extensions, Action<string> cb);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7609f7b6787a54496aa41a3053fcc76a
|
||||
timeCreated: 1483902788
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/StandaloneFileBrowser/Plugins.meta
Normal file
8
Assets/Scripts/StandaloneFileBrowser/Plugins.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ddc4e7b83981f244ba9a26b88c18cb67
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
10
Assets/Scripts/StandaloneFileBrowser/Plugins/Linux.meta
Normal file
10
Assets/Scripts/StandaloneFileBrowser/Plugins/Linux.meta
Normal file
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 82666e520ab4d4cf08bebbb8059cd6f4
|
||||
folderAsset: yes
|
||||
timeCreated: 1538224809
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bd198408642944765b9305bd99404136
|
||||
folderAsset: yes
|
||||
timeCreated: 1538230728
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
|
@ -0,0 +1,126 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b8c465928f1784a3fac8dc3766f7201c
|
||||
timeCreated: 1538230728
|
||||
licenseType: Free
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
platformData:
|
||||
- first:
|
||||
'': Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 1
|
||||
Exclude Editor: 0
|
||||
Exclude Linux: 1
|
||||
Exclude Linux64: 0
|
||||
Exclude LinuxUniversal: 0
|
||||
Exclude OSXIntel: 1
|
||||
Exclude OSXIntel64: 1
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude SamsungTV: 1
|
||||
Exclude Tizen: 1
|
||||
Exclude WebGL: 1
|
||||
Exclude Win: 0
|
||||
Exclude Win64: 0
|
||||
Exclude iOS: 1
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: ARMv7
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: x86_64
|
||||
DefaultValueInitialized: true
|
||||
OS: Linux
|
||||
- first:
|
||||
Facebook: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Facebook: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Samsung TV: SamsungTV
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
STV_MODEL: STANDARD_15
|
||||
- first:
|
||||
Standalone: Linux
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: LinuxUniversal
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: OSXIntel
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: OSXIntel64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Assets/Scripts/StandaloneFileBrowser/Plugins/Ookii.Dialogs.dll
Normal file
BIN
Assets/Scripts/StandaloneFileBrowser/Plugins/Ookii.Dialogs.dll
Normal file
Binary file not shown.
|
@ -0,0 +1,145 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e60958662eed5413d86143a0a69b731e
|
||||
timeCreated: 1491979494
|
||||
licenseType: Pro
|
||||
PluginImporter:
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
platformData:
|
||||
data:
|
||||
first:
|
||||
'': Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 1
|
||||
Exclude Editor: 0
|
||||
Exclude Linux: 1
|
||||
Exclude Linux64: 1
|
||||
Exclude LinuxUniversal: 1
|
||||
Exclude OSXIntel: 1
|
||||
Exclude OSXIntel64: 1
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude WebGL: 1
|
||||
Exclude Win: 0
|
||||
Exclude Win64: 0
|
||||
Exclude iOS: 1
|
||||
data:
|
||||
first:
|
||||
'': Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
OS: AnyOS
|
||||
data:
|
||||
first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: ARMv7
|
||||
data:
|
||||
first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
data:
|
||||
first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
data:
|
||||
first:
|
||||
Facebook: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
data:
|
||||
first:
|
||||
Facebook: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
data:
|
||||
first:
|
||||
Standalone: Linux
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
data:
|
||||
first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
data:
|
||||
first:
|
||||
Standalone: LinuxUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
data:
|
||||
first:
|
||||
Standalone: OSXIntel
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
data:
|
||||
first:
|
||||
Standalone: OSXIntel64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
data:
|
||||
first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
data:
|
||||
first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
data:
|
||||
first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
data:
|
||||
first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
data:
|
||||
first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,40 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 110fdfb459db4fc448a2ccd37e200fa4
|
||||
folderAsset: yes
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Standalone: OSXIntel
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Standalone: OSXIntel64
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 996ea0b0fb9804844ba9595686ee3e7a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildMachineOSBuild</key>
|
||||
<string>18A391</string>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>StandaloneFileBrowser</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.gkngkc.sfb</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>StandaloneFileBrowser</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0 </string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>MacOSX</string>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>CSResourcesFileMapped</key>
|
||||
<true/>
|
||||
<key>DTCompiler</key>
|
||||
<string>com.apple.compilers.llvm.clang.1_0</string>
|
||||
<key>DTPlatformBuild</key>
|
||||
<string>10A255</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>GM</string>
|
||||
<key>DTSDKBuild</key>
|
||||
<string>18A384</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>macosx10.14</string>
|
||||
<key>DTXcode</key>
|
||||
<string>1000</string>
|
||||
<key>DTXcodeBuild</key>
|
||||
<string>10A255</string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ce685769797f44046afa3e567860c94c
|
||||
timeCreated: 1505756861
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a5a66f5db020f344c9327188aec2c060
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ddf122e0e89124ce78aacfeecb3ec554
|
||||
timeCreated: 1508179371
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,90 @@
|
|||
var StandaloneFileBrowserWebGLPlugin = {
|
||||
// Open file.
|
||||
// gameObjectNamePtr: Unique GameObject name. Required for calling back unity with SendMessage.
|
||||
// methodNamePtr: Callback method name on given GameObject.
|
||||
// filter: Filter files. Example filters:
|
||||
// Match all image files: "image/*"
|
||||
// Match all video files: "video/*"
|
||||
// Match all audio files: "audio/*"
|
||||
// Custom: ".plist, .xml, .yaml"
|
||||
// multiselect: Allows multiple file selection
|
||||
UploadFile: function(gameObjectNamePtr, methodNamePtr, filterPtr, multiselect) {
|
||||
gameObjectName = Pointer_stringify(gameObjectNamePtr);
|
||||
methodName = Pointer_stringify(methodNamePtr);
|
||||
filter = Pointer_stringify(filterPtr);
|
||||
|
||||
// Delete if element exist
|
||||
var fileInput = document.getElementById(gameObjectName)
|
||||
if (fileInput) {
|
||||
document.body.removeChild(fileInput);
|
||||
}
|
||||
|
||||
fileInput = document.createElement('input');
|
||||
fileInput.setAttribute('id', gameObjectName);
|
||||
fileInput.setAttribute('type', 'file');
|
||||
fileInput.setAttribute('style','display:none;');
|
||||
fileInput.setAttribute('style','visibility:hidden;');
|
||||
if (multiselect) {
|
||||
fileInput.setAttribute('multiple', '');
|
||||
}
|
||||
if (filter) {
|
||||
fileInput.setAttribute('accept', filter);
|
||||
}
|
||||
fileInput.onclick = function (event) {
|
||||
// File dialog opened
|
||||
this.value = null;
|
||||
};
|
||||
fileInput.onchange = function (event) {
|
||||
// multiselect works
|
||||
var urls = [];
|
||||
for (var i = 0; i < event.target.files.length; i++) {
|
||||
urls.push(URL.createObjectURL(event.target.files[i]));
|
||||
}
|
||||
// File selected
|
||||
SendMessage(gameObjectName, methodName, urls.join());
|
||||
|
||||
// Remove after file selected
|
||||
document.body.removeChild(fileInput);
|
||||
}
|
||||
document.body.appendChild(fileInput);
|
||||
|
||||
document.onmouseup = function() {
|
||||
fileInput.click();
|
||||
document.onmouseup = null;
|
||||
}
|
||||
},
|
||||
|
||||
// Save file
|
||||
// DownloadFile method does not open SaveFileDialog like standalone builds, its just allows user to download file
|
||||
// gameObjectNamePtr: Unique GameObject name. Required for calling back unity with SendMessage.
|
||||
// methodNamePtr: Callback method name on given GameObject.
|
||||
// filenamePtr: Filename with extension
|
||||
// byteArray: byte[]
|
||||
// byteArraySize: byte[].Length
|
||||
DownloadFile: function(gameObjectNamePtr, methodNamePtr, filenamePtr, byteArray, byteArraySize) {
|
||||
gameObjectName = Pointer_stringify(gameObjectNamePtr);
|
||||
methodName = Pointer_stringify(methodNamePtr);
|
||||
filename = Pointer_stringify(filenamePtr);
|
||||
|
||||
var bytes = new Uint8Array(byteArraySize);
|
||||
for (var i = 0; i < byteArraySize; i++) {
|
||||
bytes[i] = HEAPU8[byteArray + i];
|
||||
}
|
||||
|
||||
var downloader = window.document.createElement('a');
|
||||
downloader.setAttribute('id', gameObjectName);
|
||||
downloader.href = window.URL.createObjectURL(new Blob([bytes], { type: 'application/octet-stream' }));
|
||||
downloader.download = filename;
|
||||
document.body.appendChild(downloader);
|
||||
|
||||
document.onmouseup = function() {
|
||||
downloader.click();
|
||||
document.body.removeChild(downloader);
|
||||
document.onmouseup = null;
|
||||
|
||||
SendMessage(gameObjectName, methodName);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mergeInto(LibraryManager.library, StandaloneFileBrowserWebGLPlugin);
|
|
@ -0,0 +1,96 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 265aaf20a6d564e0fb00a9c4a7a9c300
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
platformData:
|
||||
- first:
|
||||
'': Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Editor: 1
|
||||
Exclude Linux: 1
|
||||
Exclude Linux64: 1
|
||||
Exclude LinuxUniversal: 1
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude Win: 1
|
||||
Exclude Win64: 1
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
- first:
|
||||
Facebook: WebGL
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Facebook: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Facebook: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Standalone: Linux
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: LinuxUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
- first:
|
||||
WebGL: WebGL
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
|
@ -0,0 +1,145 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7d459a96865cc4aaab657012c6dc4833
|
||||
timeCreated: 1491979494
|
||||
licenseType: Pro
|
||||
PluginImporter:
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
platformData:
|
||||
data:
|
||||
first:
|
||||
'': Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 1
|
||||
Exclude Editor: 0
|
||||
Exclude Linux: 1
|
||||
Exclude Linux64: 1
|
||||
Exclude LinuxUniversal: 1
|
||||
Exclude OSXIntel: 1
|
||||
Exclude OSXIntel64: 1
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude WebGL: 1
|
||||
Exclude Win: 0
|
||||
Exclude Win64: 0
|
||||
Exclude iOS: 1
|
||||
data:
|
||||
first:
|
||||
'': Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
OS: AnyOS
|
||||
data:
|
||||
first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: ARMv7
|
||||
data:
|
||||
first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
data:
|
||||
first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
data:
|
||||
first:
|
||||
Facebook: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
data:
|
||||
first:
|
||||
Facebook: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
data:
|
||||
first:
|
||||
Standalone: Linux
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
data:
|
||||
first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
data:
|
||||
first:
|
||||
Standalone: LinuxUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
data:
|
||||
first:
|
||||
Standalone: OSXIntel
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
data:
|
||||
first:
|
||||
Standalone: OSXIntel64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
data:
|
||||
first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
data:
|
||||
first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
data:
|
||||
first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
data:
|
||||
first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
data:
|
||||
first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/StandaloneFileBrowser/Sample.meta
Normal file
8
Assets/Scripts/StandaloneFileBrowser/Sample.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 435c74f62ab57b448adeeb37cbc0f96b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
119
Assets/Scripts/StandaloneFileBrowser/Sample/BasicSample.cs
Normal file
119
Assets/Scripts/StandaloneFileBrowser/Sample/BasicSample.cs
Normal file
|
@ -0,0 +1,119 @@
|
|||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using SFB;
|
||||
|
||||
public class BasicSample : MonoBehaviour {
|
||||
private string _path;
|
||||
|
||||
void OnGUI() {
|
||||
var guiScale = new Vector3(Screen.width / 800.0f, Screen.height / 600.0f, 1.0f);
|
||||
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, guiScale);
|
||||
|
||||
GUILayout.Space(20);
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space(20);
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
// Open File Samples
|
||||
|
||||
if (GUILayout.Button("Open File")) {
|
||||
WriteResult(StandaloneFileBrowser.OpenFilePanel("Open File", "", "", false));
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Open File Async")) {
|
||||
StandaloneFileBrowser.OpenFilePanelAsync("Open File", "", "", false, (string[] paths) => { WriteResult(paths); });
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Open File Multiple")) {
|
||||
WriteResult(StandaloneFileBrowser.OpenFilePanel("Open File", "", "", true));
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Open File Extension")) {
|
||||
WriteResult(StandaloneFileBrowser.OpenFilePanel("Open File", "", "txt", true));
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Open File Directory")) {
|
||||
WriteResult(StandaloneFileBrowser.OpenFilePanel("Open File", Application.dataPath, "", true));
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Open File Filter")) {
|
||||
var extensions = new [] {
|
||||
new ExtensionFilter("Image Files", "png", "jpg", "jpeg" ),
|
||||
new ExtensionFilter("Sound Files", "mp3", "wav" ),
|
||||
new ExtensionFilter("All Files", "*" ),
|
||||
};
|
||||
WriteResult(StandaloneFileBrowser.OpenFilePanel("Open File", "", extensions, true));
|
||||
}
|
||||
|
||||
GUILayout.Space(15);
|
||||
|
||||
// Open Folder Samples
|
||||
|
||||
if (GUILayout.Button("Open Folder")) {
|
||||
var paths = StandaloneFileBrowser.OpenFolderPanel("Select Folder", "", true);
|
||||
WriteResult(paths);
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Open Folder Async")) {
|
||||
StandaloneFileBrowser.OpenFolderPanelAsync("Select Folder", "", true, (string[] paths) => { WriteResult(paths); });
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Open Folder Directory")) {
|
||||
var paths = StandaloneFileBrowser.OpenFolderPanel("Select Folder", Application.dataPath, true);
|
||||
WriteResult(paths);
|
||||
}
|
||||
|
||||
GUILayout.Space(15);
|
||||
|
||||
// Save File Samples
|
||||
|
||||
if (GUILayout.Button("Save File")) {
|
||||
_path = StandaloneFileBrowser.SaveFilePanel("Save File", "", "", "");
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Save File Async")) {
|
||||
StandaloneFileBrowser.SaveFilePanelAsync("Save File", "", "", "", (string path) => { WriteResult(path); });
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Save File Default Name")) {
|
||||
_path = StandaloneFileBrowser.SaveFilePanel("Save File", "", "MySaveFile", "");
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Save File Default Name Ext")) {
|
||||
_path = StandaloneFileBrowser.SaveFilePanel("Save File", "", "MySaveFile", "dat");
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Save File Directory")) {
|
||||
_path = StandaloneFileBrowser.SaveFilePanel("Save File", Application.dataPath, "", "");
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Save File Filter")) {
|
||||
// Multiple save extension filters with more than one extension support.
|
||||
var extensionList = new [] {
|
||||
new ExtensionFilter("Binary", "bin"),
|
||||
new ExtensionFilter("Text", "txt"),
|
||||
};
|
||||
_path = StandaloneFileBrowser.SaveFilePanel("Save File", "", "MySaveFile", extensionList);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.Space(20);
|
||||
GUILayout.Label(_path);
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public void WriteResult(string[] paths) {
|
||||
if (paths.Length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
_path = "";
|
||||
foreach (var p in paths) {
|
||||
_path += p + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteResult(string path) {
|
||||
_path = path;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5148400295519405d82bb0fa65246ea2
|
||||
timeCreated: 1483902788
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,248 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!29 &1
|
||||
OcclusionCullingSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_OcclusionBakeSettings:
|
||||
smallestOccluder: 5
|
||||
smallestHole: 0.25
|
||||
backfaceThreshold: 100
|
||||
m_SceneGUID: 00000000000000000000000000000000
|
||||
m_OcclusionCullingData: {fileID: 0}
|
||||
--- !u!104 &2
|
||||
RenderSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 9
|
||||
m_Fog: 0
|
||||
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
||||
m_FogMode: 3
|
||||
m_FogDensity: 0.01
|
||||
m_LinearFogStart: 0
|
||||
m_LinearFogEnd: 300
|
||||
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
|
||||
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
|
||||
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
|
||||
m_AmbientIntensity: 1
|
||||
m_AmbientMode: 3
|
||||
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
|
||||
m_SkyboxMaterial: {fileID: 0}
|
||||
m_HaloStrength: 0.5
|
||||
m_FlareStrength: 1
|
||||
m_FlareFadeSpeed: 3
|
||||
m_HaloTexture: {fileID: 0}
|
||||
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_DefaultReflectionMode: 0
|
||||
m_DefaultReflectionResolution: 128
|
||||
m_ReflectionBounces: 1
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 0}
|
||||
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 11
|
||||
m_GIWorkflowMode: 1
|
||||
m_GISettings:
|
||||
serializedVersion: 2
|
||||
m_BounceScale: 1
|
||||
m_IndirectOutputScale: 1
|
||||
m_AlbedoBoost: 1
|
||||
m_TemporalCoherenceThreshold: 1
|
||||
m_EnvironmentLightingMode: 0
|
||||
m_EnableBakedLightmaps: 0
|
||||
m_EnableRealtimeLightmaps: 0
|
||||
m_LightmapEditorSettings:
|
||||
serializedVersion: 10
|
||||
m_Resolution: 2
|
||||
m_BakeResolution: 40
|
||||
m_AtlasSize: 1024
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 1
|
||||
m_CompAOExponentDirect: 0
|
||||
m_Padding: 2
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_LightmapsBakeMode: 1
|
||||
m_TextureCompression: 1
|
||||
m_FinalGather: 0
|
||||
m_FinalGatherFiltering: 1
|
||||
m_FinalGatherRayCount: 256
|
||||
m_ReflectionCompression: 2
|
||||
m_MixedBakeMode: 1
|
||||
m_BakeBackend: 0
|
||||
m_PVRSampling: 1
|
||||
m_PVRDirectSampleCount: 32
|
||||
m_PVRSampleCount: 500
|
||||
m_PVRBounces: 2
|
||||
m_PVRFilterTypeDirect: 0
|
||||
m_PVRFilterTypeIndirect: 0
|
||||
m_PVRFilterTypeAO: 0
|
||||
m_PVRFilteringMode: 0
|
||||
m_PVRCulling: 1
|
||||
m_PVRFilteringGaussRadiusDirect: 1
|
||||
m_PVRFilteringGaussRadiusIndirect: 5
|
||||
m_PVRFilteringGaussRadiusAO: 2
|
||||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||
m_ShowResolutionOverlay: 1
|
||||
m_LightingDataAsset: {fileID: 0}
|
||||
m_UseShadowmask: 0
|
||||
--- !u!196 &4
|
||||
NavMeshSettings:
|
||||
serializedVersion: 2
|
||||
m_ObjectHideFlags: 0
|
||||
m_BuildSettings:
|
||||
serializedVersion: 2
|
||||
agentTypeID: 0
|
||||
agentRadius: 0.5
|
||||
agentHeight: 2
|
||||
agentSlope: 45
|
||||
agentClimb: 0.4
|
||||
ledgeDropHeight: 0
|
||||
maxJumpAcrossDistance: 0
|
||||
minRegionArea: 2
|
||||
manualCellSize: 0
|
||||
cellSize: 0.16666667
|
||||
manualTileSize: 0
|
||||
tileSize: 256
|
||||
accuratePlacement: 0
|
||||
debug:
|
||||
m_Flags: 0
|
||||
m_NavMeshData: {fileID: 0}
|
||||
--- !u!1 &382763637
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 382763642}
|
||||
- component: {fileID: 382763641}
|
||||
- component: {fileID: 382763640}
|
||||
- component: {fileID: 382763639}
|
||||
- component: {fileID: 382763638}
|
||||
m_Layer: 0
|
||||
m_Name: Main Camera
|
||||
m_TagString: MainCamera
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!81 &382763638
|
||||
AudioListener:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 382763637}
|
||||
m_Enabled: 1
|
||||
--- !u!124 &382763639
|
||||
Behaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 382763637}
|
||||
m_Enabled: 1
|
||||
--- !u!92 &382763640
|
||||
Behaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 382763637}
|
||||
m_Enabled: 1
|
||||
--- !u!20 &382763641
|
||||
Camera:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 382763637}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_ClearFlags: 1
|
||||
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
|
||||
m_projectionMatrixMode: 1
|
||||
m_SensorSize: {x: 36, y: 24}
|
||||
m_LensShift: {x: 0, y: 0}
|
||||
m_FocalLength: 50
|
||||
m_NormalizedViewPortRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
near clip plane: 0.3
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 1
|
||||
orthographic size: 5
|
||||
m_Depth: -1
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingPath: -1
|
||||
m_TargetTexture: {fileID: 0}
|
||||
m_TargetDisplay: 0
|
||||
m_TargetEye: 3
|
||||
m_HDR: 0
|
||||
m_AllowMSAA: 1
|
||||
m_AllowDynamicResolution: 0
|
||||
m_ForceIntoRT: 0
|
||||
m_OcclusionCulling: 1
|
||||
m_StereoConvergence: 10
|
||||
m_StereoSeparation: 0.022
|
||||
--- !u!4 &382763642
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 382763637}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: -10}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &986049433
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 986049435}
|
||||
- component: {fileID: 986049434}
|
||||
m_Layer: 0
|
||||
m_Name: GameObject
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &986049434
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 986049433}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 5148400295519405d82bb0fa65246ea2, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!4 &986049435
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 986049433}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d97280fe82b874466870f709c3315d41
|
||||
timeCreated: 1483902786
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,53 @@
|
|||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using SFB;
|
||||
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class CanvasSampleOpenFileImage : MonoBehaviour, IPointerDownHandler {
|
||||
public RawImage output;
|
||||
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
//
|
||||
// WebGL
|
||||
//
|
||||
[DllImport("__Internal")]
|
||||
private static extern void UploadFile(string gameObjectName, string methodName, string filter, bool multiple);
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData) {
|
||||
UploadFile(gameObject.name, "OnFileUpload", ".png, .jpg", false);
|
||||
}
|
||||
|
||||
// Called from browser
|
||||
public void OnFileUpload(string url) {
|
||||
StartCoroutine(OutputRoutine(url));
|
||||
}
|
||||
#else
|
||||
//
|
||||
// Standalone platforms & editor
|
||||
//
|
||||
public void OnPointerDown(PointerEventData eventData) { }
|
||||
|
||||
void Start() {
|
||||
var button = GetComponent<Button>();
|
||||
button.onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
private void OnClick() {
|
||||
var paths = StandaloneFileBrowser.OpenFilePanel("Title", "", ".png", false);
|
||||
if (paths.Length > 0) {
|
||||
StartCoroutine(OutputRoutine(new System.Uri(paths[0]).AbsoluteUri));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private IEnumerator OutputRoutine(string url) {
|
||||
var loader = new WWW(url);
|
||||
yield return loader;
|
||||
output.texture = loader.texture;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 331c95b7bf39e4792acecff50a972040
|
||||
timeCreated: 1489946149
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,53 @@
|
|||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using SFB;
|
||||
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class CanvasSampleOpenFileText : MonoBehaviour, IPointerDownHandler {
|
||||
public Text output;
|
||||
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
//
|
||||
// WebGL
|
||||
//
|
||||
[DllImport("__Internal")]
|
||||
private static extern void UploadFile(string gameObjectName, string methodName, string filter, bool multiple);
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData) {
|
||||
UploadFile(gameObject.name, "OnFileUpload", ".txt", false);
|
||||
}
|
||||
|
||||
// Called from browser
|
||||
public void OnFileUpload(string url) {
|
||||
StartCoroutine(OutputRoutine(url));
|
||||
}
|
||||
#else
|
||||
//
|
||||
// Standalone platforms & editor
|
||||
//
|
||||
public void OnPointerDown(PointerEventData eventData) { }
|
||||
|
||||
void Start() {
|
||||
var button = GetComponent<Button>();
|
||||
button.onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
private void OnClick() {
|
||||
var paths = StandaloneFileBrowser.OpenFilePanel("Title", "", "txt", false);
|
||||
if (paths.Length > 0) {
|
||||
StartCoroutine(OutputRoutine(new System.Uri(paths[0]).AbsoluteUri));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private IEnumerator OutputRoutine(string url) {
|
||||
var loader = new WWW(url);
|
||||
yield return loader;
|
||||
output.text = loader.text;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 99a65d6437df64949b37cba4eadc67a2
|
||||
timeCreated: 1489946149
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,62 @@
|
|||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using SFB;
|
||||
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class CanvasSampleOpenFileTextMultiple : MonoBehaviour, IPointerDownHandler {
|
||||
public Text output;
|
||||
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
//
|
||||
// WebGL
|
||||
//
|
||||
[DllImport("__Internal")]
|
||||
private static extern void UploadFile(string gameObjectName, string methodName, string filter, bool multiple);
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData) {
|
||||
UploadFile(gameObject.name, "OnFileUpload", ".txt", true);
|
||||
}
|
||||
|
||||
// Called from browser
|
||||
public void OnFileUpload(string urls) {
|
||||
StartCoroutine(OutputRoutine(urls.Split(',')));
|
||||
}
|
||||
#else
|
||||
//
|
||||
// Standalone platforms & editor
|
||||
//
|
||||
public void OnPointerDown(PointerEventData eventData) { }
|
||||
|
||||
void Start() {
|
||||
var button = GetComponent<Button>();
|
||||
button.onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
private void OnClick() {
|
||||
// var paths = StandaloneFileBrowser.OpenFilePanel("Title", "", "txt", true);
|
||||
var paths = StandaloneFileBrowser.OpenFilePanel("Open File", "", "", true);
|
||||
if (paths.Length > 0) {
|
||||
var urlArr = new List<string>(paths.Length);
|
||||
for (int i = 0; i < paths.Length; i++) {
|
||||
urlArr.Add(new System.Uri(paths[i]).AbsoluteUri);
|
||||
}
|
||||
StartCoroutine(OutputRoutine(urlArr.ToArray()));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private IEnumerator OutputRoutine(string[] urlArr) {
|
||||
var outputText = "";
|
||||
for (int i = 0; i < urlArr.Length; i++) {
|
||||
var loader = new WWW(urlArr[i]);
|
||||
yield return loader;
|
||||
outputText += loader.text;
|
||||
}
|
||||
output.text = outputText;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 71c09849449d61e47a4599e06b964998
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,65 @@
|
|||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using SFB;
|
||||
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class CanvasSampleSaveFileImage : MonoBehaviour, IPointerDownHandler {
|
||||
public Text output;
|
||||
|
||||
private byte[] _textureBytes;
|
||||
|
||||
void Awake() {
|
||||
// Create red texture
|
||||
var width = 100;
|
||||
var height = 100;
|
||||
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
tex.SetPixel(i, j, Color.red);
|
||||
}
|
||||
}
|
||||
tex.Apply();
|
||||
_textureBytes = tex.EncodeToPNG();
|
||||
UnityEngine.Object.Destroy(tex);
|
||||
}
|
||||
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
//
|
||||
// WebGL
|
||||
//
|
||||
[DllImport("__Internal")]
|
||||
private static extern void DownloadFile(string gameObjectName, string methodName, string filename, byte[] byteArray, int byteArraySize);
|
||||
|
||||
// Broser plugin should be called in OnPointerDown.
|
||||
public void OnPointerDown(PointerEventData eventData) {
|
||||
DownloadFile(gameObject.name, "OnFileDownload", "sample.png", _textureBytes, _textureBytes.Length);
|
||||
}
|
||||
|
||||
// Called from browser
|
||||
public void OnFileDownload() {
|
||||
output.text = "File Successfully Downloaded";
|
||||
}
|
||||
#else
|
||||
//
|
||||
// Standalone platforms & editor
|
||||
//
|
||||
public void OnPointerDown(PointerEventData eventData) { }
|
||||
|
||||
// Listen OnClick event in standlone builds
|
||||
void Start() {
|
||||
var button = GetComponent<Button>();
|
||||
button.onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
public void OnClick() {
|
||||
var path = StandaloneFileBrowser.SaveFilePanel("Title", "", "sample", "png");
|
||||
if (!string.IsNullOrEmpty(path)) {
|
||||
File.WriteAllBytes(path, _textureBytes);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6e681018aa67241a69b8447678ec3b4e
|
||||
timeCreated: 1489946149
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,52 @@
|
|||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using SFB;
|
||||
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class CanvasSampleSaveFileText : MonoBehaviour, IPointerDownHandler {
|
||||
public Text output;
|
||||
|
||||
// Sample text data
|
||||
private string _data = "Example text created by StandaloneFileBrowser";
|
||||
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
//
|
||||
// WebGL
|
||||
//
|
||||
[DllImport("__Internal")]
|
||||
private static extern void DownloadFile(string gameObjectName, string methodName, string filename, byte[] byteArray, int byteArraySize);
|
||||
|
||||
// Broser plugin should be called in OnPointerDown.
|
||||
public void OnPointerDown(PointerEventData eventData) {
|
||||
var bytes = Encoding.UTF8.GetBytes(_data);
|
||||
DownloadFile(gameObject.name, "OnFileDownload", "sample.txt", bytes, bytes.Length);
|
||||
}
|
||||
|
||||
// Called from browser
|
||||
public void OnFileDownload() {
|
||||
output.text = "File Successfully Downloaded";
|
||||
}
|
||||
#else
|
||||
//
|
||||
// Standalone platforms & editor
|
||||
//
|
||||
public void OnPointerDown(PointerEventData eventData) { }
|
||||
|
||||
// Listen OnClick event in standlone builds
|
||||
void Start() {
|
||||
var button = GetComponent<Button>();
|
||||
button.onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
public void OnClick() {
|
||||
var path = StandaloneFileBrowser.SaveFilePanel("Title", "", "sample", "txt");
|
||||
if (!string.IsNullOrEmpty(path)) {
|
||||
File.WriteAllText(path, _data);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8e97f52f0bd664ee78305dae0094a755
|
||||
timeCreated: 1489946149
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1520
Assets/Scripts/StandaloneFileBrowser/Sample/CanvasSampleScene.unity
Normal file
1520
Assets/Scripts/StandaloneFileBrowser/Sample/CanvasSampleScene.unity
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c0e4eec5741834194a946535d535405c
|
||||
timeCreated: 1483902786
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
153
Assets/Scripts/StandaloneFileBrowser/StandaloneFileBrowser.cs
Normal file
153
Assets/Scripts/StandaloneFileBrowser/StandaloneFileBrowser.cs
Normal file
|
@ -0,0 +1,153 @@
|
|||
using System;
|
||||
|
||||
namespace SFB {
|
||||
public struct ExtensionFilter {
|
||||
public string Name;
|
||||
public string[] Extensions;
|
||||
|
||||
public ExtensionFilter(string filterName, params string[] filterExtensions) {
|
||||
Name = filterName;
|
||||
Extensions = filterExtensions;
|
||||
}
|
||||
}
|
||||
|
||||
public class StandaloneFileBrowser {
|
||||
private static IStandaloneFileBrowser _platformWrapper = null;
|
||||
|
||||
static StandaloneFileBrowser() {
|
||||
#if UNITY_STANDALONE_OSX
|
||||
_platformWrapper = new StandaloneFileBrowserMac();
|
||||
#elif UNITY_STANDALONE_WIN
|
||||
_platformWrapper = new StandaloneFileBrowserWindows();
|
||||
#elif UNITY_STANDALONE_LINUX
|
||||
_platformWrapper = new StandaloneFileBrowserLinux();
|
||||
#elif UNITY_EDITOR
|
||||
_platformWrapper = new StandaloneFileBrowserEditor();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native open file dialog
|
||||
/// </summary>
|
||||
/// <param name="title">Dialog title</param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="extension">Allowed extension</param>
|
||||
/// <param name="multiselect">Allow multiple file selection</param>
|
||||
/// <returns>Returns array of chosen paths. Zero length array when cancelled</returns>
|
||||
public static string[] OpenFilePanel(string title, string directory, string extension, bool multiselect) {
|
||||
var extensions = string.IsNullOrEmpty(extension) ? null : new [] { new ExtensionFilter("", extension) };
|
||||
return OpenFilePanel(title, directory, extensions, multiselect);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native open file dialog
|
||||
/// </summary>
|
||||
/// <param name="title">Dialog title</param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="extensions">List of extension filters. Filter Example: new ExtensionFilter("Image Files", "jpg", "png")</param>
|
||||
/// <param name="multiselect">Allow multiple file selection</param>
|
||||
/// <returns>Returns array of chosen paths. Zero length array when cancelled</returns>
|
||||
public static string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect) {
|
||||
return _platformWrapper.OpenFilePanel(title, directory, extensions, multiselect);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native open file dialog async
|
||||
/// </summary>
|
||||
/// <param name="title">Dialog title</param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="extension">Allowed extension</param>
|
||||
/// <param name="multiselect">Allow multiple file selection</param>
|
||||
/// <param name="cb">Callback")</param>
|
||||
public static void OpenFilePanelAsync(string title, string directory, string extension, bool multiselect, Action<string[]> cb) {
|
||||
var extensions = string.IsNullOrEmpty(extension) ? null : new [] { new ExtensionFilter("", extension) };
|
||||
OpenFilePanelAsync(title, directory, extensions, multiselect, cb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native open file dialog async
|
||||
/// </summary>
|
||||
/// <param name="title">Dialog title</param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="extensions">List of extension filters. Filter Example: new ExtensionFilter("Image Files", "jpg", "png")</param>
|
||||
/// <param name="multiselect">Allow multiple file selection</param>
|
||||
/// <param name="cb">Callback")</param>
|
||||
public static void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions, bool multiselect, Action<string[]> cb) {
|
||||
_platformWrapper.OpenFilePanelAsync(title, directory, extensions, multiselect, cb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native open folder dialog
|
||||
/// NOTE: Multiple folder selection doesn't supported on Windows
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="multiselect"></param>
|
||||
/// <returns>Returns array of chosen paths. Zero length array when cancelled</returns>
|
||||
public static string[] OpenFolderPanel(string title, string directory, bool multiselect) {
|
||||
return _platformWrapper.OpenFolderPanel(title, directory, multiselect);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native open folder dialog async
|
||||
/// NOTE: Multiple folder selection doesn't supported on Windows
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="multiselect"></param>
|
||||
/// <param name="cb">Callback")</param>
|
||||
public static void OpenFolderPanelAsync(string title, string directory, bool multiselect, Action<string[]> cb) {
|
||||
_platformWrapper.OpenFolderPanelAsync(title, directory, multiselect, cb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native save file dialog
|
||||
/// </summary>
|
||||
/// <param name="title">Dialog title</param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="defaultName">Default file name</param>
|
||||
/// <param name="extension">File extension</param>
|
||||
/// <returns>Returns chosen path. Empty string when cancelled</returns>
|
||||
public static string SaveFilePanel(string title, string directory, string defaultName , string extension) {
|
||||
var extensions = string.IsNullOrEmpty(extension) ? null : new [] { new ExtensionFilter("", extension) };
|
||||
return SaveFilePanel(title, directory, defaultName, extensions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native save file dialog
|
||||
/// </summary>
|
||||
/// <param name="title">Dialog title</param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="defaultName">Default file name</param>
|
||||
/// <param name="extensions">List of extension filters. Filter Example: new ExtensionFilter("Image Files", "jpg", "png")</param>
|
||||
/// <returns>Returns chosen path. Empty string when cancelled</returns>
|
||||
public static string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions) {
|
||||
return _platformWrapper.SaveFilePanel(title, directory, defaultName, extensions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native save file dialog async
|
||||
/// </summary>
|
||||
/// <param name="title">Dialog title</param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="defaultName">Default file name</param>
|
||||
/// <param name="extension">File extension</param>
|
||||
/// <param name="cb">Callback")</param>
|
||||
public static void SaveFilePanelAsync(string title, string directory, string defaultName , string extension, Action<string> cb) {
|
||||
var extensions = string.IsNullOrEmpty(extension) ? null : new [] { new ExtensionFilter("", extension) };
|
||||
SaveFilePanelAsync(title, directory, defaultName, extensions, cb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Native save file dialog async
|
||||
/// </summary>
|
||||
/// <param name="title">Dialog title</param>
|
||||
/// <param name="directory">Root directory</param>
|
||||
/// <param name="defaultName">Default file name</param>
|
||||
/// <param name="extensions">List of extension filters. Filter Example: new ExtensionFilter("Image Files", "jpg", "png")</param>
|
||||
/// <param name="cb">Callback")</param>
|
||||
public static void SaveFilePanelAsync(string title, string directory, string defaultName, ExtensionFilter[] extensions, Action<string> cb) {
|
||||
_platformWrapper.SaveFilePanelAsync(title, directory, defaultName, extensions, cb);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3c708be74128e4ced9b79eaaf80e8443
|
||||
timeCreated: 1483902788
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,56 @@
|
|||
#if UNITY_EDITOR
|
||||
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace SFB {
|
||||
public class StandaloneFileBrowserEditor : IStandaloneFileBrowser {
|
||||
public string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect) {
|
||||
string path = "";
|
||||
|
||||
if (extensions == null) {
|
||||
path = EditorUtility.OpenFilePanel(title, directory, "");
|
||||
}
|
||||
else {
|
||||
path = EditorUtility.OpenFilePanelWithFilters(title, directory, GetFilterFromFileExtensionList(extensions));
|
||||
}
|
||||
|
||||
return string.IsNullOrEmpty(path) ? new string[0] : new[] { path };
|
||||
}
|
||||
|
||||
public void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions, bool multiselect, Action<string[]> cb) {
|
||||
cb.Invoke(OpenFilePanel(title, directory, extensions, multiselect));
|
||||
}
|
||||
|
||||
public string[] OpenFolderPanel(string title, string directory, bool multiselect) {
|
||||
var path = EditorUtility.OpenFolderPanel(title, directory, "");
|
||||
return string.IsNullOrEmpty(path) ? new string[0] : new[] {path};
|
||||
}
|
||||
|
||||
public void OpenFolderPanelAsync(string title, string directory, bool multiselect, Action<string[]> cb) {
|
||||
cb.Invoke(OpenFolderPanel(title, directory, multiselect));
|
||||
}
|
||||
|
||||
public string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions) {
|
||||
var ext = extensions != null ? extensions[0].Extensions[0] : "";
|
||||
var name = string.IsNullOrEmpty(ext) ? defaultName : defaultName + "." + ext;
|
||||
return EditorUtility.SaveFilePanel(title, directory, name, ext);
|
||||
}
|
||||
|
||||
public void SaveFilePanelAsync(string title, string directory, string defaultName, ExtensionFilter[] extensions, Action<string> cb) {
|
||||
cb.Invoke(SaveFilePanel(title, directory, defaultName, extensions));
|
||||
}
|
||||
|
||||
// EditorUtility.OpenFilePanelWithFilters extension filter format
|
||||
private static string[] GetFilterFromFileExtensionList(ExtensionFilter[] extensions) {
|
||||
var filters = new string[extensions.Length * 2];
|
||||
for (int i = 0; i < extensions.Length; i++) {
|
||||
filters[(i * 2)] = extensions[i].Name;
|
||||
filters[(i * 2) + 1] = string.Join(",", extensions[i].Extensions);
|
||||
}
|
||||
return filters;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2650af8de2cda46b99b1bc7cf5d30ca5
|
||||
timeCreated: 1483902788
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,115 @@
|
|||
#if UNITY_STANDALONE_LINUX
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SFB {
|
||||
|
||||
public class StandaloneFileBrowserLinux : IStandaloneFileBrowser {
|
||||
|
||||
private static Action<string[]> _openFileCb;
|
||||
private static Action<string[]> _openFolderCb;
|
||||
private static Action<string> _saveFileCb;
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
public delegate void AsyncCallback(string path);
|
||||
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern void DialogInit();
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern IntPtr DialogOpenFilePanel(string title, string directory, string extension, bool multiselect);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern void DialogOpenFilePanelAsync(string title, string directory, string extension, bool multiselect, AsyncCallback callback);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern IntPtr DialogOpenFolderPanel(string title, string directory, bool multiselect);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern void DialogOpenFolderPanelAsync(string title, string directory, bool multiselect, AsyncCallback callback);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern IntPtr DialogSaveFilePanel(string title, string directory, string defaultName, string extension);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern void DialogSaveFilePanelAsync(string title, string directory, string defaultName, string extension, AsyncCallback callback);
|
||||
|
||||
public StandaloneFileBrowserLinux()
|
||||
{
|
||||
DialogInit();
|
||||
}
|
||||
|
||||
public string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect) {
|
||||
var paths = Marshal.PtrToStringAnsi(DialogOpenFilePanel(
|
||||
title,
|
||||
directory,
|
||||
GetFilterFromFileExtensionList(extensions),
|
||||
multiselect));
|
||||
return paths.Split((char)28);
|
||||
}
|
||||
|
||||
public void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions, bool multiselect, Action<string[]> cb) {
|
||||
_openFileCb = cb;
|
||||
DialogOpenFilePanelAsync(
|
||||
title,
|
||||
directory,
|
||||
GetFilterFromFileExtensionList(extensions),
|
||||
multiselect,
|
||||
(string result) => { _openFileCb.Invoke(result.Split((char)28)); });
|
||||
}
|
||||
|
||||
public string[] OpenFolderPanel(string title, string directory, bool multiselect) {
|
||||
var paths = Marshal.PtrToStringAnsi(DialogOpenFolderPanel(
|
||||
title,
|
||||
directory,
|
||||
multiselect));
|
||||
return paths.Split((char)28);
|
||||
}
|
||||
|
||||
public void OpenFolderPanelAsync(string title, string directory, bool multiselect, Action<string[]> cb) {
|
||||
_openFolderCb = cb;
|
||||
DialogOpenFolderPanelAsync(
|
||||
title,
|
||||
directory,
|
||||
multiselect,
|
||||
(string result) => { _openFolderCb.Invoke(result.Split((char)28)); });
|
||||
}
|
||||
|
||||
public string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions) {
|
||||
return Marshal.PtrToStringAnsi(DialogSaveFilePanel(
|
||||
title,
|
||||
directory,
|
||||
defaultName,
|
||||
GetFilterFromFileExtensionList(extensions)));
|
||||
}
|
||||
|
||||
public void SaveFilePanelAsync(string title, string directory, string defaultName, ExtensionFilter[] extensions, Action<string> cb) {
|
||||
_saveFileCb = cb;
|
||||
DialogSaveFilePanelAsync(
|
||||
title,
|
||||
directory,
|
||||
defaultName,
|
||||
GetFilterFromFileExtensionList(extensions),
|
||||
(string result) => { _saveFileCb.Invoke(result); });
|
||||
}
|
||||
|
||||
private static string GetFilterFromFileExtensionList(ExtensionFilter[] extensions) {
|
||||
if (extensions == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
var filterString = "";
|
||||
foreach (var filter in extensions) {
|
||||
filterString += filter.Name + ";";
|
||||
|
||||
foreach (var ext in filter.Extensions) {
|
||||
filterString += ext + ",";
|
||||
}
|
||||
|
||||
filterString = filterString.Remove(filterString.Length - 1);
|
||||
filterString += "|";
|
||||
}
|
||||
filterString = filterString.Remove(filterString.Length - 1);
|
||||
return filterString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5d3a668018554b8a89c3fe12de72b60c
|
||||
timeCreated: 1538067919
|
119
Assets/Scripts/StandaloneFileBrowser/StandaloneFileBrowserMac.cs
Normal file
119
Assets/Scripts/StandaloneFileBrowser/StandaloneFileBrowserMac.cs
Normal file
|
@ -0,0 +1,119 @@
|
|||
#if UNITY_STANDALONE_OSX
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SFB {
|
||||
public class StandaloneFileBrowserMac : IStandaloneFileBrowser {
|
||||
private static Action<string[]> _openFileCb;
|
||||
private static Action<string[]> _openFolderCb;
|
||||
private static Action<string> _saveFileCb;
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
public delegate void AsyncCallback(string path);
|
||||
|
||||
[AOT.MonoPInvokeCallback(typeof(AsyncCallback))]
|
||||
private static void openFileCb(string result) {
|
||||
_openFileCb.Invoke(result.Split((char)28));
|
||||
}
|
||||
|
||||
[AOT.MonoPInvokeCallback(typeof(AsyncCallback))]
|
||||
private static void openFolderCb(string result) {
|
||||
_openFolderCb.Invoke(result.Split((char)28));
|
||||
}
|
||||
|
||||
[AOT.MonoPInvokeCallback(typeof(AsyncCallback))]
|
||||
private static void saveFileCb(string result) {
|
||||
_saveFileCb.Invoke(result);
|
||||
}
|
||||
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern IntPtr DialogOpenFilePanel(string title, string directory, string extension, bool multiselect);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern void DialogOpenFilePanelAsync(string title, string directory, string extension, bool multiselect, AsyncCallback callback);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern IntPtr DialogOpenFolderPanel(string title, string directory, bool multiselect);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern void DialogOpenFolderPanelAsync(string title, string directory, bool multiselect, AsyncCallback callback);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern IntPtr DialogSaveFilePanel(string title, string directory, string defaultName, string extension);
|
||||
[DllImport("StandaloneFileBrowser")]
|
||||
private static extern void DialogSaveFilePanelAsync(string title, string directory, string defaultName, string extension, AsyncCallback callback);
|
||||
|
||||
public string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect) {
|
||||
var paths = Marshal.PtrToStringAnsi(DialogOpenFilePanel(
|
||||
title,
|
||||
directory,
|
||||
GetFilterFromFileExtensionList(extensions),
|
||||
multiselect));
|
||||
return paths.Split((char)28);
|
||||
}
|
||||
|
||||
public void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions, bool multiselect, Action<string[]> cb) {
|
||||
_openFileCb = cb;
|
||||
DialogOpenFilePanelAsync(
|
||||
title,
|
||||
directory,
|
||||
GetFilterFromFileExtensionList(extensions),
|
||||
multiselect,
|
||||
openFileCb);
|
||||
}
|
||||
|
||||
public string[] OpenFolderPanel(string title, string directory, bool multiselect) {
|
||||
var paths = Marshal.PtrToStringAnsi(DialogOpenFolderPanel(
|
||||
title,
|
||||
directory,
|
||||
multiselect));
|
||||
return paths.Split((char)28);
|
||||
}
|
||||
|
||||
public void OpenFolderPanelAsync(string title, string directory, bool multiselect, Action<string[]> cb) {
|
||||
_openFolderCb = cb;
|
||||
DialogOpenFolderPanelAsync(
|
||||
title,
|
||||
directory,
|
||||
multiselect,
|
||||
openFolderCb);
|
||||
}
|
||||
|
||||
public string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions) {
|
||||
return Marshal.PtrToStringAnsi(DialogSaveFilePanel(
|
||||
title,
|
||||
directory,
|
||||
defaultName,
|
||||
GetFilterFromFileExtensionList(extensions)));
|
||||
}
|
||||
|
||||
public void SaveFilePanelAsync(string title, string directory, string defaultName, ExtensionFilter[] extensions, Action<string> cb) {
|
||||
_saveFileCb = cb;
|
||||
DialogSaveFilePanelAsync(
|
||||
title,
|
||||
directory,
|
||||
defaultName,
|
||||
GetFilterFromFileExtensionList(extensions),
|
||||
saveFileCb);
|
||||
}
|
||||
|
||||
private static string GetFilterFromFileExtensionList(ExtensionFilter[] extensions) {
|
||||
if (extensions == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
var filterString = "";
|
||||
foreach (var filter in extensions) {
|
||||
filterString += filter.Name + ";";
|
||||
|
||||
foreach (var ext in filter.Extensions) {
|
||||
filterString += ext + ",";
|
||||
}
|
||||
|
||||
filterString = filterString.Remove(filterString.Length - 1);
|
||||
filterString += "|";
|
||||
}
|
||||
filterString = filterString.Remove(filterString.Length - 1);
|
||||
return filterString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bcb49ddb0ed5644fda9c3b055cafa27a
|
||||
timeCreated: 1483902788
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,137 @@
|
|||
#if UNITY_STANDALONE_WIN
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using System.Runtime.InteropServices;
|
||||
using Ookii.Dialogs;
|
||||
|
||||
namespace SFB {
|
||||
// For fullscreen support
|
||||
// - WindowWrapper class and GetActiveWindow() are required for modal file dialog.
|
||||
// - "PlayerSettings/Visible In Background" should be enabled, otherwise when file dialog opened app window minimizes automatically.
|
||||
|
||||
public class WindowWrapper : IWin32Window {
|
||||
private IntPtr _hwnd;
|
||||
public WindowWrapper(IntPtr handle) { _hwnd = handle; }
|
||||
public IntPtr Handle { get { return _hwnd; } }
|
||||
}
|
||||
|
||||
public class StandaloneFileBrowserWindows : IStandaloneFileBrowser {
|
||||
[DllImport("user32.dll")]
|
||||
private static extern IntPtr GetActiveWindow();
|
||||
|
||||
public string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect) {
|
||||
var fd = new VistaOpenFileDialog();
|
||||
fd.Title = title;
|
||||
if (extensions != null) {
|
||||
fd.Filter = GetFilterFromFileExtensionList(extensions);
|
||||
fd.FilterIndex = 1;
|
||||
}
|
||||
else {
|
||||
fd.Filter = string.Empty;
|
||||
}
|
||||
fd.Multiselect = multiselect;
|
||||
if (!string.IsNullOrEmpty(directory)) {
|
||||
fd.FileName = GetDirectoryPath(directory);
|
||||
}
|
||||
var res = fd.ShowDialog(new WindowWrapper(GetActiveWindow()));
|
||||
var filenames = res == DialogResult.OK ? fd.FileNames : new string[0];
|
||||
fd.Dispose();
|
||||
return filenames;
|
||||
}
|
||||
|
||||
public void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions, bool multiselect, Action<string[]> cb) {
|
||||
cb.Invoke(OpenFilePanel(title, directory, extensions, multiselect));
|
||||
}
|
||||
|
||||
public string[] OpenFolderPanel(string title, string directory, bool multiselect) {
|
||||
var fd = new VistaFolderBrowserDialog();
|
||||
fd.Description = title;
|
||||
if (!string.IsNullOrEmpty(directory)) {
|
||||
fd.SelectedPath = GetDirectoryPath(directory);
|
||||
}
|
||||
var res = fd.ShowDialog(new WindowWrapper(GetActiveWindow()));
|
||||
var filenames = res == DialogResult.OK ? new []{ fd.SelectedPath } : new string[0];
|
||||
fd.Dispose();
|
||||
return filenames;
|
||||
}
|
||||
|
||||
public void OpenFolderPanelAsync(string title, string directory, bool multiselect, Action<string[]> cb) {
|
||||
cb.Invoke(OpenFolderPanel(title, directory, multiselect));
|
||||
}
|
||||
|
||||
public string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions) {
|
||||
var fd = new VistaSaveFileDialog();
|
||||
fd.Title = title;
|
||||
|
||||
var finalFilename = "";
|
||||
|
||||
if (!string.IsNullOrEmpty(directory)) {
|
||||
finalFilename = GetDirectoryPath(directory);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(defaultName)) {
|
||||
finalFilename += defaultName;
|
||||
}
|
||||
|
||||
fd.FileName = finalFilename;
|
||||
if (extensions != null) {
|
||||
fd.Filter = GetFilterFromFileExtensionList(extensions);
|
||||
fd.FilterIndex = 1;
|
||||
fd.DefaultExt = extensions[0].Extensions[0];
|
||||
fd.AddExtension = true;
|
||||
}
|
||||
else {
|
||||
fd.DefaultExt = string.Empty;
|
||||
fd.Filter = string.Empty;
|
||||
fd.AddExtension = false;
|
||||
}
|
||||
var res = fd.ShowDialog(new WindowWrapper(GetActiveWindow()));
|
||||
var filename = res == DialogResult.OK ? fd.FileName : "";
|
||||
fd.Dispose();
|
||||
return filename;
|
||||
}
|
||||
|
||||
public void SaveFilePanelAsync(string title, string directory, string defaultName, ExtensionFilter[] extensions, Action<string> cb) {
|
||||
cb.Invoke(SaveFilePanel(title, directory, defaultName, extensions));
|
||||
}
|
||||
|
||||
// .NET Framework FileDialog Filter format
|
||||
// https://msdn.microsoft.com/en-us/library/microsoft.win32.filedialog.filter
|
||||
private static string GetFilterFromFileExtensionList(ExtensionFilter[] extensions) {
|
||||
var filterString = "";
|
||||
foreach (var filter in extensions) {
|
||||
filterString += filter.Name + "(";
|
||||
|
||||
foreach (var ext in filter.Extensions) {
|
||||
filterString += "*." + ext + ",";
|
||||
}
|
||||
|
||||
filterString = filterString.Remove(filterString.Length - 1);
|
||||
filterString += ") |";
|
||||
|
||||
foreach (var ext in filter.Extensions) {
|
||||
filterString += "*." + ext + "; ";
|
||||
}
|
||||
|
||||
filterString += "|";
|
||||
}
|
||||
filterString = filterString.Remove(filterString.Length - 1);
|
||||
return filterString;
|
||||
}
|
||||
|
||||
private static string GetDirectoryPath(string directory) {
|
||||
var directoryPath = Path.GetFullPath(directory);
|
||||
if (!directoryPath.EndsWith("\\")) {
|
||||
directoryPath += "\\";
|
||||
}
|
||||
if (Path.GetPathRoot(directoryPath) == directoryPath) {
|
||||
return directory;
|
||||
}
|
||||
return Path.GetDirectoryName(directoryPath) + Path.DirectorySeparatorChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 194e247414a78461d83ae606c1b96917
|
||||
timeCreated: 1483902788
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue