static GrassBender CreateBender(UnityEditor.MenuCommand menuCommand) { GrassBender gb = CreateBender(); UnityEditor.Selection.activeObject = gb.gameObject; return(gb); }
static GrassBender CreateBender(string name = "Grass Bender") { GameObject go = new GameObject(name); GrassBender gb = go.AddComponent <GrassBender>(); //UnityEditor.GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject); UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Create " + go.name); return(gb); }
static GrassBender CreateWind(UnityEditor.MenuCommand menuCommand) { GrassBender gb = CreateBender("Wind"); GameObject go = gb.gameObject; go.transform.localScale = new Vector3(1, 1, 5); gb.Noise = 1f; gb.Hardness = 5f; gb.Direction = 1f; gb.Power = 1f; UnityEditor.Selection.activeObject = go; return(gb); }
static GrassBender CreateChildBender(UnityEditor.MenuCommand menuCommand) { GrassBender gb = CreateBender(); if (UnityEditor.Selection.activeTransform != null) { gb.transform.SetParent(UnityEditor.Selection.activeTransform, false); gb.transform.localPosition = Vector3.zero; gb.transform.localRotation = Quaternion.identity; gb.transform.localScale = Vector3.one; } UnityEditor.Selection.activeObject = gb.gameObject; return(gb); }
/// <summary> /// Add a bender to this manager. /// </summary> public static void AddBender(GrassBender bender) { if (master == null) { master = bender; } if (benders == null) { benders = new List <GrassBender>(); } if (!benders.Contains(bender)) { benders.Add(bender); } }
static GrassBender CreateCharacterBender(UnityEditor.MenuCommand menuCommand) { GrassBender gb = CreateBender("Character Bender"); //gb.transform.localRotation = Quaternion.Euler(90, 0, 0); gb.Direction = .9f; gb.Hardness = 7f; gb.Power = 3f; gb.PermanentBending = true; if (UnityEditor.Selection.activeTransform != null) { gb.transform.SetParent(UnityEditor.Selection.activeTransform, true); gb.AdaptToBounds(UnityEditor.Selection.activeTransform); } UnityEditor.Selection.activeObject = gb.gameObject; return(gb); }
/// <summary> /// Remove a bender from this manager. /// </summary> public static void Remove(GrassBender bender) { if (benders.Contains(bender)) { benders.Remove(bender); } // if this bender was the master if (bender.IsMaster) { // we try to find a new one master = FindNewMaster(); if (!master) { UpdateBendersShaderArray(); } } }
//In-place bubble sort to order the benders by distance public static void SortBendersByDist() { GrassBender temp = benders[0]; bool flag = false; int n = benders.Count; int p = benders.Count; do { flag = false; for (int i = 0; i < (n - 1); i++) { if (benders[i].cullDist > benders[i + 1].cullDist) { temp = benders[i]; benders[i] = benders[i + 1]; benders[i + 1] = temp; flag = true; p = i + 1; } } n = p; }while (flag); }
// Use this for initialization void Start() { bender = GetComponentInChildren <BendinGrass.GrassBender>(); }