/// <summary> /// Make use of internal Unity functionality to change which assembly a MonoScript points to. /// /// We change this to allow Unity to reconnect references to the script when loaded into KTaNE. Normally, a MonoScript /// points to the Assembly-CSharp.dll assembly. Because we are forced to build the mod assembly with a different name, /// Unity would not normally be able to reconnect the script. Here we can change the assembly name a MonoScript points to /// and resolve the problem. /// /// WARNING! The Unity Editor expects MonoScripts to resolve to the Assembly-CSharp assembly, so you MUST change it back /// or else the editor will lose the script reference (and you'll be forced to delete your Library to recover). /// </summary> /// <param name="script"></param> /// <param name="assemblyName"></param> protected void ChangeMonoScriptAssembly(MonoScript script, string assemblyName) { //MonoScript //internal extern void Init(string scriptContents, string className, string nameSpace, string assemblyName, bool isEditorScript); MethodInfo dynMethod = script.GetType().GetMethod("Init", BindingFlags.NonPublic | BindingFlags.Instance); dynMethod.Invoke(script, new object[] { script.text, script.name, "", assemblyName, false }); Debug.LogFormat("Changed {0} assembly to {1}", script.name, assemblyName); }
public void OnGUI() { target = (MonoScript)EditorGUILayout.ObjectField("Script :", target, typeof(MonoScript), true); minRange = EditorGUILayout.IntField("Min Range :", minRange); if (target != null) { //SpellScript spell = ; //Debug.Log(spell + " " + target); //minRange = spell.minRange; Debug.Log(target.GetType()); } //spell.minRange = Vector3.one * size.SizeOfCube; }
public override void OnInspectorGUI() { base.OnInspectorGUI(); CardSlot myTarget = (CardSlot)target; //TODO improve card selection if (Application.isPlaying) { selectedCard = (MonoScript)EditorGUILayout.ObjectField("Card", selectedCard, typeof(MonoScript), false); if (selectedCard != null) { if (selectedCard.GetClass().IsSubclassOf(typeof(Card))) { if (GUILayout.Button("make card")) { myTarget.removeCard(); myTarget.receiveCard((Card)System.Activator.CreateInstance(selectedCard.GetType())); } } } } }
public override void OnInspectorGUI() { OZOPlayer player = (OZOPlayer)target; EditorGUI.BeginDisabledGroup(true); MonoScript ozoplayer = MonoScript.FromMonoBehaviour(player); MonoScript script = EditorGUILayout.ObjectField("Script", ozoplayer, typeof(MonoScript), false) as MonoScript; script.GetType(); EditorGUI.EndDisabledGroup(); Undo.RecordObject(player, "OZO Player settings"); //enable undo for everything { string licenseId = EditorGUILayout.TextField("OZO Player SDK License ID", player.licenseId); if (licenseId != player.licenseId) { player.licenseId = licenseId; } EditorGUILayout.Space(); } { //Camera Settings EditorGUILayout.LabelField("Camera Settings", EditorStyles.boldLabel); EditorGUI.indentLevel++; Color clearColor = EditorGUILayout.ColorField("OZO Render Clear Color", player.OZORendererClearColor); if (clearColor != player.OZORendererClearColor) { player.OZORendererClearColor = clearColor; player.SetClearColor(clearColor); //the SDK } float cameraDepth = EditorGUILayout.FloatField("OZO Camera Depth", player.OZOCameraDepth); if (cameraDepth != player.OZOCameraDepth) { player.OZOCameraDepth = cameraDepth; if (null != player.OZOViewCameras) { foreach (Camera cam in player.OZOViewCameras) { cam.depth = cameraDepth; } } } Vector2 cameraClipPlanes = EditorGUILayout.Vector2Field("OZO Camera Clip Planes", player.OZOCameraClipPlanes); if (cameraClipPlanes != player.OZOCameraClipPlanes) { player.OZOCameraClipPlanes = cameraClipPlanes; if (null != player.OZOViewCameras) { foreach (Camera cam in player.OZOViewCameras) { cam.nearClipPlane = cameraClipPlanes.x; cam.farClipPlane = cameraClipPlanes.x; } } } CameraClearFlags flags = (CameraClearFlags)EditorGUILayout.EnumPopup("OZO Camera Clear Flags", player.OZOCameraClearFlags); if (flags != player.OZOCameraClearFlags) { player.OZOCameraClearFlags = flags; if (null != player.OZOViewCameras) { foreach (Camera cam in player.OZOViewCameras) { cam.clearFlags = flags; } } } Undo.RecordObject(player.OZOCameraMaterial, "Changed Material Settings"); Material mat = player.OZOCameraMaterial; player.OZOCameraMaterial = (Material)EditorGUILayout.ObjectField("OZO Camera Material", player.OZOCameraMaterial, typeof(Material), true); if (mat != player.OZOCameraMaterial) { if (null != player.OZOViewRenderer) //runtime params { foreach (OZORender r in player.OZOViewRenderer) { r.material = null; r.material = new Material(player.OZOCameraMaterial); r.material.SetTexture("_MainTex", r.renderTexture); r.material.SetTexture("_DepthTex", r.renderTextureDepth); } } } EditorGUILayout.BeginVertical(); if (null != player.OZOCameraMaterial) { Shader sh = player.OZOCameraMaterial.shader; if (sh.name != "OZO/OZODefault") { EditorGUI.indentLevel++; EditorGUILayout.LabelField("(The following setting changes will be stored also in runtime)", EditorStyles.miniLabel); for (int i = 0; i < ShaderUtil.GetPropertyCount(sh); ++i) { ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(sh, i); if (ShaderUtil.ShaderPropertyType.Range == type) { string name = ShaderUtil.GetPropertyName(sh, i); float value = player.OZOCameraMaterial.GetFloat(name); float selValue = EditorGUILayout.Slider(name, value, ShaderUtil.GetRangeLimits(sh, i, 1), ShaderUtil.GetRangeLimits(sh, i, 2)); if (value != selValue) { player.OZOCameraMaterial.SetFloat(name, selValue); if (null != player.OZOViewRenderer) //runtime params { foreach (OZORender r in player.OZOViewRenderer) { r.material.SetFloat(name, selValue); } } } } else if (ShaderUtil.ShaderPropertyType.Color == type) { string name = ShaderUtil.GetPropertyName(sh, i); Color color = player.OZOCameraMaterial.GetColor(name); Color selColor = EditorGUILayout.ColorField(name, color); if (color != selColor) { player.OZOCameraMaterial.SetColor(name, selColor); if (null != player.OZOViewRenderer) //runtime params { foreach (OZORender r in player.OZOViewRenderer) { r.material.SetColor(name, selColor); } } } } } EditorGUI.indentLevel--; } } EditorGUILayout.EndVertical(); EditorGUI.indentLevel--; EditorGUILayout.Space(); //Clip areas SerializedProperty clipProperty = serializedObject.FindProperty("clipAreas"); if (null != clipProperty) { clipFoldout = EditorGUILayout.Foldout(clipFoldout, "Clip Areas: " + player.clipAreas.Count); if (clipFoldout) { EditorGUI.indentLevel++; bool modified = false; EditorGUILayout.LabelField("(Clip Areas define the areas of the video that will be rendered, if none the whole video will be rendered)", EditorStyles.miniLabel); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Areas", "" + player.clipAreas.Count); //buttons GUI.enabled = player.clipAreas.Count < MAX_CLIP_AREAS; if (GUILayout.Button("+", EditorStyles.miniButtonLeft, GUILayout.Width(20))) { OZO.ClipArea area = new OZO.ClipArea(); area.centerLongitude = 0.0f; area.centerLatitude = 0.0f; area.spanLongitude = 90.0f; area.spanLatitude = 90.0f; area.opacity = 1.0f; player.clipAreas.Add(area); modified = true; } GUI.enabled = player.clipAreas.Count > 0; if (GUILayout.Button("-", EditorStyles.miniButtonRight, GUILayout.Width(20))) { if (0 < player.clipAreas.Count) { player.clipAreas.RemoveAt(player.clipAreas.Count - 1); modified = true; } } GUI.enabled = true; EditorGUILayout.EndHorizontal(); //draw property fields int numAreas = clipProperty.arraySize; for (int areaIdx = 0; areaIdx < numAreas; ++areaIdx) { SerializedProperty areaProp = clipProperty.GetArrayElementAtIndex(areaIdx); //EditorGUILayout.PropertyField(areaProp); if (areaProp.hasChildren) { EditorGUILayout.LabelField("Area #" + areaIdx, EditorStyles.boldLabel); string root = areaProp.propertyPath; EditorGUI.indentLevel++; SerializedProperty it = areaProp.Copy(); bool hasMore = it.Next(true); while (hasMore) { //only children if (!it.propertyPath.Contains(root)) { break; } string type = it.type; if ("float" == type) { EditorGUILayout.PropertyField(it, EditorStyles.miniFont); if (player.clipAreas.Count > areaIdx) { var prop = typeof(OZO.ClipArea).GetField(it.name); float val = (float)prop.GetValue(player.clipAreas[areaIdx]); if (val != it.floatValue) { prop.SetValue(player.clipAreas[areaIdx], it.floatValue); modified = true; } } } it.Next(false); } EditorGUI.indentLevel--; } } EditorGUI.indentLevel--; if (modified) { player.SetClipAreas(player.clipAreas.ToArray()); } } } if (GUI.changed) { serializedObject.ApplyModifiedProperties(); } } }
private static ITableCheckValidateNodeBase DoMakeValidateNode(string validateNodeName, string parameter, List <ValidateConfig> childeConfigs, ref string err) { ITableCheckValidateNodeBase validateNode = null; if (string.Compare(validateNodeName, "DirectoryExist", StringComparison.OrdinalIgnoreCase) == 0) { validateNode = new DirectoryExistValidate(parameter); } else if (string.Compare(validateNodeName, "FileExist", StringComparison.OrdinalIgnoreCase) == 0) { validateNode = new FileExistValidate(parameter); } else if (string.Compare(validateNodeName, "Equal", StringComparison.OrdinalIgnoreCase) == 0) { validateNode = new EqualValidate(parameter); } else if (string.Compare(validateNodeName, "NoEqual", StringComparison.OrdinalIgnoreCase) == 0) { validateNode = new NoEqualValidate(parameter); } else if (string.Compare(validateNodeName, "Range", StringComparison.OrdinalIgnoreCase) == 0) { string[] rangeValues = parameter.Split(','); double min, max; if (rangeValues.Length == 2 && double.TryParse(rangeValues[0], out min) && double.TryParse(rangeValues[1], out max)) { validateNode = new RangeValidate(min, max); } else { err = "期望的参数为2个,以,进行分格,并可以转化为浮点数"; } } else if (string.Compare(validateNodeName, "NoEmpty", StringComparison.OrdinalIgnoreCase) == 0) { validateNode = new NoEmptyValidate(); } else if (string.Compare(validateNodeName, "Lua", StringComparison.OrdinalIgnoreCase) == 0) { //validateNode = new LuaValidate(parameter); } else if (string.Compare(validateNodeName, "SpriteExist", StringComparison.OrdinalIgnoreCase) == 0) { validateNode = new SpriteExistValidate(parameter); } else if (string.Compare(validateNodeName, "ClassExist", StringComparison.OrdinalIgnoreCase) == 0) { validateNode = new ClassExist(parameter); } else if (string.Compare(validateNodeName, "FieldDependent", StringComparison.OrdinalIgnoreCase) == 0) { string[] rangeValues = parameter.Split(':'); bool bOk = true; do { if (rangeValues.Length == 2) { string tableName = rangeValues[0]; string fieldName = rangeValues[1]; #if UNITY_EDITOR string tablePath = ClientDataBaseManager.Get().m_config.GetTableClassPath() + ClientDataBaseManager .Get().m_config.GetTableClassScriptName(tableName, true); MonoScript script = AssetDatabase.LoadAssetAtPath <MonoScript>(tablePath); if (script == null || script.GetClass() == null) { // 表不存在 bOk = false; break; } var realFieldName = Utility.TypeRelate.CorrectFieldName(fieldName); var filedObj = script.GetType().GetProperty(realFieldName); if (filedObj != null) { // 字段不存在 bOk = false; break; } #endif validateNode = new FieldDependentValidate(tableName, fieldName); } }while (false); if (!bOk) { err = "期望的参数为1个(表名:字段名), 同时要求表名跟字段名存在"; } } else if (string.Compare(validateNodeName, "Filter", StringComparison.OrdinalIgnoreCase) == 0) { string[] filterValues = parameter.Split('|'); if (filterValues.Length == 2) { string filterErr = string.Empty; ITableCheckValidateNodeBase filterNode = DoMakeValidateNode(filterValues[0], filterValues[1], childeConfigs, ref filterErr); if (filterNode == null) { err = string.Format("过滤参数配置出错:({0})", filterErr); return(null); } List <ITableCheckValidateNodeBase> childValidateNodes = new List <ITableCheckValidateNodeBase>(); if (childeConfigs != null) { foreach (var childConfig in childeConfigs) { filterErr = string.Empty; ITableCheckValidateNodeBase childeValide = DoMakeValidateNode(childConfig.ValidateNode, childConfig.Parameter, childConfig.ChildConfigs, ref filterErr); if (childeValide == null) { err = string.Format("过滤结点的子验证结点配置出错:([{0}]{1})", childConfig.ValidateNode, filterErr); return(null); } childValidateNodes.Add(childeValide); } } if (childValidateNodes.Count != 1) { err = "过滤结点的子验证没有配置或者配置过多,期望配置一个"; return(null); } validateNode = new FilterValidate(filterNode, childValidateNodes); } else { err = "期望的参数以'|'分割,前面的为真正的验证结点,后面的为验证结点的参数"; } } else { err = "无法找到对应的验证器:" + validateNodeName; } return(validateNode); }
public void UpdateScriptType() { this.type = script.GetType(); this.name = script.name; }