public static GameObject AddAXGameObjectTo(AXParametricObject po, GameObject ngo) { //GameObject obj = new GameObject(prefab.name); //GameObject ngo = GameObject.Instantiate(go); AXGameObject axgo = ngo.AddComponent <AXGameObject>(); axgo.makerPO_GUID = po.Guid; // STATIC FLAGS #if UNITY_EDITOR // *** Could temporarily remove the Lightmap static flag here to allow for Auto... http://forum.unity3d.com/threads/how-to-set-use-staticeditorflags-cant-seem-to-set-them-from-script.137024/ // flags = flags & ~(StaticEditorFlags.LightmapStatic); AXStaticEditorFlags axflags = po.axStaticEditorFlags; if (!po.model.staticFlagsEnabled) { axflags = axflags & ~AXStaticEditorFlags.LightmapStatic; } StaticEditorFlags flags = (StaticEditorFlags)axflags; GameObjectUtility.SetStaticEditorFlags(ngo, flags); #endif if (!string.IsNullOrEmpty(po.tag)) { ngo.tag = po.tag; } ngo.layer = po.layer; po.copyComponentsFromPrototypeToGameObject(ngo); return(ngo); }
public static GameObject createAXGameObject(string name, AXParametricObject po, string subItemAddress = "") { GameObject obj = new GameObject(name); AXGameObject axgo = obj.AddComponent <AXGameObject>(); axgo.makerPO_GUID = po.Guid; // STATIC FLAGS #if UNITY_EDITOR // *** Could temporarily remove the Lightmap static flag here to allow for Auto... http://forum.unity3d.com/threads/how-to-set-use-staticeditorflags-cant-seem-to-set-them-from-script.137024/ // flags = flags & ~(StaticEditorFlags.LightmapStatic); AXStaticEditorFlags axflags = po.axStaticEditorFlags; if (!po.model.staticFlagsEnabled) { //var mask = ~AXStaticEditorFlags.LightmapStatic; //var newValue = originalValue & mask; axflags = axflags & ~AXStaticEditorFlags.LightmapStatic; } StaticEditorFlags flags = (StaticEditorFlags)axflags; GameObjectUtility.SetStaticEditorFlags(obj, flags); #endif if (!string.IsNullOrEmpty(po.tag)) { obj.tag = po.tag; } obj.layer = po.layer; //Debug.Log ("copying protos"); po.copyComponentsFromPrototypeToGameObject(obj); return(obj); }
// ON_SELECT // When you click on an AX-gerneated GameObject in the scene, // AX selects a PO in the AX NodeGraph. // It finds its consumerMatrix and then sets the matrix up its DependsOn chain using setSelectedConsumerOfAllInputs() public void OnSelect() { //Debug.Log("AXGameObject: OnSelect"); if (transform.parent == null) { return; } if (model == null) { return; } if (model.selectedPOs != null) { model.selectedPOs.Clear(); } model.clickSelectedAXGO = this; model.cycleSelectedAXGO = this; // To support "cycle select" functionality model.selectedTransfromAncestry = ancestry; // SET WORLD_DISPLAY_MATRIX // Foreach Ancestor GO in the scene heirachy... // use the GO's location in SceneView space of each ancestor GO // to set the worldDisplayMatrix for the PO that generated that GO. AXGameObject ancestorAXGO = null; for (int i = 0; i < ancestry.Count; i++) { //Debug.Log("["+i+"] " + ancestry[i].gameObject.name); ancestorAXGO = ancestry[i].gameObject.GetComponent <AXGameObject> (); if (ancestorAXGO == null || ancestorAXGO.parametricObject == null || ancestorAXGO.parametricObject.generator is Instance || ancestorAXGO.parametricObject.generator is Replicant) { //if (ancestorAXGO) //Debug.Log("Nope "+ancestorAXGO.parametricObject.Name); continue; } if (ancestry[i] == null || parametricObject == null) { continue; } // SET_worldDisplayMatrix ancestorAXGO.parametricObject.consumerMatrix = model.transform.localToWorldMatrix.inverse * ancestry[i].localToWorldMatrix * parametricObject.getLocalMatrix().inverse; if (i < (ancestry.Count - 2)) { AXGameObject consumerAXGO = ancestry[i + 1].gameObject.GetComponent <AXGameObject>(); if (consumerAXGO != null && consumerAXGO.parametricObject != null) { //Debug.Log("!!!!!!!!!!!!!!!!!!!!!!! "+ancestorAXGO.parametricObject.Name+".selectedConsumer = " + consumerAXGO.parametricObject.Name); ancestorAXGO.parametricObject.selectedConsumer = consumerAXGO.parametricObject; } } if (!string.IsNullOrEmpty(ancestorAXGO.consumerAddress)) { ancestorAXGO.parametricObject.selectedConsumerAddress = ancestorAXGO.consumerAddress; //Debug.Log("ancestorAXGO.parametricObject.selectedConsumerAddress="+ancestorAXGO.parametricObject.selectedConsumerAddress); } } model.cycleSelectedPO = parametricObject; model.selectPO(parametricObject); if (parametricObject == null) { return; } parametricObject.generator.adjustWorldMatrices(); // NOW SET CONSUMER_M's UPSTREAM... // This is a key step. if (!(parametricObject.generator is Instance)) { //Debug.Log("Nope 2 "+parametricObject.Name); parametricObject.setSelectedConsumerOfAllInputs(); } parametricObject.selectedAXGO = this; }