확장
부분 구현
partial class
구현을 통해 KCC 애드온을 확장하는 것은 원래 소스 코드를 수정하지 않고도 기존 클래스의 기능을 강화할 수 있는 강력한 기술입니다.
Class.Feature.cs
또는 Class.Game.cs
파일을 새로 만들고 로직을 작성하기만 하면 애드온 업데이트 프로세스가 훨씬 쉬워지고 프로젝트가 체계적으로 유지됩니다.
다음 섹션에서는 기존 클래스를 확장하는 방법을 보여줍니다.
KCC 확장
다음 구현을 갖고 있는 KCC.Sprint.cs
파일을 생성합니다:
C#
namespace Fusion.KCC
{
public partial class KCC
{
public void SetSprint(bool sprint)
{
Data.Sprint = sprint;
}
}
}
EKCCData 확장
다음 구현을 갖고 있는 KCCData.Sprint.cs
파일을 생성합니다:
C#
namespace Fusion.KCC
{
public partial class KCCData
{
public bool Sprint;
partial void CopyUserDataFromOther(KCCData other)
{
// Making a deep copy for correct rollback from local history.
// This method is executed when you get a new state from server.
// It is also executed after fixed updates to copy fixed data to render data.
Sprint = other.Sprint;
// Because this method is partial and cannot be implemented for each property separately, you have to copy all properties here.
// Or use this method as a wrapper and split execution into multiple calls.
}
}
}
⚠️ KCCData
에 추가된 모든 속성은 partial void CopyUserDataFromOther(KCCData other)
에 추가해야 합니다. 그렇지 않으면 올바르게 작동하지 않습니다.
KCCSettings 확장하기
다음 구현을 갖고 있는 KCCSettings.CustomProperty.cs
파일을 생성합니다:
C#
namespace Fusion.KCC
{
public partial class KCCSettings
{
public bool CustomProperty;
partial void CopyUserSettingsFromOther(KCCSettings other)
{
// Make a deep copy of your properties.
// This method is also executed on spawn/despawn to store/restore backup.
CustomProperty = other.CustomProperty;
// Because this method is partial and cannot be implemented for each property separately, you have to copy all properties here.
// Or use this method as a wrapper and split execution into multiple calls.
}
}
}
⚠️ KCCSettings
에 추가된 모든 속성은 partial void CopyUserDataFromOther(KCCSettings other)
에 추가해야 합니다. 그렇지 않으면 올바르게 작동하지 않습니다.
Extending KCCInteraction 및 KCCInteractions 확장하기
다음 구현을 갖고 있는 KCCInteractions.Game.cs
파일을 생성합니다:
C#
namespace Fusion.KCC
{
// Returns HUD information from interactions for displaying on screen.
public interface IHUDProvider
{
string Description { get; }
}
// KCCInteraction is a container which contains information related to single interaction.
// KCCInteraction is abstract class, extending it also affects derived classes (all other interaction container types).
public abstract partial class KCCInteraction<TInteraction>
{
// This instance is pooled, only stateless getters!
public IHUDProvider HUDProvider => Provider as IHUDProvider;
}
// KCCInteractions is a collection which maintains all interactions.
// KCCInteractions is abstract class, extending it also extends derived classes (all other interaction collection types).
public abstract partial class KCCInteractions<TInteraction>
{
// You can iterate over All property and apply custom filtering.
public T GetHUDProvider<T>() where T : IHUDProvider
{
for (int i = 0, count = All.Count; i < count; ++i)
{
if (All[i].HUDProvider is T hudProvider)
return hudProvider;
}
return default;
}
}
}
Extending KCCCollision 및 KCCCollisions 확장하기
다음 구현을 갖고 있는 KCCCollisions.Game.cs
파일을 생성합니다:
C#
namespace Fusion.KCC
{
using UnityEngine;
// Returns climb information from networked collisions.
public interface IClimbProvider
{
Transform Target { get; }
}
// KCCCollision is a container which contains information related to a single networked collision.
public partial class KCCCollision
{
// This instance is pooled, only stateless getters!
public IClimbProvider ClimbProvider => Processor as IClimbProvider;
}
// KCCCollisions is a collection which maintains all networked collisions.
public partial class KCCCollisions
{
// You can iterate over All property and apply custom filtering.
// Example: returns first climb provider of a specific type.
public T GetClimbProvider<T>() where T : IClimbProvider
{
for (int i = 0, count = All.Count; i < count; ++i)
{
if (All[i].ClimbProvider is T climbProvider)
return climbProvider;
}
return default;
}
}
}
KCCModifier 및 KCCModifiers 확장하기
외부에 정의된 기존 유형 사용 예제:
C#
namespace Game
{
// Base interface for all abilities.
public interface IAbility
{
// ...
}
}
다음 구현을 갖고 있는 KCCModifiers.Game.cs
파일을 생성합니다:
C#
namespace Fusion.KCC
{
using System.Collections.Generic;
using Game;
// KCCModifier is a container which contains information related to single modifier.
public partial class KCCModifier
{
// This instance is pooled, only stateless getters!
public IAbility Ability => Processor as IAbility;
}
// KCCModifiers is a collection which maintains all modifiers.
public partial class KCCModifiers
{
// You can iterate over All property and apply custom filter.
// Example: returns list of abilities of a specific type.
public bool GetAbilities<T>(List<T> abilities) where T : IAbility
{
abilities.Clear();
for (int i = 0, count = All.Count; i < count; ++i)
{
if (All[i].Ability is T ability)
{
abilities.Add(ability);
}
}
return abilities.Count > 0;
}
}
}
Back to top