Menu

Supply的技能框架

2018年7月6日 - 游戏开发

首先Supply的技能框架是先有

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

定义了IElementEffect的接口

public interface IElementEffect
{
void Effect(GameObject player);
bool EffectComplete();//效果是否完成
}

定义了效果类

public abstract class Element : MonoBehaviour
{
public virtual bool CanAttachEffect(GameObject player) { return true; }
public abstract void AttachEffect(GameObject player);
public abstract Color GetElementColor();

public static void ElementGenerator(System.Type type, Transform p)
{
GameObject prefab = Resources.Load<GameObject>(“perfab/” + type.ToString().Replace(“_”, “-“));
GameObject obj = GameObject.Instantiate(prefab);
var dir = p.forward;
dir.y = 0.0f;
obj.transform.localPosition = p.position + dir * 1.8f;
}
}

分别是C,H,O,N对应的不同技能

public class ElementEffect_H : IElementEffect
{

private bool m_complete=false;
private Vector3 moveDirection;
private float m_time = 0.0f;
public void Effect(GameObject player)
{
PlayerMove player_mov = player.GetComponent<PlayerMove>();
player_mov.LongJump();
m_complete = true;
}

public bool EffectComplete()
{
return m_complete;
}
}

public class Element_H : Element {

public override void AttachEffect(GameObject player)
{
player.GetComponent<Player>().AddEffect(new ElementEffect_H());
}

public override bool CanAttachEffect(GameObject player)
{
return !player.GetComponent<PlayerMove>().IsJump();
}
public override Color GetElementColor()
{
return new Color(0.909803921f, 0.95686274509803f, 0.1529411f);
}
}

 

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ElementEffect_N : IElementEffect
{

bool m_complete = false;
bool m_first = true;
float m_time = 0.0f;
float player_speed;
public void Effect(GameObject player)
{

Vector3 dir = player.transform.forward.normalized;
RaycastHit hit = new RaycastHit();
dir.y = 0.0f;
if (!Physics.Raycast(player.transform.position, dir, out hit, 3.0f))
player.transform.Translate(dir * 3.0f,Space.World);
else
player.transform.Translate(dir * hit.distance – dir * 0.8f,Space.World);
m_complete = true;
}

public bool EffectComplete()
{
return m_complete;
}
}

public class Element_N : Element
{
public override void AttachEffect(GameObject player)
{
player.GetComponent<Player>().AddEffect(new ElementEffect_N());
}

public override Color GetElementColor()
{
return new Color(0.788235f, 0.0f, 0.0f);
}
}

 

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ElementEffect_O : IElementEffect
{
bool m_complete = false;
public void Effect(GameObject player)
{
ui_time.ui_t.open_time += 5;
m_complete = true;
}

 

public bool EffectComplete()
{
return m_complete;
}
}

public class Element_O : Element {
public override void AttachEffect(GameObject player)
{
player.GetComponent<Player>().AddEffect(new ElementEffect_O());
}

public override Color GetElementColor()
{
return new Color(0.192156f,0.745098f, 0.755098f);
}
}

 

 

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ElementSpawn : MonoBehaviour {
public static ElementSpawn Instance;
public GameObject[] ElementSpawnPoints;
public Element[] Elements;

private void Awake()
{
if (Instance == null)
Instance = this;
else
throw new UnityException(“ElementSpawn.Instance!=null”);
}

public void SpawnElement(GameObject element_prefab)
{
GameObject spawn_point= ElementSpawnPoints[UnityEngine.Random.Range(0, ElementSpawnPoints.Length)];
var obj_transform=Instantiate(element_prefab, spawn_point.transform).transform;
obj_transform.localPosition = Vector3.zero;
obj_transform.localRotation = Quaternion.identity;
}

public void SpawnElementFromType(Type element_type)
{
foreach(var ele in Elements)
if(ele.GetComponent<Element>().GetType()==element_type)
SpawnElement(ele.gameObject);
}

float time = 0.0f;
private void FixedUpdate()
{
if (time > 1.0f)
{
time = 0.0f;
SpawnElement(Elements[UnityEngine.Random.Range(0, Elements.Length)].gameObject);
}
time += Time.deltaTime;
}
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注

%d 博主赞过: