public static CUIPanel Create(CUICanvas oCanvas) { GameObject oPanelResGO = Resources.Load("UI/CUIPanel") as GameObject; GameObject oPanelGO = Instantiate(oPanelResGO) as GameObject; oPanelGO.transform.SetParent(oCanvas.transform, false); oPanelGO.transform.localPosition = Vector3.zero; oPanelGO.transform.localRotation = Quaternion.identity; CUIPanel oPanel = oPanelGO.GetComponent<CUIPanel>(); //oPanel.Init(); return oPanel; }
//Color col1F = CUtility.Color_HSVtoRGB(135, 20, 213); Color32 col1 = new Color32((byte)(255 * col1F.r), (byte)(255 * col1F.g), (byte)(255 * col1F.b), 0); //###BUG Conversion not working... negative numbers, WTF??? //Color col2F = CUtility.Color_HSVtoRGB(02, 20, 213); Color32 col2 = new Color32((byte)(255 * col2F.r), (byte)(255 * col2F.g), (byte)(255 * col2F.b), 0); // public static Color Color_HSVtoRGB(float h, float s, float v) { //###LEARN: From http://www.cs.rit.edu/~ncs/color/t_convert.html // Color calcColour = new Color( 1, 1, 1, 1 ); // int i = 0; // float f = 0; // float p = 0; // float q = 0; // float t = 0; // if ( s == 0 ) { // achromatic (grey) // calcColour.r = v; // calcColour.g = v; // calcColour.b = v; // return calcColour; // } // h /= 60; // i = Mathf.FloorToInt( h ); // f = h - i; // p = v * ( 1 - s ); // q = v * ( 1 - ( s * f ) ); // t = v * ( 1 - ( s * ( 1 - f ) ) ); // switch( i ) { // case 0 : // calcColour.r = v; // calcColour.g = t; // calcColour.b = p; //break; // case 1 : // calcColour.r = q; // calcColour.g = v; // calcColour.b = p; // break; // case 2 : // calcColour.r = p; // calcColour.g = v; // calcColour.b = t; // break; // case 3 : // calcColour.r = p; // calcColour.g = q; // calcColour.b = v; // break; // case 4 : // calcColour.r = t; // calcColour.g = p; // calcColour.b = v; // break; // default : // calcColour.r = v; // calcColour.g = p; // calcColour.b = q; // break; // } // return calcColour; // } // public static Vector3 Color_RGBtoHSV(float r, float g, float b) { // Vector3 calcColour = new Vector3( 0, 1, 0 ); // H, S, V // float min = 0; // float max = 0; // float delta = 0; // min = Mathf.Min( r, g, b ); // max = Mathf.Max( r, g, b ); // calcColour.z = max; // V // delta = max - min; // if ( max != 0 ) { // calcColour.y = delta / max; // S // } else { // calcColour.y = 0; // S // r = g = b = 0 // calcColour.x = -1; // H // return calcColour; // } // if ( r == max ) // calcColour.x = ( g - b ) / delta; // H // else if ( g == max ) // calcColour.x = 2 + ( ( b - r ) / delta ); // H // else // calcColour.x = 4 + ( ( r - g ) / delta ); // H // calcColour.x *= 60; // H // if ( calcColour.x < 0 ) // calcColour.x += 360; // return calcColour; // } #endregion #region === UI === public static void WndPopup_Create(CUICanvas oCanvas, EWndPopupType eWndPopupType, CObject[] aObjects, string sNamePopup, float nX = -1, float nY = -1) { //=== Construct the dialog's content dependent on what type of dialog it is === CUIPanel oPanel = CUIPanel.Create(oCanvas); //####DESIGN! ####SOON ####CLEANUP? int nRows = 0; int nPropGrps = 0; foreach (CObject oObj in aObjects) { foreach (CPropGroup oPropGrp in oObj._aPropGroups) { //###BUG!: Inserts one extra! Why?? oPropGrp._oUIPanel = oPanel; //####IMPROVE ####MOVE?? //////////oPropGrp.CreateWidget(oListBoxContent); foreach (int nPropID in oPropGrp._aPropIDs) { CProp oProp = oObj.PropFind(nPropID); nRows += oProp.CreateWidget(oPropGrp); } nPropGrps++; } } //oCanvas.transform.position = CGame.INSTANCE._oCursor.transform.position; //oCanvas.transform.rotation = Camera.main.transform.rotation; }
//--------------------------------------------------------------------------- CREATION HELPERS public void WndPopup_Create(CUICanvas oCanvas, CObject[] aObjects, float nX = -1, float nY = -1) { // Create a popup window capable of end-user editing of the public properties of this object. CUtility.WndPopup_Create(oCanvas, EWndPopupType.PropertyEditor, aObjects, _sNameHotspot, nX, nY); }
CObjectBlender _oObj; // The Blender-implemented Object that exposes RTTI-like information for change Blender shape keys from Unity UI panels #endregion Fields #region Constructors public CBodyBase(int nBodyID, EBodySex eBodySex) { _nBodyID = nBodyID; _eBodySex = eBodySex; _sBodyPrefix = "Body" + _nBodyID.ToString(); //=== Create default values for important body parameters from the sex === if (_eBodySex == EBodySex.Man) { _sMeshSource = "ManA"; _sHumanCharacterName = (_nBodyID == 0) ? "Karl" : "Brent"; //###IMPROVE: Database of names? From user??? } else { _sMeshSource = "WomanA"; _sHumanCharacterName = (_nBodyID == 0) ? "Emily" : "Eve"; } switch (_eBodySex) { //###CHECK ####TEMP ####DESIGN: Loaded from file or user top-level selection! ####DESIGN: Public properties? case EBodySex.Man: _sNameSrcGenitals = "PenisM-Erotic9-A-Big"; //###TODO#11: Cleanup? break; case EBodySex.Woman: _sNameSrcGenitals = "V****a-Erotic9-A"; //###DESIGN??? Crotch and not v****a??? break; case EBodySex.Shemale: _sNameSrcGenitals = "PenisW-Erotic9-A-Big"; //###TODO: Comes from GUI! break; } //=== Instantiate the proper prefab for our body type (Man or Woman), which defines our bones and colliders === GameObject oBodyTemplateGO = Resources.Load("Prefabs/Prefab" + _sMeshSource, typeof(GameObject)) as GameObject; //###TODO: Different gender / body types enum that matches Blender //oBody._sMeshSource + _oBodyRootGO = GameObject.Instantiate(oBodyTemplateGO) as GameObject; _oBodyRootGO.name = _sBodyPrefix; _oBodyRootGO.SetActive(true); // Prefab is stored with top object deactivated to ease development... activate it here... //=== Obtain references to needed sub-objects of our prefab === _oBonesT = CUtility.FindChild(_oBodyRootGO.transform, "Bones"); // Set key nodes of Bones and Base we'll need quick access to over and over. _oBaseT = CUtility.FindChild(_oBodyRootGO.transform, "Base"); //===== CREATE THE BODY PYTHON INSTANCE IN BLENDER ===== CGame.gBL_SendCmd("CBody", "CBodyBase_Create(" + _nBodyID.ToString() + ", '" + _sMeshSource + "', '" + eBodySex.ToString() + "','" + _sNameSrcGenitals + "')"); // This new instance is an extension of this Unity CBody instance and contains most instance members _sBlenderInstancePath_CBodyBase = "CBodyBase_GetBodyBase(" + _nBodyID.ToString() + ")"; // Simplify access to Blender CBodyBase instance //=== Download our morphing non-skinned body from Blender === GameObject oBodyBaseGO = new GameObject(_sBodyPrefix); // Create the root Unity node that will keep together all the many subnodes of this body. _oMeshMorphResult = CBMesh.Create(oBodyBaseGO, this, ".oMeshMorphResult", typeof(CBMesh), true); // Get the baked-morph mesh Blender updates for us at every morph update. (And keep Blender share so we can update) _oMeshMorphResult.transform.SetParent(_oBodyRootGO.transform); _oMeshMorphResult.name = "MorphingBody"; //=== DEFINE THE FLEX COLLIDER: Read the collection of verts that will from the Flex collider (responsible to repell master Bodysuit from morph-time body) === _aVertsFlexCollider = CByteArray.GetArray_USHORT("'CBody'", _sBlenderInstancePath_CBodyBase + ".aVertsFlexCollider.Unity_GetBytes()"); FlexObjects_Create(); // Create the Flex objects the first time.They will be destroyed upon going to gametime //=== Create the managing object and related hotspot === _oObj = new CObjectBlender(this, _sBlenderInstancePath_CBodyBase + ".oObjectMeshShapeKeys", _nBodyID); _oObj.Event_PropertyValueChanged += Event_PropertyChangedValue; //_oHotSpot = CHotSpot.CreateHotspot(this, null, "Body Morphing", false, new Vector3(0, 0, 0)); _oCanvas = CUICanvas.Create(_oMeshMorphResult.transform); _oCanvas.transform.position = new Vector3(0.31f, 1.35f, 0.13f); //###WEAK#11: Hardcoded panel placement in code? Base on a node in a template instead?? ###IMPROVE: Autorotate? CUtility.WndPopup_Create(_oCanvas, EWndPopupType.PropertyEditor, new CObject[] { _oObj }, "Body Morphing"); //=== Switch to morphing / configure mode === OnChangeBodyMode(EBodyBaseModes.Configure); // Enter configure mode so we can programmatically apply morphs to customize this body //=== Create bodycloth clothing instance. It will be simulated as the user adjusts morphing sliders so as to set the master cloth to closely match the body's changing shape === _oCloth_BodySuit = CBCloth.Create(this, "MyShirt", "Shirt", "BodySuit", "_ClothSkinnedArea_ShoulderTop"); //###DEV#13 //=== Change some morphing channels === //###TODO#11: Programmatic load & adjustments of sliders from file? //_oObj.PropSet(0, 1); //###IMPROVE#11: Would be of benefit to change properties by string in code? (e.g. not UI?) //_oObj.PropSet(1, 1); //###WEAK#11: Properties appear in non-deterministic order! }