// 27 Slicer // Copyright 2021 Deftly Games // https://slicer.deftly.games/ using System; using UnityEngine; using Slicer.Core; namespace Slicer { /// /// The base class for all of the Slicers /// /// ///

[REFERENCE MANUAL](xref:manual\components\slicer_components) ///
[RequireComponent(typeof(SlicerController))] [DefaultExecutionOrder(650)] public abstract class SlicerComponent : MonoBehaviour { /// /// Is the slicing currently enabled. /// /// true by default. public bool SlicingEnabled { get; private set; } = true; /// /// When set to true it will not calculate the bounds for the items it is tracking. /// /// false by default. [Tooltip("When this property is checked it will not calculate the bounds for the items it is tracking.")] public bool SkipBoundsCalculation = false; /// /// It is called by the parent prior to calling . /// /// /// It is primarily used to set the field to false. /// The that are still false after is run will be removed by . /// public virtual void PreGatherDetails() { } /// /// Gathers details required for slicing. /// It is called by the parent and used to search for valid items to slice and gather details on those items. /// /// The transform of the GameObject that will be searched for suitable item/s to slice. /// The transform of the GameObject containing the . public abstract void GatherDetails(Transform childTransform, Transform rootTransform); /// /// It is called by the parent after calling . /// /// /// It is primarily used to remove that have field set to false after is run. /// /// It also calculated the hash of all the details that where gathered during the previous execution of . /// This hash is then used to determine if the details have changed enough to require re-slicing the items. /// /// The hash of the details gathered during the previous execution of . public virtual Hash128 PostGatherDetails() { var enabledHash = HashUtility.CalculateHash(SlicingEnabled, 1); var skipBoundsCalculationHash = HashUtility.CalculateHash(SkipBoundsCalculation, 2); HashUtility.AppendHash(skipBoundsCalculationHash, ref enabledHash); return enabledHash; } /// /// Calculates the bounds for all of the items being managed by this SlicerComponent. /// /// It is in Local Object Space the parent SlicerController. /// /// /// These bounds are calculated from details gathered while running . /// /// /// Returns the bounds in Local Object Space of the parent SlicerController. /// Returns null if there are no items that have valid bounds. /// public abstract Bounds? CalculateBounds(); /// /// Slices the tracked items, this is where the magic happens! /// /// The final size (as a scale) of all the items that are to be sliced. See for more information. /// The transform of the parent /// The complete bounding box of all sliced items after being sliced. See for more information. /// The bounding box of the slices that will be made in object space. See for more information. /// The slices that have been chosen, Ranging from 0 (the center of the object), to 1 being the furthest extents of the object. See for more information. public abstract void Slice(Vector3 size, Transform rootTransform, Bounds completeBounds, Bounds slicedBounds, Vector3 slices); /// /// Enables slicing for this SlicerComponent. /// public virtual void EnableSlicing() { SlicingEnabled = true; } /// /// Disables slicing for this SlicerComponent. /// public virtual void DisableSlicing() { SlicingEnabled = false; } /// /// Finalizes slicing for this Slicer Component. /// public abstract void FinalizeSlicing(); } }