Skip to content

Commit

Permalink
v0.11.90
Browse files Browse the repository at this point in the history
1. InputField 增加回车提交功能(OnEnterSubmit)
2. GetOrAddComponent 支持 Component 对象
  • Loading branch information
liangxiegame committed Apr 5, 2021
1 parent 98fad36 commit db507f8
Show file tree
Hide file tree
Showing 11 changed files with 298 additions and 171 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
/****************************************************************************
* Copyright (c) 2021.4 liangxie
*
* https://qframework.cn
* https://github.com/liangxiegame/QFramework
* https://gitee.com/liangxiegame/QFramework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
****************************************************************************/

using System;
using UnityEngine;

namespace QFramework
{
/// <summary>
/// GameObject's Util/Static This Extension
/// </summary>
public static class GameObjectExtension
{
public static void Example()
{
var gameObject = new GameObject();
var transform = gameObject.transform;
var selfScript = gameObject.AddComponent<MonoBehaviour>();
var boxCollider = gameObject.AddComponent<BoxCollider>();

gameObject.Show(); // gameObject.SetActive(true)
selfScript.Show(); // this.gameObject.SetActive(true)
boxCollider.Show(); // boxCollider.gameObject.SetActive(true)
gameObject.transform.Show(); // transform.gameObject.SetActive(true)

gameObject.Hide(); // gameObject.SetActive(false)
selfScript.Hide(); // this.gameObject.SetActive(false)
boxCollider.Hide(); // boxCollider.gameObject.SetActive(false)
transform.Hide(); // transform.gameObject.SetActive(false)

selfScript.DestroyGameObj();
boxCollider.DestroyGameObj();
transform.DestroyGameObj();

selfScript.DestroyGameObjGracefully();
boxCollider.DestroyGameObjGracefully();
transform.DestroyGameObjGracefully();

selfScript.DestroyGameObjAfterDelay(1.0f);
boxCollider.DestroyGameObjAfterDelay(1.0f);
transform.DestroyGameObjAfterDelay(1.0f);

selfScript.DestroyGameObjAfterDelayGracefully(1.0f);
boxCollider.DestroyGameObjAfterDelayGracefully(1.0f);
transform.DestroyGameObjAfterDelayGracefully(1.0f);

gameObject.Layer(0);
selfScript.Layer(0);
boxCollider.Layer(0);
transform.Layer(0);

gameObject.Layer("Default");
selfScript.Layer("Default");
boxCollider.Layer("Default");
transform.Layer("Default");
}

#region CEGO001 Show

public static GameObject Show(this GameObject selfObj)
{
selfObj.SetActive(true);
return selfObj;
}

public static T Show<T>(this T selfComponent) where T : Component
{
selfComponent.gameObject.Show();
return selfComponent;
}

#endregion

#region CEGO002 Hide

public static GameObject Hide(this GameObject selfObj)
{
selfObj.SetActive(false);
return selfObj;
}

public static T Hide<T>(this T selfComponent) where T : Component
{
selfComponent.gameObject.Hide();
return selfComponent;
}

#endregion

#region CEGO003 DestroyGameObj

public static void DestroyGameObj<T>(this T selfBehaviour) where T : Component
{
selfBehaviour.gameObject.DestroySelf();
}

#endregion

#region CEGO004 DestroyGameObjGracefully

public static void DestroyGameObjGracefully<T>(this T selfBehaviour) where T : Component
{
if (selfBehaviour && selfBehaviour.gameObject)
{
selfBehaviour.gameObject.DestroySelfGracefully();
}
}

#endregion

#region CEGO005 DestroyGameObjGracefully

public static T DestroyGameObjAfterDelay<T>(this T selfBehaviour, float delay) where T : Component
{
selfBehaviour.gameObject.DestroySelfAfterDelay(delay);
return selfBehaviour;
}

public static T DestroyGameObjAfterDelayGracefully<T>(this T selfBehaviour, float delay) where T : Component
{
if (selfBehaviour && selfBehaviour.gameObject)
{
selfBehaviour.gameObject.DestroySelfAfterDelay(delay);
}

return selfBehaviour;
}

#endregion

#region CEGO006 Layer

public static GameObject Layer(this GameObject selfObj, int layer)
{
selfObj.layer = layer;
return selfObj;
}

public static T Layer<T>(this T selfComponent, int layer) where T : Component
{
selfComponent.gameObject.layer = layer;
return selfComponent;
}

public static GameObject Layer(this GameObject selfObj, string layerName)
{
selfObj.layer = LayerMask.NameToLayer(layerName);
return selfObj;
}

public static T Layer<T>(this T selfComponent, string layerName) where T : Component
{
selfComponent.gameObject.layer = LayerMask.NameToLayer(layerName);
return selfComponent;
}

#endregion

#region CEGO007 Component

public static T GetOrAddComponent<T>(this GameObject selfComponent) where T : Component
{
var comp = selfComponent.gameObject.GetComponent<T>();
return comp ? comp : selfComponent.gameObject.AddComponent<T>();
}

public static T GetOrAddComponent<T>(this Component component) where T : Component
{
return component.gameObject.GetOrAddComponent<T>();
}

public static Component GetOrAddComponent(this GameObject selfComponent, Type type)
{
var comp = selfComponent.gameObject.GetComponent(type);
return comp ? comp : selfComponent.gameObject.AddComponent(type);
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1435,173 +1435,6 @@ public static Color HtmlStringToColor(this string htmlString)
public static Color White = Color.white;
}

/// <summary>
/// GameObject's Util/Static This Extension
/// </summary>
public static class GameObjectExtension
{
public static void Example()
{
var gameObject = new GameObject();
var transform = gameObject.transform;
var selfScript = gameObject.AddComponent<MonoBehaviour>();
var boxCollider = gameObject.AddComponent<BoxCollider>();

gameObject.Show(); // gameObject.SetActive(true)
selfScript.Show(); // this.gameObject.SetActive(true)
boxCollider.Show(); // boxCollider.gameObject.SetActive(true)
gameObject.transform.Show(); // transform.gameObject.SetActive(true)

gameObject.Hide(); // gameObject.SetActive(false)
selfScript.Hide(); // this.gameObject.SetActive(false)
boxCollider.Hide(); // boxCollider.gameObject.SetActive(false)
transform.Hide(); // transform.gameObject.SetActive(false)

selfScript.DestroyGameObj();
boxCollider.DestroyGameObj();
transform.DestroyGameObj();

selfScript.DestroyGameObjGracefully();
boxCollider.DestroyGameObjGracefully();
transform.DestroyGameObjGracefully();

selfScript.DestroyGameObjAfterDelay(1.0f);
boxCollider.DestroyGameObjAfterDelay(1.0f);
transform.DestroyGameObjAfterDelay(1.0f);

selfScript.DestroyGameObjAfterDelayGracefully(1.0f);
boxCollider.DestroyGameObjAfterDelayGracefully(1.0f);
transform.DestroyGameObjAfterDelayGracefully(1.0f);

gameObject.Layer(0);
selfScript.Layer(0);
boxCollider.Layer(0);
transform.Layer(0);

gameObject.Layer("Default");
selfScript.Layer("Default");
boxCollider.Layer("Default");
transform.Layer("Default");
}

#region CEGO001 Show

public static GameObject Show(this GameObject selfObj)
{
selfObj.SetActive(true);
return selfObj;
}

public static T Show<T>(this T selfComponent) where T : Component
{
selfComponent.gameObject.Show();
return selfComponent;
}

#endregion

#region CEGO002 Hide

public static GameObject Hide(this GameObject selfObj)
{
selfObj.SetActive(false);
return selfObj;
}

public static T Hide<T>(this T selfComponent) where T : Component
{
selfComponent.gameObject.Hide();
return selfComponent;
}

#endregion

#region CEGO003 DestroyGameObj

public static void DestroyGameObj<T>(this T selfBehaviour) where T : Component
{
selfBehaviour.gameObject.DestroySelf();
}

#endregion

#region CEGO004 DestroyGameObjGracefully

public static void DestroyGameObjGracefully<T>(this T selfBehaviour) where T : Component
{
if (selfBehaviour && selfBehaviour.gameObject)
{
selfBehaviour.gameObject.DestroySelfGracefully();
}
}

#endregion

#region CEGO005 DestroyGameObjGracefully

public static T DestroyGameObjAfterDelay<T>(this T selfBehaviour, float delay) where T : Component
{
selfBehaviour.gameObject.DestroySelfAfterDelay(delay);
return selfBehaviour;
}

public static T DestroyGameObjAfterDelayGracefully<T>(this T selfBehaviour, float delay) where T : Component
{
if (selfBehaviour && selfBehaviour.gameObject)
{
selfBehaviour.gameObject.DestroySelfAfterDelay(delay);
}

return selfBehaviour;
}

#endregion

#region CEGO006 Layer

public static GameObject Layer(this GameObject selfObj, int layer)
{
selfObj.layer = layer;
return selfObj;
}

public static T Layer<T>(this T selfComponent, int layer) where T : Component
{
selfComponent.gameObject.layer = layer;
return selfComponent;
}

public static GameObject Layer(this GameObject selfObj, string layerName)
{
selfObj.layer = LayerMask.NameToLayer(layerName);
return selfObj;
}

public static T Layer<T>(this T selfComponent, string layerName) where T : Component
{
selfComponent.gameObject.layer = LayerMask.NameToLayer(layerName);
return selfComponent;
}

#endregion

#region CEGO007 Component

public static T GetOrAddComponent<T>(this GameObject selfComponent) where T : Component
{
var comp = selfComponent.gameObject.GetComponent<T>();
return comp ? comp : selfComponent.gameObject.AddComponent<T>();
}

public static Component GetOrAddComponent(this GameObject selfComponent, Type type)
{
var comp = selfComponent.gameObject.GetComponent(type);
return comp ? comp : selfComponent.gameObject.AddComponent(type);
}

#endregion
}

public static class GraphicExtension
{
public static void Example()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
<Compile Include="Core\CodeGen\ViewController.cs" />
<Compile Include="Core\CodeGen\Writer\FileCodeWriter.cs" />
<Compile Include="Core\CodeGen\Writer\ICodeWriter.cs" />
<Compile Include="Core\CSharpExtension\GameObjectExtension.cs" />
<Compile Include="Core\CSharpExtension\MaterialExtensions.cs" />
<Compile Include="Core\CSharpExtension\QFramework.CSharpExtension.cs" />
<Compile Include="Core\CSharpExtension\TextureExtensions.cs" />
Expand Down Expand Up @@ -291,6 +292,7 @@
<Compile Include="UIKit\ActionKitSupport\UIKitOpenPanel.cs" />
<Compile Include="UIKit\ActionKitSupport\UIKitSetResolution.cs" />
<Compile Include="UIKit\Deprecated.cs" />
<Compile Include="UIKit\Helper\InputFieldEnterSubmitTrigger.cs" />
<Compile Include="UIKit\PanelInfo.cs" />
<Compile Include="UIKit\PanelSearchKeys.cs" />
<Compile Include="UIKit\UIKit.cs" />
Expand Down
Loading

0 comments on commit db507f8

Please sign in to comment.