// 27 Slicer
// Copyright 2021 Deftly Games
// https://slicer.deftly.games/
using Slicer.Core;
using System;
using UnityEngine;
namespace Slicer
{
///
/// The base class of details about an item that is being sliced.
///
[Serializable]
public abstract class Details
{
///
/// The Id of the item being tracked.
///
///
/// This ID is normally obtained using the MonoBehaviour.GetInstanceID() of the primary component used during slicing.
///
///
/// For example the following Slicer Components use these IDs.
/// - : MeshFilter.GetInstanceID()
/// - : Collider.GetInstanceID()
///
public int Id;
///
/// The Transform on the GameObject being tracked by this details object.
///
public Transform Transform;
///
/// During this bool will be set to true.
/// If it is used during is will be set to false.
/// Any Details that remain false during will be removed from the list.
///
[NonSerialized]
public bool Remove;
///
/// Used to destroy any components that is being managing.
///
public abstract void Destroy();
///
/// Resets any component to its original state.
///
public abstract void DisableSlicing();
///
/// Sets any component to its sliced state.
///
public abstract void EnableSlicing();
///
/// Readies this component up to finalize slicing
///
public abstract void FinalizeSlicing();
///
/// Calculates the hash of this details object using important properties.
///
/// The calculated hash.
public virtual Hash128 CalculateHash()
{
var hash = HashUtility.CalculateHash(Id);
var posHash = HashUtility.CalculateHash(Transform.position);
var rotHash = HashUtility.CalculateHash(Transform.rotation);
var scaleHash = HashUtility.CalculateHash(Transform.lossyScale);
HashUtility.AppendHash(posHash, rotHash, scaleHash, ref hash);
return hash;
}
}
}