private IEnumerator FadeRoutine(ProjectionRenderer Projection, float UpdateRate) { //Execution check if (executing || fade == null) { yield break; } else { executing = true; } //Cache alpha & scale float originalAlpha = GetAlpha(Projection); Vector3 originalScale = Projection.transform.localScale; //Setup wrap mode switch (wrapMode) { case FadeWrapMode.Loop: fade.postWrapMode = WrapMode.Loop; break; case FadeWrapMode.PingPong: fade.postWrapMode = WrapMode.PingPong; break; case FadeWrapMode.Once: case FadeWrapMode.Clamp: fade.postWrapMode = WrapMode.ClampForever; break; } //Perform fade float timeElapsed = 0; while ((wrapMode != FadeWrapMode.Clamp && wrapMode != FadeWrapMode.Once) || timeElapsed <= fadeLength) { ApplyFade(Projection, originalAlpha, originalScale, timeElapsed / fadeLength); //Update time elapsed timeElapsed += UpdateRate; yield return(new WaitForSeconds(UpdateRate)); } //Apply final value if (wrapMode == FadeWrapMode.Clamp) { ApplyFade(Projection, originalAlpha, originalScale, 1); } //Destroy if (wrapMode == FadeWrapMode.Once) { Projection.Destroy(); } //No longer executing executing = false; }
private void PrintProjection(ProjectionRenderer Projection, Vector3 Position, Quaternion Rotation, Transform Surface) { if (Projection != null) { ProjectionRenderer proj = Pool.Request(Projection, printBehaviours); //Set Transform Data proj.transform.position = Position; proj.transform.rotation = Rotation; //Set Parent if (parent == PrintParent.Surface) { //Create a sub parent //Fixes Non-Uniform scaling and is generally cleaner Transform subParent = null; foreach (Transform child in Surface) { if (child.name == "Projections") { subParent = child; } } if (subParent == null) { subParent = new GameObject("Projections").transform; subParent.SetParent(Surface); } proj.transform.SetParent(subParent); } } }
public IEnumerator CullRoutine(ProjectionRenderer Projection, float UpdateRate) { //Execution check if (executing) { yield break; } else { executing = true; } //Perform fade float timeElapsed = 0; while (timeElapsed < cullTime) { //Update time elapsed timeElapsed += UpdateRate; //Reset time elapsed if visible if (Projection.Renderer.isVisible) { timeElapsed = 0; } yield return(new WaitForSeconds(UpdateRate)); } //Destroy projection Projection.Destroy(); //No longer executing executing = false; }
public void Deregister(ProjectionRenderer Instance) { if (Instance != null) { //Determine our projection Projection projection = Instance.Projection; //Check if our projection has been registered for (int i = 0; i < Projections.Count; i++) { if (Projections[i].projection == projection) { //Remove instance from projection Projections[i].Remove(Instance); //Remove empty projections if (Projections[i].instances.Count == 0) { Projections.RemoveAt(i); } return; } } } }
//Intialize / Terminate internal void Initialize(ProjectionRenderer Renderer = null, bool IncludeBehaviours = false) { if (Valid) { //Set parent renderer.transform.SetParent(pool.Parent); //Copy Renderer Properties if (Renderer != null) { //Copy projection renderer.Projection = Renderer.Projection; //Copy properties renderer.Tiling = Renderer.Tiling; renderer.Offset = Renderer.Offset; renderer.MaskMethod = Renderer.MaskMethod; renderer.MaskLayer1 = Renderer.MaskLayer1; renderer.MaskLayer2 = Renderer.MaskLayer2; renderer.MaskLayer3 = Renderer.MaskLayer3; renderer.MaskLayer4 = Renderer.MaskLayer4; renderer.Properties = Renderer.Properties; if (IncludeBehaviours) { foreach (MonoBehaviour component in Renderer.GetComponents <MonoBehaviour>()) { //Don't copy transform and projection renderer components if (component.GetType() == typeof(Transform)) { continue; } if (component.GetType() == typeof(ProjectionRenderer)) { continue; } renderer.gameObject.AddComponent(component); } } //Copy scale renderer.transform.localScale = Renderer.transform.localScale; //Copy layer & tag renderer.gameObject.layer = Renderer.gameObject.layer; renderer.gameObject.tag = Renderer.gameObject.tag; } else { //Reset scale renderer.transform.localScale = Vector3.one; } //Enable renderer.gameObject.SetActive(true); } }
private ProjectionRenderer RequestRenderer(ProjectionRenderer Renderer = null, bool IncludeBehaviours = false) { //Initialize active pool if required if (activePool == null) { activePool = new List <PoolItem>(); } if (inactivePool != null && inactivePool.Count > 0) { //Grab first item in inactive pool PoolItem item = inactivePool[0]; //Remove from inactive pool inactivePool.RemoveAt(0); //Add to active pool activePool.Add(item); //Initialize item item.Initialize(Renderer, IncludeBehaviours); return(item.Renderer); } else if (activePool.Count < Limit) { //Create item PoolItem item = new PoolItem(this); //Initialize item item.Initialize(Renderer, IncludeBehaviours); //Add to active pool activePool.Add(item); return(item.Renderer); } else { //Grab oldest item in active pool PoolItem item = activePool[0]; //Terminate item item.Terminate(); //Move to end of pool activePool.RemoveAt(0); activePool.Add(item); //Initialize item item.Initialize(Renderer, IncludeBehaviours); return(item.Renderer); } }
//Request /** * Returns a projection of the specified type from the pool. * Projection will be enabled and ready to use. Use the return method once your done with it, do not delete it. * @param Renderer Optional - The renderer to copy from. In 90% of use cases this should be a prefab. * @param IncludeScripts Optional - Should the renderer being copied have it's scripts copied as well? */ public ProjectionRenderer Request(ProjectionRenderer Renderer = null, bool IncludeBehaviours = false) { //Request Renderers until we get a valid ProjectionRenderer pr = null; while (pr == null) { pr = RequestRenderer(Renderer, IncludeBehaviours); } return(pr); }
public void MoveToBottom(ProjectionRenderer Instance) { //Remove the instance from the list instances.Remove(Instance); //Add instance to top of list instances.Insert(0, Instance); //Mark renderers to change DynamicDecals.System.MarkRenderers(); }
public void Remove(ProjectionRenderer Instance) { //Attempt to remove the instance from the list instances.Remove(Instance); //Notify instance of data change if (Instance.Data == this) { Instance.Data = null; } }
protected virtual void Start() { if (projection != null) { //Generate our Projection proj = ((GameObject)Instantiate(projection.gameObject, DynamicDecals.System.DefaultPool.Parent)).GetComponent <ProjectionRenderer>(); proj.name = "Positioned Projection"; } else { Debug.LogWarning("Positioner has no projection to position."); } }
public void Add(ProjectionRenderer Instance) { //If the instance isn't already in the list, add it if (!instances.Contains(Instance)) { //Add our instance instances.Add(Instance); //Notify instance of data change Instance.Data = this; //Mark renderers to change DynamicDecals.System.MarkRenderers(); } }
private float GetAlpha(ProjectionRenderer Projection) { switch (Projection.Properties[0].type) { case PropertyType.Float: return(Projection.Properties[0].value); case PropertyType.Color: return(Projection.Properties[0].color.a); case PropertyType.Combo: return(Projection.Properties[0].value); } return(1); }
private ProjectionRenderer GenerateRenderer(string Name) { //Generate new gameObject GameObject gameObject = new GameObject(Name); gameObject.transform.parent = transform; gameObject.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector; //Generate projection renderer ProjectionRenderer renderer = gameObject.AddComponent <ProjectionRenderer>(); //Add ninesprite piece so we know to delete gameObject.AddComponent <NineSpritePiece>(); return(renderer); }
//Constructor public PoolItem(ProjectionPool Pool) { //Set Pool pool = Pool; //Generate GameObject GameObject go = new GameObject("Projection"); go.transform.SetParent(pool.Parent); //Disable go.SetActive(false); //Attach Renderer renderer = go.AddComponent <ProjectionRenderer>(); renderer.PoolItem = this; }
private void SetAlpha(ProjectionRenderer Projection, float Alpha) { switch (Projection.Properties[0].type) { case PropertyType.Float: case PropertyType.Combo: Projection.SetFloat(0, Alpha); break; case PropertyType.Color: Color color = Projection.Properties[0].color; color.a = Alpha; Projection.SetColor(0, color); break; } Projection.UpdateProperties(); }
private void DrawProjection(ProjectionRenderer Projection, Vector3 Position, Quaternion Rotation, Transform Surface) { if (Projection != null) { //Instantiate projection ProjectionRenderer proj = Instantiate(Projection); proj.name = Projection.name; Undo.RegisterCreatedObjectUndo(proj.gameObject, "Place Projection"); //Get randomized scale float scaleMod = Random.Range(min, max); //Set Transform Data proj.transform.position = Position; proj.transform.rotation = Rotation; proj.transform.localScale *= scaleMod; //Set Parent if (parent == PrintParent.Surface) { //Create a sub parent //Fixes Non-Uniform scaling and is generally cleaner Transform subParent = null; foreach (Transform child in Surface) { if (child.name == "Projections") { subParent = child; } } if (subParent == null) { subParent = new GameObject("Projections").transform; subParent.SetParent(Surface); } proj.transform.SetParent(subParent); } else if (defaultParent != null) { proj.transform.SetParent(defaultParent); } } }
private void ApplyFade(ProjectionRenderer Projection, float Time) { //Calculate fade value float fadeValue = fade.Evaluate(Time); //Update projection switch (type) { case FadeType.Alpha: SetAlpha(Projection, originalAlpha * fadeValue); break; case FadeType.Scale: SetScale(Projection, originalScale * fadeValue); break; case FadeType.Both: SetAlpha(Projection, originalAlpha * fadeValue); SetScale(Projection, originalScale * fadeValue); break; } }
//Registration public bool Register(ProjectionRenderer Instance) { if (Instance != null) { //Determine our projection Projection projection = Instance.Projection; //Check if our projection has been registered ProjectionData data = GetProjectionData(projection); if (data != null) { data.Add(Instance); return(true); } else { //Create and register our projection data data = new ProjectionData(projection); data.Add(Instance); //If we are lower priority than a projection in the list, insert ourself before them for (int i = 0; i < Projections.Count; i++) { if (projection.Priority < Projections[i].projection.Priority) { Projections.Insert(i, data); return(true); } } //If we are higher priority than everything in the list, just add ourself Projections.Add(data); return(true); } } return(false); }
private void Awake() { //Grab our projection projection = GetComponent <ProjectionRenderer>(); }
private void SetScale(ProjectionRenderer Projection, Vector3 Scale) { Projection.transform.localScale = Scale; }