コード例 #1
0
    private void UpdateFocusedObject()
    {
        GameObject prevFocusedObject = focusedObject;

        focusedObject = null;

        // Compare distances and focus on the closest interactable
        float minDistance = float.MaxValue;

        foreach (GameObject go in objectsInRange)
        {
            float dist = Vector3.Distance(go.transform.position, transform.position);
            if (dist < minDistance && go.GetComponent <InteractionObject>().GetInteractable())
            {
                minDistance   = dist;
                focusedObject = go;
            }
        }

        if (focusedObject != prevFocusedObject)
        {
            if (focusedObject != null)
            {
                SpriteGlow.SpriteGlow sGlow = focusedObject.AddComponent <SpriteGlow.SpriteGlow>();
                sGlow.GlowColor    = itemHighlightColor;
                sGlow.OutlineWidth = 8;
            }
            if (prevFocusedObject != null)
            {
                prevFocusedObject.GetComponent <SpriteRenderer>().material = defaultSpriteMaterial;
                Destroy(prevFocusedObject.GetComponent <SpriteGlow.SpriteGlow>());
            }
        }
    }
コード例 #2
0
        public static Material GetSharedFor(SpriteGlow spriteGlow)
        {
            var material = sharedMaterials.Find(m =>
                                                m.SpriteTexture == spriteGlow.Renderer.sprite.texture &&
                                                m.DrawOutside == spriteGlow.DrawOutside &&
                                                m.InstancingEnabled == spriteGlow.EnableInstancing);

            if (!material)
            {
                material           = new SpriteGlowMaterial(spriteGlow.Renderer.sprite.texture, spriteGlow.DrawOutside, spriteGlow.EnableInstancing);
                material.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor | HideFlags.NotEditable;
                sharedMaterials.Add(material);
            }

            return(material);
        }