unity and native osx bundles and frameworks build from the same project now

This commit is contained in:
Joseph Henry
2016-06-16 11:47:08 -07:00
parent 621970619d
commit 699edf8f30
111 changed files with 11112 additions and 14 deletions

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:ZeroTierSDK_Apple.xcodeproj">
</FileRef>
</Workspace>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
</Bucket>

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7CC0032F1D1216F8003E68DC"
BuildableName = "ZeroTierSDK_OSX.framework"
BlueprintName = "ZeroTierSDK_OSX"
ReferencedContainer = "container:ZeroTierSDK_Apple.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7CC0032F1D1216F8003E68DC"
BuildableName = "ZeroTierSDK_OSX.framework"
BlueprintName = "ZeroTierSDK_OSX"
ReferencedContainer = "container:ZeroTierSDK_Apple.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7CC0032F1D1216F8003E68DC"
BuildableName = "ZeroTierSDK_OSX.framework"
BlueprintName = "ZeroTierSDK_OSX"
ReferencedContainer = "container:ZeroTierSDK_Apple.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7CC0033B1D121741003E68DC"
BuildableName = "ZeroTierSDK_Unity3D_OSX.bundle"
BlueprintName = "ZeroTierSDK_Unity3D_OSX"
ReferencedContainer = "container:ZeroTierSDK_Apple.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7CC0033B1D121741003E68DC"
BuildableName = "ZeroTierSDK_Unity3D_OSX.bundle"
BlueprintName = "ZeroTierSDK_Unity3D_OSX"
ReferencedContainer = "container:ZeroTierSDK_Apple.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7CC0033B1D121741003E68DC"
BuildableName = "ZeroTierSDK_Unity3D_OSX.bundle"
BlueprintName = "ZeroTierSDK_Unity3D_OSX"
ReferencedContainer = "container:ZeroTierSDK_Apple.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7CC003171D1216B0003E68DC"
BuildableName = "ZeroTierSDK_Unity3D_iOS.bundle"
BlueprintName = "ZeroTierSDK_Unity3D_iOS"
ReferencedContainer = "container:ZeroTierSDK_Apple.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7CC003171D1216B0003E68DC"
BuildableName = "ZeroTierSDK_Unity3D_iOS.bundle"
BlueprintName = "ZeroTierSDK_Unity3D_iOS"
ReferencedContainer = "container:ZeroTierSDK_Apple.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7CC003171D1216B0003E68DC"
BuildableName = "ZeroTierSDK_Unity3D_iOS.bundle"
BlueprintName = "ZeroTierSDK_Unity3D_iOS"
ReferencedContainer = "container:ZeroTierSDK_Apple.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7CC003221D1216E3003E68DC"
BuildableName = "ZeroTierSDK_iOS.framework"
BlueprintName = "ZeroTierSDK_iOS"
ReferencedContainer = "container:ZeroTierSDK_Apple.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7CC003221D1216E3003E68DC"
BuildableName = "ZeroTierSDK_iOS.framework"
BlueprintName = "ZeroTierSDK_iOS"
ReferencedContainer = "container:ZeroTierSDK_Apple.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7CC003221D1216E3003E68DC"
BuildableName = "ZeroTierSDK_iOS.framework"
BlueprintName = "ZeroTierSDK_iOS"
ReferencedContainer = "container:ZeroTierSDK_Apple.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -0,0 +1,57 @@
<?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>SchemeUserState</key>
<dict>
<key>ZeroTierSDK_OSX.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
</dict>
<key>ZeroTierSDK_Unity3D_OSX.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>4</integer>
</dict>
<key>ZeroTierSDK_Unity3D_iOS.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>ZeroTierSDK_iOS.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>7CC003041D12164D003E68DC</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>7CC003171D1216B0003E68DC</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>7CC003221D1216E3003E68DC</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>7CC0032F1D1216F8003E68DC</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>7CC0033B1D121741003E68DC</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,28 @@
<?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>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2016 ZeroTier Inc. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

View File

@@ -0,0 +1,19 @@
//
// ZeroTierSDK_OSX.h
// ZeroTierSDK_OSX
//
// Created by Joseph Henry on 6/15/16.
// Copyright © 2016 ZeroTier Inc. All rights reserved.
//
#import <Cocoa/Cocoa.h>
//! Project version number for ZeroTierSDK_OSX.
FOUNDATION_EXPORT double ZeroTierSDK_OSXVersionNumber;
//! Project version string for ZeroTierSDK_OSX.
FOUNDATION_EXPORT const unsigned char ZeroTierSDK_OSXVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <ZeroTierSDK_OSX/PublicHeader.h>

View File

@@ -0,0 +1,28 @@
<?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>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2016 ZeroTier Inc. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

View File

@@ -0,0 +1,28 @@
<?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>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2016 ZeroTier Inc. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

View File

@@ -0,0 +1,26 @@
<?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>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

View File

@@ -0,0 +1,19 @@
//
// ZeroTierSDK_iOS.h
// ZeroTierSDK_iOS
//
// Created by Joseph Henry on 6/15/16.
// Copyright © 2016 ZeroTier Inc. All rights reserved.
//
#import <UIKit/UIKit.h>
//! Project version number for ZeroTierSDK_iOS.
FOUNDATION_EXPORT double ZeroTierSDK_iOSVersionNumber;
//! Project version string for ZeroTierSDK_iOS.
FOUNDATION_EXPORT const unsigned char ZeroTierSDK_iOSVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <ZeroTierSDK_iOS/PublicHeader.h>

View File

@@ -9,7 +9,7 @@ This short tutorial will show you how to enable ZeroTier functionality for your
**Step 1: Build the ZeroTier service binaries** **Step 1: Build the ZeroTier service binaries**
From the ZeroTier source directory, `make netcon` Optionally, if you'd like to see some debug output during execution, use `make netcon NETCON_DEBUG=1` From the ZeroTier source directory, `make netcon` Optionally, if you'd like to see some debug output during execution, use `make sdk ZT_SDK_DEBUG=1`
**Step 2: Build your Docker image** **Step 2: Build your Docker image**

View File

