浏览代码

select and rotate object

/add_hero_sample
siyao 3 年前
当前提交
e20612cb
共有 10 个文件被更改,包括 165 次插入61 次删除
  1. 13
      AwesomeUIWidgets/Assets/Prefabs/Cube.prefab
  2. 13
      AwesomeUIWidgets/Assets/Prefabs/Cylinder.prefab
  3. 15
      AwesomeUIWidgets/Assets/Prefabs/Sphere.prefab
  4. 87
      AwesomeUIWidgets/Assets/Scenes/RaycastablePickerRoom.unity
  5. 47
      AwesomeUIWidgets/Assets/Scripts/RaycastableScene/GameObjectManager.cs
  6. 2
      AwesomeUIWidgets/Assets/Scripts/RaycastableScene/ItemPickerMainUIPanel.cs
  7. 1
      AwesomeUIWidgets/Assets/Scripts/RaycastableScene/LeftUIPanel.cs
  8. 7
      AwesomeUIWidgets/Assets/Scripts/RaycastableScene/RaycastableSceneConfig.cs
  9. 38
      AwesomeUIWidgets/Assets/Scripts/RaycastableScene/DragRotate.cs
  10. 3
      AwesomeUIWidgets/Assets/Scripts/RaycastableScene/DragRotate.cs.meta

13
AwesomeUIWidgets/Assets/Prefabs/Cube.prefab


- component: {fileID: 217986789939320856}
- component: {fileID: 576961217026804357}
- component: {fileID: 3906594783066886855}
- component: {fileID: 2098119701279412936}
m_Layer: 0
m_Name: Cube
m_TagString: Untagged

serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &2098119701279412936
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8961943036043786051}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 70433a8c34b64295acbc20adc0a670f5, type: 3}
m_Name:
m_EditorClassIdentifier:

13
AwesomeUIWidgets/Assets/Prefabs/Cylinder.prefab


- component: {fileID: 6957062373009968899}
- component: {fileID: 8774268852477691989}
- component: {fileID: 9163324703857710}
- component: {fileID: 4320369047231173523}
m_Layer: 0
m_Name: Cylinder
m_TagString: Untagged

m_Height: 2
m_Direction: 1
m_Center: {x: 0.000000059604645, y: 0, z: -0.00000008940697}
--- !u!114 &4320369047231173523
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2581742516055541185}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 70433a8c34b64295acbc20adc0a670f5, type: 3}
m_Name:
m_EditorClassIdentifier:

15
AwesomeUIWidgets/Assets/Prefabs/Sphere.prefab


- component: {fileID: 4444717868203319654}
- component: {fileID: 5085546952128025868}
- component: {fileID: 8770364505366370893}
- component: {fileID: 8714588551592826972}
m_Layer: 0
m_Name: Sphere
m_TagString: Untagged

m_GameObject: {fileID: 3259445113941571833}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalScale: {x: 1, y: 0.8, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0

serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &8714588551592826972
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3259445113941571833}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 70433a8c34b64295acbc20adc0a670f5, type: 3}
m_Name:
m_EditorClassIdentifier:

87
AwesomeUIWidgets/Assets/Scenes/RaycastablePickerRoom.unity


m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Texture: {fileID: 1057609342}
m_Texture: {fileID: 1714763606}
m_UVRect:
serializedVersion: 2
x: 0

m_Father: {fileID: 1227377083}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!28 &1057609342
Texture2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 2
m_Width: 0
m_Height: 0
m_CompleteImageSize: 0
m_TextureFormat: 0
m_MipCount: 1
m_IsReadable: 1
m_IgnoreMasterTextureLimit: 0
m_IsPreProcessed: 0
m_StreamingMipmaps: 0
m_StreamingMipmapsPriority: 0
m_AlphaIsTransparency: 0
m_ImageCount: 0
m_TextureDimension: 2
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 0
m_WrapV: 0
m_WrapW: 0
m_LightmapFormat: 0
m_ColorSpace: 0
image data: 0
_typelessdata:
m_StreamData:
offset: 0
size: 0
path:
--- !u!1 &1078121410
GameObject:
m_ObjectHideFlags: 0

cylinder: {fileID: 2581742516055541185, guid: 26a44dfb8d31fa74b89ff502c058df6b,
type: 3}
center: {fileID: 1561398317}
camera: {fileID: 1078121413}
--- !u!1001 &1688741613
PrefabInstance:
m_ObjectHideFlags: 0

objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 6d6892a877c0a664cb5a53eb2dd13c88, type: 3}
--- !u!28 &1714763606
Texture2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 2
m_Width: 0
m_Height: 0
m_CompleteImageSize: 0
m_TextureFormat: 0
m_MipCount: 1
m_IsReadable: 1
m_IgnoreMasterTextureLimit: 0
m_IsPreProcessed: 0
m_StreamingMipmaps: 0
m_StreamingMipmapsPriority: 0
m_AlphaIsTransparency: 0
m_ImageCount: 0
m_TextureDimension: 2
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 0
m_WrapV: 0
m_WrapW: 0
m_LightmapFormat: 0
m_ColorSpace: 0
image data: 0
_typelessdata:
m_StreamData:
offset: 0
size: 0
path:
--- !u!1 &1841365878
GameObject:
m_ObjectHideFlags: 0

47
AwesomeUIWidgets/Assets/Scripts/RaycastableScene/GameObjectManager.cs


public GameObject obj;
public Vector3 position;
public string name;
public bool active;
public class GameObjectManager : MonoBehaviour
{
public GameObject cube;

public static Transform centerInstance;
public static Dictionary<string, ObjectItem> objects = new Dictionary<string, ObjectItem>();
public static Vector3? cameraPosition;
public static Camera cameraInstance;
public Camera camera;
// public static List<GameObject> closeObjects = new List<GameObject>();

c = sq;
}
var s = 2;
var s = RaycastableSceneConfig.scaterScale;
return center.position + new Vector3(r * s, c * s, 0);
}

{
obj = newObj,
name = newObj.name,
position = newObj.transform.position
position = newObj.transform.position,
active = true
});
}
}

centerInstance = center;
cameraInstance = camera;
CreateGameObject(cube, RaycastableSceneConfig.cubeCount, RaycastableSceneConfig.cubeName);
CreateGameObject(ball, RaycastableSceneConfig.ballCount, RaycastableSceneConfig.ballName);
CreateGameObject(cylinder, RaycastableSceneConfig.cylinderCount, RaycastableSceneConfig.cylinderName);

void Update()
{
// int count = closeObjects.Count;
// transform.Rotate(new Vector3(0,1,0), Time.deltaTime);
// for (int i = 0; i < count; i++)
// {
// closeObjects[i].transform.position()
// }
{
if (cameraPosition != null )
{
var dif = cameraPosition.Value - camera.transform.position;
if (dif.sqrMagnitude > RaycastableSceneConfig.delta)
{
camera.transform.position = dif.normalized * Time.deltaTime + camera.transform.position;
}
}
}
void OnDestroy()

}
}
public static void FocusOnObject(string name)
{
var obj = objects.getOrDefault(name);
if (obj != null && obj.active)
{
cameraPosition = new Vector3(obj.position.x, obj.position.y, cameraInstance.transform.position.z);
}
}
obj.obj.transform.position = obj.position;// centerInstance.position;
// closeObjects.Add(obj);
obj.obj.transform.position = obj.position;
obj.active = true;
}
}

if (obj != null)
{
obj.obj.transform.position = RaycastableSceneConfig.far;
// closeObjects.Remove(obj);
obj.active = false;
}
}
}

2
AwesomeUIWidgets/Assets/Scripts/RaycastableScene/ItemPickerMainUIPanel.cs


itemCheckCallback: (index, active) =>
{
//TODO: callback when item is activated/inactivated
Debug.Log($"item {index}'s state is {active}");
Debug.Log($"item {index} is selected");
}
)));
}

1
AwesomeUIWidgets/Assets/Scripts/RaycastableScene/LeftUIPanel.cs


setState(() =>
{
selectedIndex = index;
GameObjectManager.FocusOnObject(_searchResult[index].itemName);
widget.itemSelectCallback?.Invoke(selectedIndex);
});
},

7
AwesomeUIWidgets/Assets/Scripts/RaycastableScene/RaycastableSceneConfig.cs


public const string LightSliderName = "Color Slider";
public const string cubeName = "cube";
public const int cubeCount = 15;
public const int cubeCount = 4;
public const int scaterScale = 2;
public const float delta = 0.2f;
public static readonly Vector3 far = new Vector3(1000, 0, 0);
}
}

38
AwesomeUIWidgets/Assets/Scripts/RaycastableScene/DragRotate.cs


using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UInput = UnityEngine.Input;
namespace UIWidgetsSample.RaycastableScene
{
public class DragRotate : MonoBehaviour
{
Vector2? _lastPosition = Vector2.zero;
public static Vector2 mousePosition
{
get
{
return new Vector2(UInput.mousePosition.x, UInput.mousePosition.y);
}
}
void OnMouseDown()
{
_lastPosition = mousePosition;
}
private void OnMouseUp()
{
_lastPosition = null;
}
private void OnMouseDrag()
{
Vector2 direction = mousePosition - _lastPosition.Value;
_lastPosition = mousePosition;
transform.Rotate(-direction.y, -direction.x, 0, Space.World);
}
}
}

3
AwesomeUIWidgets/Assets/Scripts/RaycastableScene/DragRotate.cs.meta


fileFormatVersion: 2
guid: 70433a8c34b64295acbc20adc0a670f5
timeCreated: 1627531440
正在加载...
取消
保存