Page 1 of 1

Highlighting usable objects

Posted: Sun May 22, 2016 5:38 am
by mandi
Hello Tony,
I want to highlight any usable object by default, so that my player knows which objects to interact with. I created a component which, depending on enum, can be set as OnEnable or according to distance. Now, how to automatically bind that highlighting component with each object that has Usable? I know I can iterate over each object, but that's ineffective. I can modify Usable component, but any changes would be lost in case of DS update. Is there a way to extend Usable? A partial class somewhere?
Best!

Re: Highlighting usable objects

Posted: Sun May 22, 2016 1:13 pm
by Tony Li
Hi Artur,

You can create a subclass of Usable and add this to your GameObjects instead of Usable. The only method that's not currently overridable is Start. I just made the Start method virtual. This will be in the next release. So if you need to override Start, please feel free to change Usable's Start method to virtual:

Code: Select all

public virtual void Start() {
and then call the base method in your subclass. For example:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class UsableExtended : Usable {

    public enum Mode { OnEnable, ByDistance}
    public Mode mode;
    
    public override void Start() {
        base.Start();
        // Your code here to do extra work in Start.
    }
    
    public void OnEnable() {
        if (mode == Mode.OnEnable) Highlight(1);
    }
    
    public void Update() {
        if (mode == Mode.ByDistance) Highlight(distanceFromPlayer);
    }
    
    public void Highlight(float intensity) {
        ...
    }
}

Re: Highlighting usable objects

Posted: Mon May 23, 2016 9:03 am
by mandi
Tony,
thank you very much!
Best!