Skip to content

Commit

Permalink
Merge branch 'LuaParamsPropertyDrawer'
Browse files Browse the repository at this point in the history
  • Loading branch information
yaukeywang committed Mar 28, 2016
2 parents cb181e2 + 24b8763 commit 8f83505
Show file tree
Hide file tree
Showing 30 changed files with 569 additions and 108 deletions.
Binary file modified Assets/Game/Prefabs/Characters/enemy1.prefab
Binary file not shown.
Binary file modified Assets/Game/Prefabs/Characters/enemy2.prefab
Binary file not shown.
Binary file modified Assets/Game/Prefabs/Characters/hero.prefab
Binary file not shown.
Binary file modified Assets/Game/Prefabs/Environment/backgroundAnimation.prefab
Binary file not shown.
Binary file modified Assets/Game/Prefabs/Environment/backgrounds.prefab
Binary file not shown.
Binary file modified Assets/Game/Prefabs/FX/part_splash.prefab
Binary file not shown.
Binary file modified Assets/Game/Prefabs/Props/bomb.prefab
Binary file not shown.
Binary file modified Assets/Game/Prefabs/Props/bombCrate.prefab
Binary file not shown.
Binary file modified Assets/Game/Prefabs/Props/explosionParticle.prefab
Binary file not shown.
Binary file modified Assets/Game/Prefabs/Props/healthCrate.prefab
Binary file not shown.
Binary file modified Assets/Game/Prefabs/Props/rocket.prefab
Binary file not shown.
Binary file modified Assets/Game/Prefabs/UI/ui_healthDisplay.prefab
Binary file not shown.
Binary file modified Assets/Game/Prefabs/killTrigger.prefab
Binary file not shown.
Binary file modified Assets/Game/Prefabs/mainCamera.prefab
Binary file not shown.
Binary file modified Assets/Game/Prefabs/pickupManager.prefab
Binary file not shown.
Binary file modified Assets/Game/Prefabs/spawner.prefab
Binary file not shown.
Binary file modified Assets/Game/Scenes/Level.unity
Binary file not shown.
Binary file modified Assets/Game/Scenes/LevelStart.unity
Binary file not shown.
82 changes: 49 additions & 33 deletions Assets/Game/Scripts/Base/YwLuaMonoBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
using System.Collections.Generic;
using SLua;

// The lua mono behaviour class.
public class YwLuaMonoBehaviour : YwLuaMonoBehaviourBase
{
// The params of class YwLuaMonoBehaviour.
[System.Serializable]
public class YwLuaMonoBehaviourParams
{
// The mono method types.
public enum EMonoMethod
{
Expand All @@ -36,19 +37,27 @@ public enum EMonoMethod
OnCollisionExit,
OnCollisionExit2D,
// Add more if your need.
}

}

// The lua class name.
public string m_className = string.Empty;
public string m_strLuaClassName = string.Empty;

// All mono method we have.
public List<EMonoMethod> m_monoMethods = new List<EMonoMethod>();
public List<EMonoMethod> m_cMonoMethods = new List<EMonoMethod>();

// The parameters used to pass to lua.
public GameObject[] m_parameters = null;
public GameObject[] m_aParameters = null;
}

// The lua mono behaviour class.
public class YwLuaMonoBehaviour : YwLuaMonoBehaviourBase
{
// The mono behaviour params to lua.
[DoNotToLua]
public YwLuaMonoBehaviourParams m_luaParameters = new YwLuaMonoBehaviourParams();

// The static method array.
private bool[] m_aMonoMethodFlags = new bool[System.Enum.GetValues(typeof(EMonoMethod)).Length];
private bool[] m_aMonoMethodFlags = new bool[System.Enum.GetValues(typeof(YwLuaMonoBehaviourParams.EMonoMethod)).Length];

// Name of enable base lua function.
private static readonly string LUA_FUNC_NAME_ON_ENABLE_BASE = "OnEnableBase";
Expand All @@ -71,32 +80,28 @@ void Awake()
}

// Directly create a lua class instance to associate with this monobehavior.
if (string.IsNullOrEmpty(m_className) || !CreateClassInstance(m_className))
if (string.IsNullOrEmpty(m_luaParameters.m_strLuaClassName) || !CreateClassInstance(m_luaParameters.m_strLuaClassName))
{
return;
}

// Initialize parameters need to be passed to lua.
if ((null != m_parameters) && (m_parameters.Length > 0))
if ((null != m_luaParameters.m_aParameters) && (m_luaParameters.m_aParameters.Length > 0))
{
m_cBehavior.SetData("m_aParameters", m_parameters);
m_cBehavior.SetData("m_aParameters", m_luaParameters.m_aParameters);
}

// Init all method flags.
for (int i = 0; i < m_aMonoMethodFlags.Length; i++)
{
m_aMonoMethodFlags[i] = m_monoMethods.Contains((EMonoMethod)i);
m_aMonoMethodFlags[i] = m_luaParameters.m_cMonoMethods.Contains((YwLuaMonoBehaviourParams.EMonoMethod)i);
}

