/// <summary>
        /// Updates the tooltip position, called every frame from <see cref="Tooltip.Update"/>.
        /// </summary>
        /// <param name="tooltip">The tooltip transform.</param>
        /// <param name="tooltipCanvas">The parent canvas.</param>
        /// <returns>Whether or not the tooltip could be positioned, this is false if the anchors have been destroyed.</returns>
        public bool UpdateTooltipPosition(RectTransform tooltip, Canvas tooltipCanvas)
        {
            if (!ReferenceEquals(this.worldAnchor, null))
            {
                if (Essentials.UnityIsNull(this.worldAnchor))
                {
                    return(false);
                }

                tooltip.position = Camera.main.WorldToScreenPoint(this.worldAnchor.position);
            }
            else if (!ReferenceEquals(this.uiAnchor, null))
            {
                if (Essentials.UnityIsNull(this.uiAnchor))
                {
                    return(false);
                }

                float x = this.uiAnchor.position.x + Mathf.Lerp(this.uiAnchor.rect.xMin, this.uiAnchor.rect.xMax, this.uiAnchorPivot.x);
                float y = this.uiAnchor.position.y + Mathf.Lerp(this.uiAnchor.rect.yMin, this.uiAnchor.rect.yMax, this.uiAnchorPivot.y);
                tooltip.position = new Vector2(x, y);
            }
            else
            {
                Vector2 pos;
                RectTransformUtility.ScreenPointToLocalPointInRectangle(tooltipCanvas.transform as RectTransform, this.fixedMousePos.HasValue ? this.fixedMousePos.Value : Input.mousePosition, tooltipCanvas.worldCamera, out pos);
                tooltip.position = tooltipCanvas.transform.TransformPoint(pos);
            }

            return(true);
        }
Example #2
0
        public static void Register(T obj)
        {
            if (!Essentials.UnityIsNull(instance))
            {
                throw new InvalidOperationException("Tried registering a singleton that already has an instance set!");
            }

            instance = obj;
        }
        public void OnDestroy()
        {
            StaticBatching batching = StaticBatching.GetInstanceOnDestroy();

            if (!Essentials.UnityIsNull(batching))
            {
                batching.DestroyVisualRepresentations(this);
            }
        }
        private void OnValidate()
        {
            if (Essentials.UnityIsNull(this.visualRepresentation))
            {
                return;
            }

            if (this.renderNodes.Count != this.visualRepresentation.GetComponentsInChildren <MeshRenderer>().Length)
            {
                this.UpdateRenderCache();
            }
        }
 /// <summary>
 /// Enforces the singleton pattern.
 /// </summary>
 private void Awake()
 {
     if (Essentials.UnityIsNull(_instance))
     {
         _instance = this;
     }
     else
     {
         Debug.LogError("Singleton pattern violated! Destroying StaticBatching!", this.gameObject);
         Destroy(this);
     }
 }
Example #6
0
        /// <summary>
        /// Opens the tooltip with the specified view model and anchor.
        /// If there is no tooltip instance it will output a warning, unless unity is running in headless mode.
        /// </summary>
        public static void Open <T>(T model, TooltipAnchorTarget anchor = default(TooltipAnchorTarget)) where T : TooltipViewModel
        {
            if (ReferenceEquals(instance, null))
            {
                if (!Essentials.IsRunningHeadless())                 // Servers and other headless apps dont care about tooltips
                {
                    Debug.LogWarning("Tried opening tooltip with no tooltip in the scene!");
                }
                return;
            }

            instance._Open(model, anchor);
        }
Example #7
0
        /// <summary>
        /// Immediately closes the tooltip.
        /// If there is no tooltip instance it will output a warning, unless unity is running in headless mode.
        /// </summary>
        public static void Close()
        {
            if (ReferenceEquals(instance, null))
            {
                if (!Essentials.IsRunningHeadless())                 // Servers and other headless apps dont care about tooltips
                {
                    Debug.LogWarning("Tried closing tooltip with no tooltip in the scene!");
                }
                return;
            }

            instance._Close();
        }
