private void Populate() { Object[] assets = AssetDatabase.GetAllAssetPaths().Where(a => a.StartsWith("Assets/Resources/Props/")).Select(a => AssetDatabase.LoadAssetAtPath <GameObject>(a)).ToArray(); PrefabDatabase database = target as PrefabDatabase; database.Prefabs.Clear(); database.Labels.Clear(); foreach (var asset in assets) { GameObject go = asset as GameObject; if (go != null) { string[] lables = AssetDatabase.GetLabels(asset); string path = AssetDatabase.GetAssetPath(asset); WorldProp prop = go.GetComponent <WorldProp>(); if (prop != null) { database.Prefabs.Add(new PrefabDatabase.PrefabEntry(prop.name, lables, AssetDatabase.AssetPathToGUID(path), path.Replace("Assets/Resources/", "").Replace("/" + prop.name + ".prefab", ""))); database.Labels.AddRange(lables.Where(l => !database.Labels.Contains(l))); } } } EditorUtility.SetDirty(target); AssetDatabase.SaveAssets(); }
public PrefabEntry() { loadedProp = false; loadedIcon = false; icon = null; prop = null; }
public static TransformData GetData(WorldProp t) { TransformData result = default(TransformData); result.SetupTransformValues(t); return(result); }
public void DestroyProp() { for (int i = 0; i < Weapons.Length; i++) { Weapons[i]?.DestroyProp(); } WorldProp?.Delete(); }
private void SetupTransformValues(WorldProp p) { this.prop = p; this.position = p.Position; this.localPosition = p.transform.localPosition; this.rotation = p.Rotation; this.scale = p.Scale; }
public void CreateProp() { WorldProp = World.CreateProp("bkr_prop_gunlocker_01a", Position - new Vector3(0f, 0f, 1f), Rotation, false, false); for (int i = 0; i < Weapons.Length; i++) { Weapons[i]?.CreateProp(WorldProp, i); } InteractionPosition = WorldProp.GetOffsetInWorldCoords(new Vector3(0f, -0.65f, 0f)); }
private void OnGUI() { if (camera == null || movementController == null || playerPlacementController == null) { camera = Player.Camera; movementController = Player.MovementController; playerPlacementController = Player.PlacementController; GUIUtility.ExitGUI(); return; } var current = Event.current; switch (current.type) { case EventType.KeyDown: switch (current.keyCode) { case KeyCode.Escape: Tools.current = RuntimeTool.Move; break; } break; case EventType.MouseDown: if (GUIUtility.hotControl == 0 && current.button == 0) { RaycastHit raycastHit; Ray ray = camera.ScreenPointToRay(Input.mousePosition); if (playerPlacementController != null && Physics.Raycast(ray, out raycastHit, float.MaxValue, WorldManager.WorldLayerMask)) { WorldProp prop = raycastHit.transform.GetComponentInParent <WorldProp>(); if (prop != null) { RuntimeSelection.Props = new[] { prop }; } else { RuntimeSelection.Props = new WorldProp[0]; } } else { RuntimeSelection.Props = new WorldProp[0]; } } break; } }
private WorldProp CreatePropGameObjectInternal(WorldObject obj) { var prefab = PrefabDatabase.Instance.GetEntry(obj.guid); GameObject instacne = Instantiate(prefab.Prop.gameObject); SetLayerRecursively(instacne, WorldLayer); WorldProp prop = instacne.GetComponent <WorldProp>(); prop.SetPrefab(prefab); prop.SetPosition(obj.pos, false); prop.SetRotation(obj.rotation, false); prop.SetScale(obj.scale, false); prop.SetColor(obj.color, false); return(prop); }
public void DeleteProp(WorldProp prop) { if (isServer && prop != null && prop.IsValid) { WorldObjectEntry entry; if (DeleteProrpInternal(prop.Id, out entry)) { NetworkServer.SendToAll(Messages.PROP_COMMAND, new Messages.PropCommandMessage(entry.id, PropCommandEnum.Delete)); } } else if (isClient && prop != null && prop.IsValid) { NetworkManager.singleton.client.Send(Messages.PROP_COMMAND, new Messages.PropCommandMessage(prop.Id, PropCommandEnum.Delete)); } }
public void RegisterProp(WorldProp p_prop) { if (m_props.ContainsKey(p_prop.Zone) == false) { m_props.Add(p_prop.Zone, new Dictionary <int, List <WorldProp> >()); } if (m_props[p_prop.Zone].ContainsKey(p_prop.State) == false) { m_props[p_prop.Zone].Add(p_prop.State, new List <WorldProp>()); } m_props[p_prop.Zone][p_prop.State].Add(p_prop); p_prop.Hide(); }
internal static Vector3 GetHandlePosition() { WorldProp activeTransform = RuntimeSelection.activeProp; if (!activeTransform) { return(new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity)); } Vector3 b = Tools.handleOffset + Tools.handleRotation * Tools.localHandleOffset; PivotMode pivotMode = Tools.get.m_PivotMode; if (pivotMode != PivotMode.Pivot) { return(new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity)); } return(activeTransform.Position + b); }
internal static Bounds CalculateSelectionBoundsInSpace(Vector3 position, Quaternion rotation, bool rectBlueprintMode) { Quaternion rotation2 = Quaternion.Inverse(rotation); Vector3 vector = new Vector3(3.40282347E+38f, 3.40282347E+38f, 3.40282347E+38f); Vector3 vector2 = new Vector3(-3.40282347E+38f, -3.40282347E+38f, -3.40282347E+38f); Vector3[] array = new Vector3[2]; WorldProp[] gameObjects = RuntimeSelection.Props; for (int i = 0; i < gameObjects.Length; i++) { WorldProp gameObject = gameObjects[i]; Bounds localBounds = GetLocalBounds(gameObject.gameObject); array[0] = localBounds.min; array[1] = localBounds.max; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { for (int l = 0; l < 2; l++) { Vector3 vector3 = new Vector3(array[j].x, array[k].y, array[l].z); if (rectBlueprintMode && SupportsRectLayout(gameObject.transform)) { Vector3 localPosition = gameObject.transform.localPosition; localPosition.z = 0f; vector3 = gameObject.transform.parent.TransformPoint(vector3 + localPosition); } else { vector3 = gameObject.transform.TransformPoint(vector3); } vector3 = rotation2 * (vector3 - position); for (int m = 0; m < 3; m++) { vector[m] = Mathf.Min(vector[m], vector3[m]); vector2[m] = Mathf.Max(vector2[m], vector3[m]); } } } } } return(new Bounds((vector + vector2) * 0.5f, vector2 - vector)); }
// Update is called once per frame private void Update() { if (!isLocalPlayer) { return; } if (RuntimeDragAndDrop.DraggedProp != null && placingProp == null) { placingProp = Instantiate(RuntimeDragAndDrop.DraggedProp.gameObject).GetComponent <WorldProp>(); placingProp.gameObject.SetActive(false); WorldManager.SetLayerRecursively(placingProp.gameObject, LayerMask.NameToLayer("Indicators")); } else if (placingProp != null && RuntimeDragAndDrop.DraggedProp == null) { Destroy(placingProp.gameObject); placingProp = null; } }
public void CloneProp(WorldProp prop) { if (prop == null || !prop.IsValid) { return; } if (isServer) { WorldObjectEntry entry; WorldObject obj = new WorldObject(); prop.SaveTo(obj); entry = CreateObjectServer(obj); RuntimeSelection.activeProp = entry.Prop; NetworkServer.SendToAll(Messages.SPAWN_PROP, new Messages.SpawnPropMessage(obj, entry.id)); } else if (isClient) { NetworkManager.singleton.client.Send(Messages.PROP_COMMAND, new Messages.PropCommandMessage(prop.Id, PropCommandEnum.Clone)); } }
private void OnGUI() { if (camera == null) { camera = Player.Camera; return; } var current = Event.current; RuntimeHandles.SetCamera(camera.pixelRect, camera); RuntimeHandlesUtility.BeginHandles(); RuntimeHandles.currentCamera = camera; WorldProp selection = RuntimeSelection.activeProp; if (selection != null) { switch (Tools.current) { case RuntimeTool.Move: MoveToolGUI(MoveToolGUI); break; case RuntimeTool.Rotate: RuntimeEditorGUI.BeginChangeCheck(); Quaternion rotation = RuntimeHandles.DoRotationHandle(selection.Rotation, Tools.handlePosition); if (RuntimeEditorGUI.EndChangeCheck()) { UndoManager.PushUndo("Rotate", r => selection.SetRotation((Quaternion)r, true), selection.Rotation); } selection.SetRotation(rotation, true); break; case RuntimeTool.Scale: Vector3 scale = RuntimeHandles.DoScaleHandle(selection.Scale, Tools.handlePosition, Tools.handleRotation); selection.SetScale(scale, true); break; } } RuntimeHandlesUtility.EndHandles(); }
private void DoInspector(WorldProp prop) { GUILayout.BeginHorizontal(); Vector3 pos = prop.Position; GUILayout.Label(new GUIContent("Position"), GUILayout.Width(90)); GUILayout.Label(new GUIContent("X"), Styles.prefixLabelClose); pos.x = RuntimeEditorGUI.FloatFieldInternal(GUILayoutUtility.GetRect(GUIContent.none, GUI.skin.textField), pos.x, GUI.skin.textField); GUILayout.Label(new GUIContent("Y"), Styles.prefixLabelClose); pos.y = RuntimeEditorGUI.FloatFieldInternal(GUILayoutUtility.GetRect(GUIContent.none, GUI.skin.textField), pos.y, GUI.skin.textField); GUILayout.Label(new GUIContent("Z"), Styles.prefixLabelClose); pos.z = RuntimeEditorGUI.FloatFieldInternal(GUILayoutUtility.GetRect(GUIContent.none, GUI.skin.textField), pos.z, GUI.skin.textField); prop.SetPosition(pos, true); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); Vector3 eualrRotation = prop.Rotation.eulerAngles; GUILayout.Label(new GUIContent("Rotation"), GUILayout.Width(90)); GUILayout.Label(new GUIContent("X"), Styles.prefixLabelClose); eualrRotation.x = RuntimeEditorGUI.FloatFieldInternal(GUILayoutUtility.GetRect(GUIContent.none, GUI.skin.textField), eualrRotation.x, GUI.skin.textField); GUILayout.Label(new GUIContent("Y"), Styles.prefixLabelClose); eualrRotation.y = RuntimeEditorGUI.FloatFieldInternal(GUILayoutUtility.GetRect(GUIContent.none, GUI.skin.textField), eualrRotation.y, GUI.skin.textField); GUILayout.Label(new GUIContent("Z"), Styles.prefixLabelClose); eualrRotation.z = RuntimeEditorGUI.FloatFieldInternal(GUILayoutUtility.GetRect(GUIContent.none, GUI.skin.textField), eualrRotation.z, GUI.skin.textField); prop.SetRotation(Quaternion.Euler(eualrRotation), true); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); Vector3 scale = prop.Scale; GUILayout.Label(new GUIContent("Scale"), GUILayout.Width(90)); GUILayout.Label(new GUIContent("X"), Styles.prefixLabelClose); scale.x = RuntimeEditorGUI.FloatFieldInternal(GUILayoutUtility.GetRect(GUIContent.none, GUI.skin.textField), scale.x, GUI.skin.textField); GUILayout.Label(new GUIContent("Y"), Styles.prefixLabelClose); scale.y = RuntimeEditorGUI.FloatFieldInternal(GUILayoutUtility.GetRect(GUIContent.none, GUI.skin.textField), scale.y, GUI.skin.textField); GUILayout.Label(new GUIContent("Z"), Styles.prefixLabelClose); scale.z = RuntimeEditorGUI.FloatFieldInternal(GUILayoutUtility.GetRect(GUIContent.none, GUI.skin.textField), scale.z, GUI.skin.textField); prop.SetScale(scale, true); GUILayout.EndHorizontal(); }
public static void StartDrag(WorldProp DraggedProp, string guid) { draggedProp = DraggedProp; draggedGuid = guid; GUIUtility.hotControl = DragHash; }
public static void TakeDrag() { draggedProp = null; draggedGuid = null; GUIUtility.hotControl = 0; }
public WorldObjectEntry(long id, WorldProp prop) { this.id = id; Prop = prop; }