void Start() { //start with light off lightScript = gameObject.GetComponent <CastLight>(); castLight.SetActive(false); lightScript.enabled = false; }
void Start() { lightScript = gameObject.GetComponent <CastLight>(); animator = gameObject.GetComponent <Animator>(); if (!isLit) { lightScript.enabled = false; //turns off light if candle starts unlit } }
/** * Turns off this mirror's light scripting. * Called internally when mirror leaves the light. */ public void Deactivate(CastLight source) { sources.Remove(source); //remove light source from list if (sources.Count <= 0) { castLight.SetActive(false); //turn off light lightScript.enabled = false; //stop calculating mesh shape (for efficiency) } }
void OnSceneGUI() { CastLight fow = (CastLight)target; Handles.color = Color.white; Handles.DrawWireArc(fow.transform.position, Vector3.forward, Vector3.up, 360, fow.viewRadius); Vector3 viewAngleA = fow.DirFromAngle(-fow.viewAngle / 2, false); Vector3 viewAngleB = fow.DirFromAngle(fow.viewAngle / 2, false); Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleA * fow.viewRadius); Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleB * fow.viewRadius); }
void Update() { //check light sources to see if mirror should be Deactivated for (int i = 0; i < sources.Count; i++) { CastLight source = sources[i]; if (!source.visibleTargets.Contains(this.transform)) { Deactivate(source); i = -1; //restart loop (necessary when List is changed) } } }
/// <summary> /// Registers a light shape handler. /// </summary> /// <param name="identifier">A unique identifier for this shape. If another mod has /// already registered that identifier, the previous mod will take precedence.</param> /// <param name="handler">The handler for that shape.</param> /// <returns>The light shape which can be used.</returns> public static PLightShape Register(string identifier, CastLight handler) { PLightShape lightShape; // In case this call is used before the library was initialized if (!PUtil.PLibInit) { PUtil.InitLibrary(false); PUtil.LogWarning("PUtil.InitLibrary was not called before using " + "PLightShape.Register!"); } lock (PSharedData.GetLock(PRegistry.KEY_LIGHTING_LOCK)) { // Get list holding lighting information var list = PSharedData.GetData <IList <object> >(PRegistry.KEY_LIGHTING_TABLE); if (list == null) { PSharedData.PutData(PRegistry.KEY_LIGHTING_TABLE, list = new List <object>(8)); } // Try to find a match for this identifier object ls = null; int n = list.Count, index = 0; for (int i = 0; i < n; i++) { var light = list[i]; // Might be from another assembly so the types may or may not be compatible if (light != null && light.ToString() == identifier && light.GetType(). Name == typeof(PLightShape).Name) { index = i; break; } } if (ls == null) { // Not currently existing lightShape = new PLightShape(n + 1, identifier, handler); PUtil.LogDebug("Registered new light shape: " + identifier); list.Add(lightShape); } else { // Exists already PUtil.LogDebug("Found existing light shape: " + identifier); lightShape = new PLightShape(n + 1, identifier, null); } } return(lightShape); }
internal PLightShape(int id, string identifier, CastLight handler) { Handler = handler; Identifier = identifier ?? throw new ArgumentNullException("identifier"); ShapeID = id; }
/** * Turns on this mirror's light scripting. * Called by CastLight.cs when mirror enters the light. */ public void Activate(CastLight source) { sources.Add(source); //keep track of what's lighting up this mirror castLight.SetActive(true); //turn on mirror's light lightScript.enabled = true; //start calculating mesh shape }