Ejemplo n.º 1
0
 /// <summary>
 /// Attaches the specified host.
 /// </summary>
 /// <param name="host">The host.</param>
 public void Attach(IRenderHost host)
 {
     Items.Attach(host);
     ViewCube.Attach(host);
     CoordinateSystem.Attach(host);
     Items2D.Attach(host);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Detaches this instance.
 /// </summary>
 public void Detach()
 {
     Items.Detach();
     ViewCube.Detach();
     CoordinateSystem.Detach();
     Items2D.Detach();
 }
Ejemplo n.º 3
0
        public void OnSettingsChanged(object sender, SettingsChangedEventArgs <ModSettings> e)
        {
            //Debug.Log ("Settings Chaned");
            if (Game.InDesignerScene)
            {
                foreach (Transform child in designer.DesignerCamera.Camera.transform.GetComponentsInChildren <Transform> ())
                {
                    if (child.gameObject.name == "ViewCube(Clone)")
                    {
                        foreach (Transform c in child.gameObject.GetComponentsInChildren <Transform> ())
                        {
                            GameObject.Destroy(c.gameObject);
                        }
                        _viewCube = null;
                    }
                }

                selectorManager.OnSettingChanged();
                if (ModSettings.Instance.viewCube)
                {
                    if (_viewCube == null)
                    {
                        _viewCube = new ViewCube(designer);
                    }
                    _viewCube.updateScale();
                }
            }
        }
Ejemplo n.º 4
0
        public void OnSceneLoaded(object sender, SceneEventArgs e)
        {
            //Debug.Log (e.Scene + " Loaded (mod.cs)");
            if (e.Scene == ModApi.Scenes.SceneNames.Designer)
            {
                designer.CraftLoaded           += OnCraftLoaded;
                designer.BeforeCraftUnloaded   += OnCraftUnloading;
                designer.CraftStructureChanged += OnCraftStructureChanged;
                designer.Click += OnClick;
                DesignerToolsUIController.OnDesignerLoaded();
                selectorManager.OnDesignerLoaded();
                if (ModSettings.Instance.viewCube && _viewCube == null)
                {
                    _viewCube = new ViewCube(designer);
                }

                // IFlyout flyout = Game.Instance.Designer.DesignerUi.Flyouts.Tools;
                // IXmlLayout layout = flyout.Transform.GetComponentInChildren<IXmlLayout> ().GetElementById ("PaintTool").XmlLayout;
                // Debug.Log ("Paint Tool Panel: " + layout.Xml);
                // Debug.Log (layout.ToString ());
                // RectTransform root = layout.GetElementById<RectTransform> ("edit-color-panel");
                // Debug.Log ("panel: " + root.ToString ());

                // _ColorPickerButton = Game.Instance.UserInterface.BuildUserInterfaceFromResource<ColorPickerButtonScript> ("DesignerTools/Designer/ColorPickerButton", (s, c) => { s.OnLayoutRebuilt (c.XmlLayout); }, root);
                // _ColorPickerButton.gameObject.AddComponent<LayoutElement> ().minHeight = 30;
                // _ColorPickerButton.transform.SetAsLastSibling ();
            }
        }
Ejemplo n.º 5
0
 public void OnSceneUnloading(object sender, SceneEventArgs e)
 {
     if (e.Scene == ModApi.Scenes.SceneNames.Designer)
     {
         //Debug.Log (e.Scene + " Unloading (mod.cs)");
         Designer.CraftLoaded -= OnCraftLoaded;
         _ViewCube             = null;
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Attaches the specified host.
 /// </summary>
 /// <param name="host">The host.</param>
 public void Attach(IRenderHost host)
 {
     Items.Attach(host.EffectsManager);
     Items.Invalidated += Items_Invalidated;
     ViewCube.Attach(host.EffectsManager);
     ViewCube.Invalidated += Items_Invalidated;
     CoordinateSystem.Attach(host.EffectsManager);
     CoordinateSystem.Invalidated += Items_Invalidated;
     Items2D.Attach(host);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Detaches this instance.
 /// </summary>
 public void Detach()
 {
     Items.Invalidated -= Items_Invalidated;
     Items.Detach();
     ViewCube.Invalidated -= Items_Invalidated;
     ViewCube.Detach();
     CoordinateSystem.Invalidated -= Items_Invalidated;
     CoordinateSystem.Detach();
     Items2D.Detach();
 }
Ejemplo n.º 8
0
 private bool ViewCubeHitTest(ref Ray ray, ref Vector2 position)
 {
     if (ViewCube.HitTest(RenderContext, ray, ref hits))
     {
         ViewCube.RaiseMouseDownEvent(this, position, hits[0]);
         var normal = hits[0].NormalAtHit;
         if (Vector3.Cross(normal, ModelUpDirection).LengthSquared() < 1e-5)
         {
             var vecLeft = new Vector3(-normal.Y, -normal.Z, -normal.X);
             ViewCubeClicked(hits[0].NormalAtHit, vecLeft);
         }
         else
         {
             ViewCubeClicked(hits[0].NormalAtHit, ModelUpDirection);
         }
         return(true);
     }
     return(false);
 }
Ejemplo n.º 9
0
    private void FixedUpdate()
    {
        if (isActive)
        {
            cameraObject = CM.cameraObject;
            if (isControllable)
            {
                //isExtraZoom = IC.inputMouseKey1;
                setFOV    = isExtraZoom ? 0.5f : 1;
                orbitView = IC.inputMouseKey0 || IC.inputMouseKey1;
            }
            targetPosition   = cameraTarget.position;
            oldMouseRotation = MouseRotationDistance;

            MouseRotationDistance = IC.inputMouseX;
            MouseVerticalDistance = IC.inputMouseY;
            MouseScrollDistance   = IC.inputMouseWheel * 2;
            if (reverseXAxis)
            {
                MouseRotationDistance = -IC.inputMouseX;
            }
            if (reverseYAxis)
            {
                MouseVerticalDistance = -IC.inputMouseY;
            }
            camFOV = Mathf.Lerp(camFOV, cameraFOV * setFOV, Time.deltaTime * 4.0f);

            axisSensitivity = new Vector2(
                Mathf.Lerp(axisSensitivity.x, mouseSensitivity.x, Time.deltaTime * 4.0f),
                Mathf.Lerp(axisSensitivity.y, mouseSensitivity.y, Time.deltaTime * 4.0f)
                );
            if (isControllable)
            {
                float followLerpSpeed = 2.0f;
                followDistance   -= MouseScrollDistance * 20.0f;
                followDistance    = Mathf.Clamp(followDistance, minZoomAmount, maxZoomAmount);
                followTgtDistance = Mathf.Lerp(followTgtDistance, followDistance, Time.deltaTime * followLerpSpeed);

                if (orbitView)
                {
                    camRotation = Mathf.Lerp(oldMouseRotation, MouseRotationDistance * axisSensitivity.x, Time.deltaTime);
                }

                if (FixedHandover)                   //固定切换
                {
                    if (FixedHandoverVertor3.x == 0) //前后左右
                    {
                        targetRotation.eulerAngles = new Vector3(
                            targetRotation.eulerAngles.x,
                            Mathf.Lerp(targetRotation.eulerAngles.y, FixedHandoverVertor3.y, Time.deltaTime * FixedHandoverSpeed),
                            targetRotation.eulerAngles.z
                            );
                        camHeight = Mathf.Lerp(camHeight, cameraTarget.transform.position.y, Time.deltaTime * FixedHandoverSpeed);
                    }
                    else//上下
                    {
                        if (followDistance > 0f)
                        {
                            followDistance -= 16f;
                        }
                    }
                }
                else
                {
                    targetRotation.eulerAngles = new Vector3(
                        targetRotation.eulerAngles.x,
                        targetRotation.eulerAngles.y + camRotation,
                        targetRotation.eulerAngles.z
                        );
                }
                cameraObject.transform.eulerAngles = new Vector3(
                    targetRotation.eulerAngles.x,
                    targetRotation.eulerAngles.y,
                    cameraObject.transform.eulerAngles.z
                    );
                if (orbitView)
                {
                    camHeight = Mathf.Lerp(camHeight, camHeight + MouseVerticalDistance * axisSensitivity.y, Time.deltaTime);
                }

                camHeight = Mathf.Clamp(camHeight, -90.0f, 90);
                if (isFoucs)
                {
                    followDistance = 10;
                    camHeight      = cameraTarget.transform.position.y;
                    isFoucs        = false;
                }
                cameraObject.transform.position = new Vector3(
                    cameraTarget.transform.position.x + cameraOffset.x + (-cameraObject.transform.up.x * followTgtDistance),
                    Mathf.Lerp(camHeight, cameraTarget.transform.position.y + cameraOffset.y + (-cameraObject.transform.up.y * followTgtDistance), Time.deltaTime * 0.5f),
                    cameraTarget.transform.position.z + cameraOffset.z + (-cameraObject.transform.up.z * followTgtDistance)
                    );
                cameraObject.transform.LookAt(new Vector3(targetPosition.x, targetPosition.y, targetPosition.z));
                cameraObject.GetComponent <Camera>().fieldOfView = camFOV;

                if (GameManager.instance.ViewCubeCamera.activeSelf)
                {
                    ViewCube.SetAngleY(cameraObject.localEulerAngles.y);
                    ViewCube.SetAngleX(cameraObject.localEulerAngles.x);
                }
            }
        }
    }