// Clear method list.
m_monoMethods.Clear();
m_monoMethods = null;

// Init update flags.
m_cBehavior.SetData("m_bUpdate", m_aMonoMethodFlags[(int)EMonoMethod.Update]);
m_cBehavior.SetData("m_bLateUpdate", m_aMonoMethodFlags[(int)EMonoMethod.LateUpdate]);
m_cBehavior.SetData("m_bFixedUpdate", m_aMonoMethodFlags[(int)EMonoMethod.FixedUpdate]);
m_cBehavior.SetData("m_bLiteUpdate", m_aMonoMethodFlags[(int)EMonoMethod.LiteUpdate]);
m_cBehavior.SetData("m_bUpdate", m_aMonoMethodFlags[(int)YwLuaMonoBehaviourParams.EMonoMethod.Update]);
m_cBehavior.SetData("m_bLateUpdate", m_aMonoMethodFlags[(int)YwLuaMonoBehaviourParams.EMonoMethod.LateUpdate]);
m_cBehavior.SetData("m_bFixedUpdate", m_aMonoMethodFlags[(int)YwLuaMonoBehaviourParams.EMonoMethod.FixedUpdate]);
m_cBehavior.SetData("m_bLiteUpdate", m_aMonoMethodFlags[(int)YwLuaMonoBehaviourParams.EMonoMethod.LiteUpdate]);