@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<RootNamespace></RootNamespace>
<ProjectGuid>{24F9E71C-1810-2FEA-B9CC-4258EB20D4CD}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<AssemblyName>Assembly-CSharp-Editor</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<BaseDirectory>Assets</BaseDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Temp\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_3_5;UNITY_5_3;UNITY_5;ENABLE_NEW_BUGREPORTER;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_SPRITE_POLYGON;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_UNITYEVENTS;ENABLE_VR;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;INCLUDE_DIRECTX12;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;ENABLE_LOCALIZATION;ENABLE_ANDROID_ATLAS_ETC1_COMPRESSION;ENABLE_EDITOR_TESTS_RUNNER;UNITY_STANDALONE_OSX;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_GAMECENTER;ENABLE_TEXTUREID_MAP;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_LOG_MIXED_STACKTRACE;ENABLE_UNITYWEBREQUEST;ENABLE_CLUSTERINPUT;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_OSX</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>0169</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>Temp\bin\Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>0169</NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.XML" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="UnityEngine">
<HintPath>/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEditor">
<HintPath>/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\OBJ-IO\Editor\OBJEditor.cs" />
<None Include="Assets\OBJ-IO\Readme.txt" />
<Reference Include="Assembly-UnityScript">
<HintPath>/Users/Joseph/ZeroTier-Unity3D-Test/Library/ScriptAssemblies/Assembly-UnityScript.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Networking">
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/Networking/UnityEngine.Networking.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.Networking">
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/Networking/Editor/UnityEditor.Networking.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.UI">
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/Editor/UnityEditor.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.Advertisements">
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/Advertisements/Editor/UnityEditor.Advertisements.dll</HintPath>
</Reference>
<Reference Include="nunit.framework">
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/EditorTestsRunner/Editor/nunit.framework.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.EditorTestsRunner">
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/EditorTestsRunner/Editor/UnityEditor.EditorTestsRunner.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.TreeEditor">
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/TreeEditor/Editor/UnityEditor.TreeEditor.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.Graphs">
<HintPath>/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.Graphs.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.Android.Extensions">
<HintPath>/Applications/Unity/PlaybackEngines/AndroidPlayer/UnityEditor.Android.Extensions.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.iOS.Extensions">
<HintPath>/Applications/Unity/PlaybackEngines/iOSSupport/UnityEditor.iOS.Extensions.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.OSXStandalone.Extensions">
<HintPath>/Applications/Unity/PlaybackEngines/MacStandaloneSupport/UnityEditor.OSXStandalone.Extensions.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.iOS.Extensions.Xcode">
<HintPath>/Applications/Unity/PlaybackEngines/iOSSupport/UnityEditor.iOS.Extensions.Xcode.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.iOS.Extensions.Common">
<HintPath>/Applications/Unity/PlaybackEngines/iOSSupport/UnityEditor.iOS.Extensions.Common.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="Assembly-CSharp.csproj">
<Project>{5AB900A8-5B14-044A-A52D-10417305A5D2}</Project> <Name>Assembly-CSharp</Name> </ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<RootNamespace></RootNamespace>
<ProjectGuid>{5AB900A8-5B14-044A-A52D-10417305A5D2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<AssemblyName>Assembly-CSharp</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<BaseDirectory>Assets</BaseDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Temp\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_3_5;UNITY_5_3;UNITY_5;ENABLE_NEW_BUGREPORTER;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_SPRITE_POLYGON;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_UNITYEVENTS;ENABLE_VR;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;INCLUDE_DIRECTX12;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;ENABLE_LOCALIZATION;ENABLE_ANDROID_ATLAS_ETC1_COMPRESSION;ENABLE_EDITOR_TESTS_RUNNER;UNITY_STANDALONE_OSX;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_GAMECENTER;ENABLE_TEXTUREID_MAP;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_LOG_MIXED_STACKTRACE;ENABLE_UNITYWEBREQUEST;ENABLE_CLUSTERINPUT;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_OSX</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>0169</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>Temp\bin\Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>0169</NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.XML" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="UnityEngine">
<HintPath>/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEditor">
<HintPath>/Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\Demo.cs" />
<Compile Include="Assets\MyZeroTier.cs" />
<Compile Include="Assets\OBJ-IO\Examples\Scripts\Example.cs" />
<Compile Include="Assets\OBJ-IO\Plugins\Extension\GameObjectExtension.cs" />
<Compile Include="Assets\OBJ-IO\Plugins\Extension\MeshExtension.cs" />
<Compile Include="Assets\OBJ-IO\Plugins\Extension\StringExtensions.cs" />
<Compile Include="Assets\OBJ-IO\Plugins\Extension\Texture2DExtension.cs" />
<Compile Include="Assets\OBJ-IO\Plugins\Extension\TransformExtension.cs" />
<Compile Include="Assets\OBJ-IO\Plugins\Extension\UnityExtension.cs" />
<Compile Include="Assets\OBJ-IO\Plugins\Extension\VectorExtension.cs" />
<Compile Include="Assets\OBJ-IO\Plugins\Mesh\OBJ\OBJData.cs" />
<Compile Include="Assets\OBJ-IO\Plugins\Mesh\OBJ\OBJFace.cs" />
<Compile Include="Assets\OBJ-IO\Plugins\Mesh\OBJ\OBJFaceVertex.cs" />
<Compile Include="Assets\OBJ-IO\Plugins\Mesh\OBJ\OBJGroup.cs" />
<Compile Include="Assets\OBJ-IO\Plugins\Mesh\OBJ\OBJLoader.cs" />
<Compile Include="Assets\OBJ-IO\Plugins\Mesh\OBJ\OBJMaterial.cs" />
<Compile Include="Assets\OBJ-IO\Plugins\Utils\Int32Converter.cs" />
<Compile Include="Assets\WorldMain.cs" />
<Compile Include="Assets\ZeroTier.cs" />
<Compile Include="Assets\ZeroTierUtils.cs" />
<None Include="Assets\OBJ-IO\Readme.txt" />
<Reference Include="UnityEngine.Networking">
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/Networking/UnityEngine.Networking.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,194 @@

var zoomSpeed : float = 3.0f;
var moveSpeed : float = 3.0f;
var rotateSpeed : float = 6.0f;
var optionalMaterialForSelection : Material;
// Some internal placeholders
private var orbitVector : GameObject;
private var materialForSelection : Material;
private var selectedObjects = new ArrayList();
private var selectedObjectsMaterial = new ArrayList();
function Start() {
// Create a capsule (which will be the lookAt target and global orbit vector)
orbitVector = GameObject.CreatePrimitive(PrimitiveType.Capsule);
orbitVector.transform.position = Vector3.zero;
// Snap the camera to align with the grid in set starting position (otherwise everything gets a bit wonky)
transform.position = Vector3(4, 4, 4);
// Point the camera towards the capsule
transform.LookAt(orbitVector.transform.position, Vector3.up);
// Hide the capsule (disable the mesh renderer)
orbitVector.GetComponent.<Renderer>().enabled = false;
// Create material to apply for selections (or use material supplied by user)
if (optionalMaterialForSelection) {
materialForSelection = optionalMaterialForSelection;
} else {
materialForSelection = new Material(Shader.Find("Diffuse"));
materialForSelection.color = Color.green;
}
}
function Update(){
orbitVector.transform.position = Vector3.zero;
if (Input.GetAxis("Mouse ScrollWheel") < 0) {
var currentZoomSpeedin = -10;
transform.Translate(Vector3.forward * ( currentZoomSpeedin));
}
if (Input.GetAxis("Mouse ScrollWheel") > 0) {
var currentZoomSpeedout = 10;
transform.Translate(Vector3.forward * ( currentZoomSpeedout));
}
}
// Call all of our functionality in LateUpdate() to avoid weird behaviour (as seen in Update())
function LateUpdate() {
// Get mouse vectors
var x = Input.GetAxis("Mouse X");
var y = Input.GetAxis("Mouse Y");
// ALT is pressed, start navigation
//if (Input.GetKey(KeyCode.RightAlt) || Input.GetKey(KeyCode.LeftAlt)) {
// Distance between camera and orbitVector. We'll need this in a few places
var distanceToOrbit = Vector3.Distance(transform.position, orbitVector.transform.position);
//RMB - ZOOM
if (Input.GetMouseButton(2)) {
// Refine the rotateSpeed based on distance to orbitVector
var currentZoomSpeed = Mathf.Clamp(zoomSpeed * (distanceToOrbit / 50), 0.1f, 2.0f);
// Move the camera in/out
transform.Translate(Vector3.forward * (x * currentZoomSpeed));
// If about to collide with the orbitVector, repulse the orbitVector slightly to keep it in front of us
if (Vector3.Distance(transform.position, orbitVector.transform.position) < 3) {
orbitVector.transform.Translate(Vector3.forward, transform);
}
//LMB - PIVOT
} else if (Input.GetMouseButton(1)) {
// Refine the rotateSpeed based on distance to orbitVector
var currentRotateSpeed = Mathf.Clamp(rotateSpeed * (distanceToOrbit / 50), 1.0f, rotateSpeed);
// Temporarily parent the camera to orbitVector and rotate orbitVector as desired
transform.parent = orbitVector.transform;
orbitVector.transform.Rotate(Vector3.right * (y * currentRotateSpeed));
orbitVector.transform.Rotate(Vector3.up * (x * currentRotateSpeed), Space.World);
transform.parent = null;
//MMB - PAN
} else if (Input.GetMouseButton(0)) {
// Calculate move speed
var translateX = Vector3.right * (x * moveSpeed) * -1;
var translateY = Vector3.up * (y * moveSpeed) * -1;
// Move the camera
transform.Translate(translateX);
transform.Translate(translateY);
// Move the orbitVector with the same values, along the camera's axes. In effect causing it to behave as if temporarily parented.
orbitVector.transform.Translate(translateX, transform);
orbitVector.transform.Translate(translateY, transform);
}
/*
// If we're not currently navigating, grab selection if something is clicked
} else if (Input.GetMouseButtonDown(0)) {
var hitInfo : RaycastHit;
var ray : Ray = camera.ScreenPointToRay(Input.mousePosition);
var allowMultiSelect : boolean = false;
// See if the user is holding in CTRL or SHIFT. If so, enable multiselection
if(Input.GetKey(KeyCode.RightShift) || Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl)) {
allowMultiSelect = true;
}
// Something was clicked. Fetch.
if (Physics.Raycast(ray, hitInfo, camera.farClipPlane)) {
target = hitInfo.transform;
// If NOT multiselection, remove all prior selections
if (!allowMultiSelect) {
deselectAll();
}
//Toggle between selected and unselected (depending on current state)
if (target.renderer.sharedMaterial != materialForSelection) {
selectedObjects.Add(target.gameObject);
selectedObjectsMaterial.Add(target.gameObject.renderer.sharedMaterial);
target.gameObject.renderer.sharedMaterial = materialForSelection;
} else {
var arrayLocation : int = selectedObjects.IndexOf(target.gameObject);
if (arrayLocation == -1) {return;}; //this shouldn't happen. Ever. But still.
target.gameObject.renderer.sharedMaterial = selectedObjectsMaterial[arrayLocation];
selectedObjects.RemoveAt(arrayLocation);
selectedObjectsMaterial.RemoveAt(arrayLocation);
}
// Else deselect all selected objects (ie. click on empty background)
} else {
// Don't deselect if allowMultiSelect is true
if (!allowMultiSelect) {deselectAll();};
}
// Fetch input of the F-button (focus) -- this is a very dodgy implementation...
} else if (Input.GetKeyDown("f")) {
var backtrack = Vector3(0, 0, -15);
var selectedObject : GameObject;
// If dealing with only one selected object
if (selectedObjects.Count == 1) {
selectedObject = selectedObjects[0];
transform.position = selectedObject.transform.position;
orbitVector.transform.position = selectedObject.transform.position;
transform.Translate(backtrack);
// Else we need to average out the position vectors (this is the proper dodgy part of the implementation)
} else if (selectedObjects.Count > 1) {
selectedObject = selectedObjects[0];
var average = selectedObject.transform.position;
for (var i = 1; i < selectedObjects.Count; i++) {
selectedObject = selectedObjects[i];
average = (average + selectedObject.transform.position) / 2;
}
transform.position = average;
orbitVector.transform.position = average;
transform.Translate(backtrack);
}
}
*/
}
// Function to handle the de-selection of all objects in scene
function deselectAll() {
// Run through the list of selected objects and restore their original materials
for (var currentItem = 0; currentItem < selectedObjects.Count; currentItem++) {
var selectedObject : GameObject = selectedObjects[currentItem];
selectedObject.GetComponent.<Renderer>().sharedMaterial = selectedObjectsMaterial[currentItem];
}
// Clear both arrays
selectedObjects.Clear();
selectedObjectsMaterial.Clear();
}

View File

@@ -0,0 +1,90 @@
using UnityEngine;
using System.Collections;
using System.Threading;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public class Demo : MonoBehaviour
{
public float speed = 300f;
private ZeroTierNetworkInterface zt;
string nwid = "";
private void zt_sample_network_test_thread()
{
print("test_network");
byte error;
// Prepare sample data buffer
/*
byte[] buffer = new byte[1024];
Stream stream = new MemoryStream(buffer);
BinaryFormatter f = new BinaryFormatter();
f.Serialize ( stream , "Welcome to the machine! (from Unity3D)" );
int error;
*/
// Connect to server
int connfd = zt.Connect (0, "172.22.211.245", 8888, out error);
print(connfd);
// Send sample data to server
//int bytes_written = zt.Send(connfd,buffer,0, out error);
//print(bytes_written);
char[] buffer = new char[1024];
buffer = "hello".ToCharArray();
//print (buffer);
//Stream stream = new MemoryStream(buffer);
//BinaryFormatter formatter = new BinaryFormatter();
//formatter.Serialize(stream, "HelloServer");
//int bufferSize = 1024;
int bytes_written = zt.Send(connfd, "hello".ToCharArray(),4, out error);
print(bytes_written);
}
public void zt_test_network()
{
Thread networkTestThread = new Thread(() => { zt_sample_network_test_thread();});
networkTestThread.IsBackground = true;
networkTestThread.Start();
}
void Start()
{
// Create new instance of ZeroTier in separate thread
zt = new ZeroTierNetworkInterface ("/Users/Joseph/utest2");
/* This new instance will communicate via a named pipe, so any
* API calls (ZeroTier.Connect(), ZeroTier.Send(), etc) will be sent to the service
* via this pipe.
*/
}
// Terminate the ZeroTier service when the application quits
void OnApplicationQuit() {
zt.Terminate ();
}
// Update is called once per frame
void Update () {
// Rotate ZTCube when ZT is running
/*
if (zt.IsRunning ()) {
GameObject go = GameObject.Find ("ZTCube");
Vector3 rotvec = new Vector3 (10f, 10f, 10f);
go.transform.Rotate (rotvec, speed * Time.deltaTime);
}
*/
/*
GameObject go = GameObject.Find("ZTCube");
Text text = go.GetComponents<Text> ()[0];
if (text) {
text.text = IsRunning() ? "ZeroTier Status: Online" : "ZeroTier Status: Offline";
}
*/
}
}

Binary file not shown.

View File

@@ -0,0 +1,8 @@
using UnityEngine;
using System.Collections;
public class MyZeroTier : MonoBehaviour {
void Start() {
Application.OpenURL("https://my.zerotier.com");
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4de3d2c20fafa4cb5a4d9fa9ff529971
folderAsset: yes
timeCreated: 1465591252
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,50 @@

using System;
using System.IO;
using System.Collections;
using UnityEngine;
using UnityEditor;
using UnityExtension;
public class OBJWindow : EditorWindow
{
//------------------------------------------------------------------------------------------------------------
private MeshFilter m_MeshFilter = null;
//------------------------------------------------------------------------------------------------------------
[MenuItem("OBJ-IO/OBJ Mesh Exporter")]
public static void Execute()
{
OBJWindow.GetWindow<OBJWindow>();
}
//------------------------------------------------------------------------------------------------------------
private void OnGUI()
{
m_MeshFilter = (MeshFilter)EditorGUILayout.ObjectField("MeshFilter", m_MeshFilter, typeof(MeshFilter), true);
if (m_MeshFilter != null)
{
if (GUILayout.Button("Export OBJ"))
{
var lOutputPath = EditorUtility.SaveFilePanel("Save Mesh as OBJ", "", m_MeshFilter.name + ".obj", "obj");
if (File.Exists(lOutputPath))
{
File.Delete(lOutputPath);
}
var lStream = new FileStream(lOutputPath, FileMode.Create);
var lOBJData = m_MeshFilter.sharedMesh.EncodeOBJ();
OBJLoader.ExportOBJ(lOBJData, lStream);
lStream.Close();
}
}
else
{
GUILayout.Label("Please provide a MeshFilter");
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 5cb377fb273c8634296cc421905b1d34
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 85a0cef7e364f48d881582114249bfd1
folderAsset: yes
timeCreated: 1465591252
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 1cec0b7c513af4f2985399042ae83c15
folderAsset: yes
timeCreated: 1465591252
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: d2f76706cb1d54b54801e02c996080eb
folderAsset: yes
timeCreated: 1465591253
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9962569753c3d46ef836238f2aa6b33b
timeCreated: 1465591475
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: de5cfcc17119041818768dc28e0c3e4b
timeCreated: 1465591253
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2c4a7e93244894f7ea111b89b950bb85
timeCreated: 1465591814
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,77 @@
fileFormatVersion: 2
guid: 53158f4ed39ed53448df438bc212f7e8
ModelImporter:
serializedVersion: 19
fileIDToRecycleName:
100000: //RootNode
100002: Teapot001
400000: //RootNode
400002: Teapot001
2300000: Teapot001
3300000: Teapot001
4300000: Teapot001
9500000: //RootNode
materials:
importMaterials: 1
materialName: 0
materialSearch: 1
animations:
legacyGenerateAnimations: 4
bakeSimulation: 0
resampleRotations: 1
optimizeGameObjects: 0
motionNodeName:
animationImportErrors:
animationImportWarnings:
animationRetargetingWarnings:
animationDoRetargetingWarnings: 0
animationCompression: 1
animationRotationError: 0.5
animationPositionError: 0.5
animationScaleError: 0.5
animationWrapMode: 0
extraExposedTransformPaths: []
clipAnimations: []
isReadable: 1
meshes:
lODScreenPercentages: []
globalScale: 0.1
meshCompression: 0
addColliders: 0
importBlendShapes: 1
swapUVChannels: 0
generateSecondaryUV: 0
useFileUnits: 1
optimizeMeshForGPU: 1
keepQuads: 0
weldVertices: 1
secondaryUVAngleDistortion: 8
secondaryUVAreaDistortion: 15.000001
secondaryUVHardAngle: 88
secondaryUVPackMargin: 4
useFileScale: 0
tangentSpace:
normalSmoothAngle: 60
normalImportMode: 1
tangentImportMode: 4
importAnimation: 1
copyAvatar: 0
humanDescription:
human: []
skeleton: []
armTwist: 0.5
foreArmTwist: 0.5
upperLegTwist: 0.5
legTwist: 0.5
armStretch: 0.05
legStretch: 0.05
feetSpacing: 0
rootMotionBoneName:
hasTranslationDoF: 0
lastHumanDescriptionAvatarSource: {instanceID: 0}
animationType: 0
humanoidOversampling: 1
additionalBone: 0
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,83 @@
fileFormatVersion: 2
guid: dacaee67ec5e14226b9ec02527c457b5
timeCreated: 1465591475
licenseType: Free
ModelImporter:
serializedVersion: 19
fileIDToRecycleName:
100000: Cube_Instance_0
100002: //RootNode
100004: Teapot001_Instance_0
400000: Cube_Instance_0
400002: //RootNode
400004: Teapot001_Instance_0
2300000: Cube_Instance_0
2300002: Teapot001_Instance_0
3300000: Cube_Instance_0
3300002: Teapot001_Instance_0
4300000: Cube_Instance_0
4300002: Teapot001_Instance_0
materials:
importMaterials: 1
materialName: 0
materialSearch: 1
animations:
legacyGenerateAnimations: 4
bakeSimulation: 0
resampleRotations: 1
optimizeGameObjects: 0
motionNodeName:
animationImportErrors:
animationImportWarnings:
animationRetargetingWarnings:
animationDoRetargetingWarnings: 0
animationCompression: 1
animationRotationError: 0.5
animationPositionError: 0.5
animationScaleError: 0.5
animationWrapMode: 0
extraExposedTransformPaths: []
clipAnimations: []
isReadable: 1
meshes:
lODScreenPercentages: []
globalScale: 1
meshCompression: 0
addColliders: 0
importBlendShapes: 1
swapUVChannels: 0
generateSecondaryUV: 0
useFileUnits: 1
optimizeMeshForGPU: 1
keepQuads: 0
weldVertices: 1
secondaryUVAngleDistortion: 8
secondaryUVAreaDistortion: 15.000001
secondaryUVHardAngle: 88
secondaryUVPackMargin: 4
useFileScale: 1
tangentSpace:
normalSmoothAngle: 60
normalImportMode: 0
tangentImportMode: 3
importAnimation: 1
copyAvatar: 0
humanDescription:
human: []
skeleton: []
armTwist: 0.5
foreArmTwist: 0.5
upperLegTwist: 0.5
legTwist: 0.5
armStretch: 0.05
legStretch: 0.05
feetSpacing: 0
rootMotionBoneName:
hasTranslationDoF: 0
lastHumanDescriptionAvatarSource: {instanceID: 0}
animationType: 0
humanoidOversampling: 1
additionalBone: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: de90c25035683439686941d132beb13c
folderAsset: yes
timeCreated: 1465591252
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: 8573b7b1c7256de4896b3054d17de1b7
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 960be3fc0da534863bcaece34b55fe5b
folderAsset: yes
timeCreated: 1465591252
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,52 @@
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityExtension;
using Random = UnityEngine.Random;
[RequireComponent(typeof(MeshFilter))]
public class Example : MonoBehaviour
{
//------------------------------------------------------------------------------------------------------------
private const string INPUT_PATH = @"Assets/OBJ-IO/Examples/Meshes/Teapot.obj";
private const string OUTPUT_PATH = @"Assets/OBJ-IO/Examples/Meshes/Teapot_Modified.obj";
//------------------------------------------------------------------------------------------------------------
private void Start()
{
// Load the OBJ in
var lStream = new FileStream(INPUT_PATH, FileMode.Open);
var lOBJData = OBJLoader.LoadOBJ(lStream);
var lMeshFilter = GetComponent<MeshFilter>();
lMeshFilter.mesh.LoadOBJ(lOBJData);
lStream.Close();
lStream = null;
lOBJData = null;
// Wiggle Vertices in Mesh
/*
var lVertices = lMeshFilter.mesh.vertices;
for (int lCount = 0; lCount < lVertices.Length; ++lCount)
{
lVertices[lCount] = lVertices[lCount] + Vector3.up * Mathf.Sin(lVertices[lCount].x) * 4f;
}
lMeshFilter.mesh.vertices = lVertices;
*/
// Export the new Wiggled Mesh
if (File.Exists(OUTPUT_PATH))
{
File.Delete(OUTPUT_PATH);
}
lStream = new FileStream(OUTPUT_PATH, FileMode.Create);
lOBJData = lMeshFilter.mesh.EncodeOBJ();
OBJLoader.ExportOBJ(lOBJData, lStream);
lStream.Close();
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: f3ab7cfdf40b84b41a7adc35c545c226
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: a34eacd8a28f549b4afede06cd79972e
folderAsset: yes
timeCreated: 1465591252
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 222144ab5ea5b4732b84d8eff5735d91
folderAsset: yes
timeCreated: 1465591252
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,112 @@

using System;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
namespace UnityExtension
{
public static class GameObjectExt
{
//------------------------------------------------------------------------------------------------------------
public static T GetOrAddComponent<T>(this GameObject lGo) where T : Component
{
T lComponent = lGo.GetComponent<T>();
if (lComponent == null)
{
lComponent = lGo.gameObject.AddComponent<T>();
}
return lComponent;
}
//------------------------------------------------------------------------------------------------------------
public static T GetComponentOfChild<T>(this GameObject lGo, string lName) where T : Component
{
T lComponent = null;
Transform lTransform = lGo.transform.FindChild(lName);
if (lTransform != null)
{
lComponent = lTransform.GetComponent<T>();
}
return lComponent;
}
//------------------------------------------------------------------------------------------------------------
public static T[] GetComponentsOfChild<T>(this GameObject lGo, string lName) where T : Component
{
T[] lComponent = null;
Transform lTransform = lGo.transform.FindChild(lName);
if (lTransform != null)
{
lComponent = lTransform.GetComponents<T>();
}
return lComponent;
}
//------------------------------------------------------------------------------------------------------------
public static GameObject InstantiateAsChild(this GameObject lGo, GameObject lObject)
{
GameObject lNewGo = lObject != null ? (GameObject)GameObject.Instantiate(lObject) : new GameObject();
lNewGo.transform.parent = lGo.transform;
lNewGo.transform.localPosition = Vector3.zero;
lNewGo.transform.localRotation = Quaternion.identity;
lNewGo.transform.localScale = Vector3.one;
return lNewGo;
}
//------------------------------------------------------------------------------------------------------------
public static bool DestroyChildIfExists(this GameObject lGo, string lName)
{
Transform lTransform = lGo.transform.FindChild(lName);
if (lTransform != null)
{
GameObject.Destroy(lTransform.gameObject);
return true;
}
else
{
return false;
}
}
//------------------------------------------------------------------------------------------------------------
public static bool ContainsChildren(this GameObject lGo, params string[] lPaths)
{
for (int lCount = 0; lCount < lPaths.Length; ++lCount)
{
if (lGo.transform.FindChild(lPaths[lCount]) == null)
{
return false;
}
}
return true;
}
//------------------------------------------------------------------------------------------------------------
public static bool IsChildOf(this GameObject lGo, GameObject lParent)
{
Transform lTransform = lGo.transform;
while (lTransform.parent != null)
{
if (lTransform == lParent.transform)
{
return true;
}
lTransform = lTransform.parent;
}
return false;
}
//------------------------------------------------------------------------------------------------------------
public static void SetLayerRecursively(this GameObject lGo, int lLayer)
{
lGo.layer = lLayer;
foreach (Transform lTransform in lGo.transform)
{
lTransform.gameObject.SetLayerRecursively(lLayer);
}
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 35b132c59c7910c4b99e560a0f9baf95
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,627 @@

using System;
using System.IO;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
namespace UnityExtension
{
public static class MeshExt
{
//------------------------------------------------------------------------------------------------------------
public static void RecalculateTangents(this Mesh lMesh)
{
//speed up math by copying the mesh arrays
int[] triangles = lMesh.triangles;
Vector3[] vertices = lMesh.vertices;
Vector2[] uv = lMesh.uv;
Vector3[] normals = lMesh.normals;
//variable definitions
int triangleCount = triangles.Length;
int vertexCount = vertices.Length;
Vector3[] tan1 = new Vector3[vertexCount];
Vector3[] tan2 = new Vector3[vertexCount];
Vector4[] tangents = new Vector4[vertexCount];
for (long a = 0; a < triangleCount; a += 3)
{
long i1 = triangles[a + 0];
long i2 = triangles[a + 1];
long i3 = triangles[a + 2];
Vector3 v1 = vertices[i1];
Vector3 v2 = vertices[i2];
Vector3 v3 = vertices[i3];
Vector2 w1 = uv[i1];
Vector2 w2 = uv[i2];
Vector2 w3 = uv[i3];
float x1 = v2.x - v1.x;
float x2 = v3.x - v1.x;
float y1 = v2.y - v1.y;
float y2 = v3.y - v1.y;
float z1 = v2.z - v1.z;
float z2 = v3.z - v1.z;
float s1 = w2.x - w1.x;
float s2 = w3.x - w1.x;
float t1 = w2.y - w1.y;
float t2 = w3.y - w1.y;
float r = 1.0f / (s1 * t2 - s2 * t1);
Vector3 sdir = new Vector3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r);
Vector3 tdir = new Vector3((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r);
tan1[i1] += sdir;
tan1[i2] += sdir;
tan1[i3] += sdir;
tan2[i1] += tdir;
tan2[i2] += tdir;
tan2[i3] += tdir;
}
for (long a = 0; a < vertexCount; ++a)
{
Vector3 n = normals[a];
Vector3 t = tan1[a];
//Vector3 tmp = (t - n * Vector3.Dot(n, t)).normalized;
//tangents[a] = new Vector4(tmp.x, tmp.y, tmp.z);
Vector3.OrthoNormalize(ref n, ref t);
tangents[a].x = t.x;
tangents[a].y = t.y;
tangents[a].z = t.z;
tangents[a].w = (Vector3.Dot(Vector3.Cross(n, t), tan2[a]) < 0.0f) ? -1.0f : 1.0f;
}
lMesh.tangents = tangents;
}
//------------------------------------------------------------------------------------------------------------
public static void LoadOBJ(this Mesh lMesh, OBJData lData)
{
List<Vector3> lVertices = new List<Vector3>();
List<Vector3> lNormals = new List<Vector3>();
List<Vector2> lUVs = new List<Vector2>();
List<int>[] lIndices = new List<int>[lData.m_Groups.Count];
Dictionary<OBJFaceVertex, int> lVertexIndexRemap = new Dictionary<OBJFaceVertex, int>();
bool lHasNormals = lData.m_Normals.Count > 0;
bool lHasUVs = lData.m_UVs.Count > 0;
lMesh.subMeshCount = lData.m_Groups.Count;
for (int lGCount = 0; lGCount < lData.m_Groups.Count; ++lGCount)
{
OBJGroup lGroup = lData.m_Groups[lGCount];
lIndices[lGCount] = new List<int>();
for (int lFCount = 0; lFCount < lGroup.Faces.Count; ++lFCount)
{
OBJFace lFace = lGroup.Faces[lFCount];
// Unity3d doesn't support non-triangle faces
// so we do simple fan triangulation
for (int lVCount = 1; lVCount < lFace.Count - 1; ++lVCount)
{
foreach (int i in new int[]{0, lVCount, lVCount + 1})
{
OBJFaceVertex lFaceVertex = lFace[i];
int lVertexIndex = -1;
if (!lVertexIndexRemap.TryGetValue(lFaceVertex, out lVertexIndex)) {
lVertexIndexRemap[lFaceVertex] = lVertices.Count;
lVertexIndex = lVertices.Count;
lVertices.Add(lData.m_Vertices[lFaceVertex.m_VertexIndex]);
if (lHasUVs)
{
lUVs.Add(lData.m_UVs[lFaceVertex.m_UVIndex]);
}
if (lHasNormals)
{
lNormals.Add(lData.m_Normals[lFaceVertex.m_NormalIndex]);
}
}
lIndices[lGCount].Add(lVertexIndex);
}
}
}
}
lMesh.triangles = new int[]{ };
lMesh.vertices = lVertices.ToArray();
lMesh.uv = lUVs.ToArray();
lMesh.normals = lNormals.ToArray();
if (!lHasNormals)
{
lMesh.RecalculateNormals();
}
lMesh.RecalculateTangents();
for (int lGCount = 0; lGCount < lData.m_Groups.Count; ++lGCount)
{
lMesh.SetTriangles(lIndices[lGCount].ToArray(), lGCount);
}
}
//------------------------------------------------------------------------------------------------------------
public static OBJData EncodeOBJ(this Mesh lMesh)
{
OBJData lData = new OBJData
{
m_Vertices = new List<Vector3>(lMesh.vertices),
m_UVs = new List<Vector2>(lMesh.uv),
m_Normals = new List<Vector3>(lMesh.normals),
m_UV2s = new List<Vector2>(lMesh.uv2),
m_Colors = new List<Color>(lMesh.colors)
};
int[] lIndices = null;
OBJGroup lGroup = null;
OBJFace lFace = null;
OBJFaceVertex lFaceVertex = null;
for (int lMCount = 0; lMCount < lMesh.subMeshCount; ++lMCount)
{
lIndices = lMesh.GetTriangles(lMCount);
lGroup = new OBJGroup(lMesh.name + "_" + lMCount.ToString());
for (int lCount = 0; lCount < lIndices.Length; lCount += 3)
{
lFace = new OBJFace();
lFaceVertex = new OBJFaceVertex();
lFaceVertex.m_VertexIndex = lData.m_Vertices.Count > 0 ? lIndices[lCount] : -1;
lFaceVertex.m_UVIndex = lData.m_UVs.Count > 0 ? lIndices[lCount] : -1;
lFaceVertex.m_NormalIndex = lData.m_Normals.Count > 0 ? lIndices[lCount] : -1;
lFaceVertex.m_UV2Index = lData.m_UV2s.Count > 0 ? lIndices[lCount] : -1;
lFaceVertex.m_ColorIndex = lData.m_Colors.Count > 0 ? lIndices[lCount] : -1;
lFace.AddVertex(lFaceVertex);
lFaceVertex = new OBJFaceVertex();
lFaceVertex.m_VertexIndex = lData.m_Vertices.Count > 0 ? lIndices[lCount + 1] : -1;
lFaceVertex.m_UVIndex = lData.m_UVs.Count > 0 ? lIndices[lCount + 1] : -1;
lFaceVertex.m_NormalIndex = lData.m_Normals.Count > 0 ? lIndices[lCount + 1] : -1;
lFaceVertex.m_UV2Index = lData.m_UV2s.Count > 0 ? lIndices[lCount + 1] : -1;
lFaceVertex.m_ColorIndex = lData.m_Colors.Count > 0 ? lIndices[lCount + 1] : -1;
lFace.AddVertex(lFaceVertex);
lFaceVertex = new OBJFaceVertex();
lFaceVertex.m_VertexIndex = lData.m_Vertices.Count > 0 ? lIndices[lCount + 2] : -1;
lFaceVertex.m_UVIndex = lData.m_UVs.Count > 0 ? lIndices[lCount + 2] : -1;
lFaceVertex.m_NormalIndex = lData.m_Normals.Count > 0 ? lIndices[lCount + 2] : -1;
lFaceVertex.m_UV2Index = lData.m_UV2s.Count > 0 ? lIndices[lCount + 2] : -1;
lFaceVertex.m_ColorIndex = lData.m_Colors.Count > 0 ? lIndices[lCount + 2] : -1;
lFace.AddVertex(lFaceVertex);
lGroup.AddFace(lFace);
}
lData.m_Groups.Add(lGroup);
}
return lData;
}
//------------------------------------------------------------------------------------------------------------
internal const int MESH_BINARY_HEADER_SIZE = 20;
internal const short MESH_BINARY_SIGNATURE = 0xF5;
internal const short MESH_BINARY_VERSION = 1;
//------------------------------------------------------------------------------------------------------------
public static bool LoadBinary(this Mesh lMesh, byte[] lData)
{
int lSizeOfVector2 = Marshal.SizeOf(typeof(Vector2));
int lSizeOfVector3 = Marshal.SizeOf(typeof(Vector3));
int lSizeOfVector4 = Marshal.SizeOf(typeof(Vector4));
int lSizeOfMatrix4x4 = Marshal.SizeOf(typeof(Matrix4x4));
int lSizeOfBoneWeight = Marshal.SizeOf(typeof(BoneWeight));
int lSizeOfColor = Marshal.SizeOf(typeof(Color));
int lDataOffset = MESH_BINARY_HEADER_SIZE;
int lDeltaOffset = 0;
if (lData == null ||
lData.Length < MESH_BINARY_HEADER_SIZE)
{
return false;
}
// Header
short lSignature = BitConverter.ToInt16(lData, 0);
short lVersion = BitConverter.ToInt16(lData, 2);
if (lSignature != MESH_BINARY_SIGNATURE ||
lVersion != MESH_BINARY_VERSION)
{
return false;
}
lMesh.Clear();
int lVertexCount = BitConverter.ToInt32(lData, 4);
int lIndexCount = BitConverter.ToInt32(lData, 8);
int lSubMeshCount = BitConverter.ToInt32(lData, 12);
byte lFlags = lData[16];
bool lUVFlag = (lFlags & 1) > 0;
bool lUV1Flag = (lFlags & 2) > 0;
bool lUV2Flag = (lFlags & 4) > 0;
bool lNormalFlag = (lFlags & 8) > 0;
bool lTangentFlag = (lFlags & 16) > 0;
bool lColorFlag = (lFlags & 32) > 0;
bool lBindPoseFlag = (lFlags & 64) > 0;
bool lBoneWeightFlag = (lFlags & 128) > 0;
// Vertices
Vector3[] lVertices = new Vector3[lVertexCount];
lDeltaOffset = lVertices.Length * lSizeOfVector3;
GCHandle lHandle = GCHandle.Alloc(lVertices, GCHandleType.Pinned);
Marshal.Copy(lData, lDataOffset, lHandle.AddrOfPinnedObject(), lDeltaOffset);
lHandle.Free();
lDataOffset += lDeltaOffset;
lMesh.vertices = lVertices;
lVertices = null;
// UV Channel 0
Vector2[] lUVs = null;
if (lUVFlag == true)
{
lUVs = new Vector2[lVertexCount];
lDeltaOffset = lUVs.Length * lSizeOfVector2;
lHandle = GCHandle.Alloc(lUVs, GCHandleType.Pinned);
Marshal.Copy(lData, lDataOffset, lHandle.AddrOfPinnedObject(), lDeltaOffset);
lHandle.Free();
lDataOffset += lDeltaOffset;
lMesh.uv = lUVs;
Debug.Log("UV Count : " + lUVs.Length);
lUVs = null;
}
// UV Channel 1
if (lUV1Flag == true)
{
lUVs = new Vector2[lVertexCount];
lDeltaOffset = lUVs.Length * lSizeOfVector2;
lHandle = GCHandle.Alloc(lUVs, GCHandleType.Pinned);
Marshal.Copy(lData, lDataOffset, lHandle.AddrOfPinnedObject(), lDeltaOffset);
lHandle.Free();
lDataOffset += lDeltaOffset;
lMesh.uv2 = lUVs;
Debug.Log("UV1 Count : " + lUVs.Length);
lUVs = null;
}
// UV Channel 2
if (lUV2Flag == true)
{
lUVs = new Vector2[lVertexCount];
lDeltaOffset = lUVs.Length * lSizeOfVector2;
lHandle = GCHandle.Alloc(lUVs, GCHandleType.Pinned);
Marshal.Copy(lData, lDataOffset, lHandle.AddrOfPinnedObject(), lDeltaOffset);
lHandle.Free();
lDataOffset += lDeltaOffset;
lMesh.uv2 = lUVs;
Debug.Log("UV2 Count : " + lUVs.Length);
lUVs = null;
}
// Normals
if (lNormalFlag == true)
{
Vector3[] lNormals = new Vector3[lVertexCount];
lDeltaOffset = lNormals.Length * lSizeOfVector3;
lHandle = GCHandle.Alloc(lNormals, GCHandleType.Pinned);
Marshal.Copy(lData, lDataOffset, lHandle.AddrOfPinnedObject(), lDeltaOffset);
lHandle.Free();
lDataOffset += lDeltaOffset;
lMesh.normals = lNormals;
Debug.Log("Normal Count : " + lNormals.Length);
lNormals = null;
}
// Tangents
if (lTangentFlag == true)
{
Vector4[] lTangents = new Vector4[lVertexCount];
lDeltaOffset = lTangents.Length * lSizeOfVector4;
lHandle = GCHandle.Alloc(lTangents, GCHandleType.Pinned);
Marshal.Copy(lData, lDataOffset, lHandle.AddrOfPinnedObject(), lDeltaOffset);
lHandle.Free();
lDataOffset += lDeltaOffset;
lMesh.tangents = lTangents;
Debug.Log("Tangents Count : " + lTangents.Length);
lTangents = null;
}
// Colors
if (lColorFlag == true)
{
Color[] lColors = new Color[lVertexCount];
lDeltaOffset = lColors.Length * lSizeOfColor;
lHandle = GCHandle.Alloc(lColors, GCHandleType.Pinned);
Marshal.Copy(lData, lDataOffset, lHandle.AddrOfPinnedObject(), lDeltaOffset);
lHandle.Free();
lDataOffset += lDeltaOffset;
lMesh.colors = lColors;
lColors = null;
}
// Bind Poses
if (lBindPoseFlag == true)
{
Matrix4x4[] lBindPoses = new Matrix4x4[lVertexCount];
lDeltaOffset = lBindPoses.Length * lSizeOfMatrix4x4;
lHandle = GCHandle.Alloc(lBindPoses, GCHandleType.Pinned);
Marshal.Copy(lData, lDataOffset, lHandle.AddrOfPinnedObject(), lDeltaOffset);
lHandle.Free();
lDataOffset += lDeltaOffset;
lMesh.bindposes = lBindPoses;
lBindPoses = null;
}
// Bone Weights
if (lBoneWeightFlag == true)
{
BoneWeight[] lBoneWeight = new BoneWeight[lVertexCount];
lDeltaOffset = lBoneWeight.Length * lSizeOfBoneWeight;
lHandle = GCHandle.Alloc(lBoneWeight, GCHandleType.Pinned);
Marshal.Copy(lData, lDataOffset, lHandle.AddrOfPinnedObject(), lDeltaOffset);
lHandle.Free();
lDataOffset += lDeltaOffset;
lMesh.boneWeights = lBoneWeight;
lBoneWeight = null;
}
// Indices
int[] lIndices = new int[lIndexCount];
lDeltaOffset = lIndices.Length * sizeof(int);
Buffer.BlockCopy(lData, lDataOffset, lIndices, 0, lDeltaOffset);
lDataOffset += lDeltaOffset;
lMesh.triangles = lIndices;
lIndices = null;
// SubMesh Indices
for (int lSubMeshIndex = 0; lSubMeshIndex < lSubMeshCount; ++lSubMeshIndex)
{
int lSubMeshIndexCount = BitConverter.ToInt32(lData, lDataOffset);
lDataOffset += sizeof(int);
lIndices = new int[lSubMeshIndexCount];
lDeltaOffset = lIndices.Length * sizeof(int);
Buffer.BlockCopy(lData, lDataOffset, lIndices, 0, lDeltaOffset);
lDataOffset += lDeltaOffset;
if (lIndices.Length > 0 &&
lIndices.Length % 3 == 0)
{
lMesh.SetTriangles(lIndices, lSubMeshIndex);
}
lIndices = null;
}
return true;
}
//------------------------------------------------------------------------------------------------------------
public static byte[] EncodeBinary(this Mesh lMesh)
{
// Currently no support for BlendShape
int lSizeOfVector2 = Marshal.SizeOf(typeof(Vector2));
int lSizeOfVector3 = Marshal.SizeOf(typeof(Vector3));
int lSizeOfVector4 = Marshal.SizeOf(typeof(Vector4));
int lSizeOfMatrix4x4 = Marshal.SizeOf(typeof(Matrix4x4));
int lSizeOfBoneWeight = Marshal.SizeOf(typeof(BoneWeight));
int lSizeOfColor = Marshal.SizeOf(typeof(Color));
int lDataSize = MESH_BINARY_HEADER_SIZE;
int lDeltaSize = 0;
bool lUVFlag = false, lUV1Flag = false, lUV2Flag = false,
lNormalFlag = false, lTangentFlag = false, lColorFlag = false,
lBindPoseFlag = false, lBoneWeightFlag = false;
byte[] lData = new byte[lDataSize];
// Vertices
Vector3[] lVertices = lMesh.vertices;
Int32Converter lVertexCount = lVertices.Length;
lDeltaSize = lVertices.Length * lSizeOfVector3;
Array.Resize(ref lData, lDataSize + lDeltaSize);
GCHandle lHandle = GCHandle.Alloc(lVertices, GCHandleType.Pinned);
Marshal.Copy(lHandle.AddrOfPinnedObject(), lData, lDataSize, lDeltaSize);
lHandle.Free();
lDataSize += lDeltaSize;
lVertices = null;
// UV Channel 0
Vector2[] lUVs = lMesh.uv;
if (lUVs.Length > 0)
{
lUVFlag = true;
lDeltaSize = lUVs.Length * lSizeOfVector2;
Array.Resize(ref lData, lDataSize + lDeltaSize);
lHandle = GCHandle.Alloc(lUVs, GCHandleType.Pinned);
Marshal.Copy(lHandle.AddrOfPinnedObject(), lData, lDataSize, lDeltaSize);
lHandle.Free();
lDataSize += lDeltaSize;
}
lUVs = null;
// UV Channel 1
lUVs = lMesh.uv2;
if (lUVs.Length > 0)
{
lUV1Flag = true;
lDeltaSize = lUVs.Length * lSizeOfVector2;
Array.Resize(ref lData, lDataSize + lDeltaSize);
lHandle = GCHandle.Alloc(lUVs, GCHandleType.Pinned);
Marshal.Copy(lHandle.AddrOfPinnedObject(), lData, lDataSize, lDeltaSize);
lHandle.Free();
lDataSize += lDeltaSize;
}
lUVs = null;
// UV Channel 2
lUVs = lMesh.uv2;
if (lUVs.Length > 0)
{
lUV2Flag = true;
lDeltaSize = lUVs.Length * lSizeOfVector2;
Array.Resize(ref lData, lDataSize + lDeltaSize);
lHandle = GCHandle.Alloc(lUVs, GCHandleType.Pinned);
Marshal.Copy(lHandle.AddrOfPinnedObject(), lData, lDataSize, lDeltaSize);
lHandle.Free();
lDataSize += lDeltaSize;
}
lUVs = null;
// Normals
Vector3[] lNormals = lMesh.normals;
if (lNormals.Length > 0)
{
lNormalFlag = true;
lDeltaSize = lNormals.Length * lSizeOfVector3;
Array.Resize(ref lData, lDataSize + lDeltaSize);
lHandle = GCHandle.Alloc(lNormals, GCHandleType.Pinned);
Marshal.Copy(lHandle.AddrOfPinnedObject(), lData, lDataSize, lDeltaSize);
lHandle.Free();
lDataSize += lDeltaSize;
}
lNormals = null;
// Tangents
Vector4[] lTangents = lMesh.tangents;
if (lTangents.Length > 0)
{
lTangentFlag = true;
lDeltaSize = lTangents.Length * lSizeOfVector4;
Array.Resize(ref lData, lDataSize + lDeltaSize);
lHandle = GCHandle.Alloc(lTangents, GCHandleType.Pinned);
Marshal.Copy(lHandle.AddrOfPinnedObject(), lData, lDataSize, lDeltaSize);
lHandle.Free();
lDataSize += lDeltaSize;
}
lTangents = null;
// Colors
Color[] lColors = lMesh.colors;
if (lColors.Length > 0)
{
lColorFlag = true;
lDeltaSize = lColors.Length * lSizeOfColor;
Array.Resize(ref lData, lDataSize + lDeltaSize);
lHandle = GCHandle.Alloc(lColors, GCHandleType.Pinned);
Marshal.Copy(lHandle.AddrOfPinnedObject(), lData, lDataSize, lDeltaSize);
lHandle.Free();
lDataSize += lDeltaSize;
}
lColors = null;
// BindPoses
Matrix4x4[] lBindPoses = lMesh.bindposes;
if (lBindPoses.Length > 0)
{
lBindPoseFlag = true;
lDeltaSize = lBindPoses.Length * lSizeOfMatrix4x4;
Array.Resize(ref lData, lDataSize + lDeltaSize);
lHandle = GCHandle.Alloc(lBindPoses, GCHandleType.Pinned);
Marshal.Copy(lHandle.AddrOfPinnedObject(), lData, lDataSize, lDeltaSize);
lHandle.Free();
lDataSize += lDeltaSize;
}
lBindPoses = null;
// BoneWeight
BoneWeight[] lBoneWeight = lMesh.boneWeights;
if (lBoneWeight.Length > 0)
{
lBoneWeightFlag = true;
lDeltaSize = lBoneWeight.Length * lSizeOfBoneWeight;
Array.Resize(ref lData, lDataSize + lDeltaSize);
lHandle = GCHandle.Alloc(lBoneWeight, GCHandleType.Pinned);
Marshal.Copy(lHandle.AddrOfPinnedObject(), lData, lDataSize, lDeltaSize);
lHandle.Free();
lDataSize += lDeltaSize;
}
lBoneWeight = null;
// Indices
int[] lIndices = lMesh.triangles;
Int32Converter lIndexCount = lIndices.Length;
lDeltaSize = lIndices.Length * sizeof(int);
Array.Resize(ref lData, lDataSize + lDeltaSize);
Buffer.BlockCopy(lIndices, 0, lData, lDataSize, lDeltaSize);
lDataSize += lDeltaSize;
lIndices = null;
// SubMesh Indices
Int32Converter lSubMeshCount = lMesh.subMeshCount;
for (int lSubMeshIndex = 0; lSubMeshIndex < lSubMeshCount; ++lSubMeshIndex)
{
lIndices = lMesh.GetTriangles(lSubMeshIndex);
Int32Converter lSubMeshIndexCount = lIndices.Length;
lDeltaSize = sizeof(int) + (lIndices.Length * sizeof(int));
Array.Resize(ref lData, lDataSize + lDeltaSize);
lData[lDataSize + 0] = lSubMeshIndexCount.Byte1;
lData[lDataSize + 1] = lSubMeshIndexCount.Byte2;
lData[lDataSize + 2] = lSubMeshIndexCount.Byte3;
lData[lDataSize + 3] = lSubMeshIndexCount.Byte4;
Buffer.BlockCopy(lIndices, 0, lData, lDataSize, lDeltaSize - sizeof(int));
lDataSize += lDeltaSize;
}
// Header
lData[0] = (byte)(MESH_BINARY_SIGNATURE & 0xFF);
lData[1] = (byte)((MESH_BINARY_SIGNATURE >> 8) & 0xFF);
lData[2] = (byte)(MESH_BINARY_VERSION & 0xFF);
lData[3] = (byte)((MESH_BINARY_VERSION >> 8) & 0xFF);
lData[4] = lVertexCount.Byte1;
lData[5] = lVertexCount.Byte2;
lData[6] = lVertexCount.Byte3;
lData[7] = lVertexCount.Byte4;
lData[8] = lIndexCount.Byte1;
lData[9] = lIndexCount.Byte2;
lData[10] = lIndexCount.Byte3;
lData[11] = lIndexCount.Byte4;
lData[12] = lSubMeshCount.Byte1;
lData[13] = lSubMeshCount.Byte2;
lData[14] = lSubMeshCount.Byte3;
lData[15] = lSubMeshCount.Byte4;
lData[16] = (byte)(
(lUVFlag ? 1 : 0) |
(lUV1Flag ? 2 : 0) |
(lUV2Flag ? 4 : 0) |
(lNormalFlag ? 8 : 0) |
(lTangentFlag ? 16 : 0) |
(lColorFlag ? 32 : 0) |
(lBindPoseFlag ? 64 : 0) |
(lBoneWeightFlag ? 128 : 0));
return lData;
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: a643d266ae55c8845ac48528640b7e8e
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,43 @@
using System;
using System.Globalization;
public static class StringExt
{
//------------------------------------------------------------------------------------------------------------
public static float ParseInvariantFloat(this string floatString)
{
return float.Parse(floatString, CultureInfo.InvariantCulture.NumberFormat);
}
//------------------------------------------------------------------------------------------------------------
public static int ParseInvariantInt(this string intString)
{
return int.Parse(intString, CultureInfo.InvariantCulture.NumberFormat);
}
//------------------------------------------------------------------------------------------------------------
public static bool EqualsInvariantCultureIgnoreCase(this string str, string s)
{
return str.Equals(s, StringComparison.InvariantCultureIgnoreCase);
}
//------------------------------------------------------------------------------------------------------------
public static bool IsNullOrEmpty(this string str)
{
return string.IsNullOrEmpty(str);
}
//------------------------------------------------------------------------------------------------------------
public static bool IsNullOrWhiteSpace(string value)
{
if (value == null)
return true;
for (int index = 0; index < value.Length; ++index)
{
if (!char.IsWhiteSpace(value[index]))
return false;
}
return true;
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 5403d11ff2ec0124a9a20522559dfcfa
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,55 @@

using System;
using System.IO;
using System.Collections.Generic;
using UnityEngine;
namespace UnityExtension
{
public static class Texture2DExt
{
//------------------------------------------------------------------------------------------------------------
public static byte[] EncodeToTGA(this Texture2D lTexture)
{
MemoryStream lDataStream = new MemoryStream(18 + (lTexture.width * lTexture.height * 3));
BinaryWriter lDataWriter = new BinaryWriter(lDataStream);
if (lDataWriter != null)
{
lDataWriter.Write((short)0);
lDataWriter.Write((byte)2);
lDataWriter.Write((int)0);
lDataWriter.Write((int)0);
lDataWriter.Write((byte)0);
lDataWriter.Write((short)lTexture.width);
lDataWriter.Write((short)lTexture.height);
lDataWriter.Write((byte)24);
lDataWriter.Write((byte)0);
Color32[] lPixelData = lTexture.GetPixels32();
for (int lCount = 0; lCount < lPixelData.Length; ++lCount)
{
lDataWriter.Write(lPixelData[lCount].b);
lDataWriter.Write(lPixelData[lCount].g);
lDataWriter.Write(lPixelData[lCount].r);
}
}
return lDataStream.GetBuffer();
}
//------------------------------------------------------------------------------------------------------------
public static void ConvertLightmapToMobile(this Texture2D lTexture)
{
Color[] lColorData = lTexture.GetPixels();
for (int lCount = 0; lCount < lColorData.Length; ++lCount)
{
lColorData[lCount] = (lColorData[lCount] * (8f * lColorData[lCount].a)) * 0.5f;
}
lTexture.SetPixels(lColorData);
lTexture.Apply();
lColorData = null;
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 9260066d99f960241b2a222401bcb685
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,28 @@

using System;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
namespace UnityExtension
{
public static class TransformExt
{
//------------------------------------------------------------------------------------------------------------
public static void LocalReset(this Transform lTransform)
{
lTransform.localPosition = Vector3.zero;
lTransform.localRotation = Quaternion.identity;
lTransform.localScale = Vector3.one;
}
//------------------------------------------------------------------------------------------------------------
public static void Align(this Transform lTransform, Transform lTarget)
{
lTransform.position = lTarget.position;
lTransform.rotation = lTarget.rotation;
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: a8e76b9c1894ec743ae076720e775f49
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,239 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
namespace UnityExtension
{
//------------------------------------------------------------------------------------------------------------
public static class Utils
{
//------------------------------------------------------------------------------------------------------------
public static bool HasKeys(Dictionary<string, object> lData, params string[] lKeys)
{
if (lKeys != null)
{
for (int lCount = 0; lCount < lKeys.Length; ++lCount)
{
if (!lData.ContainsKey(lKeys[lCount]))
{
return false;
}
}
}
return true;
}
//------------------------------------------------------------------------------------------------------------
public static void ClearChildren(GameObject lGo, string lTarget)
{
if (lGo != null)
{
Transform lTransform = null;
for (int lCount = lGo.transform.childCount - 1; lCount > -1; --lCount)
{
lTransform = lGo.transform.GetChild(lCount);
if (lTransform.name.Contains(lTarget))
{
lTransform.parent = null;
GameObject.Destroy(lTransform.gameObject);
}
}
}
}
//------------------------------------------------------------------------------------------------------------
public static void ClearChildrenRegex(GameObject lGo, string lPattern)
{
if (lGo != null)
{
Transform lTransform = null;
Regex lRegex = new Regex(lPattern);
for (int lCount = lGo.transform.childCount - 1; lCount > -1; --lCount)
{
lTransform = lGo.transform.GetChild(lCount);
if (lRegex.IsMatch(lTransform.name))
{
lTransform.parent = null;
GameObject.Destroy(lTransform.gameObject);
}
}
}
}
//------------------------------------------------------------------------------------------------------------
public static void VerifyObjects(string lMsg, params object[] lObjects)
{
for (int lCount = 0; lCount < lObjects.Length; ++lCount)
{
if (lObjects[lCount] == null)
{
Debug.LogError(lMsg);
break;
}
}
}
//------------------------------------------------------------------------------------------------------------
public static bool JSONCheck(string lText)
{
return !string.IsNullOrEmpty(lText) && lText[0] == '{';
}
//------------------------------------------------------------------------------------------------------------
public static Vector3 ParseVector3Json(string lJsonData)
{
string[] lVector3Array = lJsonData.Replace("(", "").Replace(")", "").Replace(" ", "").Split(',');
Vector3 lVector3 = Vector3.zero;
if (float.TryParse(lVector3Array[0], out lVector3.x) == false)
{
return Vector3.zero;
}
if (float.TryParse(lVector3Array[1], out lVector3.y) == false)
{
return Vector3.zero;
}
if (float.TryParse(lVector3Array[2], out lVector3.z) == false)
{
return Vector3.zero;
}
return lVector3;
}
//------------------------------------------------------------------------------------------------------------
public static Vector4 ParseVector4Json(string lJsonData)
{
string[] lVector4Array = lJsonData.Replace("(", "").Replace(")", "").Replace(" ", "").Split(',');
Vector4 lVector4 = Vector4.zero;
if (float.TryParse(lVector4Array[0], out lVector4.x) == false)
{
return Vector4.zero;
}
if (float.TryParse(lVector4Array[1], out lVector4.y) == false)
{
return Vector4.zero;
}
if (float.TryParse(lVector4Array[2], out lVector4.z) == false)
{
return Vector4.zero;
}
if (float.TryParse(lVector4Array[3], out lVector4.w) == false)
{
return Vector4.zero;
}
return lVector4;
}
//------------------------------------------------------------------------------------------------------------
public static Vector2 ParseVector2String(string lData, char lSeperator = ' ')
{
string[] lParts = lData.Split(new char[] { lSeperator }, StringSplitOptions.RemoveEmptyEntries);
float lX = lParts[0].ParseInvariantFloat();
float lY = lParts[1].ParseInvariantFloat();
return new Vector2(lX, lY);
}
//------------------------------------------------------------------------------------------------------------
public static Vector3 ParseVector3String(string lData, char lSeperator = ' ')
{
string[] lParts = lData.Split(new char[] { lSeperator }, StringSplitOptions.RemoveEmptyEntries);
float lX = lParts[0].ParseInvariantFloat();
float lY = lParts[1].ParseInvariantFloat();
float lZ = lParts[2].ParseInvariantFloat();
return new Vector3(lX, lY, lZ);
}
//------------------------------------------------------------------------------------------------------------
public static Vector4 ParseVector4String(string lData, char lSeperator = ' ')
{
string[] lParts = lData.Split(new char[] { lSeperator }, StringSplitOptions.RemoveEmptyEntries);
float lX = lParts[0].ParseInvariantFloat();
float lY = lParts[1].ParseInvariantFloat();
float lZ = lParts[2].ParseInvariantFloat();
float lW = lParts[3].ParseInvariantFloat();
return new Vector4(lX, lY, lZ, lW);
}
//------------------------------------------------------------------------------------------------------------
public static Quaternion ParseQuaternion(string lJsonData)
{
string[] lQuaternionArray = lJsonData.Replace("(", "").Replace(")", "").Replace(" ", "").Split(',');
Quaternion lQuaternion = Quaternion.identity;
if (float.TryParse(lQuaternionArray[0], out lQuaternion.x) == false)
{
return Quaternion.identity;
}
if (float.TryParse(lQuaternionArray[1], out lQuaternion.y) == false)
{
return Quaternion.identity;
}
if (float.TryParse(lQuaternionArray[2], out lQuaternion.z) == false)
{
return Quaternion.identity;
}
if (float.TryParse(lQuaternionArray[3], out lQuaternion.w) == false)
{
return Quaternion.identity;
}
return lQuaternion;
}
//------------------------------------------------------------------------------------------------------------
public static string Vector3String(Vector3 lVector3)
{
return "(" +
lVector3.x.ToString("f3") + "," +
lVector3.y.ToString("f3") + "," +
lVector3.z.ToString("f3") +
")";
}
//------------------------------------------------------------------------------------------------------------
public static string Vector4String(Vector4 lVector4)
{
return "(" +
lVector4.x.ToString("f3") + "," +
lVector4.y.ToString("f3") + "," +
lVector4.z.ToString("f3") + "," +
lVector4.w.ToString("f3") +
")";
}
//------------------------------------------------------------------------------------------------------------
public static string QuaternionString(Quaternion lQuaternion)
{
return "(" +
lQuaternion.x.ToString("f3") + "," +
lQuaternion.y.ToString("f3") + "," +
lQuaternion.z.ToString("f3") + "," +
lQuaternion.w.ToString("f3") +
")";
}
//------------------------------------------------------------------------------------------------------------
public static int FirstInt(string lJsonData)
{
string lDigits = "";
for (int lCount = 0; lCount < lJsonData.Length && Char.IsDigit(lJsonData[lCount]); ++lCount)
{
lDigits += lJsonData[lCount];
}
return int.Parse(lDigits);
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 06a010ef6a1e94840a51827a2a02badc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@

using System;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
namespace UnityExtension
{
//------------------------------------------------------------------------------------------------------------
public static class Vector3Ext
{
//------------------------------------------------------------------------------------------------------------
public static readonly Vector3 IgnoreX = new Vector3(0f, 1f, 1f);
public static readonly Vector3 IgnoreY = new Vector3(1f, 0f, 1f);
public static readonly Vector3 IgnoreZ = new Vector3(1f, 1f, 0f);
//------------------------------------------------------------------------------------------------------------
public static Color ToColor(this Vector3 lVector)
{
return new Color(lVector.x, lVector.y, lVector.z);
}
}
//------------------------------------------------------------------------------------------------------------
public static class Vector4Ext
{
//------------------------------------------------------------------------------------------------------------
public static Color ToColor(this Vector4 lVector)
{
return new Color(lVector.x, lVector.y, lVector.z, lVector.w);
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 18a26dda21abdf5468d5731a6dbd26c4
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 398bd6d854d804239926cbd17c9ee93c
folderAsset: yes
timeCreated: 1465591252
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8700a9474fed74e75b15b31742f639e2
folderAsset: yes
timeCreated: 1465591252
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@

using System.Collections.Generic;
using UnityEngine;
public class OBJData
{
//------------------------------------------------------------------------------------------------------------
public List<Vector3> m_Vertices = new List<Vector3>();
public List<Vector3> m_Normals = new List<Vector3>();
public List<Vector2> m_UVs = new List<Vector2>();
public List<Vector2> m_UV2s = new List<Vector2>();
public List<Color> m_Colors = new List<Color>();
//------------------------------------------------------------------------------------------------------------
public List<OBJMaterial> m_Materials = new List<OBJMaterial>();
public List<OBJGroup> m_Groups = new List<OBJGroup>();
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 5c57f7fdab36a3f4d9d97f4785a884f6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,101 @@

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityExtension;
public class OBJFace
{
//------------------------------------------------------------------------------------------------------------
private readonly List<OBJFaceVertex> m_Vertices = new List<OBJFaceVertex>();
//------------------------------------------------------------------------------------------------------------
public void AddVertex(OBJFaceVertex lVertex)
{
m_Vertices.Add(lVertex);
}
//------------------------------------------------------------------------------------------------------------
public void ParseVertex(string lVertexString)
{
var fields = lVertexString.Split(new[] { '/' }, StringSplitOptions.None);
var lIndex = fields[0].ParseInvariantInt();
var faceVertex = new OBJFaceVertex
{
m_VertexIndex = lIndex - 1
};
if (fields.Length > 1)
{
lIndex = fields[1].Length == 0 ? 0 : fields[1].ParseInvariantInt();
faceVertex.m_UVIndex = lIndex - 1;
}
if (fields.Length > 2)
{
lIndex = fields[2].Length == 0 ? 0 : fields[2].ParseInvariantInt();
faceVertex.m_NormalIndex = lIndex - 1;
}
if (fields.Length > 3)
{
lIndex = fields[3].Length == 0 ? 0 : fields[3].ParseInvariantInt();
faceVertex.m_UV2Index = lIndex - 1;
}
if (fields.Length > 4)
{
lIndex = fields[4].Length == 0 ? 0 : fields[4].ParseInvariantInt();
faceVertex.m_ColorIndex = lIndex - 1;
}
AddVertex(faceVertex);
}
//------------------------------------------------------------------------------------------------------------
public string ToString(int lIndex)
{
OBJFaceVertex lFaceVertex = m_Vertices[lIndex];
string lOutput = (lFaceVertex.m_VertexIndex + 1).ToString();
if (lFaceVertex.m_UVIndex > -1)
{
lOutput += string.Format("/{0}", (lFaceVertex.m_UVIndex + 1).ToString());
}
if (lFaceVertex.m_NormalIndex > -1)
{
lOutput += string.Format("/{0}", (lFaceVertex.m_NormalIndex + 1).ToString());
}
if (lFaceVertex.m_UV2Index > -1)
{
lOutput += string.Format("/{0}", (lFaceVertex.m_UV2Index + 1).ToString());
}
if (lFaceVertex.m_ColorIndex > -1)
{
lOutput += string.Format("/{0}", (lFaceVertex.m_ColorIndex + 1).ToString());
}
return lOutput;
}
//------------------------------------------------------------------------------------------------------------
public OBJFaceVertex this[int i]
{
get { return m_Vertices[i]; }
}
//------------------------------------------------------------------------------------------------------------
public int Count
{
get { return m_Vertices.Count; }
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 07402f6cbfe2d0e40ab4d7363cb0ed64
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,25 @@

public class OBJFaceVertex
{
//------------------------------------------------------------------------------------------------------------
public int m_VertexIndex = -1;
public int m_UVIndex = -1;
public int m_UV2Index = -1;
public int m_NormalIndex = -1;
public int m_ColorIndex = -1;
public override int GetHashCode()
{
return m_VertexIndex ^ m_UVIndex ^ m_UV2Index ^ m_NormalIndex ^ m_ColorIndex;
}
public override bool Equals(object obj)
{
OBJFaceVertex faceVertex = (OBJFaceVertex)obj;
return m_VertexIndex == faceVertex.m_VertexIndex
&& m_UVIndex == faceVertex.m_UVIndex
&& m_UV2Index == faceVertex.m_UV2Index
&& m_NormalIndex == faceVertex.m_NormalIndex
&& m_ColorIndex == m_ColorIndex;
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 1f5cff977d3365a4f9f33933bb603037
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@

using System.Collections.Generic;
public class OBJGroup
{
//------------------------------------------------------------------------------------------------------------
private readonly List<OBJFace> m_Faces = new List<OBJFace>();
//------------------------------------------------------------------------------------------------------------
public OBJGroup(string lName)
{
m_Name = lName;
}
//------------------------------------------------------------------------------------------------------------
public string m_Name { get; private set; }
public OBJMaterial m_Material { get; set; }
//------------------------------------------------------------------------------------------------------------
public IList<OBJFace> Faces { get { return m_Faces; } }
//------------------------------------------------------------------------------------------------------------
public void AddFace(OBJFace lFace)
{
m_Faces.Add(lFace);
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 8508b6de42212c84ebaec559aed6c7b6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,219 @@

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityExtension;
/*
* Currently only supports Triangluar Meshes
*/
public class OBJLoader
{
//------------------------------------------------------------------------------------------------------------
private static OBJData m_OBJData = null;
//------------------------------------------------------------------------------------------------------------
private static OBJMaterial m_CurrentMaterial = null;
private static OBJGroup m_CurrentGroup = null;
#region PROCESSORS
//------------------------------------------------------------------------------------------------------------
private static readonly Dictionary<string, Action<string>> m_ParseOBJActionDictionary = new Dictionary<string, Action<string>>
{
{ "mtllib", (lEntry) => { /*Load MTL*/ } },
{ "usemtl", (lEntry) => { PushOBJGroupIfNeeded(); m_CurrentGroup.m_Material = m_OBJData.m_Materials.SingleOrDefault((lX) => { return lX.m_Name.EqualsInvariantCultureIgnoreCase(lEntry); }); } },
{ "v", (lEntry) => { m_OBJData.m_Vertices.Add(Utils.ParseVector3String(lEntry)); } },
{ "vn", (lEntry) => { m_OBJData.m_Normals.Add(Utils.ParseVector3String(lEntry)); } },
{ "vt", (lEntry) => { m_OBJData.m_UVs.Add(Utils.ParseVector2String(lEntry)); } },
{ "vt2", (lEntry) => { m_OBJData.m_UV2s.Add(Utils.ParseVector2String(lEntry)); } },
{ "vc", (lEntry) => { m_OBJData.m_Colors.Add(Utils.ParseVector4String(lEntry).ToColor()); } },
{ "f", PushOBJFace },
{ "g", PushOBJGroup },
};
//------------------------------------------------------------------------------------------------------------
private static readonly Dictionary<string, Action<string>> m_ParseMTLActionDictionary = new Dictionary<string, Action<string>>
{
{ "newmtl", PushOBJMaterial },
{ "Ka", (lEntry) => { m_CurrentMaterial.m_AmbientColor = Utils.ParseVector3String(lEntry).ToColor(); } },
{ "Kd", (lEntry) => { m_CurrentMaterial.m_DiffuseColor = Utils.ParseVector3String(lEntry).ToColor(); } },
{ "Ks", (lEntry) => { m_CurrentMaterial.m_SpecularColor = Utils.ParseVector3String(lEntry).ToColor(); } },
{ "Ns", (lEntry) => { m_CurrentMaterial.m_SpecularCoefficient = lEntry.ParseInvariantFloat(); } },
{ "d", (lEntry) => { m_CurrentMaterial.m_Transparency = lEntry.ParseInvariantFloat(); } },
{ "Tr", (lEntry) => { m_CurrentMaterial.m_Transparency = lEntry.ParseInvariantFloat(); } },
{ "illum", (lEntry) => { m_CurrentMaterial.m_IlluminationModel = lEntry.ParseInvariantInt(); } },
{ "map_Ka", (lEntry) => { m_CurrentMaterial.m_AmbientTextureMap = lEntry; } },
{ "map_Kd", (lEntry) => { m_CurrentMaterial.m_DiffuseTextureMap = lEntry; } },
{ "map_Ks", (lEntry) => { m_CurrentMaterial.m_SpecularTextureMap = lEntry; } },
{ "map_Ns", (lEntry) => { m_CurrentMaterial.m_SpecularHighlightTextureMap = lEntry; } },
{ "map_d", (lEntry) => { m_CurrentMaterial.m_AlphaTextureMap = lEntry; } },
{ "map_bump", (lEntry) => { m_CurrentMaterial.m_BumpMap = lEntry; } },
{ "bump", (lEntry) => { m_CurrentMaterial.m_BumpMap = lEntry; } },
{ "disp", (lEntry) => { m_CurrentMaterial.m_DisplacementMap = lEntry; } },
{ "decal",(lEntry) => { m_CurrentMaterial.m_StencilDecalMap = lEntry; } },
};
#endregion
#region PUBLIC_INTERFACE
//------------------------------------------------------------------------------------------------------------
public static OBJData LoadOBJ(Stream lStream)
{
m_OBJData = new OBJData();
m_CurrentMaterial = null;
m_CurrentGroup = null;
StreamReader lLineStreamReader = new StreamReader(lStream);
Action<string> lAction = null;
string lCurrentLine = null;
string[] lFields = null;
string lKeyword = null;
string lData = null;
while (!lLineStreamReader.EndOfStream)
{
lCurrentLine = lLineStreamReader.ReadLine();
if (StringExt.IsNullOrWhiteSpace(lCurrentLine)
|| lCurrentLine[0] == '#')
{
continue;
}
lFields = lCurrentLine.Trim().Split(null, 2);
if (lFields.Length < 2)
{
continue;
}
lKeyword = lFields[0].Trim();
lData = lFields[1].Trim();
lAction = null;
m_ParseOBJActionDictionary.TryGetValue(lKeyword.ToLowerInvariant(), out lAction);
if (lAction != null)
{
lAction(lData);
}
}
var lOBJData = m_OBJData;
m_OBJData = null;
return lOBJData;
}
//------------------------------------------------------------------------------------------------------------
public static void ExportOBJ(OBJData lData, Stream lStream)
{
StreamWriter lLineStreamWriter = new StreamWriter(lStream);
lLineStreamWriter.WriteLine(string.Format("# File exported by Unity3D version {0}", Application.unityVersion));
for (int lCount = 0; lCount < lData.m_Vertices.Count; ++lCount)
{
lLineStreamWriter.WriteLine(string.Format("v {0} {1} {2}",
lData.m_Vertices[lCount].x.ToString("n8"),
lData.m_Vertices[lCount].y.ToString("n8"),
lData.m_Vertices[lCount].z.ToString("n8")));
}
for (int lCount = 0; lCount < lData.m_UVs.Count; ++lCount)
{
lLineStreamWriter.WriteLine(string.Format("vt {0} {1}",
lData.m_UVs[lCount].x.ToString("n5"),
lData.m_UVs[lCount].y.ToString("n5")));
}
for (int lCount = 0; lCount < lData.m_UV2s.Count; ++lCount)
{
lLineStreamWriter.WriteLine(string.Format("vt2 {0} {1}",
lData.m_UVs[lCount].x.ToString("n5"),
lData.m_UVs[lCount].y.ToString("n5")));
}
for (int lCount = 0; lCount < lData.m_Normals.Count; ++lCount)
{
lLineStreamWriter.WriteLine(string.Format("vn {0} {1} {2}",
lData.m_Normals[lCount].x.ToString("n8"),
lData.m_Normals[lCount].y.ToString("n8"),
lData.m_Normals[lCount].z.ToString("n8")));
}
for (int lCount = 0; lCount < lData.m_Colors.Count; ++lCount)
{
lLineStreamWriter.WriteLine(string.Format("vc {0} {1} {2} {3}",
lData.m_Colors[lCount].r.ToString("n8"),
lData.m_Colors[lCount].g.ToString("n8"),
lData.m_Colors[lCount].b.ToString("n8"),
lData.m_Colors[lCount].a.ToString("n8")));
}
for (int lGroup = 0; lGroup < lData.m_Groups.Count; ++lGroup)
{
lLineStreamWriter.WriteLine(string.Format("g {0}", lData.m_Groups[lGroup].m_Name));
for (int lFace = 0; lFace < lData.m_Groups[lGroup].Faces.Count; ++lFace)
{
lLineStreamWriter.WriteLine(string.Format("f {0} {1} {2}",
lData.m_Groups[lGroup].Faces[lFace].ToString(0),
lData.m_Groups[lGroup].Faces[lFace].ToString(1),
lData.m_Groups[lGroup].Faces[lFace].ToString(2)));
}
}
lLineStreamWriter.Flush();
}
#endregion
//------------------------------------------------------------------------------------------------------------
private static void PushOBJMaterial(string lMaterialName)
{
m_CurrentMaterial = new OBJMaterial(lMaterialName);
m_OBJData.m_Materials.Add(m_CurrentMaterial);
}
//------------------------------------------------------------------------------------------------------------
private static void PushOBJGroup(string lGroupName)
{
m_CurrentGroup = new OBJGroup(lGroupName);
m_OBJData.m_Groups.Add(m_CurrentGroup);
}
//------------------------------------------------------------------------------------------------------------
private static void PushOBJGroupIfNeeded()
{
if (m_CurrentGroup == null)
{
PushOBJGroup("default");
}
}
//------------------------------------------------------------------------------------------------------------
private static void PushOBJFace(string lFaceLine)
{
PushOBJGroupIfNeeded();
var vertices = lFaceLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
var face = new OBJFace();
foreach (var vertexString in vertices)
{
face.ParseVertex(vertexString);
}
m_CurrentGroup.AddFace(face);
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: bda02739f6fbaeb4c8c3da925164b8cf
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@

using UnityEngine;
public class OBJMaterial
{
//------------------------------------------------------------------------------------------------------------
public OBJMaterial(string lMaterialName)
{
m_Name = lMaterialName;
}
//------------------------------------------------------------------------------------------------------------
public string m_Name;
//------------------------------------------------------------------------------------------------------------
public Color m_AmbientColor;
public Color m_DiffuseColor;
public Color m_SpecularColor;
public float m_SpecularCoefficient;
//------------------------------------------------------------------------------------------------------------
public float m_Transparency;
//------------------------------------------------------------------------------------------------------------
public int m_IlluminationModel;
//------------------------------------------------------------------------------------------------------------
public string m_AmbientTextureMap;
public string m_DiffuseTextureMap;
//------------------------------------------------------------------------------------------------------------
public string m_SpecularTextureMap;
public string m_SpecularHighlightTextureMap;
//------------------------------------------------------------------------------------------------------------
public string m_BumpMap;
public string m_DisplacementMap;
public string m_StencilDecalMap;
//------------------------------------------------------------------------------------------------------------
public string m_AlphaTextureMap;
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: ceb2526c78b78c04592f312a4e65ec95
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 32ca95fc59e8743b3b0033ddfb038e11
folderAsset: yes
timeCreated: 1465591252
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,39 @@

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Explicit)]
public struct Int32Converter
{
//------------------------------------------------------------------------------------------------------------
[FieldOffset(0)]
public int Value;
[FieldOffset(0)]
public byte Byte1;
[FieldOffset(1)]
public byte Byte2;
[FieldOffset(2)]
public byte Byte3;
[FieldOffset(3)]
public byte Byte4;
//------------------------------------------------------------------------------------------------------------
public Int32Converter(int value)
{
Byte1 = Byte2 = Byte3 = Byte4 = 0;
Value = value;
}
//------------------------------------------------------------------------------------------------------------
public static implicit operator Int32(Int32Converter value)
{
return value.Value;
}
//------------------------------------------------------------------------------------------------------------
public static implicit operator Int32Converter(int value)
{
return new Int32Converter(value);
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 2980235c1e3576a4ab7dca278af19308
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,36 @@
/* * * * * * * * * * * * Author's note * * * * * * * * * * * * * *\
* *
* ZZ$$Z$$$$Z$$$ *
* ZZZZZZZZZZZZZ *
* ZZZZZZZZZZZZZ *
* $ZZZZZZZZZZZZ *
* $ZZZZZZZZZZZZ *
* ZZ7=$OOO$?$ZO *
* Z7 $OZ IO *
* ZZZZZZZZOOOZOOOOOZZ8OZZZZZZZZZ *
* NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO *
* NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO *
* 8O8OOOOO8 88O88O8888888 D88888888 *
* 8OOOOOOO8 8OOON OO88 DO8888888 *
* DDDDDDDDD DDDD DDDD NDDDDDDDD *
* *
* http://octo-dev.co.uk *
* *
* OBJ-IO *
* *
* Copyright (c) Octo-Dev *
* *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
The scripts for this plugin are in [OBJ-IO/Plugins/OBJ]
and [OBJ-IO/Plugins/Extension].
There is an Example scene that Imports the Teapot OBJ at runtime,
distorts the vertexs and exports it again. The Export and Import
functions take System.IO.Stream as a parameter so this can be adapted
for your needs.
The System Current only supports geometry.
If there is any issue or bugs please contact : tim.leader.octo@gmail.com

View File

@@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: e1f277bf041647445ac3bf5b643a46fe
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1 @@


Binary file not shown.

View File

@@ -0,0 +1,282 @@
/*
* ZeroTier One - Network Virtualization Everywhere
* Copyright (C) 2011-2015 ZeroTier, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --
*
* ZeroTier may be used and distributed under the terms of the GPLv3, which
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
*
* If you would like to embed ZeroTier into a commercial application or
* redistribute it in a modified binary form, please contact ZeroTier Networks
* LLC. Start here: http://www.zerotier.com/
*/
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Threading;
using UnityEngine.Networking;
using System.Net.Sockets;
using System.Net;
using System.IO;
public class ZeroTierNetworkInterface {
// ZeroTier background thread
private Thread ztThread;
// Interop structures
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet=System.Runtime.InteropServices.CharSet.Ansi)]
public struct sockaddr {
/// u_short->unsigned short
public ushort sa_family;
/// char[14]
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst=14)]
public string sa_data;
}
// Virtual network interace config
private int MaxPacketSize;
private string rpc_path = "/does/this/work";
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void MyDelegate(string str);
static void CallBackFunction(string str) {
Debug.Log("Native ZT Plugin: " + str);
}
// ZeroTier service / debug initialization
[DllImport ("ZeroTierSDK_Unity3D_OSX")]
public static extern void SetDebugFunction( IntPtr fp );
[DllImport ("ZeroTierSDK_Unity3D_OSX")]
private static extern int unity_start_service(string path);
// Connection calls
[DllImport ("ZeroTierSDK_Unity3D_OSX")]
private static extern int zt_socket(int family, int type, int protocol);
[DllImport ("ZeroTierSDK_Unity3D_OSX")]
unsafe private static extern int zt_bind(int sockfd, System.IntPtr addr, int addrlen);
[DllImport ("ZeroTierSDK_Unity3D_OSX")]
unsafe private static extern int zt_connect(int sockfd, System.IntPtr addr, int addrlen);
[DllImport ("ZeroTierSDK_Unity3D_OSX")]
private static extern int zt_accept(int sockfd);
[DllImport ("ZeroTierSDK_Unity3D_OSX")]
private static extern int zt_listen(int sockfd, int backlog);
[DllImport ("ZeroTierSDK_Unity3D_OSX")]
private static extern int zt_close(int sockfd);
// RX / TX
[DllImport ("ZeroTierSDK_Unity3D_OSX")]
unsafe private static extern int zt_recv(int sockfd, System.IntPtr buf, int len);
[DllImport ("ZeroTierSDK_Unity3D_OSX")]
unsafe private static extern int zt_send(int sockfd, System.IntPtr buf, int len);
// ZT Thread controls
[DllImport ("ZeroTierSDK_Unity3D_OSX")]
private static extern bool zt_is_running();
[DllImport ("ZeroTierSDK_Unity3D_OSX")]
private static extern void zt_terminate();
// ZT Network controls
[DllImport ("ZeroTierSDK_Unity3D_OSX")]
private static extern bool zt_join_network(string nwid);
[DllImport ("ZeroTierSDK_Unity3D_OSX")]
private static extern void zt_leave_network(string nwid);
// Thread which starts the ZeroTier service
// The ZeroTier service may spin off a SOCKS5 proxy server
// if -DUSE_SOCKS_PROXY is set when building the bundle
private void zt_service_thread()
{
MyDelegate callback_delegate = new MyDelegate( CallBackFunction );
// Convert callback_delegate into a function pointer that can be
// used in unmanaged code.
IntPtr intptr_delegate =
Marshal.GetFunctionPointerForDelegate(callback_delegate);
// Call the API passing along the function pointer.
SetDebugFunction( intptr_delegate );
unity_start_service (rpc_path);
}
// Start the ZeroTier service
private void Init()
{
// TODO: Handle exceptions from unmanaged code
ztThread = new Thread(() => {
try {
zt_service_thread();
} catch(Exception e) {
Debug.Log(e.Message.ToString());
}
});
ztThread.IsBackground = true; // Allow the thread to be aborted safely
ztThread.Start();
}
// Initialize the ZeroTier service with a given path
public ZeroTierNetworkInterface(string path)
{
rpc_path = path;
Init();
}
// Initialize the ZeroTier service
public ZeroTierNetworkInterface()
{
Init();
}
// Initialize the ZeroTier service
// Use the GlobalConfig to set things like the max packet size
public ZeroTierNetworkInterface(GlobalConfig gConfig)
{
MaxPacketSize = gConfig.MaxPacketSize; // TODO: Do something with this!
Init();
}
// Joins a ZeroTier virtual network
public void JoinNetwork(string nwid)
{
zt_join_network(nwid);
}
// Leaves a ZeroTier virtual network
public void LeaveNetwork(string nwid)
{
zt_leave_network(nwid);
}
// Creates a ZeroTier Socket and binds on the port provided
// A client instance can now connect to this "host"
public int AddHost(int port)
{
int sockfd = zt_socket ((int)AddressFamily.InterNetwork, (int)SocketType.Stream, (int)ProtocolType.Unspecified);
if (sockfd < 0) {
return -1;
}
GCHandle sockaddr_ptr = ZeroTierUtils.Generate_unmananged_sockaddr("0.0.0.0" + ":" + port);
IntPtr pSockAddr = sockaddr_ptr.AddrOfPinnedObject ();
int addrlen = Marshal.SizeOf (pSockAddr);
return zt_bind (sockfd, pSockAddr, addrlen);
}
// hostId - host socket ID for this connection
public int Connect(int hostId, string address, int port, out byte error)
{
int sockfd = zt_socket ((int)AddressFamily.InterNetwork, (int)SocketType.Stream, (int)ProtocolType.Unspecified);
Debug.Log ("sockfd = " + sockfd);
if (sockfd < 0) {
error = (byte)sockfd;
return -1;
}
GCHandle sockaddr_ptr = ZeroTierUtils.Generate_unmananged_sockaddr(address + ":" + port);
IntPtr pSockAddr = sockaddr_ptr.AddrOfPinnedObject ();
int addrlen = Marshal.SizeOf (pSockAddr);
error = (byte)zt_connect (sockfd, pSockAddr, addrlen);
return sockfd;
}
// Returns whether the ZeroTier service is currently running
public bool IsRunning()
{
return zt_is_running ();
}
// Terminates the ZeroTier service
public void Terminate()
{
zt_terminate ();
}
// Shutdown a given connection
public int Disconnect(int fd)
{
return zt_close (fd);
}
// Sends data out over the network
public int Send(int fd, char[] buf, int len, out byte error)
{
int bytes_written = 0;
error = 0;
GCHandle buf_handle = GCHandle.Alloc (buf, GCHandleType.Pinned);
IntPtr pBufPtr = buf_handle.AddrOfPinnedObject ();
//int len = Marshal.SizeOf (pBufPtr);
if((bytes_written = zt_send (fd, pBufPtr, len)) < 0) {
error = (byte)bytes_written;
}
return bytes_written;
}
// Structure used to house arrays meant to be sent to unmanaged memory and passed to the
// ZeroTier service
public struct UnityArrayInput
{
public IntPtr array;
}
/*
// Sends data out over the network
public int Send(int fd, char[] buf, int len, out byte error)
{
//char[] buffer = new char[1024];
UnityArrayInput data = new UnityArrayInput ();
data.array = Marshal.AllocHGlobal (Marshal.SizeOf (typeof(char))*buf.Length);
//data.len = buf.Length;
int bytes_written = 0;
error = 0;
try
{
Marshal.Copy(buf, 0, data.array, buf.Length);
Debug.Log(buf.Length);
// ZT API call
if((bytes_written = zt_send (fd, data.array, buf.Length)) < 0) {
error = (byte)bytes_written;
}
return bytes_written;
}
finally
{
Marshal.FreeHGlobal (data.array);
}
return 0;
}
*/
// Checks for data to RX
public int OnReceive(int fd, byte[] buf, int len)
{
return 0;
//return zt_read(fd, buf, len);
}
}

View File

@@ -0,0 +1,55 @@
using UnityEngine;
using System.Collections;
using System.Net;
using System;
using System.Globalization;
using System.Runtime.InteropServices;
public class ZeroTierUtils {
// Handles IPv4 and IPv6 notation.
public static IPEndPoint CreateIPEndPoint(string endPoint)
{
string[] ep = endPoint.Split(':');
if (ep.Length < 2) throw new FormatException("Invalid endpoint format");
IPAddress ip;
if (ep.Length > 2) {
if (!IPAddress.TryParse(string.Join(":", ep, 0, ep.Length - 1), out ip)) {
throw new FormatException("Invalid ip-adress");
}
}
else {
if (!IPAddress.TryParse(ep[0], out ip)) {
throw new FormatException("Invalid ip-adress");
}
}
int port;
if (!int.TryParse(ep[ep.Length - 1], NumberStyles.None, NumberFormatInfo.CurrentInfo, out port)) {
throw new FormatException("Invalid port");
}
return new IPEndPoint(ip, port);
}
// Generates an unmanaged sockaddr structure from a string-formatted endpoint
public static GCHandle Generate_unmananged_sockaddr(string endpoint_str)
{
IPEndPoint ipEndPoint;
ipEndPoint = ZeroTierUtils.CreateIPEndPoint (endpoint_str);
SocketAddress socketAddress = ipEndPoint.Serialize ();
// use an array of bytes instead of the sockaddr structure
byte[] sockAddrStructureBytes = new byte[socketAddress.Size];
GCHandle sockAddrHandle = GCHandle.Alloc (sockAddrStructureBytes, GCHandleType.Pinned);
for (int i = 0; i < socketAddress.Size; ++i) {
sockAddrStructureBytes [i] = socketAddress [i];
}
return sockAddrHandle;
}
public static GCHandle Generate_unmanaged_buffer(byte[] buf)
{
// use an array of bytes instead of the sockaddr structure
GCHandle sockAddrHandle = GCHandle.Alloc (buf, GCHandleType.Pinned);
return sockAddrHandle;
}
}

View File

@@ -0,0 +1 @@
-unsafe

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@@ -0,0 +1,2 @@
m_EditorVersion: 5.3.5f1
m_StandardAssetsVersion: 0

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More