Example #8
0
        /// <summary>
        /// Returns all the <see cref="handlers"/> order queus in ascendingly sorted order.
        /// </summary>
        /// <param name="preAlloc">Pre-allocated list for storing the result.</param>
        /// <returns>A sorted list with all distinct order in this event.</returns>
        protected virtual List <int> GetSortedOrders(List <int> preAlloc = null)
        {
            ListPool <int> .GetIfNull(ref preAlloc);

            // Accumulate
            foreach (var order in handlers.Keys)
            {
                preAlloc.Add(order);
            }

            // Sort
            Essentials.InsertionSort(preAlloc);
            return(preAlloc);
        }
        /// <summary>
        /// Creates a rendering cache for the specified visual representation.
        /// </summary>
        /// <param name="preAlloc">Pre-allocated list for the result.</param>
        /// <returns>preAlloc if set. If not a new list is created. The returned list contains the render cache info.</returns>
        public static List <RenderNode> CreateRenderCache(GameObject visualRepresentation, List <RenderNode> preAlloc = null)
        {
            ListPool <RenderNode> .GetIfNull(ref preAlloc);

            // Retrieve all mesh renderers
            List <MeshRenderer> renderers = ListPool <MeshRenderer> .Get();

            visualRepresentation.GetComponentsInChildren(renderers);
            var wtl = visualRepresentation.transform.worldToLocalMatrix;

            // Construct render nodes
            for (int i = 0; i < renderers.Count; i++)
            {
                // Grad renderer and filter
                var renderer = renderers[i];
                var filter   = renderer.GetComponent <MeshFilter>();

                if (Essentials.UnityIsNull(filter))
                {
                    continue;
                }

                // Calculate TRS matrix for rendering
                var trs = wtl * renderer.transform.localToWorldMatrix;
                trs = Matrix4x4.TRS(trs.MultiplyPoint3x4(Vector3.zero), trs.rotation, renderer.transform.lossyScale);

                // Write render node
                preAlloc.Add(new RenderNode()
                {
                    matrix          = trs,
                    materials       = renderer.sharedMaterials,
                    mesh            = filter.sharedMesh,
                    shadowMode      = renderer.shadowCastingMode,
                    probeAnchor     = renderer.probeAnchor,
                    recieveShadows  = renderer.receiveShadows,
                    lightProbeUsage = renderer.lightProbeUsage
                });
            }
            ListPool <MeshRenderer> .Return(renderers);

            return(preAlloc);
        }
        private void UpdateRenderCache()
        {
            if (this.renderNodes.Count > 0)
            {
                this.renderNodes.Clear();
            }

            // Retrieve all mesh renderers
            List <MeshRenderer> renderers = ListPool <MeshRenderer> .Get();

            this.visualRepresentation.GetComponentsInChildren(renderers);

            // Construct render nodes
            for (int i = 0; i < renderers.Count; i++)
            {
                // Grad renderer and filter
                var renderer = renderers[i];
                var filter   = renderer.GetComponent <MeshFilter>();

                if (Essentials.UnityIsNull(filter))
                {
                    continue;
                }

                // Write render node
                this.renderNodes.Add(new RenderNode()
                {
                    matrix          = this.visualRepresentation.transform.worldToLocalMatrix * renderer.transform.localToWorldMatrix,
                    materials       = renderer.sharedMaterials,
                    mesh            = filter.sharedMesh,
                    shadowMode      = renderer.shadowCastingMode,
                    probeAnchor     = renderer.probeAnchor,
                    recieveShadows  = renderer.receiveShadows,
                    lightProbeUsage = renderer.lightProbeUsage
                });
            }
            ListPool <MeshRenderer> .Return(renderers);

            this._visualRepresentation = this.visualRepresentation;
        }
        public void Update()
        {
            if (Essentials.UnityIsNull(this.visualRepresentation))
            {
                return;
            }

            var  renderCache                 = GetInternalRenderCache();
            bool hasMaterialReplacements     = !ReferenceEquals(this.materialOverrides, null);
            bool hasMeshMaterialReplacements = !ReferenceEquals(this.meshMaterialOverrides, null);

            // Render nodes
            for (int i = 0; i < renderCache.Count; i++)
            {
                var node = renderCache[i];

                // Execute all draw calls
                for (int j = 0; j < node.materials.Length; j++)
                {
                    // Material replacement
                    Material material = node.materials[j], replacementMat = null;
                    if (hasMaterialReplacements && this.materialOverrides.TryGetValue(material, out replacementMat))
                    {
                        material = replacementMat;
                    }

                    // Mesh material replacement
                    if (hasMeshMaterialReplacements && this.meshMaterialOverrides.TryGetValue(node.mesh, out replacementMat))
                    {
                        material = replacementMat;
                    }

                    Graphics.DrawMesh(node.mesh, this.transform.localToWorldMatrix * node.matrix, material, 8, null, j, null, node.shadowMode, node.recieveShadows, node.probeAnchor, node.lightProbeUsage != LightProbeUsage.Off);
                }
            }
        }
        public void Update()
        {
            if (Essentials.UnityIsNull(this.visualRepresentation))
            {
                return;
            }

            if (!object.ReferenceEquals(this.visualRepresentation, this._visualRepresentation))
            {
                this.UpdateRenderCache();
            }

            // Render nodes
            for (int i = 0; i < this.renderNodes.Count; i++)
            {
                var node = this.renderNodes[i];

                // Execute all draw calls
                for (int j = 0; j < node.materials.Length; j++)
                {
                    Graphics.DrawMesh(node.mesh, this.transform.localToWorldMatrix * node.matrix, node.materials[j], 8, null, j, null, node.shadowMode, node.recieveShadows, node.probeAnchor, node.lightProbeUsage != LightProbeUsage.Off);
                }
            }
        }
Example #13
0
 public override int GetHashCode()
 {
     return(Essentials.CombineHashCodes(this.action.GetHashCode(), this.state.GetHashCode()));
 }
Example #14
0
 public override int GetHashCode()
 {
     return(Essentials.CombineHashCodes(this.taskEvent.GetHashCode(), this.taskObj.GetHashCode()));
 }
 public override int GetHashCode()
 {
     return(Essentials.CombineHashCodes(this.chunk.GetHashCode(), Essentials.CombineHashCodes(this.material.GetHashCode(), this.layer.GetHashCode())));
 }