public void UpdateEquipmentColor(int colorIndex) { for (int i = MeshObjects.Count - 1; i >= 0; i--) { ColorCustomization.ApplyEquipmentColor(MeshObjects[i], colorIndex); } }
void OnEnable() { if (HeroColorPresets.Instance == null) { GameObject go = GameObject.Find("__HeroColorPreset"); if (go == null) { GameObject prefab = AssetDatabase.LoadAssetAtPath(GetHeroPresetsAssetPath(), typeof(GameObject)) as GameObject; if (prefab == null) { Debug.LogError("Failed to load hero color preset prefab"); return; } go = GameObject.Instantiate(prefab) as GameObject; go.name = "__HeroColorPreset"; m_HeroColorPresets = go.GetComponent <HeroColorPresets>(); } } else { m_HeroColorPresets = HeroColorPresets.Instance; } if (m_HeroColorPresets != null) { m_PresetList.Clear(); m_PresetList.Add("None"); int presetCount = m_HeroColorPresets.PresetColorCount; for (int i = 0; i < presetCount; i++) { m_PresetList.Add(string.Format("Preset {0}", i + 1)); } ColorCustomization customization = target as ColorCustomization; if (customization != null) { if (customization.m_SkinColorIndex >= presetCount) { customization.m_SkinColorIndex = -1; } if (customization.m_HairColorIndex >= presetCount) { customization.m_HairColorIndex = -1; } if (customization.m_EyeColorIndex >= presetCount) { customization.m_EyeColorIndex = -1; } if (customization.m_EquipmentColorIndex >= presetCount) { customization.m_EquipmentColorIndex = -1; } } } }
public void UpdateEquipmentColor(string rowName, int colorIndex) { if (_toCombine == null) { return; } for (int i = _toCombine.Length - 1; i >= 0; i--) { if (_toCombine[i].Name == rowName) { ColorCustomization.ApplyEquipmentColor(_toCombine[i].CombinedMesh, colorIndex); break; } } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); ColorCustomization customization = target as ColorCustomization; if (customization == null) { return; } customization.m_UseDefaultColor = GUILayout.Toggle(customization.m_UseDefaultColor, "Use Default Color"); if (customization.m_UseDefaultColor) { return; } customization.m_UseHeroColorPreset = GUILayout.Toggle(customization.m_UseHeroColorPreset, "Use Hero Color Presets"); if (customization.m_UseHeroColorPreset) { GUILayout.Label("Select preset colors"); NGUIEditorTools.BeginContents(); { GUILayout.BeginHorizontal(); { customization.m_SkinColorIndex = EditorGUILayout.Popup("Skin Color Preset", customization.m_SkinColorIndex + 1, m_PresetList.ToArray()) - 1; if (customization.m_SkinColorIndex >= 0 && m_HeroColorPresets != null) { GUI.enabled = false; EditorGUILayout.ColorField(m_HeroColorPresets.GetSkinColor(customization.m_SkinColorIndex)); GUI.enabled = true; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { customization.m_HairColorIndex = EditorGUILayout.Popup("Hair Color Preset", customization.m_HairColorIndex + 1, m_PresetList.ToArray()) - 1; if (customization.m_HairColorIndex >= 0 && m_HeroColorPresets != null) { GUI.enabled = false; EditorGUILayout.ColorField(m_HeroColorPresets.GetHairColor(customization.m_HairColorIndex)); GUI.enabled = true; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { customization.m_EyeColorIndex = EditorGUILayout.Popup("Eye Color Preset", customization.m_EyeColorIndex + 1, m_PresetList.ToArray()) - 1; if (customization.m_EyeColorIndex >= 0 && m_HeroColorPresets != null) { GUI.enabled = false; EditorGUILayout.ColorField(m_HeroColorPresets.GetEyeColor(customization.m_EyeColorIndex)); GUI.enabled = true; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { customization.m_EquipmentColorIndex = EditorGUILayout.Popup("Equipment Color Preset", customization.m_EquipmentColorIndex + 1, m_PresetList.ToArray()) - 1; if (customization.m_EquipmentColorIndex >= 0 && m_HeroColorPresets != null) { GUI.enabled = false; EditorGUILayout.ColorField(m_HeroColorPresets.GetEquipmentColor(customization.m_EquipmentColorIndex)); GUI.enabled = true; } } GUILayout.EndHorizontal(); if (GUILayout.Button("Enable Color Customization")) { SkinnedMeshRenderer[] renderers = customization.gameObject.GetComponentsInChildren <SkinnedMeshRenderer>(); foreach (SkinnedMeshRenderer renderer in renderers) { if (renderer != null) { foreach (Material mat in renderer.sharedMaterials) { mat.SetFloat("EBG_COLORCUSTOMIZATION", 1); mat.DisableKeyword("EBG_COLORCUSTOMIZATION_OFF"); mat.EnableKeyword("EBG_COLORCUSTOMIZATION_ON"); } } } } if (GUILayout.Button("Disable Color Customization")) { SkinnedMeshRenderer[] renderers = customization.gameObject.GetComponentsInChildren <SkinnedMeshRenderer>(); foreach (SkinnedMeshRenderer renderer in renderers) { if (renderer != null) { foreach (Material mat in renderer.sharedMaterials) { mat.SetFloat("EBG_COLORCUSTOMIZATION", 0); mat.DisableKeyword("EBG_COLORCUSTOMIZATION_ON"); mat.EnableKeyword("EBG_COLORCUSTOMIZATION_OFF"); } } } } } NGUIEditorTools.EndContents(); } else { GUILayout.Label("Set tint colors"); NGUIEditorTools.BeginContents(); { customization.m_TintColor1 = EditorGUILayout.ColorField("Tint Color 1 (R Channel)", customization.m_TintColor1); customization.m_TintColor2 = EditorGUILayout.ColorField("Tint Color 2 (G Channel)", customization.m_TintColor2); customization.m_TintColor3 = EditorGUILayout.ColorField("Tint Color 3 (B Channel)", customization.m_TintColor3); customization.m_TintColor4 = EditorGUILayout.ColorField("Tint Color 4 (A Channel)", customization.m_TintColor4); } NGUIEditorTools.EndContents(); } }
private void Refresh(int toRefreshIndex = -1, string equipmentDataId = null) { //Step -1 int[] refreshIndices = new int[_toCombine.Length]; for (int i = 0; i < refreshIndices.Length; i++) { refreshIndices [i] = toRefreshIndex == -1 || i == toRefreshIndex ? 1 : 0; } for (int ii = 0; ii < _toCombine.Length; ++ii) { if (_toCombine[ii].GameObject != null) { CombinedMeshExtender cme = _toCombine[ii].GameObject.GetComponent <CombinedMeshExtender>(); if (cme != null) { for (int jj = 0; jj < cme.rowEntries.Length; ++jj) { int rowIndex = System.Array.FindIndex(_toCombine, arg => arg.Name == cme.rowEntries[jj].combineRowName); _toCombine[rowIndex].GameObject = cme.rowEntries[jj].mesh; refreshIndices [rowIndex] = 1; } } } } //Step 0 //Remove any preview nodes if (_toDelete != null) { Transform deleteTransform = gameObject.transform.Find(_toDelete); deleteTransform.gameObject.SetActive(false); } //Step 1 // Remove old mesh components GameObject skeleton = gameObject; SkinnedMeshRenderer old_smr = skeleton.GetComponent("SkinnedMeshRenderer") as SkinnedMeshRenderer; if (old_smr != null) { DestroyImmediate(old_smr); } //Step 2 //first we need to try and download each of the Assetbundles for this dude //Step 3 //Grab each piece and reskin it to our skeleton //Vector3 position = skeleton.transform.position; //List<CombineInstance> combineInstances = new List<CombineInstance> (); //List<Material> materials = new List<Material> (); List <Transform> bones = new List <Transform> (); Transform[] transforms = skeleton.GetComponentsInChildren <Transform> (); //bool should_unload_unused_items = false; for (int i = 0; i < _toCombine.Length; ++i) { bones = new List <Transform> (); if (refreshIndices[i] == 0) { continue; } if (_toCombine[i].GameObject == null) { continue; } if (_toCombine[i].CombinedMesh != null) { Destroy(_toCombine[i].CombinedMesh); } GameObject customization_object = (GameObject)GameObject.Instantiate(_toCombine[i].GameObject); customization_object.transform.parent = gameObject.transform; customization_object.SetActive(true); if (customization_object == null) { EB.Debug.LogWarning("CombineMesh: customization_object is null. type = {0}", _toCombine[i].Name); continue; } SkinnedMeshRenderer[] smrs = customization_object.GetComponentsInChildren <SkinnedMeshRenderer> (); if (smrs == null || smrs.Length == 0) { continue; } for (int j = 0; j < smrs.Length; j++) { if (_toCombine[i].OverrideMaterial.Length > 0) { if (smrs[j].materials.Length == _toCombine[i].OverrideMaterial.Length) { smrs[j].materials = _toCombine[i].OverrideMaterial; } else { smrs[j].material = _toCombine[i].OverrideMaterial[0]; } } smrs[j].receiveShadows = false; } //set customizatioin color; ColorCustomization customization = customization_object.GetComponent <ColorCustomization>(); if (customization != null) { //now we use this component to check whether current gameobject is hero instance, not a good way. if (GetComponent <HeroEquipmentDataLookup>() != null) { customization.m_UseHeroColorPreset = true; int skinColorIndex = 0; DataLookupsCache.Instance.SearchIntByID("heroStats.skinColorIndex", out skinColorIndex); customization.m_SkinColorIndex = skinColorIndex - 1; int hairColorIndex = 0; DataLookupsCache.Instance.SearchIntByID("heroStats.hairColorIndex", out hairColorIndex); customization.m_HairColorIndex = hairColorIndex - 1; int eyeColorIndex = 0; DataLookupsCache.Instance.SearchIntByID("heroStats.eyesColorIndex", out eyeColorIndex); customization.m_EyeColorIndex = eyeColorIndex - 1; if (!string.IsNullOrEmpty(equipmentDataId)) { int colorIndex = 0; DataLookupsCache.Instance.SearchIntByID(string.Format("{0}.equipmentColorIndex", equipmentDataId), out colorIndex); customization.m_EquipmentColorIndex = colorIndex - 1; } } customization.ApplyColor(); } SkinnedMeshRenderer smr = smrs [0]; Transform root = null; //reskin this thing to the new skeleton foreach (Transform bone in smr.bones) { foreach (Transform transform in transforms) { if (transform.name == smr.rootBone.name) { root = transform; } if (transform.name != bone.name) { continue; } bones.Add(transform); break; } } smr.bones = bones.ToArray(); smr.rootBone = root; smr.transform.parent = gameObject.transform; _toCombine[i].CombinedMesh = smr.gameObject; GameObject.Destroy(customization_object); } //Step 4 //Combine meshes using the same material/shader combo into one if (_CombineTo1Draw) { CombineMeshes1Draw(meshes); } else { //CombineMeshesMultiDraw(meshes); } gameObject.SendMessage("ForceUpdateColorScale", SendMessageOptions.DontRequireReceiver); /* * //Raise character mesh update event. * if(_meshUpdateEvent == null) * { * _meshUpdateEvent = new CharacterMeshUpdateEvent(gameObject); * } * EventManager.instance.Raise(_meshUpdateEvent); */ }
/// <summary> /// 更新部件 /// </summary> /// <param name="name">部件名称</param> /// <param name="assetName">资源名称</param> /// <param name="partitionObj">部件数据对象</param> /// <param name="isLinkObj">是否有部件信息组件</param> void UpdatePartition(string name, string assetName, GameObject partitionObj, bool isLinkObj = false) { if (!m_Partitions.ContainsKey(name)) { EB.Debug.LogError(string.Format("更新部件,发现这个部件不存在部件列表当中,: {0} ,部件的资源名称: {1}!", name, assetName)); } PartitionObject partition = m_Partitions[name]; if (partition == null) { return; } if (!isLinkObj) //现在默认都是没有部件列表的组件了,每次都进去 { partition.ClearMeshObjects(); } //initialize character partition: load skinnedmeshes and set materials CharacterPartition characterPartition = partitionObj.GetComponent <CharacterPartition>(); if (characterPartition != null) { characterPartition.Initialize(); } ColorCustomization customization = partitionObj.GetComponent <ColorCustomization>(); if (customization != null) { customization.ApplyColor(); } bool isChildrenPatition = IsChildrenPartition(name, assetName); //日志 EB.Debug.LogObjectMgrAsset("<color=#00ff00>更新合并部件的骨骼:{0}</color>,,assetName:<color=#00ff00>{1}</color>是否为这个角色的子级:<color=#00ff00>{2}</color>,isLinkObj:<color=#00ff00>{3}</color>" , name, assetName, isChildrenPatition, isLinkObj); // if (isChildrenPatition) { //更新部件,先注掉,因为业务逻辑已经过老了 UpdateChildrenPartition(partition, name, assetName, partitionObj); } else { try { UpdateCombineBonePartition(partition, name, assetName, partitionObj, isLinkObj); } catch (System.NullReferenceException e) { EB.Debug.LogError(e.ToString()); } partition.UnregisterObject(partitionObj); } if (SyncLoad && m_ToLoad.Count == 0) { var iter = m_Partitions.GetEnumerator(); while (iter.MoveNext()) { iter.Current.Value.ShowMeshObjects(); } iter.Dispose(); } CharacterColorScale colorScale = GetComponent <CharacterColorScale>(); if (colorScale != null) { colorScale.ForceUpdateColorScale(); } }