Browse Source

Редактор стен

Виктор Шейко 5 years ago
parent
commit
362f3f8674

+ 26 - 2
Assembly-CSharp.csproj

@@ -8,7 +8,8 @@
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
     <ProductVersion>10.0.20506</ProductVersion>
     <SchemaVersion>2.0</SchemaVersion>
-    <RootNamespace></RootNamespace>
+    <RootNamespace>
+    </RootNamespace>
     <ProjectGuid>{E6391B5F-5B7A-0657-4DD9-DB85FF22C326}</ProjectGuid>
     <OutputType>Library</OutputType>
     <AppDesignerFolder>Properties</AppDesignerFolder>
@@ -64,8 +65,9 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Assets\Scripts\Controllers\CameraController.cs" />
-    <Compile Include="Assets\Scripts\Controllers\CreateLocationController.cs" />
+    <Compile Include="Assets\Scripts\Controllers\CreateFance.cs" />
     <Compile Include="Assets\Scripts\Controllers\LocationController.cs" />
+    <Compile Include="Assets\Scripts\Controllers\ShowMousePosition.cs" />
     <Compile Include="Assets\Scripts\Controllers\TimePickerController.cs" />
     <Compile Include="Assets\Scripts\Controllers\WorkerController.cs" />
     <Compile Include="Assets\Scripts\Models\Structure.cs" />
@@ -652,6 +654,28 @@
       <HintPath>C:/Program Files/Unity/Editor/Data/NetStandard/compat/2.0.0/shims/netfx/System.Xml.Serialization.dll</HintPath>
     </Reference>
   </ItemGroup>
+  <ItemGroup />
+  <ItemGroup>
+    <None Include="Assets\Materials\green.mat" />
+    <None Include="Assets\Materials\red.mat" />
+    <None Include="Assets\Resources\Fonts\OpenSans-Regular.ttf" />
+    <None Include="Assets\Resources\GameObjects\Capsule.prefab" />
+    <None Include="Assets\Resources\GameObjects\Cube.prefab" />
+    <None Include="Assets\Resources\GameObjects\Fence.prefab" />
+    <None Include="Assets\Resources\GameObjects\Grid.prefab" />
+    <None Include="Assets\Resources\GameObjects\Panel.prefab" />
+    <None Include="Assets\Resources\GameObjects\Pole.prefab" />
+    <None Include="Assets\Resources\GameObjects\Room.prefab" />
+    <None Include="Assets\Resources\GameObjects\RoomTest.prefab" />
+    <None Include="Assets\Resources\GameObjects\TimePicker.prefab" />
+    <None Include="Assets\Resources\GameObjects\Toggle.prefab" />
+    <None Include="Assets\Scenes\Editor.unity" />
+    <None Include="Assets\Scenes\Location_22.unity" />
+  </ItemGroup>
+  <ItemGroup>
+    <Content Include="Assets\Resources\SVG\keyboard_arrow_down-24px.svg" />
+    <Content Include="Assets\Resources\SVG\keyboard_arrow_up-24px.svg" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Target Name="GenerateTargetFrameworkMonikerAttribute" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

+ 77 - 0
Assets/Materials/green.mat

@@ -0,0 +1,77 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!21 &2100000
+Material:
+  serializedVersion: 6
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_Name: New Material
+  m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
+  m_ShaderKeywords: 
+  m_LightmapFlags: 4
+  m_EnableInstancingVariants: 0
+  m_DoubleSidedGI: 0
+  m_CustomRenderQueue: -1
+  stringTagMap: {}
+  disabledShaderPasses: []
+  m_SavedProperties:
+    serializedVersion: 3
+    m_TexEnvs:
+    - _BumpMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _DetailAlbedoMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _DetailMask:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _DetailNormalMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _EmissionMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _MainTex:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _MetallicGlossMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _OcclusionMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _ParallaxMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    m_Floats:
+    - _BumpScale: 1
+    - _Cutoff: 0.5
+    - _DetailNormalMapScale: 1
+    - _DstBlend: 0
+    - _GlossMapScale: 1
+    - _Glossiness: 0.5
+    - _GlossyReflections: 1
+    - _Metallic: 0
+    - _Mode: 0
+    - _OcclusionStrength: 1
+    - _Parallax: 0.02
+    - _SmoothnessTextureChannel: 0
+    - _SpecularHighlights: 1
+    - _SrcBlend: 1
+    - _UVSec: 0
+    - _ZWrite: 1
+    m_Colors:
+    - _Color: {r: 1, g: 1, b: 1, a: 1}
+    - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

+ 77 - 0
Assets/Materials/red.mat

@@ -0,0 +1,77 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!21 &2100000
+Material:
+  serializedVersion: 6
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_Name: red
+  m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
+  m_ShaderKeywords: 
+  m_LightmapFlags: 4
+  m_EnableInstancingVariants: 0
+  m_DoubleSidedGI: 0
+  m_CustomRenderQueue: -1
+  stringTagMap: {}
+  disabledShaderPasses: []
+  m_SavedProperties:
+    serializedVersion: 3
+    m_TexEnvs:
+    - _BumpMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _DetailAlbedoMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _DetailMask:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _DetailNormalMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _EmissionMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _MainTex:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _MetallicGlossMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _OcclusionMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _ParallaxMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    m_Floats:
+    - _BumpScale: 1
+    - _Cutoff: 0.5
+    - _DetailNormalMapScale: 1
+    - _DstBlend: 0
+    - _GlossMapScale: 1
+    - _Glossiness: 0.5
+    - _GlossyReflections: 1
+    - _Metallic: 0
+    - _Mode: 0
+    - _OcclusionStrength: 1
+    - _Parallax: 0.02
+    - _SmoothnessTextureChannel: 0
+    - _SpecularHighlights: 1
+    - _SrcBlend: 1
+    - _UVSec: 0
+    - _ZWrite: 1
+    m_Colors:
+    - _Color: {r: 1, g: 1, b: 1, a: 1}
+    - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

+ 71 - 0
Assets/Scripts/Controllers/CreateFance.cs

@@ -0,0 +1,71 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class CreateFance : MonoBehaviour
+{
+    bool creating;
+    ShowMousePosition pointer;
+    public GameObject polePrefab;
+    public GameObject fencePrefab;
+    GameObject lastPole;
+
+    // Start is called before the first frame update
+    void Start()
+    {
+        pointer = GetComponent<ShowMousePosition>();
+    }
+
+    // Update is called once per frame
+    void Update()
+    {
+        getInput();
+    }
+
+    void getInput()
+    {
+        if(Input.GetMouseButtonDown(0))
+        {
+            startFence();
+        }
+        else if (creating)
+        {
+            updateFence();
+        }
+    }
+
+    void startFence()
+    {
+        creating = true;
+        var startPos = pointer.getWorldPoint();
+        startPos = pointer.snapPosition(startPos);
+        var startPole = Instantiate(polePrefab, startPos, Quaternion.identity);
+        startPole.transform.position = new Vector3(startPos.x, startPos.y + 0.3f, startPos.z);
+        lastPole = startPole;
+    }
+
+    void setFence()
+    {
+        creating = false;
+    }
+
+    void updateFence()
+    {
+        var current = pointer.getWorldPoint();
+        current = pointer.snapPosition(current);
+        current = new Vector3(current.x, current.y + 0.3f, current.z);
+        if(!current.Equals(lastPole.transform.position))
+        {
+            CreateFenceSegment(current);
+        }
+    }
+
+    void CreateFenceSegment(Vector3 current)
+    {
+        var newPole = Instantiate(polePrefab, current, Quaternion.identity);
+        var middle = Vector3.Lerp(newPole.transform.position, lastPole.transform.position, 0.5f);
+        var newFence = Instantiate(fencePrefab, middle, Quaternion.identity);
+        newFence.transform.LookAt(lastPole.transform);
+        lastPole = newPole;
+    }
+}

+ 0 - 18
Assets/Scripts/Controllers/CreateLocationController.cs

@@ -1,18 +0,0 @@
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-public class CreateLocationController : MonoBehaviour
-{
-    // Start is called before the first frame update
-    void Start()
-    {
-        
-    }
-
-    // Update is called once per frame
-    void Update()
-    {
-        
-    }
-}

+ 40 - 0
Assets/Scripts/Controllers/ShowMousePosition.cs

@@ -0,0 +1,40 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class ShowMousePosition : MonoBehaviour
+{
+    public GameObject mousePointer;
+    // Start is called before the first frame update
+    void Start()
+    {
+
+    }
+
+    // Update is called once per frame
+    void Update()
+    {
+
+        mousePointer.transform.position = snapPosition(getWorldPoint());
+    }
+
+    public Vector3 getWorldPoint()
+    {
+        Camera cam = GetComponent<Camera>();
+        Ray ray = cam.ScreenPointToRay(Input.mousePosition);
+        RaycastHit hit;
+        if(Physics.Raycast(ray, out hit)) {
+            return hit.point;
+        }
+        return Vector3.zero;
+    }
+
+    public Vector3 snapPosition(Vector3 original)
+    {
+        Vector3 snapped;
+        snapped.x = Mathf.Floor(original.x + 0.5f);
+        snapped.y = Mathf.Floor(original.y + 0.5f);
+        snapped.z = Mathf.Floor(original.z + 0.5f);
+        return snapped;
+    }
+}