Ejemplo n.º 1
0
 void Start()
 {
     //start with light off
     lightScript = gameObject.GetComponent <CastLight>();
     castLight.SetActive(false);
     lightScript.enabled = false;
 }
Ejemplo n.º 2
0
 void Start()
 {
     lightScript = gameObject.GetComponent <CastLight>();
     animator    = gameObject.GetComponent <Animator>();
     if (!isLit)
     {
         lightScript.enabled = false;         //turns off light if candle starts unlit
     }
 }
Ejemplo n.º 3
0
 /**
  *  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)
     }
 }
Ejemplo n.º 4
0
    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);
    }
Ejemplo n.º 5
0
 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)
         }
     }
 }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
 internal PLightShape(int id, string identifier, CastLight handler)
 {
     Handler    = handler;
     Identifier = identifier ?? throw new ArgumentNullException("identifier");
     ShapeID    = id;
 }
Ejemplo n.º 8
0
 /**
  *  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
 }