Initial commit
BIN
Documentation/Documentation.odt
Normal file
BIN
Documentation/Pictures/neighbour-1.png
Normal file
After Width: | Height: | Size: 503 KiB |
BIN
Documentation/Pictures/neighbour-5.png
Normal file
After Width: | Height: | Size: 362 KiB |
BIN
Documentation/Pictures/simplex-1.png
Normal file
After Width: | Height: | Size: 175 KiB |
BIN
Documentation/Pictures/simplex-2.png
Normal file
After Width: | Height: | Size: 69 KiB |
BIN
Documentation/Pictures/simplex-4.png
Normal file
After Width: | Height: | Size: 133 KiB |
BIN
Documentation/Pictures/simplex-8.png
Normal file
After Width: | Height: | Size: 221 KiB |
BIN
Documentation/Pictures/white-noise.png
Normal file
After Width: | Height: | Size: 347 KiB |
67
Game/Assembly-CSharp-firstpass-vs.csproj
Normal file
@ -0,0 +1,67 @@
|
||||
<?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>
|
||||
<ProjectGuid>{D8888F6A-ABE1-C49B-1A38-F65A81021668}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace></RootNamespace>
|
||||
<AssemblyName>Assembly-CSharp-firstpass</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_4_6_1;UNITY_4_6;UNITY_STANDALONE_WIN;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;UNITY_STANDALONE;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_MOVIES;ENABLE_WWW;ENABLE_IMAGEEFFECTS;ENABLE_4_6_FEATURES;INCLUDE_WP_BLUE_SUPPORT;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;RENDER_SOFTWARE_CURSOR;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_DUCK_TYPING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_WIN</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>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<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>E:/SDKs/Unity/Editor/Data/Managed/UnityEngine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEditor">
|
||||
<HintPath>E:/SDKs/Unity/Editor/Data/Managed/UnityEditor.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\Standard Assets\Character Controllers\Sources\Scripts\MouseLook.cs" />
|
||||
<Compile Include="Assets\Standard Assets\Water (Basic)\Sources\Scripts\WaterSimple.cs" />
|
||||
<None Include="Assets\Data\Biomes\Mountain\Mountain.xml" />
|
||||
<None Include="Assets\Standard Assets\Water (Basic)\Sources\Shaders\FX-Water Simple.shader" />
|
||||
<None Include="Assets\Data\Biomes\Grassland\Grassland.xml" />
|
||||
<Reference Include="UnityEngine.UI">
|
||||
<HintPath>E:/SDKs/Unity/Editor/Data/UnityExtensions/Unity/GUISystem/4.6.1/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>
|
67
Game/Assembly-CSharp-firstpass.csproj
Normal file
@ -0,0 +1,67 @@
|
||||
<?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>
|
||||
<ProjectGuid>{D8888F6A-ABE1-C49B-1A38-F65A81021668}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace></RootNamespace>
|
||||
<AssemblyName>Assembly-CSharp-firstpass</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_4_6_1;UNITY_4_6;UNITY_STANDALONE_WIN;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;UNITY_STANDALONE;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_MOVIES;ENABLE_WWW;ENABLE_IMAGEEFFECTS;ENABLE_4_6_FEATURES;INCLUDE_WP_BLUE_SUPPORT;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;RENDER_SOFTWARE_CURSOR;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_DUCK_TYPING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_WIN</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>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<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>E:/SDKs/Unity/Editor/Data/Managed/UnityEngine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEditor">
|
||||
<HintPath>E:/SDKs/Unity/Editor/Data/Managed/UnityEditor.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\Standard Assets\Character Controllers\Sources\Scripts\MouseLook.cs" />
|
||||
<Compile Include="Assets\Standard Assets\Water (Basic)\Sources\Scripts\WaterSimple.cs" />
|
||||
<None Include="Assets\Data\Biomes\Mountain\Mountain.xml" />
|
||||
<None Include="Assets\Standard Assets\Water (Basic)\Sources\Shaders\FX-Water Simple.shader" />
|
||||
<None Include="Assets\Data\Biomes\Grassland\Grassland.xml" />
|
||||
<Reference Include="UnityEngine.UI">
|
||||
<HintPath>E:/SDKs/Unity/Editor/Data/UnityExtensions/Unity/GUISystem/4.6.1/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>
|
90
Game/Assembly-CSharp-vs.csproj
Normal file
@ -0,0 +1,90 @@
|
||||
<?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>
|
||||
<ProjectGuid>{DDFBC18F-9396-3137-9CFE-DEB2CDB74636}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace></RootNamespace>
|
||||
<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_4_6_1;UNITY_4_6;UNITY_STANDALONE_WIN;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;UNITY_STANDALONE;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_MOVIES;ENABLE_WWW;ENABLE_IMAGEEFFECTS;ENABLE_4_6_FEATURES;INCLUDE_WP_BLUE_SUPPORT;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;RENDER_SOFTWARE_CURSOR;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_DUCK_TYPING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_WIN</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>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<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>E:/SDKs/Unity/Editor/Data/Managed/UnityEngine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEditor">
|
||||
<HintPath>E:/SDKs/Unity/Editor/Data/Managed/UnityEditor.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\Scripts\Business\BiomeManager.cs" />
|
||||
<Compile Include="Assets\Scripts\Business\ConfigurationManager.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\MapImageRenderer.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\TerrainGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\InitializeScript.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\Biome.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\Config\TerrainGeneratorConfig.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\Map.cs" />
|
||||
<Compile Include="Assets\Scripts\Noise\NoiseGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Noise\PerlinNoiseGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\TerrainGeneratorScript.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\Algorithms.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\Algorithms\GridTraverseAlgorithm.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\ColorHelper.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\Logger.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\RandomExtensions.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\Range.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\Texture2DExtensions.cs" />
|
||||
<None Include="Assets\Data\Biomes\Mountain\Mountain.xml" />
|
||||
<None Include="Assets\Standard Assets\Water (Basic)\Sources\Shaders\FX-Water Simple.shader" />
|
||||
<None Include="Assets\Data\Biomes\Grassland\Grassland.xml" />
|
||||
<Reference Include="Assembly-UnityScript-firstpass">
|
||||
<HintPath>E:/Facultate/$ Licenta/Game/Library/ScriptAssemblies/Assembly-UnityScript-firstpass.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UI">
|
||||
<HintPath>E:/SDKs/Unity/Editor/Data/UnityExtensions/Unity/GUISystem/4.6.1/UnityEngine.UI.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="Assembly-CSharp-firstpass-vs.csproj">
|
||||
<Project>{D8888F6A-ABE1-C49B-1A38-F65A81021668}</Project> <Name>Assembly-CSharp-firstpass-vs</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>
|
89
Game/Assembly-CSharp.csproj
Normal file
@ -0,0 +1,89 @@
|
||||
<?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>
|
||||
<ProjectGuid>{DDFBC18F-9396-3137-9CFE-DEB2CDB74636}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace></RootNamespace>
|
||||
<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_4_6_1;UNITY_4_6;UNITY_STANDALONE_WIN;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;UNITY_STANDALONE;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_MOVIES;ENABLE_WWW;ENABLE_IMAGEEFFECTS;ENABLE_4_6_FEATURES;INCLUDE_WP_BLUE_SUPPORT;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;RENDER_SOFTWARE_CURSOR;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_DUCK_TYPING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_WIN</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>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<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>E:/SDKs/Unity/Editor/Data/Managed/UnityEngine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEditor">
|
||||
<HintPath>E:/SDKs/Unity/Editor/Data/Managed/UnityEditor.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\Scripts\Business\BiomeManager.cs" />
|
||||
<Compile Include="Assets\Scripts\Business\ConfigurationManager.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\MapImageRenderer.cs" />
|
||||
<Compile Include="Assets\Scripts\Generator\TerrainGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\InitializeScript.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\Biome.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\Config\TerrainGeneratorConfig.cs" />
|
||||
<Compile Include="Assets\Scripts\Model\Map.cs" />
|
||||
<Compile Include="Assets\Scripts\Noise\NoiseGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\Noise\PerlinNoiseGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\TerrainGeneratorScript.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\Algorithms.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\Algorithms\GridTraverseAlgorithm.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\ColorHelper.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\Logger.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\RandomExtensions.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\Range.cs" />
|
||||
<Compile Include="Assets\Scripts\Utils\Texture2DExtensions.cs" />
|
||||
<None Include="Assets\Data\Biomes\Mountain\Mountain.xml" />
|
||||
<None Include="Assets\Standard Assets\Water (Basic)\Sources\Shaders\FX-Water Simple.shader" />
|
||||
<None Include="Assets\Data\Biomes\Grassland\Grassland.xml" />
|
||||
<Reference Include="UnityEngine.UI">
|
||||
<HintPath>E:/SDKs/Unity/Editor/Data/UnityExtensions/Unity/GUISystem/4.6.1/UnityEngine.UI.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="Assembly-CSharp-firstpass.csproj">
|
||||
<Project>{D8888F6A-ABE1-C49B-1A38-F65A81021668}</Project> <Name>Assembly-CSharp-firstpass</Name> </ProjectReference>
|
||||
<ProjectReference Include="Assembly-UnityScript-firstpass.unityproj">
|
||||
<Project>{6F824ECF-F2BC-827E-A29D-FB10759A3283}</Project> <Name>Assembly-UnityScript-firstpass</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>
|
68
Game/Assembly-UnityScript-firstpass-vs.unityproj
Normal file
@ -0,0 +1,68 @@
|
||||
<?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>
|
||||
<ProjectGuid>{6F824ECF-F2BC-827E-A29D-FB10759A3283}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace></RootNamespace>
|
||||
<AssemblyName>Assembly-UnityScript-firstpass</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_4_6_1;UNITY_4_6;UNITY_STANDALONE_WIN;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;UNITY_STANDALONE;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_MOVIES;ENABLE_WWW;ENABLE_IMAGEEFFECTS;ENABLE_4_6_FEATURES;INCLUDE_WP_BLUE_SUPPORT;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;RENDER_SOFTWARE_CURSOR;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_DUCK_TYPING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_WIN</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>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<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>E:/SDKs/Unity/Editor/Data/Managed/UnityEngine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEditor">
|
||||
<HintPath>E:/SDKs/Unity/Editor/Data/Managed/UnityEditor.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\Standard Assets\Character Controllers\Sources\Scripts\CharacterMotor.js" />
|
||||
<Compile Include="Assets\Standard Assets\Character Controllers\Sources\Scripts\FPSInputController.js" />
|
||||
<Compile Include="Assets\Standard Assets\Character Controllers\Sources\Scripts\PlatformInputController.js" />
|
||||
<None Include="Assets\Data\Biomes\Mountain\Mountain.xml" />
|
||||
<None Include="Assets\Standard Assets\Water (Basic)\Sources\Shaders\FX-Water Simple.shader" />
|
||||
<None Include="Assets\Data\Biomes\Grassland\Grassland.xml" />
|
||||
<Reference Include="UnityEngine.UI">
|
||||
<HintPath>E:/SDKs/Unity/Editor/Data/UnityExtensions/Unity/GUISystem/4.6.1/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>
|
68
Game/Assembly-UnityScript-firstpass.unityproj
Normal file
@ -0,0 +1,68 @@
|
||||
<?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>
|
||||
<ProjectGuid>{6F824ECF-F2BC-827E-A29D-FB10759A3283}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace></RootNamespace>
|
||||
<AssemblyName>Assembly-UnityScript-firstpass</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_4_6_1;UNITY_4_6;UNITY_STANDALONE_WIN;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;UNITY_STANDALONE;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_MOVIES;ENABLE_WWW;ENABLE_IMAGEEFFECTS;ENABLE_4_6_FEATURES;INCLUDE_WP_BLUE_SUPPORT;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;RENDER_SOFTWARE_CURSOR;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_DUCK_TYPING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_WIN</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>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<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>E:/SDKs/Unity/Editor/Data/Managed/UnityEngine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEditor">
|
||||
<HintPath>E:/SDKs/Unity/Editor/Data/Managed/UnityEditor.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\Standard Assets\Character Controllers\Sources\Scripts\CharacterMotor.js" />
|
||||
<Compile Include="Assets\Standard Assets\Character Controllers\Sources\Scripts\FPSInputController.js" />
|
||||
<Compile Include="Assets\Standard Assets\Character Controllers\Sources\Scripts\PlatformInputController.js" />
|
||||
<None Include="Assets\Data\Biomes\Mountain\Mountain.xml" />
|
||||
<None Include="Assets\Standard Assets\Water (Basic)\Sources\Shaders\FX-Water Simple.shader" />
|
||||
<None Include="Assets\Data\Biomes\Grassland\Grassland.xml" />
|
||||
<Reference Include="UnityEngine.UI">
|
||||
<HintPath>E:/SDKs/Unity/Editor/Data/UnityExtensions/Unity/GUISystem/4.6.1/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>
|
5
Game/Assets/Data.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ffafb571841a6a4eab181ab39f2dd7b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
5
Game/Assets/Data/Biomes.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4398a2c63a0df143943c8718cc74e40
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
5
Game/Assets/Data/Biomes/Grassland.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61ae52d5f1b61634dad1bf5f17f2ffbd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
7
Game/Assets/Data/Biomes/Grassland/Grassland.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<biome>
|
||||
<name>Grassland</name>
|
||||
<heightRange min="0" max="1" />
|
||||
<moisture min=".1" max=".5"/>
|
||||
<vegetationDensity min=".2" max=".5" />
|
||||
</biome>
|
4
Game/Assets/Data/Biomes/Grassland/Grassland.xml.meta
Normal file
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69e9c08fb2f75174182f358acfd9e046
|
||||
TextScriptImporter:
|
||||
userData:
|
5
Game/Assets/Data/Biomes/Mountain.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64548912db7fa384bae6c01a19c19da8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
7
Game/Assets/Data/Biomes/Mountain/Mountain.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<biome>
|
||||
<name>Mountain</name>
|
||||
<heightRange min="0" max="10" />
|
||||
<moisture min=".1" max=".3"/>
|
||||
<vegetationDensity min=".5" max=".9" />
|
||||
</biome>
|
4
Game/Assets/Data/Biomes/Mountain/Mountain.xml.meta
Normal file
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 50d52558244dee444936bce1f2bd9e0a
|
||||
TextScriptImporter:
|
||||
userData:
|
5
Game/Assets/Data/Config.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7728461dde998444ab0667b82741a27
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
BIN
Game/Assets/Main.unity
Normal file
4
Game/Assets/Main.unity.meta
Normal file
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d90d5223619e67c40af973fd455a513c
|
||||
DefaultImporter:
|
||||
userData:
|
5
Game/Assets/Scripts.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1bf12227f09bb646a5c0a9081791c24
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
5
Game/Assets/Scripts/Business.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44471b44c7c4ac24da59e339e3d53ef4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
54
Game/Assets/Scripts/Business/BiomeManager.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using TransportGame.Model;
|
||||
using TransportGame.Utils;
|
||||
|
||||
namespace TransportGame.Business
|
||||
{
|
||||
public static class BiomeManager
|
||||
{
|
||||
private static Dictionary<string, Biome> biomes = new Dictionary<string, Biome>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the loaded biomes
|
||||
/// </summary>
|
||||
public static IEnumerable<Biome> Biomes
|
||||
{
|
||||
get
|
||||
{
|
||||
return biomes.Values;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the biomes from the Biome directory.
|
||||
/// </summary>
|
||||
public static void LoadBiomes()
|
||||
{
|
||||
foreach (var file in Directory.GetFiles(ConfigurationManager.BiomeDirectory, "*.xml", SearchOption.AllDirectories))
|
||||
{
|
||||
try
|
||||
{
|
||||
// Open file
|
||||
var stream = File.OpenRead(file);
|
||||
|
||||
// Try to deserialize biome
|
||||
XmlSerializer serializer = new XmlSerializer(typeof(Biome));
|
||||
var biome = (Biome)serializer.Deserialize(stream);
|
||||
|
||||
// Add it to biome list
|
||||
biomes.Add(file, biome);
|
||||
Logger.Info("Loaded biome '{0}' from file '{1}'.", biome.Name, file);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Exception(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Business/BiomeManager.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82e9dc6ef4e61c2468a98567ff4d4a17
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
20
Game/Assets/Scripts/Business/ConfigurationManager.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Assets.Scripts.Model.Config;
|
||||
|
||||
namespace TransportGame.Business
|
||||
{
|
||||
public static class ConfigurationManager
|
||||
{
|
||||
public static readonly string BiomeDirectory = "Assets\\Data\\Biomes";
|
||||
public static readonly string ConfigurationDirectory = "Assets\\Data\\Config";
|
||||
|
||||
public static TerrainGeneratorConfig TerrGenConfig { get; private set; }
|
||||
|
||||
public static void LoadConfiguration()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e18c16459f0ad3b4aa2ce07825b41222
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
5
Game/Assets/Scripts/Generator.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48bbce5a58e77054b8048679600cd5d8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
155
Game/Assets/Scripts/Generator/MapImageRenderer.cs
Normal file
@ -0,0 +1,155 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using TransportGame.Model;
|
||||
using TransportGame.Utils;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TransportGame.Generators
|
||||
{
|
||||
public static class MapImageRenderer
|
||||
{
|
||||
[Flags]
|
||||
public enum Layers
|
||||
{
|
||||
None = 0,
|
||||
Elevation = 1,
|
||||
Grid = 2,
|
||||
Centers = 4,
|
||||
All = Elevation | Grid | Centers
|
||||
};
|
||||
|
||||
private const int Scale = 20;
|
||||
|
||||
/// <summary>
|
||||
/// Renders a map to a file
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="layers"></param>
|
||||
//public static void Render(this Map map, string file, Layers layers = Layers.All)
|
||||
//{
|
||||
// // Create texture on which to draw
|
||||
// Texture2D texture = new Texture2D(
|
||||
// map.Width * Scale,
|
||||
// map.Height * Scale,
|
||||
// TextureFormat.RGB24,
|
||||
// false);
|
||||
|
||||
// // First layer - cells
|
||||
// DrawCells(texture, map, (layers & Layers.Elevation) > 0, (layers & Layers.Centers) > 0);
|
||||
|
||||
// // Second layer - grid
|
||||
// if ((layers & Layers.Grid) > 0)
|
||||
// DrawGrid(texture, map);
|
||||
|
||||
// // Write to file
|
||||
// File.WriteAllBytes(file + ".png", texture.EncodeToPNG());
|
||||
//}
|
||||
|
||||
//private static void DrawCells(Texture2D texture, Map map, bool elevation, bool centers)
|
||||
//{
|
||||
// for (int x = 0; x < map.Width; x++)
|
||||
// for (int y = 0; y < map.Height; y++)
|
||||
// {
|
||||
// // Calculate scaled corners
|
||||
// Vector2 c00 = new Vector2(
|
||||
// map[x, y].Corner00.Pos.x * Scale,
|
||||
// map[x, y].Corner00.Pos.y * Scale);
|
||||
// Vector2 c01 = new Vector2(
|
||||
// map[x, y].Corner01.Pos.x * Scale,
|
||||
// map[x, y].Corner01.Pos.y * Scale);
|
||||
// Vector2 c10 = new Vector2(
|
||||
// map[x, y].Corner10.Pos.x * Scale,
|
||||
// map[x, y].Corner10.Pos.y * Scale);
|
||||
// Vector2 c11 = new Vector2(
|
||||
// map[x, y].Corner11.Pos.x * Scale,
|
||||
// map[x, y].Corner11.Pos.y * Scale);
|
||||
|
||||
// // Calculate color
|
||||
// Color c = ColorHelper.FromArgb(0x555500);
|
||||
|
||||
// // Water - always blue
|
||||
// if (map.IsWater(x, y))
|
||||
// c = Color.blue;
|
||||
|
||||
// // Map type is elevation map - get elevation color
|
||||
// else if (elevation)
|
||||
// c = GetCollorOfTerrain(map[x, y].Elevation);
|
||||
|
||||
// // Draw polygon
|
||||
// texture.FillPolygon(c, c00, c01, c11, c10);
|
||||
|
||||
// // Draw center
|
||||
// if (centers)
|
||||
// texture.DrawPoint(Color.red,
|
||||
// Convert.ToInt32(map[x, y].Center.x * Scale),
|
||||
// Convert.ToInt32(map[x, y].Center.y * Scale),
|
||||
// 2);
|
||||
// }
|
||||
//}
|
||||
|
||||
//private static void DrawGrid(Texture2D texture, Map map)
|
||||
//{
|
||||
// for (int x = 0; x < map.Width + 1; x++)
|
||||
// for (int y = 0; y < map.Height + 1; y++)
|
||||
// {
|
||||
// Corner c0 = map.Corner(x, y);
|
||||
// Vector2 c0pos = new Vector2(c0.Pos.x * Scale, c0.Pos.y * Scale);
|
||||
|
||||
// // Draw edges
|
||||
// if (x > 0)
|
||||
// {
|
||||
// Corner c1 = map.Corner(x - 1, y);
|
||||
// Vector2 c1pos = new Vector2(c1.Pos.x * Scale, c1.Pos.y * Scale);
|
||||
// texture.DrawLine(Color.white, c0pos, c1pos);
|
||||
// }
|
||||
// if (y > 0)
|
||||
// {
|
||||
// Corner c1 = map.Corner(x, y - 1);
|
||||
// Vector2 c1pos = new Vector2(c1.Pos.x * Scale, c1.Pos.y * Scale);
|
||||
// texture.DrawLine(Color.white, c0pos, c1pos);
|
||||
// }
|
||||
|
||||
// // Draw corner
|
||||
// texture.DrawPoint(Color.white, c0pos, 2);
|
||||
// }
|
||||
//}
|
||||
|
||||
private static Color GetCollorOfTerrain(float height)
|
||||
{
|
||||
Color color1, color2;
|
||||
float alpha;
|
||||
|
||||
if (height < 10f)
|
||||
{
|
||||
color1 = ColorHelper.FromArgb(0x00ffa2);
|
||||
color2 = ColorHelper.FromArgb(0xFCD628);
|
||||
alpha = height / 10f;
|
||||
}
|
||||
|
||||
else if (height < 25f)
|
||||
{
|
||||
color1 = ColorHelper.FromArgb(0xFCD628);
|
||||
color2 = ColorHelper.FromArgb(0x9C6713);
|
||||
alpha = (height - 10f) / 15f;
|
||||
}
|
||||
|
||||
else if (height < 50f)
|
||||
{
|
||||
color1 = ColorHelper.FromArgb(0xaaaaaa);
|
||||
color2 = ColorHelper.FromArgb(0xffffff);
|
||||
alpha = (height - 25f) / 25f;
|
||||
}
|
||||
else
|
||||
{
|
||||
color1 = color2 = Color.white;
|
||||
alpha = 1;
|
||||
}
|
||||
|
||||
return Color.Lerp(color1, color2, alpha);
|
||||
}
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Generator/MapImageRenderer.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d89d584776261fe4b81720b3615755bb
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
61
Game/Assets/Scripts/Generator/TerrainGenerator.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using TransportGame.Business;
|
||||
using TransportGame.Model;
|
||||
using TransportGame.Noise;
|
||||
using TransportGame.Utils;
|
||||
using TransportGame.Utils.Algorithms;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TransportGame.Generator
|
||||
{
|
||||
public class TerrainGenerator
|
||||
{
|
||||
public NoiseGenerator Noise { get; set; }
|
||||
|
||||
private System.Random random = new System.Random();
|
||||
|
||||
public TerrainGenerator()
|
||||
{
|
||||
Noise = new PerlinNoiseGenerator();
|
||||
Noise.Octaves = ConfigurationManager.TerrGenConfig.NoiseOctaves;
|
||||
Noise.NonLinearPower = ConfigurationManager.TerrGenConfig.NoiseNonLinearPower;
|
||||
Noise.Scale = ConfigurationManager.TerrGenConfig.ElevationScale;
|
||||
}
|
||||
|
||||
public Map Generate(int width, int height)
|
||||
{
|
||||
// Create map
|
||||
Map map = new Map(width, height);
|
||||
|
||||
// Pick a random biome
|
||||
map.Biome = PickBiome();
|
||||
|
||||
// Generate elevation
|
||||
GenerateElevation(map);
|
||||
|
||||
// Generate water level
|
||||
float waterAmount = random.NextSingle(map.Biome.Moisture.Minimum, map.Biome.Moisture.Maximum);
|
||||
map.WaterLevel = Mathf.Pow(waterAmount, 3) * (map.Biome.HeightRange.Maximum - map.Biome.HeightRange.Minimum) + map.Biome.HeightRange.Minimum;
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private Biome PickBiome()
|
||||
{
|
||||
int biomeCount = BiomeManager.Biomes.Count();
|
||||
int biome = random.Next(biomeCount);
|
||||
|
||||
return BiomeManager.Biomes.ElementAt(biome);
|
||||
}
|
||||
|
||||
private void GenerateElevation(Map map)
|
||||
{
|
||||
for (int x = 0; x < map.Width; ++x)
|
||||
for (int y = 0; y < map.Height; ++y)
|
||||
map[x, y] = Noise.Generate(x, y, map.Biome.HeightRange.Minimum, map.Biome.HeightRange.Maximum);
|
||||
}
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Generator/TerrainGenerator.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4042531a480f4149bdda36c67975b0c
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
109
Game/Assets/Scripts/InitializeScript.cs
Normal file
@ -0,0 +1,109 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using TransportGame.Utils;
|
||||
using TransportGame.Model;
|
||||
using TransportGame.Generators;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using TransportGame.Business;
|
||||
|
||||
public class InitializeScript : MonoBehaviour
|
||||
{
|
||||
public Material TerrainMaterial;
|
||||
public int TerrainWidth = 256, TerrainHeight = 256;
|
||||
|
||||
private Map map;
|
||||
|
||||
// Use this for initialization
|
||||
public void Start()
|
||||
{
|
||||
StartCoroutine(GenerateMap());
|
||||
}
|
||||
|
||||
private IEnumerator GenerateMap()
|
||||
{
|
||||
// Load biomes
|
||||
Logger.Info("Loading biomes...");
|
||||
BiomeManager.LoadBiomes();
|
||||
Logger.Info("Finished loading biomes.");
|
||||
|
||||
// Generate map in the other thread
|
||||
Thread thread = new Thread(GenerateMapThread);
|
||||
thread.Start();
|
||||
|
||||
while (thread.ThreadState == ThreadState.Running)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
thread.Join();
|
||||
|
||||
// map.Render(@"C:\Users\Tiberiu\Desktop\img");
|
||||
|
||||
// Log - Generate mesh
|
||||
yield return null;
|
||||
Debug.Log("Generating mesh...");
|
||||
|
||||
var heights = new float[map.Width, map.Height];
|
||||
for (int x = 0; x < map.Width; x++)
|
||||
for (int y = 0; y < map.Height; y++)
|
||||
heights[x, y] = map[y, x] / 50f;
|
||||
|
||||
// Generate mesh using terraindata
|
||||
TerrainData terrainData = new TerrainData();
|
||||
terrainData.heightmapResolution = map.Width;
|
||||
terrainData.size = new Vector3(map.Width * MapMeshGenerator.Scale, 50.0f * MapMeshGenerator.Strength, map.Height * MapMeshGenerator.Scale);
|
||||
//terrainData.baseMapResolution = 1024;
|
||||
//terrainData.alphamapResolution = 512;
|
||||
terrainData.SetDetailResolution(1024, 8);
|
||||
terrainData.SetHeights(0, 0, heights);
|
||||
terrainData.name = "Le terrain data";
|
||||
|
||||
GameObject terrainObj = Terrain.CreateTerrainGameObject(terrainData);
|
||||
terrainObj.name = "Le Terrain";
|
||||
Terrain t1 = terrainObj.GetComponent<Terrain>();
|
||||
t1.heightmapPixelError = 1;
|
||||
|
||||
MapMeshGenerator meshGen = new MapMeshGenerator(map);
|
||||
//for (int x = 0; x < meshGen.ChunksWidth; x++)
|
||||
// for (int y = 0; y < meshGen.ChunksHeight; y++)
|
||||
// {
|
||||
// CreateGameObjectFromMesh(string.Format("chunk_{0}_{1}", x, y), meshGen[x, y], TerrainMaterial);
|
||||
// yield return null;
|
||||
// }
|
||||
|
||||
// Generate water
|
||||
GameObject water = GameObject.Find("Water");
|
||||
MeshFilter waterFilter = water.GetComponent<MeshFilter>();
|
||||
waterFilter.mesh = meshGen.Water;
|
||||
yield return null;
|
||||
|
||||
Debug.Log("Finished generating map.");
|
||||
yield return null;
|
||||
}
|
||||
|
||||
private void CreateGameObjectFromMesh(string name, Mesh mesh, Material material)
|
||||
{
|
||||
GameObject gameObject = new GameObject(name);
|
||||
|
||||
// Add mesh filter component
|
||||
MeshFilter meshFilter = gameObject.AddComponent<MeshFilter>();
|
||||
meshFilter.mesh = mesh;
|
||||
|
||||
// Add mesh render component
|
||||
MeshRenderer meshRenderer = gameObject.AddComponent<MeshRenderer>();
|
||||
meshRenderer.material = material;
|
||||
}
|
||||
|
||||
private void GenerateMapThread()
|
||||
{
|
||||
MapGenerator mapGen = new MapGenerator();
|
||||
map = mapGen.Generate(TerrainWidth, TerrainHeight);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/InitializeScript.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1e1bcc13284685449456c96db1d1754
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
5
Game/Assets/Scripts/Model.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a9b1f8f4e926c744ca43952af763e85b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
44
Game/Assets/Scripts/Model/Biome.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using TransportGame.Utils;
|
||||
|
||||
namespace TransportGame.Model
|
||||
{
|
||||
[XmlRoot("biome")]
|
||||
public class Biome
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the biome
|
||||
/// </summary>
|
||||
[XmlElement("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the height range of the biome.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 1 unit = 100 meters.
|
||||
/// </remarks>
|
||||
[XmlElement("heightRange")]
|
||||
public Range HeightRange { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the moisture range.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Moisture is the amount of water on a map.
|
||||
/// Value is a probability, should be between 0 and 1.
|
||||
/// </remarks>
|
||||
[XmlElement("moisture")]
|
||||
public Range Moisture { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the vegetation density of the biome
|
||||
/// </summary>
|
||||
[XmlElement("vegetationDensity")]
|
||||
public Range VegetationDensity { get; set; }
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Model/Biome.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15c4c7a1393cf2b4e9520d38705830a3
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
5
Game/Assets/Scripts/Model/Config.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 976fce089fd84a043888fb58c4c5580a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
19
Game/Assets/Scripts/Model/Config/TerrainGeneratorConfig.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Assets.Scripts.Model.Config
|
||||
{
|
||||
[XmlRoot("terrgenConfig")]
|
||||
public class TerrainGeneratorConfig
|
||||
{
|
||||
public int NoiseOctaves { get; set; }
|
||||
|
||||
public float NoiseNonLinearPower { get; set; }
|
||||
|
||||
public float ElevationScale { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a3817f3a7058cc41b46eb849acf069b
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
72
Game/Assets/Scripts/Model/Map.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TransportGame.Model
|
||||
{
|
||||
public class Map
|
||||
{
|
||||
private float[,] grid;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the water level
|
||||
/// </summary>
|
||||
public float WaterLevel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the biome
|
||||
/// </summary>
|
||||
public Biome Biome { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the map
|
||||
/// </summary>
|
||||
/// <param name="width"></param>
|
||||
/// <param name="height"></param>
|
||||
public Map(int width, int height)
|
||||
{
|
||||
grid = new float[width, height];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the cell at specified position
|
||||
/// </summary>
|
||||
/// <param name="x">X</param>
|
||||
/// <param name="y">Y</param>
|
||||
/// <returns>Cell</returns>
|
||||
public float this[int x, int y]
|
||||
{
|
||||
get
|
||||
{
|
||||
return grid[x, y];
|
||||
}
|
||||
set
|
||||
{
|
||||
grid[x, y] = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets width of map
|
||||
/// </summary>
|
||||
public int Width { get { return grid.GetLength(0); } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets height of map
|
||||
/// </summary>
|
||||
public int Height { get { return grid.GetLength(1); } }
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if specified cell is a water cell
|
||||
/// </summary>
|
||||
/// <param name="x">X</param>
|
||||
/// <param name="y">Y</param>
|
||||
/// <returns></returns>
|
||||
public bool IsWater(int x, int y)
|
||||
{
|
||||
return grid[x, y] <= WaterLevel;
|
||||
}
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Model/Map.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc6d250254fab4447aa1b764a56d3373
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
5
Game/Assets/Scripts/Noise.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0f8f06d46c43004e86c37ef7faed5f3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
137
Game/Assets/Scripts/Noise/NoiseGenerator.cs
Normal file
@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using TransportGame.Utils;
|
||||
|
||||
namespace TransportGame.Noise
|
||||
{
|
||||
public abstract class NoiseGenerator
|
||||
{
|
||||
public float Scale { get; set; }
|
||||
public float Low { get; set; }
|
||||
public float High { get; set; }
|
||||
public float NonLinearPower { get; set; }
|
||||
public int Octaves { get; set; }
|
||||
public float Persistence { get; set; }
|
||||
|
||||
private float seedX, seedY;
|
||||
|
||||
public NoiseGenerator()
|
||||
{
|
||||
System.Random random = new System.Random();
|
||||
seedX = random.NextSingle(-10000f, 10000f);
|
||||
seedY = random.NextSingle(-10000f, 10000f);
|
||||
|
||||
Scale = 1f;
|
||||
Low = -1f;
|
||||
High = 1f;
|
||||
NonLinearPower = 1f;
|
||||
Octaves = 1;
|
||||
Persistence = .5f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Produces noise in the [-1,1] interval
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <returns></returns>
|
||||
protected abstract float GenerateNoise(float x, float y);
|
||||
|
||||
/// <summary>
|
||||
/// Generates noise
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate</param>
|
||||
/// <param name="y">Y coordinate</param>
|
||||
/// <param name="low">Minimum value</param>
|
||||
/// <param name="high">Maximum value</param>
|
||||
/// <param name="scale">Scale</param>
|
||||
/// <param name="octaves">Number of octaves (layers)</param>
|
||||
/// <param name="persistence">Persistence (impact of each layer)</param>
|
||||
/// <param name="nonLinearPower">Non-linearity</param>
|
||||
/// <returns>Noise</returns>
|
||||
public float Generate(float x, float y, float low, float high, float scale, int octaves, float persistence, float nonLinearPower)
|
||||
{
|
||||
float value = 0;
|
||||
int freq = 1;
|
||||
float amp = 1;
|
||||
float maxAmp = 0;
|
||||
|
||||
for (int i = 0; i < octaves; ++i)
|
||||
{
|
||||
value += GenerateNoise(seedX + freq * scale * x, seedY + freq * scale * y) * amp;
|
||||
maxAmp += amp;
|
||||
amp *= persistence;
|
||||
freq *= 2;
|
||||
}
|
||||
|
||||
// Bring to [0,1]
|
||||
value = (value / maxAmp) / 2f + .5f;
|
||||
|
||||
// Raise to non-linear power
|
||||
value = Mathf.Pow(value, nonLinearPower);
|
||||
|
||||
// Bring to required interval
|
||||
value = value * (high - low) + low;
|
||||
|
||||
// Done
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates noise
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate</param>
|
||||
/// <param name="y">Y coordinate</param>
|
||||
/// <param name="low">Minimum value</param>
|
||||
/// <param name="high">Maximum value</param>
|
||||
/// <param name="scale">Scale</param>
|
||||
/// <param name="octaves">Number of octaves (layers)</param>
|
||||
/// <param name="persistence">Persistence (impact of each layer)</param>
|
||||
/// <returns>Noise</returns>
|
||||
public float Generate(float x, float y, float low, float high, float scale, int octaves, float persistence)
|
||||
{
|
||||
return Generate(x, y, low, high, scale, octaves, persistence, NonLinearPower);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates noise
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate</param>
|
||||
/// <param name="y">Y coordinate</param>
|
||||
/// <param name="low">Minimum value</param>
|
||||
/// <param name="high">Maximum value</param>
|
||||
/// <param name="scale">Scale</param>
|
||||
/// <returns>Noise</returns>
|
||||
public float Generate(float x, float y, float low, float high, float scale)
|
||||
{
|
||||
return Generate(x, y, low, high, scale, Octaves, Persistence, NonLinearPower);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates noise
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate</param>
|
||||
/// <param name="y">Y coordinate</param>
|
||||
/// <param name="low">Minimum value</param>
|
||||
/// <param name="high">Maximum value</param>
|
||||
/// <returns>Noise</returns>
|
||||
public float Generate(float x, float y, float low, float high)
|
||||
{
|
||||
return Generate(x, y, low, high, Scale, Octaves, Persistence, NonLinearPower);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates noise
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate</param>
|
||||
/// <param name="y">Y coordinate</param>
|
||||
/// <returns>Noise</returns>
|
||||
public float Generate(float x, float y)
|
||||
{
|
||||
return Generate(x, y, Low, High, Scale, Octaves, Persistence, NonLinearPower);
|
||||
}
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Noise/NoiseGenerator.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b305f77f2146ba4ab22c5c2eb8848e4
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
16
Game/Assets/Scripts/Noise/PerlinNoiseGenerator.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TransportGame.Noise
|
||||
{
|
||||
public class PerlinNoiseGenerator : NoiseGenerator
|
||||
{
|
||||
protected override float GenerateNoise(float x, float y)
|
||||
{
|
||||
return Mathf.PerlinNoise(x, y) * 2 - 1.0f;
|
||||
}
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Noise/PerlinNoiseGenerator.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db1266b6bfc5ebf42834bd9355eb7975
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
15
Game/Assets/Scripts/TerrainGeneratorScript.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class TerrainGeneratorScript : MonoBehaviour {
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/TerrainGeneratorScript.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 204c90c5b648fab4eaf221d2d96e56c9
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
5
Game/Assets/Scripts/Utils.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: baad3629baf40e54694152a7dd8f97f1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
12
Game/Assets/Scripts/Utils/Algorithms.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TransportGame.Utils
|
||||
{
|
||||
public static class Algorithmss
|
||||
{
|
||||
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Utils/Algorithms.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67f24adfb8b21234184d0caf81f424ea
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
5
Game/Assets/Scripts/Utils/Algorithms.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fccffaafa6b9b0418cbdec944cef4ec
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
198
Game/Assets/Scripts/Utils/Algorithms/GridTraverseAlgorithm.cs
Normal file
@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TransportGame.Utils.Algorithms
|
||||
{
|
||||
[Flags]
|
||||
public enum TravelDirections
|
||||
{
|
||||
North = 0x1,
|
||||
NorthEast = 0x2,
|
||||
East = 0x4,
|
||||
SouthEast = 0x8,
|
||||
South = 0x10,
|
||||
SouthWest = 0x20,
|
||||
West = 0x40,
|
||||
NorthWest = 0x80,
|
||||
NESW = North | East | West | South,
|
||||
All = North | NorthEast | East | SouthEast | South | SouthWest | West | NorthWest,
|
||||
}
|
||||
|
||||
public abstract class GridTraverseAlgorithm<T>
|
||||
{
|
||||
protected class TraverseVisitItem<TItem>
|
||||
{
|
||||
public TItem Item { get; private set; }
|
||||
public int X { get; private set; }
|
||||
public int Y { get; private set; }
|
||||
|
||||
public TraverseVisitItem(TItem item, int x, int y)
|
||||
{
|
||||
Item = item;
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
}
|
||||
|
||||
private static void GenerateDirections(out int[] dx, out int[] dy, TravelDirections dirs)
|
||||
{
|
||||
List<int> ddx = new List<int>();
|
||||
List<int> ddy = new List<int>();
|
||||
|
||||
if ((dirs & TravelDirections.North) > 0)
|
||||
{
|
||||
ddx.Add(0);
|
||||
ddy.Add(1);
|
||||
}
|
||||
if ((dirs & TravelDirections.NorthEast) > 0)
|
||||
{
|
||||
ddx.Add(1);
|
||||
ddy.Add(1);
|
||||
}
|
||||
if ((dirs & TravelDirections.East) > 0)
|
||||
{
|
||||
ddx.Add(1);
|
||||
ddy.Add(0);
|
||||
}
|
||||
if ((dirs & TravelDirections.SouthEast) > 0)
|
||||
{
|
||||
ddx.Add(1);
|
||||
ddy.Add(-1);
|
||||
}
|
||||
if ((dirs & TravelDirections.South) > 0)
|
||||
{
|
||||
ddx.Add(0);
|
||||
ddy.Add(-1);
|
||||
}
|
||||
if ((dirs & TravelDirections.SouthWest) > 0)
|
||||
{
|
||||
ddx.Add(-1);
|
||||
ddy.Add(-1);
|
||||
}
|
||||
if ((dirs & TravelDirections.West) > 0)
|
||||
{
|
||||
ddx.Add(-1);
|
||||
ddy.Add(0);
|
||||
}
|
||||
if ((dirs & TravelDirections.NorthWest) > 0)
|
||||
{
|
||||
ddx.Add(-1);
|
||||
ddy.Add(1);
|
||||
}
|
||||
|
||||
dx = ddx.ToArray();
|
||||
dy = ddy.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns element at specified position in the map
|
||||
/// </summary>
|
||||
/// <param name="x">X</param>
|
||||
/// <param name="y">Y</param>
|
||||
/// <returns>Element</returns>
|
||||
protected abstract T ElementAt(int x, int y);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the specified coordinates are valid (e.g. inside the map)
|
||||
/// </summary>
|
||||
/// <param name="x">X</param>
|
||||
/// <param name="y">Y</param>
|
||||
/// <returns>True if coordinates are valid</returns>
|
||||
protected abstract bool CoordinatesValid(int x, int y);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if specified item on the map can be visited
|
||||
/// </summary>
|
||||
/// <param name="toVisit">Item to visit</param>
|
||||
/// <param name="previous">Previous node</param>
|
||||
/// <returns>True if can be visited</returns>
|
||||
protected abstract bool CanVisit(TraverseVisitItem<T> toVisit, TraverseVisitItem<T> previous);
|
||||
|
||||
/// <summary>
|
||||
/// Called when an item enqueued to be visited later
|
||||
/// </summary>
|
||||
/// <param name="toVisit">Item to visit</param>
|
||||
/// <param name="current">Previous node</param>
|
||||
/// <returns>True if can be visited</returns>
|
||||
protected virtual void OnEnqueued(TraverseVisitItem<T> toVisit, TraverseVisitItem<T> previous)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when an item is visited
|
||||
/// </summary>
|
||||
/// <param name="item">Visited item</param>
|
||||
protected virtual void OnVisit(TraverseVisitItem<T> item)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Traverses a grid map
|
||||
/// </summary>
|
||||
/// <param name="originX">X coordinate of traversal starting point</param>
|
||||
/// <param name="originY">Y coordinate of traversal starting point</param>
|
||||
/// <param name="travelDirections">Possible traversal directions</param>
|
||||
public virtual void Traverse(IEnumerable<int> originsX, IEnumerable<int> originsY, TravelDirections travelDirections = TravelDirections.NESW)
|
||||
{
|
||||
// Get directions
|
||||
int[] dx, dy;
|
||||
GenerateDirections(out dx, out dy, travelDirections);
|
||||
|
||||
// Queue
|
||||
var toVisit = new Queue<TraverseVisitItem<T>>();
|
||||
|
||||
// Enqueue origins
|
||||
var itX = originsX.GetEnumerator();
|
||||
var itY = originsY.GetEnumerator();
|
||||
|
||||
while (itX.MoveNext() && itY.MoveNext())
|
||||
{
|
||||
if (CoordinatesValid(itX.Current, itY.Current))
|
||||
{
|
||||
var origin = new TraverseVisitItem<T>(ElementAt(itX.Current, itY.Current), itX.Current, itY.Current);
|
||||
toVisit.Enqueue(origin);
|
||||
}
|
||||
}
|
||||
|
||||
// Visit nodes in queue
|
||||
while (toVisit.Count > 0)
|
||||
{
|
||||
var item = toVisit.Dequeue();
|
||||
|
||||
// Visit item
|
||||
OnVisit(item);
|
||||
|
||||
// Enqueue neighbours in each direction
|
||||
for (int k = 0; k < dx.Length; k++)
|
||||
{
|
||||
int newx = item.X + dx[k];
|
||||
int newy = item.Y + dy[k];
|
||||
|
||||
if (CoordinatesValid(newx, newy))
|
||||
{
|
||||
var newitem = new TraverseVisitItem<T>(ElementAt(newx, newy), newx, newy);
|
||||
|
||||
if (CanVisit(newitem, item))
|
||||
{
|
||||
toVisit.Enqueue(newitem);
|
||||
OnEnqueued(newitem, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// Traverses a grid map
|
||||
///// </summary>
|
||||
///// <param name="originX">X coordinate of traversal starting point</param>
|
||||
///// <param name="originY">Y coordinate of traversal starting point</param>
|
||||
///// <param name="travelDirections">Possible traversal directions</param>
|
||||
//public virtual void Traverse(int originX, int originY, TravelDirections travelDirections = TravelDirections.NESW)
|
||||
//{
|
||||
// Traverse(Enumerable.Repeat(originX, 1), Enumerable.Repeat(originY, 1), travelDirections);
|
||||
//}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 033176dc0e4c5594bbf5d1ec0034fbad
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
21
Game/Assets/Scripts/Utils/ColorHelper.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TransportGame.Utils
|
||||
{
|
||||
public static class ColorHelper
|
||||
{
|
||||
public static Color FromArgb(int argb)
|
||||
{
|
||||
float a = ((argb >> 24) & 0xff) / 255f;
|
||||
float r = ((argb >> 16) & 0xff) / 255f;
|
||||
float g = ((argb >> 8) & 0xff) / 255f;
|
||||
float b = ((argb) & 0xff) / 255f;
|
||||
|
||||
return new Color(r, g, b, a);
|
||||
}
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Utils/ColorHelper.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec6caa7302e5ebd49815993ec3b07516
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
73
Game/Assets/Scripts/Utils/Logger.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TransportGame.Utils
|
||||
{
|
||||
public static class Logger
|
||||
{
|
||||
private static StreamWriter logFile;
|
||||
|
||||
public enum Level
|
||||
{
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
Critical
|
||||
}
|
||||
|
||||
public static void Log(Level level, string format, params object[] args)
|
||||
{
|
||||
// Open log file if not opened
|
||||
if (logFile == null)
|
||||
{
|
||||
logFile = new StreamWriter(String.Format("Logs\\{0}.log", DateTime.Now.Ticks));
|
||||
}
|
||||
|
||||
// Log to file
|
||||
logFile.Write("[{0}] ", Enum.GetName(typeof(Level), level));
|
||||
logFile.Write(DateTime.Now.ToLongTimeString());
|
||||
logFile.WriteLine(": " + format, args);
|
||||
|
||||
// Log to unity
|
||||
switch (level)
|
||||
{
|
||||
case Level.Warning:
|
||||
UnityEngine.Debug.LogWarning(String.Format(format, args));
|
||||
break;
|
||||
|
||||
case Level.Error:
|
||||
UnityEngine.Debug.LogError(String.Format(format, args));
|
||||
break;
|
||||
|
||||
case Level.Critical:
|
||||
UnityEngine.Debug.LogError(String.Format(format, args));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Info(string format, params object[] args)
|
||||
{
|
||||
Log(Level.Info, format, args);
|
||||
}
|
||||
|
||||
public static void Warning(string format, params object[] args)
|
||||
{
|
||||
Log(Level.Warning, format, args);
|
||||
}
|
||||
public static void Error(string format, params object[] args)
|
||||
{
|
||||
Log(Level.Error, format, args);
|
||||
}
|
||||
public static void Critical(string format, params object[] args)
|
||||
{
|
||||
Log(Level.Critical, format, args);
|
||||
}
|
||||
public static void Exception(Exception ex)
|
||||
{
|
||||
Log(Level.Critical, "{0}: {1}\nStack trace:{2}", ex.GetType().ToString(), ex.Message, ex.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Utils/Logger.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab20d455f95d206489bf47b3c54fea3a
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
20
Game/Assets/Scripts/Utils/RandomExtensions.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TransportGame.Utils
|
||||
{
|
||||
public static class RandomExtensions
|
||||
{
|
||||
public static float NextSingle(this Random @this)
|
||||
{
|
||||
return Convert.ToSingle(@this.NextDouble());
|
||||
}
|
||||
|
||||
public static float NextSingle(this Random @this, float minValue, float maxValue)
|
||||
{
|
||||
return @this.NextSingle() * (maxValue - minValue) + minValue;
|
||||
}
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Utils/RandomExtensions.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f49fb05c61ea6943963db5618373c75
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
29
Game/Assets/Scripts/Utils/Range.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace TransportGame.Utils
|
||||
{
|
||||
public class Range
|
||||
{
|
||||
[XmlAttribute("min")]
|
||||
public float Minimum { get; set; }
|
||||
|
||||
[XmlAttribute("max")]
|
||||
public float Maximum { get; set; }
|
||||
|
||||
public Range()
|
||||
{
|
||||
Minimum = 0;
|
||||
Maximum = 1;
|
||||
}
|
||||
|
||||
public Range(float min, float max)
|
||||
{
|
||||
Minimum = min;
|
||||
Maximum = max;
|
||||
}
|
||||
}
|
||||
}
|
8
Game/Assets/Scripts/Utils/Range.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b436281f9c7d49f4d935ae009d4559a8
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
197
Game/Assets/Scripts/Utils/Texture2DExtensions.cs
Normal file
@ -0,0 +1,197 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TransportGame.Utils
|
||||
{
|
||||
public static class Texture2DExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Draws a line between two vectors
|
||||
/// </summary>
|
||||
/// <param name="this">Texture</param>
|
||||
/// <param name="color">Color</param>
|
||||
/// <param name="p0">Position 1</param>
|
||||
/// <param name="p1">Position 2</param>
|
||||
public static void DrawLine(this Texture2D @this, Color color, Vector2 p0, Vector2 p1)
|
||||
{
|
||||
DrawLine(@this, color, Convert.ToInt32(p0.x), Convert.ToInt32(p0.y), Convert.ToInt32(p1.x), Convert.ToInt32(p1.y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a line between 2 points
|
||||
/// </summary>
|
||||
/// <param name="this">The texture</param>
|
||||
/// <param name="x0">X0</param>
|
||||
/// <param name="y0">Y0</param>
|
||||
/// <param name="x1">X1</param>
|
||||
/// <param name="y1">Y1</param>
|
||||
/// <param name="color">Color</param>
|
||||
public static void DrawLine(this Texture2D @this, Color color, int x0, int y0, int x1, int y1)
|
||||
{
|
||||
int dy = (int)(y1 - y0);
|
||||
int dx = (int)(x1 - x0);
|
||||
int stepx, stepy;
|
||||
|
||||
if (dy < 0) { dy = -dy; stepy = -1; }
|
||||
else { stepy = 1; }
|
||||
if (dx < 0) { dx = -dx; stepx = -1; }
|
||||
else { stepx = 1; }
|
||||
dy <<= 1;
|
||||
dx <<= 1;
|
||||
|
||||
float fraction = 0;
|
||||
|
||||
@this.SetPixelSafe(x0, y0, color);
|
||||
if (dx > dy)
|
||||
{
|
||||
fraction = dy - (dx >> 1);
|
||||
while (Mathf.Abs(x0 - x1) > 1)
|
||||
{
|
||||
if (fraction >= 0)
|
||||
{
|
||||
y0 += stepy;
|
||||
fraction -= dx;
|
||||
}
|
||||
x0 += stepx;
|
||||
fraction += dy;
|
||||
@this.SetPixelSafe(x0, y0, color);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fraction = dx - (dy >> 1);
|
||||
while (Mathf.Abs(y0 - y1) > 1)
|
||||
{
|
||||
if (fraction >= 0)
|
||||
{
|
||||
x0 += stepx;
|
||||
fraction -= dy;
|
||||
}
|
||||
y0 += stepy;
|
||||
fraction += dx;
|
||||
@this.SetPixelSafe(x0, y0, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rhombus-like point
|
||||
/// </summary>
|
||||
/// <param name="this">Texture</param>
|
||||
/// <param name="p0">Position</param>
|
||||
/// <param name="radius">Radius</param>
|
||||
/// <param name="color">Color</param>
|
||||
public static void DrawPoint(this Texture2D @this, Color color, Vector2 p0, int radius)
|
||||
{
|
||||
DrawPoint(@this, color, Convert.ToInt32(p0.x), Convert.ToInt32(p0.y), radius);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws a rhombus-like point
|
||||
/// </summary>
|
||||
/// <param name="this">Texture</param>
|
||||
/// <param name="x0">Position</param>
|
||||
/// <param name="y0">Position</param>
|
||||
/// <param name="radius">Radius</param>
|
||||
/// <param name="color">Color</param>
|
||||
public static void DrawPoint(this Texture2D @this, Color color, int x0, int y0, int radius)
|
||||
{
|
||||
for (int y = y0 - radius; y <= y0 + radius; ++y)
|
||||
{
|
||||
int pts = radius - Math.Abs(y - y0);
|
||||
|
||||
for (int x = x0 - pts; x <= x0 + pts; ++x)
|
||||
@this.SetPixelSafe(x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fills a polygon
|
||||
/// </summary>
|
||||
/// <param name="this">Texture</param>
|
||||
/// <param name="color">color</param>
|
||||
/// <param name="points">Points</param>
|
||||
public static void FillPolygon(this Texture2D @this, Color color, params Vector2[] points)
|
||||
{
|
||||
int minY = Int32.MaxValue, maxY = Int32.MinValue;
|
||||
// Unused... int[] ptX = points.Select(p => Convert.ToInt32(p.x)).ToArray();
|
||||
int[] ptY = points.Select(p => Convert.ToInt32(p.y)).ToArray();
|
||||
|
||||
// Find min and max row
|
||||
for (int i = 0; i < points.Length; i++)
|
||||
{
|
||||
minY = Math.Min(minY, ptY[i]);
|
||||
maxY = Math.Max(maxY, ptY[i]);
|
||||
}
|
||||
|
||||
List<int> intersPoints = new List<int>();
|
||||
|
||||
// Go through each row
|
||||
for (int y = minY; y <= maxY; ++y)
|
||||
{
|
||||
intersPoints.Clear();
|
||||
|
||||
// Find intersection points
|
||||
int j = points.Length - 1;
|
||||
for (int i = 0; i < points.Length; ++i)
|
||||
{
|
||||
// Treat special case where we have 2 points on the y axis
|
||||
if (ptY[i] == y && ptY[j] == y)
|
||||
{
|
||||
intersPoints.Add(Convert.ToInt32(points[i].x));
|
||||
intersPoints.Add(Convert.ToInt32(points[j].x));
|
||||
}
|
||||
|
||||
// Intersection
|
||||
else if ((ptY[i] >= y && ptY[j] <= y) ||
|
||||
(ptY[i] <= y && ptY[j] >= y))
|
||||
{
|
||||
int x = Convert.ToInt32(points[i].x + (y - points[i].y) * (points[j].x - points[i].x) / (points[j].y - points[i].y));
|
||||
intersPoints.Add(x);
|
||||
}
|
||||
|
||||
j = i;
|
||||
}
|
||||
|
||||
// Order pairs
|
||||
var intersPointsSorted = intersPoints.OrderBy(x => x).Distinct().ToArray();
|
||||
|
||||
// Draw
|
||||
for (int i = 0; i < intersPointsSorted.Length / 2; i++)
|
||||
{
|
||||
for (int x = intersPointsSorted[2 * i]; x <= intersPointsSorted[2 * i + 1]; x++)
|
||||
@this.SetPixelSafe(x, y, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fills texture with specified color
|
||||
/// </summary>
|
||||
/// <param name="this">Texture</param>
|
||||
/// <param name="color">Color</param>
|
||||
public static void Fill(this Texture2D @this, Color color)
|
||||
{
|
||||
for (int x = 0; x < @this.width; ++x)
|
||||
for (int y = 0; y < @this.height; ++y)
|
||||
@this.SetPixelSafe(x, y, color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a pixel after checking if coordinates are inside image
|
||||
/// </summary>
|
||||
/// <param name="this">Texture</param>
|
||||
/// <param name="x">X</param>
|
||||
/// <param name="y">Y</param>
|
||||
/// <param name="color">Color</param>
|
||||
public static void SetPixelSafe(this Texture2D @this, int x, int y, Color color)
|
||||
{
|
||||
if (x >= 0 && y >= 0 && x < @this.width && y < @this.height)
|
||||
@this.SetPixel(x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
8
Game/Assets/Scripts/Utils/Texture2DExtensions.cs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d8f9264c2fb7e4459a82d533613c0f1
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
5
Game/Assets/Standard Assets.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7bff92baf08d7774182134804a867de4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
5
Game/Assets/Standard Assets/Character Controllers.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54216e9ed42974e30967824b7f0b2806
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d4133d5d30b644bd87802a347eaccbe
|
||||
NativeFormatImporter:
|
||||
userData:
|
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e0b0a994d8934541a387e092630b5db
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c81df2918c80c054ca3d436e62090893
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
@ -0,0 +1,289 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 449b48f7eb5d87a4baaa5fb73f875a59
|
||||
ModelImporter:
|
||||
serializedVersion: 16
|
||||
fileIDToRecycleName:
|
||||
100000: Bip001 R Finger1
|
||||
100002: Bip001 R Finger21
|
||||
100004: Bip001 R Finger11
|
||||
100006: Bip001 R Finger02
|
||||
100010: Bip001 R Finger12
|
||||
100012: Bip001 R Finger41
|
||||
100014: Bip001 R Finger4
|
||||
100018: Bip001 R Finger32
|
||||
100020: Bip001 R Finger31
|
||||
100022: Bip001 R Finger3
|
||||
100026: hip_adjustment_bone_right
|
||||
100028: Bip001 R Finger42
|
||||
100032: hip_adjustment_bone_left
|
||||
100034: Bip001 R Finger2
|
||||
100036: Bip001 R Finger22
|
||||
100040: Bip001 R UpperArm
|
||||
100042: Bip001 R Forearm
|
||||
100044: Bip001 R Finger0
|
||||
100046: Bip001 R Finger01
|
||||
100052: //RootNode
|
||||
100054: Bip001 R Clavicle
|
||||
100058: Bip001 L Finger3
|
||||
100060: Bip001 L Finger31
|
||||
100062: Bip001 L Finger32
|
||||
100066: Bip001 L Finger4
|
||||
100068: Bip001 L Finger41
|
||||
100070: Bip001 L Finger42
|
||||
100074: Bip001 L Finger22
|
||||
100076: Bip001 L Finger02
|
||||
100080: Bip001 L Finger1
|
||||
100082: Bip001 L Finger11
|
||||
100084: Bip001 L Finger12
|
||||
100088: Bip001 L Finger2
|
||||
100090: Bip001 L Finger21
|
||||
100092: Bip001 L Finger0
|
||||
100094: Bip001 L Finger01
|
||||
100096: Bip001 L Forearm
|
||||
100098: Bip001 L UpperArm
|
||||
100100: Bip001 L Clavicle
|
||||
100102: construction_worker
|
||||
100104: Bip001 R Toe0
|
||||
100106: Bip001 R Foot
|
||||
100108: Bip001 R Calf
|
||||
100110: Bip001 R Thigh
|
||||
100112: Bip001 L Toe0
|
||||
100114: Bip001 L Foot
|
||||
100116: Bip001 L Calf
|
||||
100118: Bip001 L Thigh
|
||||
100120: helmet_bone
|
||||
100124: Bip001 Head
|
||||
100126: wrench
|
||||
100128: Bip001 R Hand
|
||||
100130: Bip001 L Hand
|
||||
100132: Bip001 Neck
|
||||
100134: Bip001 Spine1
|
||||
100136: Bip001 Spine
|
||||
100138: Bip001 Pelvis
|
||||
100140: Bip001
|
||||
400000: Bip001 R Finger1
|
||||
400002: Bip001 R Finger21
|
||||
400004: Bip001 R Finger11
|
||||
400006: Bip001 R Finger02
|
||||
400010: Bip001 R Finger12
|
||||
400012: Bip001 R Finger41
|
||||
400014: Bip001 R Finger4
|
||||
400018: Bip001 R Finger32
|
||||
400020: Bip001 R Finger31
|
||||
400022: Bip001 R Finger3
|
||||
400026: hip_adjustment_bone_right
|
||||
400028: Bip001 R Finger42
|
||||
400032: hip_adjustment_bone_left
|
||||
400034: Bip001 R Finger2
|
||||
400036: Bip001 R Finger22
|
||||
400040: Bip001 R UpperArm
|
||||
400042: Bip001 R Forearm
|
||||
400044: Bip001 R Finger0
|
||||
400046: Bip001 R Finger01
|
||||
400052: //RootNode
|
||||
400054: Bip001 R Clavicle
|
||||
400058: Bip001 L Finger3
|
||||
400060: Bip001 L Finger31
|
||||
400062: Bip001 L Finger32
|
||||
400066: Bip001 L Finger4
|
||||
400068: Bip001 L Finger41
|
||||
400070: Bip001 L Finger42
|
||||
400074: Bip001 L Finger22
|
||||
400076: Bip001 L Finger02
|
||||
400080: Bip001 L Finger1
|
||||
400082: Bip001 L Finger11
|
||||
400084: Bip001 L Finger12
|
||||
400088: Bip001 L Finger2
|
||||
400090: Bip001 L Finger21
|
||||
400092: Bip001 L Finger0
|
||||
400094: Bip001 L Finger01
|
||||
400096: Bip001 L Forearm
|
||||
400098: Bip001 L UpperArm
|
||||
400100: Bip001 L Clavicle
|
||||
400102: construction_worker
|
||||
400104: Bip001 R Toe0
|
||||
400106: Bip001 R Foot
|
||||
400108: Bip001 R Calf
|
||||
400110: Bip001 R Thigh
|
||||
400112: Bip001 L Toe0
|
||||
400114: Bip001 L Foot
|
||||
400116: Bip001 L Calf
|
||||
400118: Bip001 L Thigh
|
||||
400120: helmet_bone
|
||||
400124: Bip001 Head
|
||||
400126: wrench
|
||||
400128: Bip001 R Hand
|
||||
400130: Bip001 L Hand
|
||||
400132: Bip001 Neck
|
||||
400134: Bip001 Spine1
|
||||
400136: Bip001 Spine
|
||||
400138: Bip001 Pelvis
|
||||
400140: Bip001
|
||||
2300000: wrench
|
||||
3300000: wrench
|
||||
4300000: construction_worker
|
||||
4300002: wrench
|
||||
7400012: idle
|
||||
7400014: run
|
||||
7400016: walk
|
||||
7400018: jump_pose
|
||||
11100000: //RootNode
|
||||
13700000: Bip001 Pelvis
|
||||
materials:
|
||||
importMaterials: 1
|
||||
materialName: 3
|
||||
materialSearch: 1
|
||||
animations:
|
||||
legacyGenerateAnimations: 3
|
||||
bakeSimulation: 0
|
||||
optimizeGameObjects: 0
|
||||
motionNodeName:
|
||||
animationCompression: 0
|
||||
animationRotationError: .5
|
||||
animationPositionError: .5
|
||||
animationScaleError: .5
|
||||
animationWrapMode: 0
|
||||
extraExposedTransformPaths: []
|
||||
clipAnimations:
|
||||
- serializedVersion: 16
|
||||
name: idle
|
||||
takeName:
|
||||
firstFrame: 2
|
||||
lastFrame: 62
|
||||
wrapMode: 2
|
||||
orientationOffsetY: 0
|
||||
level: 0
|
||||
cycleOffset: 0
|
||||
loop: 0
|
||||
loopTime: 0
|
||||
loopBlend: 0
|
||||
loopBlendOrientation: 0
|
||||
loopBlendPositionY: 0
|
||||
loopBlendPositionXZ: 0
|
||||
keepOriginalOrientation: 0
|
||||
keepOriginalPositionY: 1
|
||||
keepOriginalPositionXZ: 0
|
||||
heightFromFeet: 0
|
||||
mirror: 0
|
||||
bodyMask: 01000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000
|
||||
curves: []
|
||||
events: []
|
||||
transformMask: []
|
||||
maskType: 0
|
||||
maskSource: {instanceID: 0}
|
||||
- serializedVersion: 16
|
||||
name: run
|
||||
takeName:
|
||||
firstFrame: 65
|
||||
lastFrame: 81
|
||||
wrapMode: 2
|
||||
orientationOffsetY: 0
|
||||
level: 0
|
||||
cycleOffset: 0
|
||||
loop: 0
|
||||
loopTime: 0
|
||||
loopBlend: 0
|
||||
loopBlendOrientation: 0
|
||||
loopBlendPositionY: 0
|
||||
loopBlendPositionXZ: 0
|
||||
keepOriginalOrientation: 0
|
||||
keepOriginalPositionY: 1
|
||||
keepOriginalPositionXZ: 0
|
||||
heightFromFeet: 0
|
||||
mirror: 0
|
||||
bodyMask: 01000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000
|
||||
curves: []
|
||||
events: []
|
||||
transformMask: []
|
||||
maskType: 0
|
||||
maskSource: {instanceID: 0}
|
||||
- serializedVersion: 16
|
||||
name: walk
|
||||
takeName:
|
||||
firstFrame: 84
|
||||
lastFrame: 116
|
||||
wrapMode: 2
|
||||
orientationOffsetY: 0
|
||||
level: 0
|
||||
cycleOffset: 0
|
||||
loop: 0
|
||||
loopTime: 0
|
||||
loopBlend: 0
|
||||
loopBlendOrientation: 0
|
||||
loopBlendPositionY: 0
|
||||
loopBlendPositionXZ: 0
|
||||
keepOriginalOrientation: 0
|
||||
keepOriginalPositionY: 1
|
||||
keepOriginalPositionXZ: 0
|
||||
heightFromFeet: 0
|
||||
mirror: 0
|
||||
bodyMask: 01000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000
|
||||
curves: []
|
||||
events: []
|
||||
transformMask: []
|
||||
maskType: 0
|
||||
maskSource: {instanceID: 0}
|
||||
- serializedVersion: 16
|
||||
name: jump_pose
|
||||
takeName:
|
||||
firstFrame: 118
|
||||
lastFrame: 123
|
||||
wrapMode: 0
|
||||
orientationOffsetY: 0
|
||||
level: 0
|
||||
cycleOffset: 0
|
||||
loop: 0
|
||||
loopTime: 0
|
||||
loopBlend: 0
|
||||
loopBlendOrientation: 0
|
||||
loopBlendPositionY: 0
|
||||
loopBlendPositionXZ: 0
|
||||
keepOriginalOrientation: 0
|
||||
keepOriginalPositionY: 1
|
||||
keepOriginalPositionXZ: 0
|
||||
heightFromFeet: 0
|
||||
mirror: 0
|
||||
bodyMask: 01000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000
|
||||
curves: []
|
||||
events: []
|
||||
transformMask: []
|
||||
maskType: 0
|
||||
maskSource: {instanceID: 0}
|
||||
isReadable: 1
|
||||
meshes:
|
||||
lODScreenPercentages: []
|
||||
globalScale: .00999999978
|
||||
meshCompression: 0
|
||||
addColliders: 0
|
||||
importBlendShapes: 1
|
||||
swapUVChannels: 0
|
||||
generateSecondaryUV: 0
|
||||
useFileUnits: 1
|
||||
optimizeMeshForGPU: 1
|
||||
weldVertices: 1
|
||||
secondaryUVAngleDistortion: 8
|
||||
secondaryUVAreaDistortion: 15.000001
|
||||
secondaryUVHardAngle: 88
|
||||
secondaryUVPackMargin: 4
|
||||
tangentSpace:
|
||||
normalSmoothAngle: 60
|
||||
splitTangentsAcrossUV: 1
|
||||
normalImportMode: 0
|
||||
tangentImportMode: 1
|
||||
importAnimation: 1
|
||||
copyAvatar: 0
|
||||
humanDescription:
|
||||
human: []
|
||||
skeleton: []
|
||||
armTwist: .5
|
||||
foreArmTwist: .5
|
||||
upperLegTwist: .5
|
||||
legTwist: .5
|
||||
armStretch: .0500000007
|
||||
legStretch: .0500000007
|
||||
feetSpacing: 0
|
||||
rootMotionBoneName:
|
||||
lastHumanDescriptionAvatarSource: {instanceID: 0}
|
||||
animationType: 1
|
||||
additionalBone: 0
|
||||
userData:
|
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e53c8c3dcc4ff59438bc9e86cb45c3f6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca49380a71a2bb64c830d06bd421b9d1
|
||||
NativeFormatImporter:
|
||||
userData:
|
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b365e6042890d4b1987423ed6bb8a08c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
After Width: | Height: | Size: 678 KiB |
@ -0,0 +1,47 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97b050d43ac7c4d2b9f6cbb587650761
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
serializedVersion: 2
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
linearTexture: 0
|
||||
correctGamma: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: .25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: -1
|
||||
maxTextureSize: 1024
|
||||
textureSettings:
|
||||
filterMode: -1
|
||||
aniso: -1
|
||||
mipBias: -1
|
||||
wrapMode: -1
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: .5, y: .5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaIsTransparency: 0
|
||||
textureType: -1
|
||||
buildTargetSettings: []
|
||||
spriteSheet:
|
||||
sprites: []
|
||||
spritePackingTag:
|
||||
userData:
|
After Width: | Height: | Size: 1.2 MiB |
@ -0,0 +1,47 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 531c14f8d5cdc4e5baa83ee6e16f783a
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
serializedVersion: 2
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
linearTexture: 1
|
||||
correctGamma: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 1
|
||||
heightScale: .25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: -1
|
||||
maxTextureSize: 1024
|
||||
textureSettings:
|
||||
filterMode: 1
|
||||
aniso: -1
|
||||
mipBias: -1
|
||||
wrapMode: -1
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: .5, y: .5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaIsTransparency: 0
|
||||
textureType: 1
|
||||
buildTargetSettings: []
|
||||
spriteSheet:
|
||||
sprites: []
|
||||
spritePackingTag:
|
||||
userData:
|
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f781c091d1c8647c380d5230adfaee54
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
@ -0,0 +1,587 @@
|
||||
#pragma strict
|
||||
#pragma implicit
|
||||
#pragma downcast
|
||||
|
||||
// Does this script currently respond to input?
|
||||
var canControl : boolean = true;
|
||||
|
||||
var useFixedUpdate : boolean = true;
|
||||
|
||||
// For the next variables, @System.NonSerialized tells Unity to not serialize the variable or show it in the inspector view.
|
||||
// Very handy for organization!
|
||||
|
||||
// The current global direction we want the character to move in.
|
||||
@System.NonSerialized
|
||||
var inputMoveDirection : Vector3 = Vector3.zero;
|
||||
|
||||
// Is the jump button held down? We use this interface instead of checking
|
||||
// for the jump button directly so this script can also be used by AIs.
|
||||
@System.NonSerialized
|
||||
var inputJump : boolean = false;
|
||||
|
||||
class CharacterMotorMovement {
|
||||
// The maximum horizontal speed when moving
|
||||
var maxForwardSpeed : float = 10.0;
|
||||
var maxSidewaysSpeed : float = 10.0;
|
||||
var maxBackwardsSpeed : float = 10.0;
|
||||
|
||||
// Curve for multiplying speed based on slope (negative = downwards)
|
||||
var slopeSpeedMultiplier : AnimationCurve = AnimationCurve(Keyframe(-90, 1), Keyframe(0, 1), Keyframe(90, 0));
|
||||
|
||||
// How fast does the character change speeds? Higher is faster.
|
||||
var maxGroundAcceleration : float = 30.0;
|
||||
var maxAirAcceleration : float = 20.0;
|
||||
|
||||
// The gravity for the character
|
||||
var gravity : float = 10.0;
|
||||
var maxFallSpeed : float = 20.0;
|
||||
|
||||
// For the next variables, @System.NonSerialized tells Unity to not serialize the variable or show it in the inspector view.
|
||||
// Very handy for organization!
|
||||
|
||||
// The last collision flags returned from controller.Move
|
||||
@System.NonSerialized
|
||||
var collisionFlags : CollisionFlags;
|
||||
|
||||
// We will keep track of the character's current velocity,
|
||||
@System.NonSerialized
|
||||
var velocity : Vector3;
|
||||
|
||||
// This keeps track of our current velocity while we're not grounded
|
||||
@System.NonSerialized
|
||||
var frameVelocity : Vector3 = Vector3.zero;
|
||||
|
||||
@System.NonSerialized
|
||||
var hitPoint : Vector3 = Vector3.zero;
|
||||
|
||||
@System.NonSerialized
|
||||
var lastHitPoint : Vector3 = Vector3(Mathf.Infinity, 0, 0);
|
||||
}
|
||||
|
||||
var movement : CharacterMotorMovement = CharacterMotorMovement();
|
||||
|
||||
enum MovementTransferOnJump {
|
||||
None, // The jump is not affected by velocity of floor at all.
|
||||
InitTransfer, // Jump gets its initial velocity from the floor, then gradualy comes to a stop.
|
||||
PermaTransfer, // Jump gets its initial velocity from the floor, and keeps that velocity until landing.
|
||||
PermaLocked // Jump is relative to the movement of the last touched floor and will move together with that floor.
|
||||
}
|
||||
|
||||
// We will contain all the jumping related variables in one helper class for clarity.
|
||||
class CharacterMotorJumping {
|
||||
// Can the character jump?
|
||||
var enabled : boolean = true;
|
||||
|
||||
// How high do we jump when pressing jump and letting go immediately
|
||||
var baseHeight : float = 1.0;
|
||||
|
||||
// We add extraHeight units (meters) on top when holding the button down longer while jumping
|
||||
var extraHeight : float = 4.1;
|
||||
|
||||
// How much does the character jump out perpendicular to the surface on walkable surfaces?
|
||||
// 0 means a fully vertical jump and 1 means fully perpendicular.
|
||||
var perpAmount : float = 0.0;
|
||||
|
||||
// How much does the character jump out perpendicular to the surface on too steep surfaces?
|
||||
// 0 means a fully vertical jump and 1 means fully perpendicular.
|
||||
var steepPerpAmount : float = 0.5;
|
||||
|
||||
// For the next variables, @System.NonSerialized tells Unity to not serialize the variable or show it in the inspector view.
|
||||
// Very handy for organization!
|
||||
|
||||
// Are we jumping? (Initiated with jump button and not grounded yet)
|
||||
// To see if we are just in the air (initiated by jumping OR falling) see the grounded variable.
|
||||
@System.NonSerialized
|
||||
var jumping : boolean = false;
|
||||
|
||||
@System.NonSerialized
|
||||
var holdingJumpButton : boolean = false;
|
||||
|
||||
// the time we jumped at (Used to determine for how long to apply extra jump power after jumping.)
|
||||
@System.NonSerialized
|
||||
var lastStartTime : float = 0.0;
|
||||
|
||||
@System.NonSerialized
|
||||
var lastButtonDownTime : float = -100;
|
||||
|
||||
@System.NonSerialized
|
||||
var jumpDir : Vector3 = Vector3.up;
|
||||
}
|
||||
|
||||
var jumping : CharacterMotorJumping = CharacterMotorJumping();
|
||||
|
||||
class CharacterMotorMovingPlatform {
|
||||
var enabled : boolean = true;
|
||||
|
||||
var movementTransfer : MovementTransferOnJump = MovementTransferOnJump.PermaTransfer;
|
||||
|
||||
@System.NonSerialized
|
||||
var hitPlatform : Transform;
|
||||
|
||||
@System.NonSerialized
|
||||
var activePlatform : Transform;
|
||||
|
||||
@System.NonSerialized
|
||||
var activeLocalPoint : Vector3;
|
||||
|
||||
@System.NonSerialized
|
||||
var activeGlobalPoint : Vector3;
|
||||
|
||||
@System.NonSerialized
|
||||
var activeLocalRotation : Quaternion;
|
||||
|
||||
@System.NonSerialized
|
||||
var activeGlobalRotation : Quaternion;
|
||||
|
||||
@System.NonSerialized
|
||||
var lastMatrix : Matrix4x4;
|
||||
|
||||
@System.NonSerialized
|
||||
var platformVelocity : Vector3;
|
||||
|
||||
@System.NonSerialized
|
||||
var newPlatform : boolean;
|
||||
}
|
||||
|
||||
var movingPlatform : CharacterMotorMovingPlatform = CharacterMotorMovingPlatform();
|
||||
|
||||
class CharacterMotorSliding {
|
||||
// Does the character slide on too steep surfaces?
|
||||
var enabled : boolean = true;
|
||||
|
||||
// How fast does the character slide on steep surfaces?
|
||||
var slidingSpeed : float = 15;
|
||||
|
||||
// How much can the player control the sliding direction?
|
||||
// If the value is 0.5 the player can slide sideways with half the speed of the downwards sliding speed.
|
||||
var sidewaysControl : float = 1.0;
|
||||
|
||||
// How much can the player influence the sliding speed?
|
||||
// If the value is 0.5 the player can speed the sliding up to 150% or slow it down to 50%.
|
||||
var speedControl : float = 0.4;
|
||||
}
|
||||
|
||||
var sliding : CharacterMotorSliding = CharacterMotorSliding();
|
||||
|
||||
@System.NonSerialized
|
||||
var grounded : boolean = true;
|
||||
|
||||
@System.NonSerialized
|
||||
var groundNormal : Vector3 = Vector3.zero;
|
||||
|
||||
private var lastGroundNormal : Vector3 = Vector3.zero;
|
||||
|
||||
private var tr : Transform;
|
||||
|
||||
private var controller : CharacterController;
|
||||
|
||||
function Awake () {
|
||||
controller = GetComponent (CharacterController);
|
||||
tr = transform;
|
||||
}
|
||||
|
||||
private function UpdateFunction () {
|
||||
// We copy the actual velocity into a temporary variable that we can manipulate.
|
||||
var velocity : Vector3 = movement.velocity;
|
||||
|
||||
// Update velocity based on input
|
||||
velocity = ApplyInputVelocityChange(velocity);
|
||||
|
||||
// Apply gravity and jumping force
|
||||
velocity = ApplyGravityAndJumping (velocity);
|
||||
|
||||
// Moving platform support
|
||||
var moveDistance : Vector3 = Vector3.zero;
|
||||
if (MoveWithPlatform()) {
|
||||
var newGlobalPoint : Vector3 = movingPlatform.activePlatform.TransformPoint(movingPlatform.activeLocalPoint);
|
||||
moveDistance = (newGlobalPoint - movingPlatform.activeGlobalPoint);
|
||||
if (moveDistance != Vector3.zero)
|
||||
controller.Move(moveDistance);
|
||||
|
||||
// Support moving platform rotation as well:
|
||||
var newGlobalRotation : Quaternion = movingPlatform.activePlatform.rotation * movingPlatform.activeLocalRotation;
|
||||
var rotationDiff : Quaternion = newGlobalRotation * Quaternion.Inverse(movingPlatform.activeGlobalRotation);
|
||||
|
||||
var yRotation = rotationDiff.eulerAngles.y;
|
||||
if (yRotation != 0) {
|
||||
// Prevent rotation of the local up vector
|
||||
tr.Rotate(0, yRotation, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Save lastPosition for velocity calculation.
|
||||
var lastPosition : Vector3 = tr.position;
|
||||
|
||||
// We always want the movement to be framerate independent. Multiplying by Time.deltaTime does this.
|
||||
var currentMovementOffset : Vector3 = velocity * Time.deltaTime;
|
||||
|
||||
// Find out how much we need to push towards the ground to avoid loosing grouning
|
||||
// when walking down a step or over a sharp change in slope.
|
||||
var pushDownOffset : float = Mathf.Max(controller.stepOffset, Vector3(currentMovementOffset.x, 0, currentMovementOffset.z).magnitude);
|
||||
if (grounded)
|
||||
currentMovementOffset -= pushDownOffset * Vector3.up;
|
||||
|
||||
// Reset variables that will be set by collision function
|
||||
movingPlatform.hitPlatform = null;
|
||||
groundNormal = Vector3.zero;
|
||||
|
||||
// Move our character!
|
||||
movement.collisionFlags = controller.Move (currentMovementOffset);
|
||||
|
||||
movement.lastHitPoint = movement.hitPoint;
|
||||
lastGroundNormal = groundNormal;
|
||||
|
||||
if (movingPlatform.enabled && movingPlatform.activePlatform != movingPlatform.hitPlatform) {
|
||||
if (movingPlatform.hitPlatform != null) {
|
||||
movingPlatform.activePlatform = movingPlatform.hitPlatform;
|
||||
movingPlatform.lastMatrix = movingPlatform.hitPlatform.localToWorldMatrix;
|
||||
movingPlatform.newPlatform = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the velocity based on the current and previous position.
|
||||
// This means our velocity will only be the amount the character actually moved as a result of collisions.
|
||||
var oldHVelocity : Vector3 = new Vector3(velocity.x, 0, velocity.z);
|
||||
movement.velocity = (tr.position - lastPosition) / Time.deltaTime;
|
||||
var newHVelocity : Vector3 = new Vector3(movement.velocity.x, 0, movement.velocity.z);
|
||||
|
||||
// The CharacterController can be moved in unwanted directions when colliding with things.
|
||||
// We want to prevent this from influencing the recorded velocity.
|
||||
if (oldHVelocity == Vector3.zero) {
|
||||
movement.velocity = new Vector3(0, movement.velocity.y, 0);
|
||||
}
|
||||
else {
|
||||
var projectedNewVelocity : float = Vector3.Dot(newHVelocity, oldHVelocity) / oldHVelocity.sqrMagnitude;
|
||||
movement.velocity = oldHVelocity * Mathf.Clamp01(projectedNewVelocity) + movement.velocity.y * Vector3.up;
|
||||
}
|
||||
|
||||
if (movement.velocity.y < velocity.y - 0.001) {
|
||||
if (movement.velocity.y < 0) {
|
||||
// Something is forcing the CharacterController down faster than it should.
|
||||
// Ignore this
|
||||
movement.velocity.y = velocity.y;
|
||||
}
|
||||
else {
|
||||
// The upwards movement of the CharacterController has been blocked.
|
||||
// This is treated like a ceiling collision - stop further jumping here.
|
||||
jumping.holdingJumpButton = false;
|
||||
}
|
||||
}
|
||||
|
||||
// We were grounded but just loosed grounding
|
||||
if (grounded && !IsGroundedTest()) {
|
||||
grounded = false;
|
||||
|
||||
// Apply inertia from platform
|
||||
if (movingPlatform.enabled &&
|
||||
(movingPlatform.movementTransfer == MovementTransferOnJump.InitTransfer ||
|
||||
movingPlatform.movementTransfer == MovementTransferOnJump.PermaTransfer)
|
||||
) {
|
||||
movement.frameVelocity = movingPlatform.platformVelocity;
|
||||
movement.velocity += movingPlatform.platformVelocity;
|
||||
}
|
||||
|
||||
SendMessage("OnFall", SendMessageOptions.DontRequireReceiver);
|
||||
// We pushed the character down to ensure it would stay on the ground if there was any.
|
||||
// But there wasn't so now we cancel the downwards offset to make the fall smoother.
|
||||
tr.position += pushDownOffset * Vector3.up;
|
||||
}
|
||||
// We were not grounded but just landed on something
|
||||
else if (!grounded && IsGroundedTest()) {
|
||||
grounded = true;
|
||||
jumping.jumping = false;
|
||||
SubtractNewPlatformVelocity();
|
||||
|
||||
SendMessage("OnLand", SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
|
||||
// Moving platforms support
|
||||
if (MoveWithPlatform()) {
|
||||
// Use the center of the lower half sphere of the capsule as reference point.
|
||||
// This works best when the character is standing on moving tilting platforms.
|
||||
movingPlatform.activeGlobalPoint = tr.position + Vector3.up * (controller.center.y - controller.height*0.5 + controller.radius);
|
||||
movingPlatform.activeLocalPoint = movingPlatform.activePlatform.InverseTransformPoint(movingPlatform.activeGlobalPoint);
|
||||
|
||||
// Support moving platform rotation as well:
|
||||
movingPlatform.activeGlobalRotation = tr.rotation;
|
||||
movingPlatform.activeLocalRotation = Quaternion.Inverse(movingPlatform.activePlatform.rotation) * movingPlatform.activeGlobalRotation;
|
||||
}
|
||||
}
|
||||
|
||||
function FixedUpdate () {
|
||||
if (movingPlatform.enabled) {
|
||||
if (movingPlatform.activePlatform != null) {
|
||||
if (!movingPlatform.newPlatform) {
|
||||
var lastVelocity : Vector3 = movingPlatform.platformVelocity;
|
||||
|
||||
movingPlatform.platformVelocity = (
|
||||
movingPlatform.activePlatform.localToWorldMatrix.MultiplyPoint3x4(movingPlatform.activeLocalPoint)
|
||||
- movingPlatform.lastMatrix.MultiplyPoint3x4(movingPlatform.activeLocalPoint)
|
||||
) / Time.deltaTime;
|
||||
}
|
||||
movingPlatform.lastMatrix = movingPlatform.activePlatform.localToWorldMatrix;
|
||||
movingPlatform.newPlatform = false;
|
||||
}
|
||||
else {
|
||||
movingPlatform.platformVelocity = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
if (useFixedUpdate)
|
||||
UpdateFunction();
|
||||
}
|
||||
|
||||
function Update () {
|
||||
if (!useFixedUpdate)
|
||||
UpdateFunction();
|
||||
}
|
||||
|
||||
private function ApplyInputVelocityChange (velocity : Vector3) {
|
||||
if (!canControl)
|
||||
inputMoveDirection = Vector3.zero;
|
||||
|
||||
// Find desired velocity
|
||||
var desiredVelocity : Vector3;
|
||||
if (grounded && TooSteep()) {
|
||||
// The direction we're sliding in
|
||||
desiredVelocity = Vector3(groundNormal.x, 0, groundNormal.z).normalized;
|
||||
// Find the input movement direction projected onto the sliding direction
|
||||
var projectedMoveDir = Vector3.Project(inputMoveDirection, desiredVelocity);
|
||||
// Add the sliding direction, the spped control, and the sideways control vectors
|
||||
desiredVelocity = desiredVelocity + projectedMoveDir * sliding.speedControl + (inputMoveDirection - projectedMoveDir) * sliding.sidewaysControl;
|
||||
// Multiply with the sliding speed
|
||||
desiredVelocity *= sliding.slidingSpeed;
|
||||
}
|
||||
else
|
||||
desiredVelocity = GetDesiredHorizontalVelocity();
|
||||
|
||||
if (movingPlatform.enabled && movingPlatform.movementTransfer == MovementTransferOnJump.PermaTransfer) {
|
||||
desiredVelocity += movement.frameVelocity;
|
||||
desiredVelocity.y = 0;
|
||||
}
|
||||
|
||||
if (grounded)
|
||||
desiredVelocity = AdjustGroundVelocityToNormal(desiredVelocity, groundNormal);
|
||||
else
|
||||
velocity.y = 0;
|
||||
|
||||
// Enforce max velocity change
|
||||
var maxVelocityChange : float = GetMaxAcceleration(grounded) * Time.deltaTime;
|
||||
var velocityChangeVector : Vector3 = (desiredVelocity - velocity);
|
||||
if (velocityChangeVector.sqrMagnitude > maxVelocityChange * maxVelocityChange) {
|
||||
velocityChangeVector = velocityChangeVector.normalized * maxVelocityChange;
|
||||
}
|
||||
// If we're in the air and don't have control, don't apply any velocity change at all.
|
||||
// If we're on the ground and don't have control we do apply it - it will correspond to friction.
|
||||
if (grounded || canControl)
|
||||
velocity += velocityChangeVector;
|
||||
|
||||
if (grounded) {
|
||||
// When going uphill, the CharacterController will automatically move up by the needed amount.
|
||||
// Not moving it upwards manually prevent risk of lifting off from the ground.
|
||||
// When going downhill, DO move down manually, as gravity is not enough on steep hills.
|
||||
velocity.y = Mathf.Min(velocity.y, 0);
|
||||
}
|
||||
|
||||
return velocity;
|
||||
}
|
||||
|
||||
private function ApplyGravityAndJumping (velocity : Vector3) {
|
||||
|
||||
if (!inputJump || !canControl) {
|
||||
jumping.holdingJumpButton = false;
|
||||
jumping.lastButtonDownTime = -100;
|
||||
}
|
||||
|
||||
if (inputJump && jumping.lastButtonDownTime < 0 && canControl)
|
||||
jumping.lastButtonDownTime = Time.time;
|
||||
|
||||
if (grounded)
|
||||
velocity.y = Mathf.Min(0, velocity.y) - movement.gravity * Time.deltaTime;
|
||||
else {
|
||||
velocity.y = movement.velocity.y - movement.gravity * Time.deltaTime;
|
||||
|
||||
// When jumping up we don't apply gravity for some time when the user is holding the jump button.
|
||||
// This gives more control over jump height by pressing the button longer.
|
||||
if (jumping.jumping && jumping.holdingJumpButton) {
|
||||
// Calculate the duration that the extra jump force should have effect.
|
||||
// If we're still less than that duration after the jumping time, apply the force.
|
||||
if (Time.time < jumping.lastStartTime + jumping.extraHeight / CalculateJumpVerticalSpeed(jumping.baseHeight)) {
|
||||
// Negate the gravity we just applied, except we push in jumpDir rather than jump upwards.
|
||||
velocity += jumping.jumpDir * movement.gravity * Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we don't fall any faster than maxFallSpeed. This gives our character a terminal velocity.
|
||||
velocity.y = Mathf.Max (velocity.y, -movement.maxFallSpeed);
|
||||
}
|
||||
|
||||
if (grounded) {
|
||||
// Jump only if the jump button was pressed down in the last 0.2 seconds.
|
||||
// We use this check instead of checking if it's pressed down right now
|
||||
// because players will often try to jump in the exact moment when hitting the ground after a jump
|
||||
// and if they hit the button a fraction of a second too soon and no new jump happens as a consequence,
|
||||
// it's confusing and it feels like the game is buggy.
|
||||
if (jumping.enabled && canControl && (Time.time - jumping.lastButtonDownTime < 0.2)) {
|
||||
grounded = false;
|
||||
jumping.jumping = true;
|
||||
jumping.lastStartTime = Time.time;
|
||||
jumping.lastButtonDownTime = -100;
|
||||
jumping.holdingJumpButton = true;
|
||||
|
||||
// Calculate the jumping direction
|
||||
if (TooSteep())
|
||||
jumping.jumpDir = Vector3.Slerp(Vector3.up, groundNormal, jumping.steepPerpAmount);
|
||||
else
|
||||
jumping.jumpDir = Vector3.Slerp(Vector3.up, groundNormal, jumping.perpAmount);
|
||||
|
||||
// Apply the jumping force to the velocity. Cancel any vertical velocity first.
|
||||
velocity.y = 0;
|
||||
velocity += jumping.jumpDir * CalculateJumpVerticalSpeed (jumping.baseHeight);
|
||||
|
||||
// Apply inertia from platform
|
||||
if (movingPlatform.enabled &&
|
||||
(movingPlatform.movementTransfer == MovementTransferOnJump.InitTransfer ||
|
||||
movingPlatform.movementTransfer == MovementTransferOnJump.PermaTransfer)
|
||||
) {
|
||||
movement.frameVelocity = movingPlatform.platformVelocity;
|
||||
velocity += movingPlatform.platformVelocity;
|
||||
}
|
||||
|
||||
SendMessage("OnJump", SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
else {
|
||||
jumping.holdingJumpButton = false;
|
||||
}
|
||||
}
|
||||
|
||||
return velocity;
|
||||
}
|
||||
|
||||
function OnControllerColliderHit (hit : ControllerColliderHit) {
|
||||
if (hit.normal.y > 0 && hit.normal.y > groundNormal.y && hit.moveDirection.y < 0) {
|
||||
if ((hit.point - movement.lastHitPoint).sqrMagnitude > 0.001 || lastGroundNormal == Vector3.zero)
|
||||
groundNormal = hit.normal;
|
||||
else
|
||||
groundNormal = lastGroundNormal;
|
||||
|
||||
movingPlatform.hitPlatform = hit.collider.transform;
|
||||
movement.hitPoint = hit.point;
|
||||
movement.frameVelocity = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
private function SubtractNewPlatformVelocity () {
|
||||
// When landing, subtract the velocity of the new ground from the character's velocity
|
||||
// since movement in ground is relative to the movement of the ground.
|
||||
if (movingPlatform.enabled &&
|
||||
(movingPlatform.movementTransfer == MovementTransferOnJump.InitTransfer ||
|
||||
movingPlatform.movementTransfer == MovementTransferOnJump.PermaTransfer)
|
||||
) {
|
||||
// If we landed on a new platform, we have to wait for two FixedUpdates
|
||||
// before we know the velocity of the platform under the character
|
||||
if (movingPlatform.newPlatform) {
|
||||
var platform : Transform = movingPlatform.activePlatform;
|
||||
yield WaitForFixedUpdate();
|
||||
yield WaitForFixedUpdate();
|
||||
if (grounded && platform == movingPlatform.activePlatform)
|
||||
yield 1;
|
||||
}
|
||||
movement.velocity -= movingPlatform.platformVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
private function MoveWithPlatform () : boolean {
|
||||
return (
|
||||
movingPlatform.enabled
|
||||
&& (grounded || movingPlatform.movementTransfer == MovementTransferOnJump.PermaLocked)
|
||||
&& movingPlatform.activePlatform != null
|
||||
);
|
||||
}
|
||||
|
||||
private function GetDesiredHorizontalVelocity () {
|
||||
// Find desired velocity
|
||||
var desiredLocalDirection : Vector3 = tr.InverseTransformDirection(inputMoveDirection);
|
||||
var maxSpeed : float = MaxSpeedInDirection(desiredLocalDirection);
|
||||
if (grounded) {
|
||||
// Modify max speed on slopes based on slope speed multiplier curve
|
||||
var movementSlopeAngle = Mathf.Asin(movement.velocity.normalized.y) * Mathf.Rad2Deg;
|
||||
maxSpeed *= movement.slopeSpeedMultiplier.Evaluate(movementSlopeAngle);
|
||||
}
|
||||
return tr.TransformDirection(desiredLocalDirection * maxSpeed);
|
||||
}
|
||||
|
||||
private function AdjustGroundVelocityToNormal (hVelocity : Vector3, groundNormal : Vector3) : Vector3 {
|
||||
var sideways : Vector3 = Vector3.Cross(Vector3.up, hVelocity);
|
||||
return Vector3.Cross(sideways, groundNormal).normalized * hVelocity.magnitude;
|
||||
}
|
||||
|
||||
private function IsGroundedTest () {
|
||||
return (groundNormal.y > 0.01);
|
||||
}
|
||||
|
||||
function GetMaxAcceleration (grounded : boolean) : float {
|
||||
// Maximum acceleration on ground and in air
|
||||
if (grounded)
|
||||
return movement.maxGroundAcceleration;
|
||||
else
|
||||
return movement.maxAirAcceleration;
|
||||
}
|
||||
|
||||
function CalculateJumpVerticalSpeed (targetJumpHeight : float) {
|
||||
// From the jump height and gravity we deduce the upwards speed
|
||||
// for the character to reach at the apex.
|
||||
return Mathf.Sqrt (2 * targetJumpHeight * movement.gravity);
|
||||
}
|
||||
|
||||
function IsJumping () {
|
||||
return jumping.jumping;
|
||||
}
|
||||
|
||||
function IsSliding () {
|
||||
return (grounded && sliding.enabled && TooSteep());
|
||||
}
|
||||
|
||||
function IsTouchingCeiling () {
|
||||
return (movement.collisionFlags & CollisionFlags.CollidedAbove) != 0;
|
||||
}
|
||||
|
||||
function IsGrounded () {
|
||||
return grounded;
|
||||
}
|
||||
|
||||
function TooSteep () {
|
||||
return (groundNormal.y <= Mathf.Cos(controller.slopeLimit * Mathf.Deg2Rad));
|
||||
}
|
||||
|
||||
function GetDirection () {
|
||||
return inputMoveDirection;
|
||||
}
|
||||
|
||||
function SetControllable (controllable : boolean) {
|
||||
canControl = controllable;
|
||||
}
|
||||
|
||||
// Project a direction onto elliptical quater segments based on forward, sideways, and backwards speed.
|
||||
// The function returns the length of the resulting vector.
|
||||
function MaxSpeedInDirection (desiredMovementDirection : Vector3) : float {
|
||||
if (desiredMovementDirection == Vector3.zero)
|
||||
return 0;
|
||||
else {
|
||||
var zAxisEllipseMultiplier : float = (desiredMovementDirection.z > 0 ? movement.maxForwardSpeed : movement.maxBackwardsSpeed) / movement.maxSidewaysSpeed;
|
||||
var temp : Vector3 = new Vector3(desiredMovementDirection.x, 0, desiredMovementDirection.z / zAxisEllipseMultiplier).normalized;
|
||||
var length : float = new Vector3(temp.x, 0, temp.z * zAxisEllipseMultiplier).magnitude * movement.maxSidewaysSpeed;
|
||||
return length;
|
||||
}
|
||||
}
|
||||
|
||||
function SetVelocity (velocity : Vector3) {
|
||||
grounded = false;
|
||||
movement.velocity = velocity;
|
||||
movement.frameVelocity = Vector3.zero;
|
||||
SendMessage("OnExternalVelocity");
|
||||
}
|
||||
|
||||
// Require a character controller to be attached to the same game object
|
||||
@script RequireComponent (CharacterController)
|
||||
@script AddComponentMenu ("Character/Character Motor")
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ab79d7f243824f5d9826bd83522c8df
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
@ -0,0 +1,37 @@
|
||||
private var motor : CharacterMotor;
|
||||
|
||||
// Use this for initialization
|
||||
function Awake () {
|
||||
motor = GetComponent(CharacterMotor);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
function Update () {
|
||||
// Get the input vector from keyboard or analog stick
|
||||
var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
|
||||
|
||||
if (directionVector != Vector3.zero) {
|
||||
// Get the length of the directon vector and then normalize it
|
||||
// Dividing by the length is cheaper than normalizing when we already have the length anyway
|
||||
var directionLength = directionVector.magnitude;
|
||||
directionVector = directionVector / directionLength;
|
||||
|
||||
// Make sure the length is no bigger than 1
|
||||
directionLength = Mathf.Min(1, directionLength);
|
||||
|
||||
// Make the input vector more sensitive towards the extremes and less sensitive in the middle
|
||||
// This makes it easier to control slow speeds when using analog sticks
|
||||
directionLength = directionLength * directionLength;
|
||||
|
||||
// Multiply the normalized direction vector by the modified length
|
||||
directionVector = directionVector * directionLength;
|
||||
}
|
||||
|
||||
// Apply the direction to the CharacterMotor
|
||||
motor.inputMoveDirection = transform.rotation * directionVector;
|
||||
motor.inputJump = Input.GetButton("Jump");
|
||||
}
|
||||
|
||||
// Require a character controller to be attached to the same game object
|
||||
@script RequireComponent (CharacterMotor)
|
||||
@script AddComponentMenu ("Character/FPS Input Controller")
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60bca8f58a0b8478e946e6e86658cb29
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
@ -0,0 +1,63 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
/// MouseLook rotates the transform based on the mouse delta.
|
||||
/// Minimum and Maximum values can be used to constrain the possible rotation
|
||||
|
||||
/// To make an FPS style character:
|
||||
/// - Create a capsule.
|
||||
/// - Add the MouseLook script to the capsule.
|
||||
/// -> Set the mouse look to use LookX. (You want to only turn character but not tilt it)
|
||||
/// - Add FPSInputController script to the capsule
|
||||
/// -> A CharacterMotor and a CharacterController component will be automatically added.
|
||||
|
||||
/// - Create a camera. Make the camera a child of the capsule. Reset it's transform.
|
||||
/// - Add a MouseLook script to the camera.
|
||||
/// -> Set the mouse look to use LookY. (You want the camera to tilt up and down like a head. The character already turns.)
|
||||
[AddComponentMenu("Camera-Control/Mouse Look")]
|
||||
public class MouseLook : MonoBehaviour {
|
||||
|
||||
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
|
||||
public RotationAxes axes = RotationAxes.MouseXAndY;
|
||||
public float sensitivityX = 15F;
|
||||
public float sensitivityY = 15F;
|
||||
|
||||
public float minimumX = -360F;
|
||||
public float maximumX = 360F;
|
||||
|
||||
public float minimumY = -60F;
|
||||
public float maximumY = 60F;
|
||||
|
||||
float rotationY = 0F;
|
||||
|
||||
void Update ()
|
||||
{
|
||||
if (axes == RotationAxes.MouseXAndY)
|
||||
{
|
||||
float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
|
||||
|
||||
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
|
||||
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
|
||||
|
||||
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
|
||||
}
|
||||
else if (axes == RotationAxes.MouseX)
|
||||
{
|
||||
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
|
||||
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
|
||||
|
||||
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void Start ()
|
||||
{
|
||||
// Make the rigid body not change rotation
|
||||
if (GetComponent<Rigidbody>())
|
||||
GetComponent<Rigidbody>().freezeRotation = true;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68ec2fe99d1108b9d0006a298d76c639
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
@ -0,0 +1,68 @@
|
||||
// This makes the character turn to face the current movement speed per default.
|
||||
var autoRotate : boolean = true;
|
||||
var maxRotationSpeed : float = 360;
|
||||
|
||||
private var motor : CharacterMotor;
|
||||
|
||||
// Use this for initialization
|
||||
function Awake () {
|
||||
motor = GetComponent(CharacterMotor);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
function Update () {
|
||||
// Get the input vector from keyboard or analog stick
|
||||
var directionVector = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
|
||||
|
||||
if (directionVector != Vector3.zero) {
|
||||
// Get the length of the directon vector and then normalize it
|
||||
// Dividing by the length is cheaper than normalizing when we already have the length anyway
|
||||
var directionLength = directionVector.magnitude;
|
||||
directionVector = directionVector / directionLength;
|
||||
|
||||
// Make sure the length is no bigger than 1
|
||||
directionLength = Mathf.Min(1, directionLength);
|
||||
|
||||
// Make the input vector more sensitive towards the extremes and less sensitive in the middle
|
||||
// This makes it easier to control slow speeds when using analog sticks
|
||||
directionLength = directionLength * directionLength;
|
||||
|
||||
// Multiply the normalized direction vector by the modified length
|
||||
directionVector = directionVector * directionLength;
|
||||
}
|
||||
|
||||
// Rotate the input vector into camera space so up is camera's up and right is camera's right
|
||||
directionVector = Camera.main.transform.rotation * directionVector;
|
||||
|
||||
// Rotate input vector to be perpendicular to character's up vector
|
||||
var camToCharacterSpace = Quaternion.FromToRotation(-Camera.main.transform.forward, transform.up);
|
||||
directionVector = (camToCharacterSpace * directionVector);
|
||||
|
||||
// Apply the direction to the CharacterMotor
|
||||
motor.inputMoveDirection = directionVector;
|
||||
motor.inputJump = Input.GetButton("Jump");
|
||||
|
||||
// Set rotation to the move direction
|
||||
if (autoRotate && directionVector.sqrMagnitude > 0.01) {
|
||||
var newForward : Vector3 = ConstantSlerp(
|
||||
transform.forward,
|
||||
directionVector,
|
||||
maxRotationSpeed * Time.deltaTime
|
||||
);
|
||||
newForward = ProjectOntoPlane(newForward, transform.up);
|
||||
transform.rotation = Quaternion.LookRotation(newForward, transform.up);
|
||||
}
|
||||
}
|
||||
|
||||
function ProjectOntoPlane (v : Vector3, normal : Vector3) {
|
||||
return v - Vector3.Project(v, normal);
|
||||
}
|
||||
|
||||
function ConstantSlerp (from : Vector3, to : Vector3, angle : float) {
|
||||
var value : float = Mathf.Min(1, angle / Vector3.Angle(from, to));
|
||||
return Vector3.Slerp(from, to, value);
|
||||
}
|
||||
|
||||
// Require a character controller to be attached to the same game object
|
||||
@script RequireComponent (CharacterMotor)
|
||||
@script AddComponentMenu ("Character/Platform Input Controller")
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da93ddd6928094e24bb1f3f665f143d3
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
BIN
Game/Assets/Standard Assets/New Material.mat
Normal file
4
Game/Assets/Standard Assets/New Material.mat.meta
Normal file
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 459f66c86c775d24b9a261341915b549
|
||||
NativeFormatImporter:
|
||||
userData:
|
5
Game/Assets/Standard Assets/Terrain Assets.meta
Normal file
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e6f84bf81c8d4de280f1133cff7e601
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
@ -0,0 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2af333648c334319bd43c214449ab50
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
@ -0,0 +1,47 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c528fec5d95e4ac28cf46399b887662
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
serializedVersion: 2
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
linearTexture: 0
|
||||
correctGamma: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapFadeDistanceStart: 2
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: .25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: -1
|
||||
maxTextureSize: 1024
|
||||
textureSettings:
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapMode: 1
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: .5, y: .5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaIsTransparency: 0
|
||||
textureType: 0
|
||||
buildTargetSettings: []
|
||||
spriteSheet:
|
||||
sprites: []
|
||||
spritePackingTag:
|
||||
userData:
|