Interfaces

Проверено с версией:: 4.1

-

Сложность: Средняя

How to create interfaces and implement them in classes.

Interfaces

Средняя Scripting

Interfaces

Code snippet

using UnityEngine;
using System.Collections;
//This is a basic interface with a single required
//method.
public interface IKillable
{
void Kill();
}
//This is a generic interface where T is a placeholder
//for a data type that will be provided by the
//implementing class.
public interface IDamageable<T>
{
void Damage(T damageTaken);
}

#pragma strict
//This is a basic interface with a single required
//method.
public interface IKillable
{
function Kill();
}
//Javascript does not allow generic types to
//be defined, so this version of IDamageable
//uses a float type
public interface IDamageable
{
function Damage(damageTaken : float);
}

import UnityEngine
import System.Collections
//This is a basic interface with a single required
//method.
public interface IKillable:
def Kill()
//This is a generic interface where T is a placeholder
//for a data type that will be provided by the
//implementing class.
public interface IDamageable[of T]:
def Damage(damageTaken as T)