// To set custom parameters need to be passed to lua.
OnSetCustomParameters();
Expand All @@ -112,7 +117,7 @@ void Awake()
// Use this for initialization.
void Start()
{
if (!m_bReady || !m_aMonoMethodFlags[(int)EMonoMethod.Start])
if (!m_bReady || !m_aMonoMethodFlags[(int)YwLuaMonoBehaviourParams.EMonoMethod.Start])
{
return;
}
Expand All @@ -132,7 +137,7 @@ void OnEnable()
m_cBehavior.CallMethod(ref m_cOnEnableBase, LUA_FUNC_NAME_ON_ENABLE_BASE, m_cBehavior.GetChunk());

// Call enable.
if (m_aMonoMethodFlags[(int)EMonoMethod.OnEnable])
if (m_aMonoMethodFlags[(int)YwLuaMonoBehaviourParams.EMonoMethod.OnEnable])
{
m_cBehavior.OnEnable();
}
Expand All @@ -150,7 +155,7 @@ void OnDisable()
m_cBehavior.CallMethod(ref m_cOnDisableBase, LUA_FUNC_NAME_ON_DISENABLE_BASE, m_cBehavior.GetChunk());

// Call disable.
if (m_aMonoMethodFlags[(int)EMonoMethod.OnDisable])
if (m_aMonoMethodFlags[(int)YwLuaMonoBehaviourParams.EMonoMethod.OnDisable])
{
m_cBehavior.OnDisable();
}
Expand All @@ -169,7 +174,7 @@ void OnDestroy()
m_cBehavior.CallMethod(ref cOnDestroyBase, "OnDestroyBase", m_cBehavior.GetChunk());

// Call on destroy.
if (m_aMonoMethodFlags[(int)EMonoMethod.OnDestroy])
if (m_aMonoMethodFlags[(int)YwLuaMonoBehaviourParams.EMonoMethod.OnDestroy])
{
m_cBehavior.OnDestroy();
}
Expand All @@ -178,7 +183,7 @@ void OnDestroy()
// OnTriggerEnter is called when the Collider other enters the trigger.
void OnTriggerEnter(Collider cOther)
{
if (!m_bReady || !m_aMonoMethodFlags[(int)EMonoMethod.OnTriggerEnter])
if (!m_bReady || !m_aMonoMethodFlags[(int)YwLuaMonoBehaviourParams.EMonoMethod.OnTriggerEnter])
{
return;
}
Expand All @@ -189,7 +194,7 @@ void OnTriggerEnter(Collider cOther)
// Sent when another object enters a trigger collider attached to this object (2D physics only).
void OnTriggerEnter2D(Collider2D cOther)
{
if (!m_bReady || !m_aMonoMethodFlags[(int)EMonoMethod.OnTriggerEnter2D])
if (!m_bReady || !m_aMonoMethodFlags[(int)YwLuaMonoBehaviourParams.EMonoMethod.OnTriggerEnter2D])
{
return;
}
Expand All @@ -200,7 +205,7 @@ void OnTriggerEnter2D(Collider2D cOther)
// OnTriggerExit is called when the Collider other has stopped touching the trigger.
void OnTriggerExit(Collider cOther)
{
if (!m_bReady || !m_aMonoMethodFlags[(int)EMonoMethod.OnTriggerExit])
if (!m_bReady || !m_aMonoMethodFlags[(int)YwLuaMonoBehaviourParams.EMonoMethod.OnTriggerExit])
{
return;
}
Expand All @@ -211,7 +216,7 @@ void OnTriggerExit(Collider cOther)
// Sent when another object leaves a trigger collider attached to this object (2D physics only).
void OnTriggerExit2D(Collider2D cOther)
{
if (!m_bReady || !m_aMonoMethodFlags[(int)EMonoMethod.OnTriggerExit2D])
if (!m_bReady || !m_aMonoMethodFlags[(int)YwLuaMonoBehaviourParams.EMonoMethod.OnTriggerExit2D])
{
return;
}
Expand All @@ -222,7 +227,7 @@ void OnTriggerExit2D(Collider2D cOther)
// OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
void OnCollisionEnter(Collision cCollision)
{
if (!m_bReady || !m_aMonoMethodFlags[(int)EMonoMethod.OnCollisionEnter])
if (!m_bReady || !m_aMonoMethodFlags[(int)YwLuaMonoBehaviourParams.EMonoMethod.OnCollisionEnter])
{
return;
}
Expand All @@ -233,7 +238,7 @@ void OnCollisionEnter(Collision cCollision)
// Sent when an incoming collider makes contact with this object's collider (2D physics only).
void OnCollisionEnter2D(Collision2D cCollision)
{
if (!m_bReady || !m_aMonoMethodFlags[(int)EMonoMethod.OnCollisionEnter2D])
if (!m_bReady || !m_aMonoMethodFlags[(int)YwLuaMonoBehaviourParams.EMonoMethod.OnCollisionEnter2D])
{
return;
}
Expand All @@ -244,7 +249,7 @@ void OnCollisionEnter2D(Collision2D cCollision)
// OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.
void OnCollisionExit(Collision cCollision)
{
if (!m_bReady || !m_aMonoMethodFlags[(int)EMonoMethod.OnCollisionExit])
if (!m_bReady || !m_aMonoMethodFlags[(int)YwLuaMonoBehaviourParams.EMonoMethod.OnCollisionExit])
{
return;
}
Expand All @@ -255,14 +260,25 @@ void OnCollisionExit(Collision cCollision)
// Sent when a collider on another object stops touching this object's collider (2D physics only).
void OnCollisionExit2D(Collision2D cCollision)
{
if (!m_bReady || !m_aMonoMethodFlags[(int)EMonoMethod.OnCollisionExit2D])
if (!m_bReady || !m_aMonoMethodFlags[(int)YwLuaMonoBehaviourParams.EMonoMethod.OnCollisionExit2D])
{
return;
}

m_cBehavior.OnCollisionExit2D(cCollision);
}

/**
* Get lua class name.
*
* @param void.
* @return string - The name of the associated lua class.
*/
public string GetLuaClassName()
{
return m_luaParameters.m_strLuaClassName;
}

/**
* To set custom parameters need to be passed to lua.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* The custom export lua type class, this is editor class.
*
* @filename CustomExportTypeToLua.cs
* @filename LgCustomExportTypeToLua.cs
* @copyright Copyright (c) 2015 Yaukey/yaukeywang/WangYaoqi ([email protected]) all rights reserved.
* @license The MIT License (MIT)
* @author Yaukey
Expand All @@ -14,7 +14,7 @@
using SLua;

// The custom export lua type class.
public class CustomExportTypeToLua : ICustomExportPost
public class LgCustomExportTypeToLua : ICustomExportPost
{
/**
* Get custom assembly to generate extension method.
Expand Down
47 changes: 47 additions & 0 deletions Assets/Game/Scripts/Editor/YwLuaMonoBehaviourEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* The custom editor of the YwLuaMonoBehaviourEditor class.
*
* @filename YwLuaMonoBehaviourEditor.cs
* @copyright Copyright (c) 2015 Yaukey/yaukeywang/WangYaoqi ([email protected]) all rights reserved.
* @license The MIT License (MIT)
* @author Yaukey
* @date 2016-03-25
*/

using UnityEngine;
using UnityEditor;
using System.Collections;
using System;

// The custom editor of the YwLuaMonoBehaviourEditor class.
[CustomEditor(typeof(YwLuaMonoBehaviour), true)]
public class YwLuaMonoBehaviourEditor : Editor
{
// The lua params property.
protected SerializedProperty m_cLuaParams = null;

/**
* This function is called when the object is loaded.
*
* @param void.
* @return void.
*/
protected virtual void OnEnable()
{
m_cLuaParams = serializedObject.FindProperty("m_luaParameters");
}

/**
* Implement this function to make a custom inspector.
* Inside this function you can add your own custom GUI for the inspector of a specific object class.
*
* @param void.
* @return void.
*/
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(m_cLuaParams);
serializedObject.ApplyModifiedProperties();
}
}
12 changes: 12 additions & 0 deletions Assets/Game/Scripts/Editor/YwLuaMonoBehaviourEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8f83505

Please sign in to comment.