add
This commit is contained in:
283
Assets/CoolapeFrame/Scripts/role/CLRoleAction.cs
Normal file
283
Assets/CoolapeFrame/Scripts/role/CLRoleAction.cs
Normal file
@@ -0,0 +1,283 @@
|
||||
/*
|
||||
********************************************************************************
|
||||
*Copyright(C),coolae.net
|
||||
*Author: chenbin
|
||||
*Version: 2.0
|
||||
*Date: 2017-01-09
|
||||
*Description: 角色动作
|
||||
/// 注意: 通过tag来判断当前正在执行状态是否为设置的状态,
|
||||
/// 因此在创建控制器中要把状态的tag的值与该文件中的ActionValue保持一至
|
||||
*Others:
|
||||
*History:
|
||||
*********************************************************************************
|
||||
*/
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace Coolape
|
||||
{
|
||||
public class CLRoleAction : MonoBehaviour
|
||||
{
|
||||
Animator _animator = null;
|
||||
|
||||
public Animator animator {
|
||||
get {
|
||||
if (_animator == null) {
|
||||
_animator = GetComponent<Animator>();
|
||||
}
|
||||
return _animator;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Action
|
||||
{
|
||||
idel,
|
||||
//0 空闲
|
||||
idel2,
|
||||
//1 空闲
|
||||
walk,
|
||||
//2 走
|
||||
run,
|
||||
//3 跑
|
||||
jump,
|
||||
//4 跳
|
||||
slide,
|
||||
//5 滑行,滚动,
|
||||
drop,
|
||||
//6 下落,击飞
|
||||
attack,
|
||||
//7 攻击
|
||||
attack2,
|
||||
//8 攻击2
|
||||
skill,
|
||||
//9 技能
|
||||
skill2,
|
||||
//10 技能2
|
||||
skill3,
|
||||
//11 技能3
|
||||
skill4,
|
||||
//12 技能4
|
||||
hit,
|
||||
//13 受击
|
||||
dead,
|
||||
//14 死亡
|
||||
happy,
|
||||
//15 高兴
|
||||
sad,
|
||||
//16 悲伤
|
||||
up,
|
||||
//17 起立
|
||||
down,
|
||||
//18 倒下
|
||||
biggestAK,
|
||||
//19 最大的大招
|
||||
dizzy,
|
||||
//20 晕
|
||||
stiff,
|
||||
//21 僵硬
|
||||
idel3,
|
||||
//22 空闲
|
||||
}
|
||||
|
||||
public static Action getActByName(string name)
|
||||
{
|
||||
try {
|
||||
return (Action)(Enum.Parse(typeof(Action), name));
|
||||
} catch (Exception e) {
|
||||
return Action.idel;
|
||||
}
|
||||
}
|
||||
|
||||
// public void Start()
|
||||
// {
|
||||
// setAction (Action.walk, null);
|
||||
// }
|
||||
|
||||
public void pause()
|
||||
{
|
||||
animator.enabled = false;
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
public void regain()
|
||||
{
|
||||
animator.enabled = true;
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
public Action currAction = Action.idel;
|
||||
public int currActionValue = -1;
|
||||
int cbCount = 1;
|
||||
|
||||
public void setSpeedAdd(float addSpeed)
|
||||
{
|
||||
animator.speed = 1 + addSpeed * 0.5f;
|
||||
}
|
||||
|
||||
public void setAction(Action action, object onCompleteMotion)
|
||||
{
|
||||
setAction((int)action, onCompleteMotion);
|
||||
}
|
||||
|
||||
Coroutine coroutineAction;
|
||||
|
||||
public void setAction(int actionValue, object onCompleteMotion)
|
||||
{
|
||||
__setAction(actionValue, onCompleteMotion); //为了做回放,不能用StartCoroutine
|
||||
|
||||
/*
|
||||
#if UNITY_4_6 || UNITY_5 || UNITY_5_6_OR_NEWER
|
||||
if(coroutineAction != null) {
|
||||
StopCoroutine(coroutineAction);
|
||||
coroutineAction = null;
|
||||
}
|
||||
coroutineAction = StartCoroutine(_setAction(actionValue, onCompleteMotion, 0.01f));
|
||||
#else
|
||||
Debug.LogError ("This function cannot surport current version unity!!!");
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
||||
IEnumerator _setAction(int actionValue, object onCompleteMotion, float sec)
|
||||
{
|
||||
yield return new WaitForSeconds(sec);
|
||||
__setAction(actionValue, onCompleteMotion);
|
||||
}
|
||||
|
||||
void __setAction(int actionValue, object onCompleteMotion)
|
||||
{
|
||||
if (onCompleteMotion != null && onCompleteMotion.GetType() == typeof(ArrayList)) {
|
||||
doSetActionWithCallback(actionValue, (ArrayList)onCompleteMotion);
|
||||
} else {
|
||||
ArrayList list = null;
|
||||
if (onCompleteMotion != null) {
|
||||
list = new ArrayList();
|
||||
list.Add(100);
|
||||
list.Add(onCompleteMotion);
|
||||
}
|
||||
doSetActionWithCallback(actionValue, list);
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList progressPoints = new ArrayList();
|
||||
//检测动作过程的点(百分比)
|
||||
ArrayList progressCallback = new ArrayList();
|
||||
//动作过程的回调
|
||||
Hashtable callbackMap = new Hashtable();
|
||||
int progressIndex = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the action.
|
||||
/// </summary>
|
||||
/// <param name="actionValue">Action value.动作对应的value</param>
|
||||
/// <param name="callbackInfor">Callback infor. 是一个key:value的键值对
|
||||
/// key:是0~100的整数,表示动作播放到百分之多少时执行回调,
|
||||
/// 而回调方法就是该key所对应的value
|
||||
/// </param>
|
||||
|
||||
public void doSetActionWithCallback(int actionValue, ArrayList progressCallbackInfor)
|
||||
{
|
||||
// if (currActionValue == actionValue) {
|
||||
// return;
|
||||
// }
|
||||
//////////////////////////////////////////////////////////////////
|
||||
progressPoints.Clear();
|
||||
progressCallback.Clear();
|
||||
callbackMap.Clear();
|
||||
if (progressCallbackInfor != null) {
|
||||
int count = progressCallbackInfor.Count;
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (i % 2 == 0) {
|
||||
progressPoints.Add(NumEx.stringToInt(progressCallbackInfor [i].ToString()) / 100.0f);
|
||||
} else {
|
||||
progressCallback.Add(progressCallbackInfor [i]);
|
||||
}
|
||||
}
|
||||
|
||||
progressCallbackInfor.Clear();
|
||||
progressCallbackInfor = null;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////
|
||||
currActionValue = actionValue;
|
||||
currAction = (Action)(Enum.ToObject(typeof(Action), actionValue));
|
||||
if (!animator.isInitialized) {
|
||||
return;
|
||||
}
|
||||
animator.SetInteger("Action", actionValue);
|
||||
if (progressPoints.Count > 0) {
|
||||
progressIndex = 0;
|
||||
isCheckProgress = true; // place the code after setAction, beacuse in setAction function ,set isCheckProgress = false;
|
||||
} else {
|
||||
isCheckProgress = false;
|
||||
}
|
||||
}
|
||||
|
||||
AnimatorStateInfo currentState;
|
||||
int oldMotionTime = 0;
|
||||
//old动作播放次数
|
||||
int MotionTime = 0;
|
||||
//动作播放次数
|
||||
bool isCheckProgress = false;
|
||||
// object callback = null;
|
||||
|
||||
void FixedUpdate() //用FixedUpdate是为可以回放
|
||||
{
|
||||
if (!isCheckProgress)
|
||||
return;
|
||||
if (animator.layerCount <= 0) {
|
||||
return;
|
||||
}
|
||||
currentState = animator.GetCurrentAnimatorStateInfo(0);
|
||||
/*
|
||||
* 通过tag来判断当前正在执行状态是否为设置的状态,
|
||||
* 因此在创建控制器中要把状态的tag的值与该文件中的ActionValue保持一至
|
||||
*/
|
||||
if (!currentState.IsTag(currActionValue.ToString())) {
|
||||
return;
|
||||
}
|
||||
if (currentState.loop) {
|
||||
isCheckProgress = false;
|
||||
// //normalizedTime的整数部分为:该动作循环了几次,小数部分为:该动作的进程
|
||||
// MotionTime = (int)(currentState.normalizedTime);
|
||||
// if (MotionTime > oldMotionTime) {
|
||||
// oldMotionTime = MotionTime;
|
||||
// //完成一次动作
|
||||
// if (onCompleteMotion != null) {
|
||||
// if (typeof(LuaFunction) == onCompleteMotion.GetType()) {
|
||||
// ((LuaFunction)onCompleteMotion).Call(this);
|
||||
// } else if (typeof(Callback) == onCompleteMotion.GetType()) {
|
||||
// ((Callback)onCompleteMotion)(this);
|
||||
// }
|
||||
// }
|
||||
// if (onWillCompleteMotion != null) {
|
||||
// isCheckWillFinish = true;
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
while (true) {
|
||||
if (progressIndex < progressPoints.Count) {
|
||||
if (currentState.normalizedTime + 0.009f > (float)(progressPoints [progressIndex])) {
|
||||
StartCoroutine(exeCallback(progressCallback [progressIndex]));
|
||||
progressIndex++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
isCheckProgress = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator exeCallback(object cbFunc)
|
||||
{
|
||||
yield return null;
|
||||
if (cbFunc != null) {
|
||||
Utl.doCallback(cbFunc, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/CoolapeFrame/Scripts/role/CLRoleAction.cs.meta
Normal file
12
Assets/CoolapeFrame/Scripts/role/CLRoleAction.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0bd81622f0744a1abdbc25b10016eff
|
||||
timeCreated: 1484055600
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
256
Assets/CoolapeFrame/Scripts/role/CLRoleAvata.cs
Normal file
256
Assets/CoolapeFrame/Scripts/role/CLRoleAvata.cs
Normal file
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
********************************************************************************
|
||||
*Copyright(C),coolae.net
|
||||
*Author: chenbin
|
||||
*Version: 2.0
|
||||
*Date: 2017-01-09
|
||||
*Description: 纸娃娃
|
||||
*Others:
|
||||
*History:
|
||||
*********************************************************************************
|
||||
*/
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace Coolape
|
||||
{
|
||||
// [RequireComponent(typeof(Animator))]
|
||||
public class CLRoleAvata : MonoBehaviour
|
||||
{
|
||||
// 需要用到的骨骼关节点
|
||||
[SerializeField]
|
||||
public List<string> bonesNames = new List<string> ();
|
||||
[SerializeField]
|
||||
public List<Transform> bonesList = new List<Transform> ();
|
||||
Hashtable _bonesMap;
|
||||
|
||||
public Hashtable bonesMap {
|
||||
get {
|
||||
if (_bonesMap == null) {
|
||||
_bonesMap = new Hashtable ();
|
||||
for (int i = 0; i < bonesNames.Count; i++) {
|
||||
_bonesMap [bonesNames [i]] = bonesList [i];
|
||||
}
|
||||
}
|
||||
return _bonesMap;
|
||||
}
|
||||
}
|
||||
|
||||
public Transform getBoneByName (string bname)
|
||||
{
|
||||
return (Transform)(bonesMap [bname]);
|
||||
}
|
||||
|
||||
public Animator animator;
|
||||
|
||||
[SerializeField]
|
||||
public List<string> bodyPartNames = new List<string> ();
|
||||
[SerializeField]
|
||||
public List<CLBodyPart> bodyParts = new List<CLBodyPart> ();
|
||||
Hashtable mapIndex = new Hashtable ();
|
||||
bool isInited = false;
|
||||
|
||||
public void setMapindex ()
|
||||
{
|
||||
for (int i = 0; i < bodyPartNames.Count; i++) {
|
||||
mapIndex [bodyPartNames [i]] = i;
|
||||
}
|
||||
}
|
||||
bool isQuit = false;
|
||||
public void OnApplicationQuit (){
|
||||
isQuit = true;
|
||||
}
|
||||
|
||||
public void OnDestroy ()
|
||||
{
|
||||
if(!isQuit)
|
||||
cleanMaterial ();
|
||||
}
|
||||
public void cleanMaterial ()
|
||||
{
|
||||
if (!isInited) {
|
||||
isInited = true;
|
||||
setMapindex ();
|
||||
}
|
||||
for (int i = 0; i < bodyParts.Count; i++) {
|
||||
bodyParts [i].cleanMaterial ();
|
||||
}
|
||||
}
|
||||
|
||||
public void setDefaultMaterial ()
|
||||
{
|
||||
if (!isInited) {
|
||||
isInited = true;
|
||||
setMapindex ();
|
||||
}
|
||||
for (int i = 0; i < bodyParts.Count; i++) {
|
||||
bodyParts [i].setDefaultMaterial ();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Switch2xx the specified partName and cellName.变装
|
||||
/// </summary>
|
||||
/// <param name="partName">Part name.</param>身体部位
|
||||
/// <param name="cellName">Cell name.</param>服装、表情、装备等的名称
|
||||
public void switch2xx (string partName, string cellName)
|
||||
{
|
||||
switch2xx (partName, cellName, null);
|
||||
}
|
||||
public void switch2xx (string partName, string cellName, object callback)
|
||||
{
|
||||
if (!isInited) {
|
||||
isInited = true;
|
||||
setMapindex ();
|
||||
}
|
||||
try {
|
||||
int index = MapEx.getInt (mapIndex, partName);
|
||||
CLBodyPart part = bodyParts [index];
|
||||
if (part == null)
|
||||
return;
|
||||
part.switchByName (cellName, animator, callback);
|
||||
} catch (System.Exception e) {
|
||||
Debug.LogError (e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class CLBodyPart
|
||||
{
|
||||
public string partName = "";
|
||||
//身体部位
|
||||
public CLSwitchType switchType = CLSwitchType.showOrHide;
|
||||
public List<string> cellNames = new List<string> ();
|
||||
//身体部位中各个部件的名字
|
||||
public Renderer render;
|
||||
// [System.NonSerialized]
|
||||
// public List<Material> materials = null;
|
||||
public List<string> materialNames = new List<string> ();
|
||||
public List<GameObject> partObjs = new List<GameObject> ();
|
||||
public bool needSwitchController = false;
|
||||
public List<RuntimeAnimatorController> animatorControllers = new List<RuntimeAnimatorController> ();
|
||||
public Hashtable mapIndex = new Hashtable ();
|
||||
[System.NonSerialized]
|
||||
bool isInited = false;
|
||||
|
||||
public void init ()
|
||||
{
|
||||
if (!isInited) {
|
||||
isInited = true;
|
||||
for (int i = 0; i < cellNames.Count; i++) {
|
||||
mapIndex [cellNames [i]] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void cleanMaterial ()
|
||||
{
|
||||
if (switchType == CLSwitchType.switchShader) {
|
||||
if (render.sharedMaterial != null) {
|
||||
#if UNITY_EDITOR
|
||||
if (Application.isPlaying) {
|
||||
CLMaterialPool.returnObj (render.sharedMaterial.name);
|
||||
}
|
||||
#else
|
||||
CLMaterialPool.returnObj (render.sharedMaterial.name);
|
||||
#endif
|
||||
render.sharedMaterial = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setDefaultMaterial ()
|
||||
{
|
||||
if (switchType == CLSwitchType.switchShader) {
|
||||
if (materialNames.Count > 0) {
|
||||
setMat (render, materialNames [0], null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void switchByName (string cellName, Animator animator, object callback)
|
||||
{
|
||||
if (!isInited) {
|
||||
init ();
|
||||
}
|
||||
int index = MapEx.getInt (mapIndex, cellName);
|
||||
|
||||
if (needSwitchController) {
|
||||
if (animator != null) {
|
||||
animator.runtimeAnimatorController = animatorControllers [index];
|
||||
} else {
|
||||
Debug.LogError ("animator is null");
|
||||
}
|
||||
}
|
||||
|
||||
if (switchType == CLSwitchType.showOrHide) {
|
||||
for (int i = 0; i < partObjs.Count; i++) {
|
||||
if (i == index) {
|
||||
NGUITools.SetActive (partObjs [i], true);
|
||||
} else {
|
||||
NGUITools.SetActive (partObjs [i], false);
|
||||
}
|
||||
}
|
||||
Utl.doCallback (callback);
|
||||
} else if (switchType == CLSwitchType.switchShader) {
|
||||
if (render.sharedMaterial != null) {
|
||||
string mName = render.sharedMaterial.name;
|
||||
// mName = mName.Replace(" (Instance)", "");
|
||||
CLMaterialPool.returnObj (mName);
|
||||
render.sharedMaterial = null;
|
||||
}
|
||||
setMat (render, materialNames [index], callback);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setMat (Renderer render, string materialName, object callback)
|
||||
{
|
||||
ArrayList list = new ArrayList ();
|
||||
list.Add (render);
|
||||
list.Add (materialName);
|
||||
list.Add (callback);
|
||||
#if UNITY_EDITOR
|
||||
if (Application.isPlaying) {
|
||||
CLMaterialPool.borrowObjAsyn (materialName, (Callback)onSetPrefab, list);
|
||||
} else {
|
||||
string path = "Assets/" + CLPathCfg.self.basePath + "/upgradeRes4Dev/other/Materials/" + materialName.Replace (".", "/") + ".mat";
|
||||
Material mat = AssetDatabase.LoadAssetAtPath (path, typeof(Material)) as Material;
|
||||
render.sharedMaterial = mat;
|
||||
}
|
||||
#else
|
||||
CLMaterialPool.borrowObjAsyn (materialName, (Callback)onSetPrefab, list);
|
||||
#endif
|
||||
}
|
||||
|
||||
void onSetPrefab (params object[] args)
|
||||
{
|
||||
Material mat = (Material)(args [1]);
|
||||
if (mat != null) {
|
||||
ArrayList list = (ArrayList)(args [2]);
|
||||
Renderer render = (Renderer)(list [0]);
|
||||
string name = list [1].ToString ();
|
||||
object callback = list [2];
|
||||
// setMat(render, name);
|
||||
if (render != null) {
|
||||
render.sharedMaterial = mat;
|
||||
}
|
||||
Utl.doCallback (callback);
|
||||
} else {
|
||||
Debug.LogWarning ("Get material is null: " + args [0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum CLSwitchType
|
||||
{
|
||||
showOrHide,
|
||||
switchShader,
|
||||
}
|
||||
}
|
||||
12
Assets/CoolapeFrame/Scripts/role/CLRoleAvata.cs.meta
Normal file
12
Assets/CoolapeFrame/Scripts/role/CLRoleAvata.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f487deb1e0ae4215b97a58363a7bb19
|
||||
timeCreated: 1484055746
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
417
Assets/CoolapeFrame/Scripts/role/CLUnit.cs
Normal file
417
Assets/CoolapeFrame/Scripts/role/CLUnit.cs
Normal file
@@ -0,0 +1,417 @@
|
||||
/*
|
||||
********************************************************************************
|
||||
*Copyright(C),coolae.net
|
||||
*Author: chenbin
|
||||
*Version: 2.0
|
||||
*Date: 2017-01-09
|
||||
*Description: 角色、怪物、战斗单元的基类
|
||||
*Others:
|
||||
*History:
|
||||
*********************************************************************************
|
||||
*/
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System;
|
||||
|
||||
namespace Coolape
|
||||
{
|
||||
public abstract class CLUnit : CLBehaviour4Lua
|
||||
{
|
||||
public static float SCANRange = 30;
|
||||
//视野
|
||||
public int instanceID = 0;
|
||||
//id
|
||||
[HideInInspector]
|
||||
public int type;
|
||||
//类型
|
||||
// [HideInInspector]
|
||||
public int id;
|
||||
//id
|
||||
[HideInInspector]
|
||||
byte[] _lev;
|
||||
//等级
|
||||
public int lev {
|
||||
get {
|
||||
return NumEx.bio2Int(_lev);
|
||||
}
|
||||
set {
|
||||
_lev = NumEx.int2Bio(value);
|
||||
}
|
||||
}
|
||||
|
||||
public CLUnit mTarget;
|
||||
//目标
|
||||
public CLUnit mAttacker;
|
||||
//攻击我的对象
|
||||
// [HideInInspector]
|
||||
// public SBSliderBar _sliderLifeBar;
|
||||
//血条
|
||||
|
||||
// public SBSliderBar lifeBar {
|
||||
// get {
|
||||
// if (_sliderLifeBar == null) {
|
||||
// createLifeBar();
|
||||
// }
|
||||
// return _sliderLifeBar;
|
||||
// }
|
||||
// set {
|
||||
// _sliderLifeBar = value;
|
||||
// }
|
||||
// }
|
||||
|
||||
// public void createLifeBar()
|
||||
// {
|
||||
// try {
|
||||
// _sliderLifeBar = SBSliderBar.instance(hudAnchor, Vector3.zero);
|
||||
// } catch (Exception e) {
|
||||
// Debug.LogError(name + ":" + e.ToString());
|
||||
// }
|
||||
// }
|
||||
|
||||
// public void hiddenLifeBar()
|
||||
// {
|
||||
// if (_sliderLifeBar != null) {
|
||||
// lifeBar.hide();
|
||||
// }
|
||||
// _sliderLifeBar = null;
|
||||
// }
|
||||
|
||||
public bool isDead = false;
|
||||
//是否死亡
|
||||
|
||||
public Transform hudAnchor;
|
||||
//HUD的锚点
|
||||
public CLRoleState state = CLRoleState.idel;
|
||||
//状态
|
||||
[HideInInspector]
|
||||
public bool isOffense;
|
||||
//是否进攻方
|
||||
public bool isDefense {
|
||||
get {
|
||||
return !isOffense;
|
||||
}
|
||||
}
|
||||
|
||||
public bool isCopyBody = false;
|
||||
//是否分身
|
||||
|
||||
public override void clean()
|
||||
{
|
||||
mAttacker = null;
|
||||
// hiddenLifeBar();
|
||||
isDead = true;
|
||||
isCopyBody = false;
|
||||
CancelInvoke();
|
||||
StopAllCoroutines();
|
||||
state = CLRoleState.idel;
|
||||
base.clean();
|
||||
}
|
||||
|
||||
Collider bc;
|
||||
|
||||
public Collider collider { //取得boxcollider
|
||||
get {
|
||||
if (bc == null) {
|
||||
bc = GetComponent<Collider>();
|
||||
}
|
||||
return bc;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 size = Vector3.one;
|
||||
|
||||
public float minSize {
|
||||
get {
|
||||
if (collider == null)
|
||||
return 0;
|
||||
Vector3 v3 = size;
|
||||
// float ret = v3.x < v3.y ? v3.x : (v3.y < v3.z ? v3.y : v3.z);
|
||||
float ret = v3.x < v3.z ? v3.x : v3.z;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
Matrix4x4 boundsMatrix;
|
||||
|
||||
public virtual void OnDrawGizmos()
|
||||
{
|
||||
Gizmos.color = Color.blue;
|
||||
Gizmos.DrawWireCube(transform.position, size);
|
||||
Gizmos.color = Color.white;
|
||||
}
|
||||
#endif
|
||||
|
||||
Material _materials;
|
||||
|
||||
public Material materials { //Old materials
|
||||
get {
|
||||
if (_materials == null) {
|
||||
_materials = getBodyMat(mbody);
|
||||
}
|
||||
return _materials;
|
||||
}
|
||||
}
|
||||
|
||||
public Transform mbody;
|
||||
//主体
|
||||
bool isOutLineMode = false;
|
||||
public static Hashtable matMap = new Hashtable();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the mat out line.
|
||||
/// </summary>
|
||||
public void setMatOutLine()
|
||||
{
|
||||
setMatOutLineWithColor(Color.white, ColorEx.getColor(255, 0, 0, 150));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the mat ice effect.冰冻效果
|
||||
/// </summary>
|
||||
public void setMatIceEffect()
|
||||
{
|
||||
// setMatOutLineWithColor (Utl.newColor (0, 255, 255), Utl.newColor (0, 255, 255));
|
||||
setMatToonWithColor(ColorEx.getColor(0, 255, 255));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the mat violent.狂暴效果
|
||||
/// </summary>
|
||||
public void setMatViolent()
|
||||
{
|
||||
// setMatOutLineWithColor (Color.red, Color.red);
|
||||
setMatToonWithColor(Color.red);
|
||||
}
|
||||
|
||||
public void setMatOutLineWithColor(Color mainColor, Color outLineColor)
|
||||
{
|
||||
if (isOutLineMode)
|
||||
return;
|
||||
isOutLineMode = true;
|
||||
if (materials == null)
|
||||
return;
|
||||
Material mat = null;
|
||||
object obj = matMap [materials.mainTexture.name];
|
||||
if (obj == null) {
|
||||
mat = new Material(Shader.Find("Outlined/Silhouetted Diffuse"));
|
||||
mat.mainTexture = materials.mainTexture;
|
||||
matMap [materials.mainTexture.name] = mat;
|
||||
} else {
|
||||
mat = obj as Material;
|
||||
}
|
||||
mat.SetColor("_Color", mainColor);
|
||||
mat.SetColor("_OutlineColor", outLineColor);
|
||||
setBodyMat(mbody, mat);
|
||||
}
|
||||
|
||||
public void setMatToonWithColor(Color mainColor)
|
||||
{
|
||||
// if (isOutLineMode)
|
||||
// return;
|
||||
isOutLineMode = true;
|
||||
if (materials == null)
|
||||
return;
|
||||
Material mat = null;
|
||||
object obj = matMap [materials.mainTexture.name];
|
||||
if (obj == null) {
|
||||
mat = new Material(Shader.Find("Toon/Basic"));
|
||||
mat.mainTexture = materials.mainTexture;
|
||||
matMap [materials.mainTexture.name] = mat;
|
||||
} else {
|
||||
mat = obj as Material;
|
||||
}
|
||||
mat.SetColor("_Color", mainColor);
|
||||
setBodyMat(mbody, mat);
|
||||
}
|
||||
|
||||
public Material getBodyMat(Transform tr)
|
||||
{
|
||||
if (tr == null)
|
||||
return null;
|
||||
|
||||
Renderer rd = tr.GetComponent<Renderer>();
|
||||
if (rd != null && rd.sharedMaterial != null) {
|
||||
return rd.sharedMaterial;
|
||||
} else {
|
||||
SkinnedMeshRenderer smr = tr.GetComponent<SkinnedMeshRenderer>();
|
||||
if (smr != null) {
|
||||
return smr.sharedMaterial;
|
||||
}
|
||||
}
|
||||
Transform trch = null;
|
||||
for (int i = 0; i < tr.childCount; i++) {
|
||||
trch = tr.GetChild(i);
|
||||
rd = trch.GetComponent<Renderer>();
|
||||
if (rd != null && rd.sharedMaterial != null) {
|
||||
return rd.sharedMaterial;
|
||||
} else {
|
||||
SkinnedMeshRenderer smr = trch.GetComponent<SkinnedMeshRenderer>();
|
||||
if (smr != null) {
|
||||
return smr.sharedMaterial;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < tr.childCount; i++) {
|
||||
Material m = getBodyMat(tr.GetChild(i));
|
||||
if (m != null)
|
||||
return m;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setBodyMat(Transform tr, Material mat)
|
||||
{
|
||||
if (tr == null)
|
||||
return;
|
||||
Renderer rd = tr.GetComponent<Renderer>();
|
||||
if (rd != null && rd.sharedMaterial != null &&
|
||||
rd.sharedMaterial.mainTexture == mat.mainTexture) {
|
||||
rd.sharedMaterial = mat;
|
||||
} else {
|
||||
SkinnedMeshRenderer smr = tr.GetComponent<SkinnedMeshRenderer>();
|
||||
if (smr != null && smr.sharedMaterial != null && smr.sharedMaterial.mainTexture == mat.mainTexture) {
|
||||
smr.sharedMaterial = mat;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < tr.childCount; i++) {
|
||||
setBodyMat(tr.GetChild(i), mat);
|
||||
}
|
||||
}
|
||||
|
||||
public void setMatToon()
|
||||
{
|
||||
// if (!isOutLineMode)
|
||||
// return;
|
||||
isOutLineMode = false;
|
||||
if (materials != null) {
|
||||
setBodyMat(mbody, materials);
|
||||
}
|
||||
}
|
||||
|
||||
public override void pause()
|
||||
{
|
||||
isPause = true;
|
||||
enabled = false;
|
||||
StopAllCoroutines();
|
||||
CancelInvoke();
|
||||
base.pause();
|
||||
}
|
||||
|
||||
public override void regain()
|
||||
{
|
||||
isPause = false;
|
||||
enabled = true;
|
||||
base.regain();
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
|
||||
#if UNITY_EDITOR
|
||||
//因为是通过assetebundle加载的,在真机上不需要处理,只有在pc上需要重设置shader
|
||||
// Utl.setBodyMatEdit(mbody);
|
||||
#endif
|
||||
base.Start();
|
||||
}
|
||||
|
||||
//==========================================
|
||||
//=== 伪随机
|
||||
//==========================================
|
||||
public float RandomFactor = 0;
|
||||
|
||||
public float initRandomFactor()
|
||||
{
|
||||
RandomFactor = NumEx.NextInt(0, 1001) / 1000.0f;
|
||||
return RandomFactor;
|
||||
}
|
||||
|
||||
public int fakeRandom(int min, int max)
|
||||
{
|
||||
int diff = (max - min);
|
||||
int point = Mathf.FloorToInt(diff * RandomFactor);
|
||||
return min + point;
|
||||
}
|
||||
|
||||
public float RandomFactor2 = 0;
|
||||
|
||||
public float initRandomFactor2()
|
||||
{
|
||||
RandomFactor2 = NumEx.NextInt(0, 1001) / 1000.0f;
|
||||
return RandomFactor2;
|
||||
}
|
||||
|
||||
public int fakeRandom2(int min, int max)
|
||||
{
|
||||
int diff = (max - min);
|
||||
int point = Mathf.FloorToInt(diff * RandomFactor2);
|
||||
return min + point;
|
||||
}
|
||||
public float RandomFactor3 = 0;
|
||||
|
||||
public float initRandomFactor3()
|
||||
{
|
||||
RandomFactor3 = NumEx.NextInt(0, 1001) / 1000.0f;
|
||||
return RandomFactor3;
|
||||
}
|
||||
|
||||
public int fakeRandom3(int min, int max)
|
||||
{
|
||||
int diff = (max - min);
|
||||
int point = Mathf.FloorToInt(diff * RandomFactor3);
|
||||
return min + point;
|
||||
}
|
||||
//====================================================
|
||||
//====================================================
|
||||
public virtual void init(int id, int star, int lev, bool isOffense, object other)
|
||||
{
|
||||
this.id = id;
|
||||
this.lev = lev;
|
||||
this.isOffense = isOffense;
|
||||
isDead = false;
|
||||
// setMatToon ();
|
||||
instanceID = gameObject.GetInstanceID();
|
||||
}
|
||||
|
||||
public abstract CLUnit doSearchTarget();
|
||||
|
||||
public abstract void onBeTarget(CLUnit attacker);
|
||||
|
||||
public abstract void onRelaseTarget(CLUnit attacker);
|
||||
|
||||
public abstract void doAttack();
|
||||
|
||||
public abstract void onHurtHP(int hurt, object skillAttr);
|
||||
|
||||
public abstract bool onHurt(int hurt, object skillAttr, CLUnit attacker);
|
||||
|
||||
public abstract void onHurtFinish(object skillAttr, CLUnit attacker);
|
||||
|
||||
public abstract void onDead();
|
||||
|
||||
public abstract void moveTo(Vector3 toPos);
|
||||
|
||||
public abstract void moveToTarget(Transform target);
|
||||
|
||||
}
|
||||
|
||||
public enum CLRoleState
|
||||
{
|
||||
// -- 空闲
|
||||
idel,
|
||||
// -- 到处走动
|
||||
walkAround,
|
||||
// -- 归到队伍位置中
|
||||
formation,
|
||||
//等待攻击
|
||||
waitAttack,
|
||||
// -- 攻击
|
||||
attack,
|
||||
// -- 寻敌
|
||||
searchTarget,
|
||||
// --击退
|
||||
beakBack,
|
||||
}
|
||||
}
|
||||
12
Assets/CoolapeFrame/Scripts/role/CLUnit.cs.meta
Normal file
12
Assets/CoolapeFrame/Scripts/role/CLUnit.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4df94e0387c0d474ab7e057199b5d331
|
||||
timeCreated: 1484055404
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user