Skip to content

Commit

Permalink
add mover
Browse files Browse the repository at this point in the history
  • Loading branch information
tmori committed Dec 10, 2024
1 parent 8ba9091 commit c7b34e3
Show file tree
Hide file tree
Showing 5 changed files with 263 additions and 12 deletions.
146 changes: 138 additions & 8 deletions Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ Transform:
m_GameObject: {fileID: 86337324}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.2, y: -0.5515887, z: 0}
m_LocalPosition: {x: -0.2, y: 0, z: 0}
m_LocalScale: {x: 0.1, y: 0.3, z: 0.1}
m_ConstrainProportionsScale: 0
m_Children: []
Expand Down Expand Up @@ -568,12 +568,13 @@ Transform:
m_GameObject: {fileID: 243028773}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.51, z: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 86337328}
- {fileID: 1398337323}
- {fileID: 1760306887}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &491118249
Expand Down Expand Up @@ -798,7 +799,7 @@ Camera:
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
field of view: 81
orthographic: 0
orthographic size: 5
m_Depth: -1
Expand All @@ -824,13 +825,13 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225}
serializedVersion: 2
m_LocalRotation: {x: -0, y: 0.0062899366, z: -0, w: 0.9999802}
m_LocalPosition: {x: 0.4595791, y: 0.26266205, z: -0.7694214}
m_LocalRotation: {x: -0.5558553, y: 0.003920326, z: -0.0026218833, w: -0.8312657}
m_LocalPosition: {x: 0.21, y: 2.34, z: -0.65}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1979740995}
m_LocalEulerAnglesHint: {x: 0, y: 0.721, z: 0}
m_LocalEulerAnglesHint: {x: 67.54, y: 359.46, z: 0}
--- !u!114 &963194229
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -861,6 +862,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 1294778541}
- component: {fileID: 1294778542}
m_Layer: 0
m_Name: GUI
m_TagString: Untagged
Expand All @@ -884,6 +886,25 @@ Transform:
- {fileID: 3088442090504903162}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1294778542
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1294778540}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a4291887377584aefb34fb8d1cdbf137, type: 3}
m_Name:
m_EditorClassIdentifier:
objects:
- {fileID: 86337324}
- {fileID: 1398337319}
- {fileID: 1760306886}
highlightColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1}
moveSpeed: 1
scaleSpeed: 0.1
--- !u!1 &1398337319
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -962,7 +983,7 @@ Transform:
m_GameObject: {fileID: 1398337319}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.2, y: -0.5515887, z: 0}
m_LocalPosition: {x: 0.2, y: 0, z: 0}
m_LocalScale: {x: 0.1, y: 0.2, z: 0.1}
m_ConstrainProportionsScale: 0
m_Children: []
Expand Down Expand Up @@ -1040,6 +1061,111 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1760306886
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1760306887}
- component: {fileID: 1760306890}
- component: {fileID: 1760306889}
- component: {fileID: 1760306888}
m_Layer: 0
m_Name: Sphere
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1760306887
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1760306886}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 2.15}
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 243028774}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!135 &1760306888
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1760306886}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &1760306889
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1760306886}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: f03aa1aea34974c8193f693c7b904689, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &1760306890
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1760306886}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &1978498665
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1205,7 +1331,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 2a192039de0004798ba7698dd1787286, type: 3}
m_Name:
m_EditorClassIdentifier:
config_filepath: urg-04lx-ug01.json
config_filepath: lidar.json
max_count: 360
robotName: LiDAR2D
pduName: scan
Expand Down Expand Up @@ -1319,6 +1445,10 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2510056811221095750, guid: 616bfedd13e3847a5b2e0d6511858033, type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5444515011665261397, guid: 616bfedd13e3847a5b2e0d6511858033, type: 3}
propertyPath: m_Name
value: LiDAR2D
Expand Down
106 changes: 106 additions & 0 deletions Assets/Scripts/GUI/ObjectMove.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ObjectMove : MonoBehaviour
{
public GameObject[] objects; // 複数のゲームオブジェクトを管理
public Color highlightColor = Color.yellow; // 選択中のオブジェクトの色
public float moveSpeed = 5f; // 移動速度
public float scaleSpeed = 0.1f; // スケール変更速度

private int currentIndex = 0; // 現在選択されているオブジェクトのインデックス
private Color[] originalColors; // 元のオブジェクトの色を保存

void Start()
{
// 元の色を保存
originalColors = new Color[objects.Length];
for (int i = 0; i < objects.Length; i++)
{
if (objects[i].TryGetComponent<Renderer>(out Renderer renderer))
{
originalColors[i] = renderer.material.color;
}
}

// 初期選択の強調表示
HighlightObject(currentIndex);
}

void Update()
{
// タブキーで選択切り替え
if (Input.GetKeyDown(KeyCode.Tab))
{
SwitchObject();
}

// 選択中のオブジェクトを移動
MoveSelectedObject();

// 選択中のオブジェクトのスケール変更
ScaleSelectedObject();
}

void SwitchObject()
{
// 現在の選択をリセット
ResetHighlight(currentIndex);

// 次のオブジェクトに切り替え
currentIndex = (currentIndex + 1) % objects.Length;

// 新しい選択を強調表示
HighlightObject(currentIndex);
}

void HighlightObject(int index)
{
if (objects[index].TryGetComponent<Renderer>(out Renderer renderer))
{
renderer.material.color = highlightColor;
}
}

void ResetHighlight(int index)
{
if (objects[index].TryGetComponent<Renderer>(out Renderer renderer))
{
renderer.material.color = originalColors[index];
}
}

void MoveSelectedObject()
{
if (objects[currentIndex] != null)
{
float moveX = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;
float moveZ = Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime;

objects[currentIndex].transform.Translate(new Vector3(moveX, 0, moveZ));
}
}

void ScaleSelectedObject()
{
if (objects[currentIndex] != null)
{
float scaleChange = 0;

if (Input.GetKey(KeyCode.E))
{
scaleChange = scaleSpeed * Time.deltaTime;
}
else if (Input.GetKey(KeyCode.Q))
{
scaleChange = -scaleSpeed * Time.deltaTime;
}

if (scaleChange != 0)
{
objects[currentIndex].transform.localScale += new Vector3(scaleChange, scaleChange, scaleChange);
}
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/GUI/ObjectMove.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion ProjectSettings/EditorBuildSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
EditorBuildSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes: []
m_Scenes:
- enabled: 1
path: Assets/Scenes/SampleScene.unity
guid: 9fc0d4010bbf28b4594072e72b8655ab
m_configObjects: {}
7 changes: 4 additions & 3 deletions ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ PlayerSettings:
bakeCollisionMeshes: 0
forceSingleInstance: 0
useFlipModelSwapchain: 1
resizableWindow: 0
resizableWindow: 1
useMacAppStoreValidation: 0
macAppStoreCategory: public.app-category.games
gpuSkinning: 1
Expand All @@ -103,7 +103,7 @@ PlayerSettings:
xboxEnableFitness: 0
visibleInBackground: 1
allowFullscreenSwitch: 1
fullscreenMode: 1
fullscreenMode: 3
xboxSpeechDB: 0
xboxEnableHeadOrientation: 0
xboxEnableGuest: 0
Expand Down Expand Up @@ -160,7 +160,8 @@ PlayerSettings:
resetResolutionOnWindowResize: 0
androidSupportedAspectRatio: 1
androidMaxAspectRatio: 2.1
applicationIdentifier: {}
applicationIdentifier:
Standalone: com.DefaultCompany.Tutorial
buildNumber:
Standalone: 0
VisionOS: 0
Expand Down

0 comments on commit c7b34e3

Please sign in to comment.