Example #1
0
        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 ManagePrefabPlacement(RaycastHit raycastHit)
    {
        Quaternion rot = Quaternion.Euler(rotation) * Quaternion.LookRotation(Vector3.forward, raycastHit.normal);

        if (placingProp != null)
        {
            if (!placingProp.gameObject.activeSelf)
            {
                placingProp.gameObject.SetActive(true);
            }
            placingProp.SetPosition(raycastHit.point, false);
            placingProp.SetRotation(rot, false);
        }
    }
Example #3
0
    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);
    }
    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();
    }