Example #1
0
 void Start()
 {
     if (ev == null)
     {
         ev = new Unity_ObjBehaviour();
     }
     if (root == null)
     {
         root = GameObject.Find("Events").transform;
     }
     name               = $"{root.childCount} | {ev.ObjData.Name}";
     transform.parent   = root;
     transform.position = new Vector3(ev.ObjData.XPosition, ev.ObjData.YPosition) + Vector3.forward * 5;
 }
Example #2
0
        public void JumpTo(GameObject gao)
        {
            Vector3?           center = null, size = null;
            Unity_ObjBehaviour obj = gao.GetComponent <Unity_ObjBehaviour>();

            if (obj != null)
            {
                if (obj.ObjData is Unity_Object_3D && LevelEditorData.Level?.IsometricData != null)
                {
                    bool orthographic = !_freeCameraMode;
                    if (orthographic)
                    {
                        Vector3 target = camera3D.transform.InverseTransformPoint(obj.midpoint);
                        center = transform.TransformPoint(new Vector3(target.x, target.y, orthographicZPosition));

                        //center = obj.midpoint;
                        size = obj.boxCollider3D?.size ?? Vector3.one;
                    }
                    else
                    {
                        center = obj.midpoint;
                        size   = obj.boxCollider3D?.size ?? Vector3.one;
                    }
                }
                else
                {
                    center = obj.midpoint;
                    size   = obj.boxCollider?.size ?? Vector3.one;
                }
            }
            else
            {
                center = gao.transform.position;
                size   = gao.transform.lossyScale;
            }
            if (center.HasValue)
            {
                float objectSize   = Mathf.Min(5f, Mathf.Max(2.25f, size.Value.x, size.Value.y, size.Value.z));
                bool  orthographic = !_freeCameraMode;
                if (orthographic)
                {
                    var cam        = this;
                    var targetSize = objectSize * 2f * 1.5f;
                    if (Mathf.Abs(fov - targetSize) > 5f)
                    {
                        targetOrthoSize = Mathf.Lerp(fov, targetSize, 0.75f);
                        targetOrthoSize = Mathf.Clamp(targetOrthoSize.Value, 3.75f, 50f);
                    }
                    //targetOrthoSize = objectSize * 2f * 1.5f;
                    Vector3 target = cam.transform.InverseTransformPoint(center.Value);
                    targetPos = cam.transform.TransformPoint(new Vector3(target.x, target.y, orthographicZPosition));
                }
                else
                {
                    var   cam            = camera3D;
                    float cameraDistance = 4.0f;                                                     // Constant factor
                    float cameraView     = 2.0f * Mathf.Tan(0.5f * Mathf.Deg2Rad * cam.fieldOfView); // Visible height 1 meter in front
                    float distance       = cameraDistance * objectSize / cameraView;                 // Combined wanted distance from the object
                    distance += objectSize;                                                          // Estimated offset from the center to the outside of the object * 2
                    targetPos = center.Value + Vector3.Normalize(cam.transform.position - center.Value) * distance;
                    if (center.Value - transform.position != Vector3.zero)
                    {
                        targetRot = Quaternion.LookRotation(center.Value - cam.transform.position, Vector3.up);
                    }
                }
            }
        }