Пример #1
0
 // 親の情報獲得
 public void AcquireParents()
 {
     ParentSet = transform.parent.GetComponent <ObjectBase>().colliderSet;
 }
Пример #2
0
        public void Initialize(ITypedDataCursor <EditorState> editorState, IObservable <Parachute> editorParachute)
        {
            if (!_isInitialized)
            {
                var configCursor = editorState.To(c => c.Config);

                var parachuteConfigViewModel = new ParachuteConfigViewModel(configCursor);
                _parachuteConfigView.Initialize(parachuteConfigViewModel);
                RegisterUIHover(_additionalSettingsParent.AddComponent <DefaultHoverEventSource>());

                var parachuteColor = configCursor.To(c => c.Color);
                _cellColorPicker.onValueChanged.AddListener(color => parachuteColor.Set(color));
                RegisterUIHover(_cellColorPicker.gameObject.AddComponent <DefaultHoverEventSource>());

                _selectedWidget = editorState.To(c => c.SelectedWidget);

                configDescription = new ConfigDescription(configCursor, _pilotTorsoScale);

                // TODO Use GUI camera?
                var mainCamera = _cameraManager.Rig.GetMainCamera();

                _radiusGizmo.InputRange               = configDescription.Radius;
                _pilotWeightGizmo.InputRange          = configDescription.PilotWeight;
                _weightShiftMagnitudeGizmo.InputRange = configDescription.WeightShiftMagnitude;
                _heightOffsetWidget.InputRange        = configDescription.HeightOffset;
                _rigAttachPosition.InputRange         = configDescription.RigAttachPosition;
                _riggingAngleGizmo.InputRange         = configDescription.RiggingAngle;
                _riggingAngleGizmo.Camera             = mainCamera;

                RegisterDraggable(_radiusGizmo.gameObject, WidgetId.Radius);
                RegisterDraggable(_pilotWeightGizmo.gameObject, WidgetId.PilotWeight);
                RegisterDraggable(_heightOffsetWidget.gameObject, WidgetId.HeightOffset);
                RegisterDraggable(_weightShiftMagnitudeGizmo.gameObject, WidgetId.WeightShiftMagnitude);
                RegisterGizmoHandlers(_riggingAngleGizmo, WidgetId.RiggingAngle);

                editorState.To(c => c.SelectedWidget)
                .OnUpdate
                .Subscribe(selectedWidget => {
                    // Render tooltip
                    //_rigAttachPositionText.gameObject.SetActive(selectedWidget == WidgetId.RigAttachPosition);

                    if (selectedWidget.HasValue)
                    {
                        var tooltip     = Tooltips[selectedWidget.Value];
                        var description = tooltip.Description + "\n\n<i>" + tooltip.Effect + "</i>";
                        _tooltipView.SetState(tooltip.Name, description);
                        _tooltipView.gameObject.SetActive(true);
                    }
                    else
                    {
                        _tooltipView.gameObject.SetActive(false);
                    }
                });

                var colliderSet = ColliderSet.Box("ParachuteUICellColliders", LayerMask.NameToLayer("UI"));

                editorState.To(c => c.IsEditing)
                .OnUpdate
                .Subscribe(isEditing => {
                    colliderSet.Parent.SetActive(isEditing);
                    _gizmosParent.SetActive(isEditing);
                    _additionalSettingsParent.SetActive(isEditing);
                    _cellColorPicker.gameObject.SetActive(isEditing);
                });

                configCursor.OnUpdate
                .CombineLatest(
                    _gameSettingsProvider.SettingChanges,
                    _activeLanguage.TableUpdates,
                    (config, settings, languageTable) => new { config, settings, languageTable })
                .Subscribe(x => {
                    _parachuteConfigView.SetState(x.languageTable.AsFunc);

                    var props = ParachuteProperties.FromConfig(x.config);
                    if (x.settings.Gameplay.UnitSystem == UnitSystem.Metric)
                    {
                        UpdateEditorState(x.config, props);
                    }
                    else
                    {
                        UpdateEditorState(x.config, props.ToImperial());
                    }
                });

                colliderSet.Parent.SetParent(gameObject);
                var canopyDragHandler = colliderSet.Parent.AddComponent <SurfaceDragHandler>();
                canopyDragHandler.Dragging += (camTransform, value) => {
                    var currentValue = configDescription.Volume.Value;
                    currentValue.x += value.x;
                    currentValue.z -= value.y;
                    configDescription.Volume.SetValue(currentValue);
                };
                _canopyHighlight.Highlightable = canopyDragHandler;

                RegisterDraggable(colliderSet.Parent, WidgetId.Area);
                editorParachute.Subscribe(p => {
                    _canopyHighlight.Renderer = p.CanopyMesh;

                    _rigAttachPosition.transform.position = p.Pilot.Torso.transform.position;
                    _rigAttachPosition.transform.rotation = p.Pilot.Torso.transform.rotation;

                    colliderSet.SetSize(p.Sections.Count);
                    for (var i = 0; i < p.Sections.Count; i++)
                    {
                        var cell = p.Sections[i].Cell;
                        colliderSet.UpdateCollider(i, cell.Collider);

                        var isLastCell = i == p.Sections.Count - 1;
                        if (isLastCell)
                        {
                            var gizmoTransform = cell.transform.MakeImmutable()
                                                 .TranslateLocally(0.8f)
                                                 .UpdateScale(Vector3.one)
                                                 .UpdateRotation(p.Root.rotation);
                            _radiusGizmo.transform.Set(gizmoTransform);
                        }
                    }
                });

//                _rigAttachPosition.OnPositionChanged += newPosition => {
//                    configDescription.RigAttachPosition.SetValue(newPosition);
//                };
//                _rigAttachPosition.ActiveAxes = ActiveAxis.X | ActiveAxis.Y | ActiveAxis.Z;
                RegisterDraggable(_rigAttachPosition.gameObject, WidgetId.RigAttachPosition);

                /*
                 * What are the problems that we need to solve:
                 * - Use a single source of truth to render the parachute
                 * - Use a single source of truth to render the GUI
                 * - The GUI widgets should not know more than just the value they need to update and
                 *   what the value is they need to render (use cursors into the app state to do this)
                 * - Use unity as a rendering engine but not as a logic engine (possibly too hard to do this now)
                 *
                 *
                 *
                 * Gizmo:
                 *
                 * - Show scaling and rotation widgets at all times and
                 *   couple them to an InputRange.
                 * - (optional) Draw box around selected thing
                 *
                 */

                _isInitialized = true;
            }
        }